Skip to content

Conversation

@jstarks
Copy link

@jstarks jstarks commented Nov 6, 2025

Description

The mcontext_t.__reserved field is documented to contain extra context, such as FP state and the ESR register. This field is 16-byte aligned, so for simplicity expose it as an array of u128 elements (similar to how musl defines it as an array of long doubles in C). This is OK because align_of::<u128>() == 16 on aarch64 all the way back to MSRV (1.63).

The other option is to expose it as [u8; 4096] and to add explicit padding in the right place. I'm open to that approach, too.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

The `mcontext_t.__reserved` field is documented to contain extra
context, such as FP state and the ESR register. This field is 16-byte
aligned, so for simplicity expose it as an array of `u128` elements
(similar to how `musl` defines it as an array of `long double`s in
C).
@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2025

Some changes occurred in the Android module

cc @maurer

@rustbot rustbot added O-android O-gnu O-linux O-musl O-unix S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Nov 6, 2025
@tgross35
Copy link
Contributor

tgross35 commented Nov 6, 2025

Is there official documentation outside of the uapi comment saying what this field contains? The manpage I found says (link):

The mcontext_t type is machine-dependent and opaque.

Given that and the fact that the field is actually named reserved, I am hesitant to expose this. If you actually need these fields and want to opt into whatever sort of instability they have, it would be better to define your own struct and transmute.

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(updating status)

@jstarks
Copy link
Author

jstarks commented Nov 6, 2025

Is there official documentation outside of the uapi comment saying what this field contains? The manpage I found says (link):

The mcontext_t type is machine-dependent and opaque.

Given that and the fact that the field is actually named reserved, I am hesitant to expose this. If you actually need these fields and want to opt into whatever sort of instability they have, it would be better to define your own struct and transmute.

The uapi header is the only documentation I am aware of. But uapi documents interfaces that are stable. I certainly agree that the __reserved name is a red flag--nonetheless, it's a guaranteed stable part of the Linux ABI and by extension the glibc/musl API. I think they're just stuck with the poor choice of name, which hasn't changed since it was introduced in 2012.

If you search around (https://github.com/search?q=__reserved+uc_mcontext&type=code), you can find lots of C/C++ code accessing this field as documented in the uapi definitions. It should be possible to port such code to Rust without manually defining types.

I suppose to really complete that promise, libc should also define _aarch64_ctx and some of the magic numbers and other types from uapi. I'd be happy to do that as well, if you think it's a good idea. musl and Android define these types in their headers but glibc does not--I would guess glibc users probably include the uapi header directly to get these definitions, but I'm not sure.

@jstarks
Copy link
Author

jstarks commented Nov 6, 2025

(I'll find another way to handle the u128 issue once you're convinced that this is otherwise a righteous change.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-android O-gnu O-linux O-musl O-unix S-waiting-on-author stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants