Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add sys/ucontext.h signatures for linux aarch64 glibc #3001

Merged
merged 1 commit into from Nov 20, 2022

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Nov 16, 2022

getcontext, setcontext, makecontext, swapcontext

From <sys/ucontext.h>. The specification for these was removed from POSIX.1-2008 in favor of POSIX threads, but glibc continues to ship an implementation for aarch64 just as it does for x86_64.

Libc crate's existing x86_64 binding with the same signatures added in this PR:

pub fn getcontext(ucp: *mut ucontext_t) -> ::c_int;
pub fn setcontext(ucp: *const ucontext_t) -> ::c_int;
pub fn makecontext(ucp: *mut ucontext_t, func: extern "C" fn(), argc: ::c_int, ...);
pub fn swapcontext(uocp: *mut ucontext_t, ucp: *const ucontext_t) -> ::c_int;

Glibc implementation:


iopl, ioperm

From <sys/io.h>. These are functions for accessing x86 I/O ports. ARM has no such I/O ports in the architecture. Linux's man 2 for both functions contains: "This call is mostly for the i386 architecture. On many other architectures it does not exist or will always return an error." Glibc ships one of these "always return an error" implementation of both functions for aarch64.

Matching signatures from x86_64:

pub fn iopl(level: ::c_int) -> ::c_int;
pub fn ioperm(from: ::c_ulong, num: ::c_ulong, turn_on: ::c_int) -> ::c_int;

Glibc implementation:

The implementation has unsigned int for the argument of iopl but I've used int in the PR to match the Linux docs, which seems more authoritative. Unclear why glibc diverges from this but it doesn't make a difference in the ABI.

@rust-highfive
Copy link

r? @JohnTitor

(rust-highfive has picked a reviewer for you, use r? to override)

Copy link
Member

@thomcc thomcc left a comment

Choose a reason for hiding this comment

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

Seems fine. Matches declaration in headers, assuming our struct ucontext is right (which this PR doesn't add).

The iopl/ioperm stuff is a bit odd to have but I suppose this allows for following a consistent error handling path rather than cfging it out.

@thomcc
Copy link
Member

thomcc commented Nov 16, 2022

The implementation has unsigned int for the argument of iopl but I've used int in the PR to match the Linux docs, which seems more authoritative

This also matches the way we expose iopl on x86, which is somewhat important.

@JohnTitor
Copy link
Member

Thanks! @bors r+

@bors
Copy link
Contributor

bors commented Nov 16, 2022

📌 Commit 5d3b73d has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 16, 2022

⌛ Testing commit 5d3b73d with merge 5848e85...

bors added a commit that referenced this pull request Nov 16, 2022
Add sys/ucontext.h and sys/io.h signatures for linux aarch64 glibc

### `getcontext`, `setcontext`, `makecontext`, `swapcontext`

From \<sys/ucontext.h\>. The specification for these was removed from POSIX.1-2008 in favor of POSIX threads, but glibc continues to ship an implementation for aarch64 just as it does for x86_64.

Libc crate's existing x86_64 binding with the same signatures added in this PR:

https://github.com/rust-lang/libc/blob/bbf929d2c8355fa19384b3551c5874c866be465f/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs#L810-L813

Glibc implementation:

- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/getcontext.S
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/setcontext.S
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/makecontext.c
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/swapcontext.S

<br>

### `iopl`, `ioperm`

From \<sys/io.h\>. These are functions for accessing x86 I/O ports. ARM has no such I/O ports in the architecture. Linux's `man 2` for both functions contains: _"This call is mostly for the i386 architecture.  On many other architectures it does not exist or will always return an error."_ Glibc ships one of these "always return an error" implementation of both functions for aarch64.

Matching signatures from x86_64:

https://github.com/rust-lang/libc/blob/bbf929d2c8355fa19384b3551c5874c866be465f/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs#L814-L815

Glibc implementation:

- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/arm/ioperm.c

The implementation has `unsigned int` for the argument of `iopl` but I've used int in the PR to match the Linux docs, which seems more authoritative. Unclear why glibc diverges from this but it doesn't make a difference in the ABI.
@bors
Copy link
Contributor

bors commented Nov 16, 2022

💔 Test failed - checks-actions

@dtolnay
Copy link
Member Author

dtolnay commented Nov 18, 2022

/checkout/target/aarch64-unknown-linux-gnu/debug/build/libc-test-5a973a03a651b470/out/main.c: In function '__test_fn_iopl':
/checkout/target/aarch64-unknown-linux-gnu/debug/build/libc-test-5a973a03a651b470/out/main.c:53524:24: error: 'iopl' undeclared (first use in this function)
53524 |                 return iopl;
      |                        ^~~~
/checkout/target/aarch64-unknown-linux-gnu/debug/build/libc-test-5a973a03a651b470/out/main.c:53524:24: note: each undeclared identifier is reported only once for each function it appears in
/checkout/target/aarch64-unknown-linux-gnu/debug/build/libc-test-5a973a03a651b470/out/main.c: In function '__test_fn_ioperm':
/checkout/target/aarch64-unknown-linux-gnu/debug/build/libc-test-5a973a03a651b470/out/main.c:53529:24: error: 'ioperm' undeclared (first use in this function); did you mean 'ipc_perm'?
53529 |                 return ioperm;
      |                        ^~~~~~
      |                        ipc_perm

I did a bit of digging in glibc, it turns out glibc ships definitions of iopl and ioperm on aarch64 but does not ship a declaration of them in any header. 🤯 I've removed those two from the PR.

@dtolnay dtolnay marked this pull request as ready for review November 18, 2022 07:42
@dtolnay dtolnay changed the title Add sys/ucontext.h and sys/io.h signatures for linux aarch64 glibc Add sys/ucontext.h signatures for linux aarch64 glibc Nov 18, 2022
@JohnTitor
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 19, 2022

📌 Commit 5aec927 has been approved by JohnTitor

It is now in the queue for this repository.

bors added a commit that referenced this pull request Nov 19, 2022
Add sys/ucontext.h signatures for linux aarch64 glibc

### `getcontext`, `setcontext`, `makecontext`, `swapcontext`

From \<sys/ucontext.h\>. The specification for these was removed from POSIX.1-2008 in favor of POSIX threads, but glibc continues to ship an implementation for aarch64 just as it does for x86_64.

Libc crate's existing x86_64 binding with the same signatures added in this PR:

https://github.com/rust-lang/libc/blob/bbf929d2c8355fa19384b3551c5874c866be465f/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs#L810-L813

Glibc implementation:

- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/getcontext.S
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/setcontext.S
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/makecontext.c
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/swapcontext.S

<br>

### ~~`iopl`, `ioperm`~~

~~From \<sys/io.h\>. These are functions for accessing x86 I/O ports. ARM has no such I/O ports in the architecture. Linux's `man 2` for both functions contains: _"This call is mostly for the i386 architecture.  On many other architectures it does not exist or will always return an error."_ Glibc ships one of these "always return an error" implementation of both functions for aarch64.~~

~~Matching signatures from x86_64:~~

https://github.com/rust-lang/libc/blob/bbf929d2c8355fa19384b3551c5874c866be465f/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs#L814-L815

~~Glibc implementation:~~

- ~~https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/arm/ioperm.c~~

~~The implementation has `unsigned int` for the argument of `iopl` but I've used int in the PR to match the Linux docs, which seems more authoritative. Unclear why glibc diverges from this but it doesn't make a difference in the ABI.~~
@bors
Copy link
Contributor

bors commented Nov 19, 2022

⌛ Testing commit 5aec927 with merge 3a37639...

@bors
Copy link
Contributor

bors commented Nov 19, 2022

💔 Test failed - checks-actions

@dtolnay
Copy link
Member Author

dtolnay commented Nov 19, 2022

Can't tell what failed. 😿

@thomcc
Copy link
Member

thomcc commented Nov 19, 2022

https://github.com/rust-lang/libc/actions/runs/3502179666/jobs/5866446110#step:5:2455 is supposed to print ^PASSED .* tests or ^test result: ok to stdout. https://github.com/rust-lang/libc/blob/master/ci/runtest-android.rs#L41-L47. I'm not sure why this is happening though.

It doesn't look like it's caused by this PR, but it also doesn't seem to be failing in other PRs.

@thomcc
Copy link
Member

thomcc commented Nov 19, 2022

Should be fixed by #3005

@JohnTitor
Copy link
Member

Sorry for the inconvenience! @bors retry

@bors
Copy link
Contributor

bors commented Nov 19, 2022

⌛ Testing commit 5aec927 with merge 0f31121...

bors added a commit that referenced this pull request Nov 19, 2022
Add sys/ucontext.h signatures for linux aarch64 glibc

### `getcontext`, `setcontext`, `makecontext`, `swapcontext`

From \<sys/ucontext.h\>. The specification for these was removed from POSIX.1-2008 in favor of POSIX threads, but glibc continues to ship an implementation for aarch64 just as it does for x86_64.

Libc crate's existing x86_64 binding with the same signatures added in this PR:

https://github.com/rust-lang/libc/blob/bbf929d2c8355fa19384b3551c5874c866be465f/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs#L810-L813

Glibc implementation:

- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/getcontext.S
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/setcontext.S
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/makecontext.c
- https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/aarch64/swapcontext.S

<br>

### ~~`iopl`, `ioperm`~~

~~From \<sys/io.h\>. These are functions for accessing x86 I/O ports. ARM has no such I/O ports in the architecture. Linux's `man 2` for both functions contains: _"This call is mostly for the i386 architecture.  On many other architectures it does not exist or will always return an error."_ Glibc ships one of these "always return an error" implementation of both functions for aarch64.~~

~~Matching signatures from x86_64:~~

https://github.com/rust-lang/libc/blob/bbf929d2c8355fa19384b3551c5874c866be465f/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs#L814-L815

~~Glibc implementation:~~

- ~~https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/arm/ioperm.c~~

~~The implementation has `unsigned int` for the argument of `iopl` but I've used int in the PR to match the Linux docs, which seems more authoritative. Unclear why glibc diverges from this but it doesn't make a difference in the ABI.~~
@bors
Copy link
Contributor

bors commented Nov 19, 2022

💔 Test failed - checks-actions

@JohnTitor
Copy link
Member

CI for 1.13 fails because it (ucontext_t precisely) needs libc_align. Could you declare them on align.rs? (We could remove this cfg after setting MSRV to a more recent version but for now let's follow the current policy.)

@dtolnay
Copy link
Member Author

dtolnay commented Nov 20, 2022

👍 Moved to align.rs so that they're properly conditional on libc_align.

@JohnTitor
Copy link
Member

Thanks! @bors r+

@bors
Copy link
Contributor

bors commented Nov 20, 2022

📌 Commit fd32da6 has been approved by JohnTitor

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Nov 20, 2022

⌛ Testing commit fd32da6 with merge 25aacfd...

@bors
Copy link
Contributor

bors commented Nov 20, 2022

☀️ Test successful - checks-actions, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13, checks-cirrus-freebsd-14
Approved by: JohnTitor
Pushing 25aacfd to master...

@bors bors merged commit 25aacfd into rust-lang:master Nov 20, 2022
@dtolnay dtolnay deleted the aarch64 branch November 20, 2022 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants