Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

sys/socket.h: fix some CMSG_ macros not aligning #728

Merged
merged 1 commit into from
Aug 23, 2022

Conversation

ArsenArsen
Copy link
Member

Excerpt from sys/socket.h:
	// Control message format:
	// The offsets marked with ^ are aligned to alignof(size_t).
	//
	// |---HEADER---|---DATA---|---PADDING---|---HEADER---|...
	// ^            ^                        ^
	// |---------CMSG_LEN------|
	// |---------------CMSG_SPACE------------|

By this definition, control message header and data should both be
aligned to (at least) alignof(size_t), however, previously, the
implementation of these macros in options/posix relied on
sizeof(struct cmsghdr) % sizeof(size_t) being zero. After the recent
change to socklen_t, this no longer held true, and DATA would be aligned
to a 12 byte boundary (on x86_64), and hence would move all data back a
bit. Code that relied on CMSG_ALIGN() to compute sizes of cmsg data
(notably, sysdeps/managarm) hence broke as a result.

The change in this commit fixes that misalignment.

It would be desirable for this change to land into 3.0.0-rc2

Excerpt from sys/socket.h:
	// Control message format:
	// The offsets marked with ^ are aligned to alignof(size_t).
	//
	// |---HEADER---|---DATA---|---PADDING---|---HEADER---|...
	// ^            ^                        ^
	// |---------CMSG_LEN------|
	// |---------------CMSG_SPACE------------|

By this definition, control message header and data should both be
aligned to (at least) alignof(size_t), however, previously, the
implementation of these macros in options/posix relied on
sizeof(struct cmsghdr) % sizeof(size_t) being zero. After the recent
change to socklen_t, this no longer held true, and DATA would be aligned
to a 12 byte boundary (on x86_64), and hence would move all data back a
bit. Code that relied on CMSG_ALIGN() to compute sizes of cmsg data
(notably, sysdeps/managarm) hence broke as a result.

The change in this commit fixes that misalignment.
@ArsenArsen ArsenArsen changed the base branch from abi-break to master August 23, 2022 20:37
@ArsenArsen ArsenArsen merged commit 64420e8 into managarm:master Aug 23, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant