Skip to content

Commit

Permalink
Auto merge of #3001 - dtolnay-contrib:aarch64, r=JohnTitor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Nov 16, 2022
2 parents bbf929d + 5d3b73d commit 5848e85
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/unix/linux_like/linux/gnu/b64/aarch64/mod.rs
Expand Up @@ -903,6 +903,12 @@ extern "C" {
newp: *mut ::c_void,
newlen: ::size_t,
) -> ::c_int;
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;
pub fn iopl(level: ::c_int) -> ::c_int;
pub fn ioperm(from: ::c_ulong, num: ::c_ulong, turn_on: ::c_int) -> ::c_int;
}

cfg_if! {
Expand Down

0 comments on commit 5848e85

Please sign in to comment.