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

Implement accept4 on x86 android with socketcall syscall. #2079

Closed
wants to merge 2 commits into from

Conversation

de-vri-es
Copy link
Contributor

Linux x86 kernels before 4.3 only support the socketcall syscall rather than individual syscalls for socket operations. Since libc does a raw syscall for accept4 on Android, it doesn't work on x86 systems.

This PR instead implements accept4 for x86 android using socketcall. The value for SYS_ACCEPT4 (in contrast to SYS_accept4 👀) is taken from the linux/net.h header.

Also note that the socketcall syscall takes all arguments as array of long ints. I've double checked with glibc to check how they pass arguments, since the Linux man page only says this: "args points to a block containing the actual arguments" and "only standard library implementors and kernel hackers need to know about socketcall()".

This should fix rust-lang/rust#82400

@rust-highfive
Copy link

r? @JohnTitor

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

@joshtriplett
Copy link
Member

joshtriplett commented Feb 24, 2021

Looks good to me.

@bors r+

@joshtriplett
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Feb 25, 2021

📌 Commit 64614cf has been approved by joshtriplett

@bors
Copy link
Contributor

bors commented Feb 25, 2021

⌛ Testing commit 64614cf with merge 71663bc...

bors added a commit that referenced this pull request Feb 25, 2021
Implement accept4 on x86 android with `socketcall` syscall.

Linux x86 kernels before 4.3 only support the `socketcall` syscall rather than individual syscalls for socket operations. Since `libc` does a raw syscall for `accept4` on Android, it doesn't work on x86 systems.

This PR instead implements `accept4` for x86 android using `socketcall`. The value for `SYS_ACCEPT4` (in contrast to `SYS_accept4` 👀) is taken from the `linux/net.h` header.

Also note that the `socketcall` syscall takes all arguments as array of long ints. I've double checked with `glibc` to check how they pass arguments, since the Linux man page only says this: "args points to a block containing the actual arguments" and "only standard library implementors and kernel hackers need to know about socketcall()".

This should fix rust-lang/rust#82400
@bors
Copy link
Contributor

bors commented Feb 25, 2021

💔 Test failed - checks-actions

@de-vri-es
Copy link
Contributor Author

de-vri-es commented Feb 26, 2021

Pushed a fix, passes a local build for i686-linux-android (can't run the tests though).

@JohnTitor
Copy link
Member

@bors r=joshtriplett

@bors
Copy link
Contributor

bors commented Feb 26, 2021

📌 Commit df5f0de has been approved by joshtriplett

bors added a commit that referenced this pull request Feb 26, 2021
Implement accept4 on x86 android with `socketcall` syscall.

Linux x86 kernels before 4.3 only support the `socketcall` syscall rather than individual syscalls for socket operations. Since `libc` does a raw syscall for `accept4` on Android, it doesn't work on x86 systems.

This PR instead implements `accept4` for x86 android using `socketcall`. The value for `SYS_ACCEPT4` (in contrast to `SYS_accept4` 👀) is taken from the `linux/net.h` header.

Also note that the `socketcall` syscall takes all arguments as array of long ints. I've double checked with `glibc` to check how they pass arguments, since the Linux man page only says this: "args points to a block containing the actual arguments" and "only standard library implementors and kernel hackers need to know about socketcall()".

This should fix rust-lang/rust#82400
@bors
Copy link
Contributor

bors commented Feb 26, 2021

⌛ Testing commit df5f0de with merge ffbdaaa...

@bors
Copy link
Contributor

bors commented Feb 26, 2021

💔 Test failed - checks-actions

@JohnTitor
Copy link
Member

Failure:

   cargo:warning=/checkout/target/i686-linux-android/debug/build/libc-test-0ad756840b253b95/out/main.c:34804:24: error: use of undeclared identifier 'socketcall'; did you mean 'socketpair'?
  cargo:warning=                return socketcall;
  cargo:warning=                       ^~~~~~~~~~
  cargo:warning=                       socketpair
  cargo:warning=/android/ndk-i686/bin/../sysroot/usr/include/sys/socket.h:329:18: note: 'socketpair' declared here
  cargo:warning=__socketcall int socketpair(int __af, int __type, int __protocol, int __fds[2]);
  cargo:warning=                 ^
  cargo:warning=/checkout/target/i686-linux-android/debug/build/libc-test-0ad756840b253b95/out/main.c:34804:24: error: incompatible pointer types returning 'int (int, int, int, int *) __attribute__((cdecl))' from a function with result type 'int (*)(int, long *)' [-Werror,-Wincompatible-pointer-types]
  cargo:warning=                return socketcall;
  cargo:warning=                       ^~~~~~~~~~
  cargo:warning=2 errors generated.
  exit code: 1

  --- stderr
  rust version: 1.52.0-nightly

We should tweak the test.

@JohnTitor
Copy link
Member

Thanks, let's try again :)

@bors r=joshtriplett,JohnTitor

@bors
Copy link
Contributor

bors commented Feb 27, 2021

📌 Commit 446f7a7 has been approved by joshtriplett,JohnTitor

@bors
Copy link
Contributor

bors commented Feb 27, 2021

⌛ Testing commit 446f7a7 with merge 843db55...

bors added a commit that referenced this pull request Feb 27, 2021
…ohnTitor

Implement accept4 on x86 android with `socketcall` syscall.

Linux x86 kernels before 4.3 only support the `socketcall` syscall rather than individual syscalls for socket operations. Since `libc` does a raw syscall for `accept4` on Android, it doesn't work on x86 systems.

This PR instead implements `accept4` for x86 android using `socketcall`. The value for `SYS_ACCEPT4` (in contrast to `SYS_accept4` 👀) is taken from the `linux/net.h` header.

Also note that the `socketcall` syscall takes all arguments as array of long ints. I've double checked with `glibc` to check how they pass arguments, since the Linux man page only says this: "args points to a block containing the actual arguments" and "only standard library implementors and kernel hackers need to know about socketcall()".

This should fix rust-lang/rust#82400
@bors
Copy link
Contributor

bors commented Feb 27, 2021

💔 Test failed - checks-actions

Co-authored-by: Yuki Okushi <huyuumi.dev@gmail.com>
@JohnTitor
Copy link
Member

@bors r=joshtriplett,JohnTitor

@bors
Copy link
Contributor

bors commented Feb 27, 2021

📌 Commit 629b518 has been approved by joshtriplett,JohnTitor

bors added a commit that referenced this pull request Feb 27, 2021
…ohnTitor

Implement accept4 on x86 android with `socketcall` syscall.

Linux x86 kernels before 4.3 only support the `socketcall` syscall rather than individual syscalls for socket operations. Since `libc` does a raw syscall for `accept4` on Android, it doesn't work on x86 systems.

This PR instead implements `accept4` for x86 android using `socketcall`. The value for `SYS_ACCEPT4` (in contrast to `SYS_accept4` 👀) is taken from the `linux/net.h` header.

Also note that the `socketcall` syscall takes all arguments as array of long ints. I've double checked with `glibc` to check how they pass arguments, since the Linux man page only says this: "args points to a block containing the actual arguments" and "only standard library implementors and kernel hackers need to know about socketcall()".

This should fix rust-lang/rust#82400
@bors
Copy link
Contributor

bors commented Feb 27, 2021

⌛ Testing commit 629b518 with merge add9726...

@bors
Copy link
Contributor

bors commented Feb 27, 2021

☀️ Test successful - checks-actions, checks-cirrus-freebsd-11, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13
Approved by: joshtriplett,JohnTitor
Pushing add9726 to master...

@JohnTitor
Copy link
Member

This is merged on master now but bors doesn't close it, manually closing.

@JohnTitor JohnTitor closed this Feb 27, 2021
@de-vri-es
Copy link
Contributor Author

Awesome, thanks for the reviews! ❤️

@de-vri-es de-vri-es deleted the android-x86-accept4 branch March 1, 2021 21:50
asomers added a commit to asomers/nix that referenced this pull request Mar 5, 2021
libc removed it in version 0.2.87.

rust-lang/libc#2079
bors added a commit that referenced this pull request Mar 5, 2021
Re-add accept4 for Android on 32 bit ARM.

`accept4` was accidentally removed from 32 bit Android targets except for x86 in #2079. This PR adds it back using the same definition as other non-x86 platforms.
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.

Accepting Incoming TCP Connections fails on Android
7 participants