What do you think about doing something like https://gitlab.winehq.org/rbernon/wine/-/commit/f264bf99b135f72496f291dcfcff..., to statically assert that the SHM is only written within SHARED_WRITE_BEGIN / SHARED_WRITE_END, and make sure the passed sequence member matches?
I'm also considering doing the same on the client side, to better match SERVER_START_REQ / SERVER_END_REQ pattern, and avoid having to pass the sequence member to SHARED_READ_END (and the potential typos), although it's not as interesting there.