Skip to content

Commit 1188eb9

Browse files
zx2c4andybons
authored andcommitted
[release-branch.go1.10] runtime: use Android O friendly syscalls on 64-bit machines
Android O disallows open on 64-bit, so let's use openat with AT_FDCWD to achieve the same behavior. Android O disallows epoll_wait on 64-bit, so let's use epoll_pwait with the last argument as NULL to achieve the same behavior. See here: https://android.googlesource.com/platform/bionic/+/master/libc/seccomp/arm64_app_policy.cpp https://android.googlesource.com/platform/bionic/+/master/libc/seccomp/mips64_app_policy.cpp https://android.googlesource.com/platform/bionic/+/master/libc/seccomp/x86_64_app_policy.cpp Fixes #23750 Change-Id: If8d5a663357471e5d2c1f516151344a9d05b188a Reviewed-on: https://go-review.googlesource.com/92895 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Austin Clements <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-on: https://go-review.googlesource.com/102792 Run-TryBot: Andrew Bonventre <[email protected]>
1 parent ee97231 commit 1188eb9

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/runtime/sys_linux_amd64.s

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#define SYS_read 0
1414
#define SYS_write 1
15-
#define SYS_open 2
1615
#define SYS_close 3
1716
#define SYS_mmap 9
1817
#define SYS_munmap 11
@@ -41,9 +40,10 @@
4140
#define SYS_sched_getaffinity 204
4241
#define SYS_epoll_create 213
4342
#define SYS_exit_group 231
44-
#define SYS_epoll_wait 232
4543
#define SYS_epoll_ctl 233
44+
#define SYS_openat 257
4645
#define SYS_pselect6 270
46+
#define SYS_epoll_pwait 281
4747
#define SYS_epoll_create1 291
4848

4949
TEXT runtime·exit(SB),NOSPLIT,$0-4
@@ -65,10 +65,12 @@ TEXT runtime·exitThread(SB),NOSPLIT,$0-8
6565
JMP 0(PC)
6666

6767
TEXT runtime·open(SB),NOSPLIT,$0-20
68-
MOVQ name+0(FP), DI
69-
MOVL mode+8(FP), SI
70-
MOVL perm+12(FP), DX
71-
MOVL $SYS_open, AX
68+
// This uses openat instead of open, because Android O blocks open.
69+
MOVL $-100, DI // AT_FDCWD, so this acts like open
70+
MOVQ name+0(FP), SI
71+
MOVL mode+8(FP), DX
72+
MOVL perm+12(FP), R10
73+
MOVL $SYS_openat, AX
7274
SYSCALL
7375
CMPQ AX, $0xfffffffffffff001
7476
JLS 2(PC)
@@ -655,11 +657,13 @@ TEXT runtime·epollctl(SB),NOSPLIT,$0
655657

656658
// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
657659
TEXT runtime·epollwait(SB),NOSPLIT,$0
660+
// This uses pwait instead of wait, because Android O blocks wait.
658661
MOVL epfd+0(FP), DI
659662
MOVQ ev+8(FP), SI
660663
MOVL nev+16(FP), DX
661664
MOVL timeout+20(FP), R10
662-
MOVL $SYS_epoll_wait, AX
665+
MOVQ $0, R8
666+
MOVL $SYS_epoll_pwait, AX
663667
SYSCALL
664668
MOVL AX, ret+24(FP)
665669
RET

src/runtime/sys_linux_mips64x.s

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define SYS_exit 5058
1717
#define SYS_read 5000
1818
#define SYS_write 5001
19-
#define SYS_open 5002
19+
#define SYS_openat 5247
2020
#define SYS_close 5003
2121
#define SYS_getpid 5038
2222
#define SYS_kill 5060
@@ -42,7 +42,7 @@
4242
#define SYS_exit_group 5205
4343
#define SYS_epoll_create 5207
4444
#define SYS_epoll_ctl 5208
45-
#define SYS_epoll_wait 5209
45+
#define SYS_epoll_pwait 5272
4646
#define SYS_clock_gettime 5222
4747
#define SYS_epoll_create1 5285
4848
#define SYS_brk 5012
@@ -66,11 +66,13 @@ TEXT runtime·exitThread(SB),NOSPLIT,$-8-8
6666
SYSCALL
6767
JMP 0(PC)
6868

69-
TEXT runtime·open(SB),NOSPLIT,$-8-20
70-
MOVV name+0(FP), R4
71-
MOVW mode+8(FP), R5
72-
MOVW perm+12(FP), R6
73-
MOVV $SYS_open, R2
69+
TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20
70+
// This uses openat instead of open, because Android O blocks open.
71+
MOVW $-100, R4 // AT_FDCWD, so this acts like open
72+
MOVV name+0(FP), R5
73+
MOVW mode+8(FP), R6
74+
MOVW perm+12(FP), R7
75+
MOVV $SYS_openat, R2
7476
SYSCALL
7577
BEQ R7, 2(PC)
7678
MOVW $-1, R2
@@ -422,12 +424,14 @@ TEXT runtime·epollctl(SB),NOSPLIT,$-8
422424
RET
423425

424426
// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
425-
TEXT runtime·epollwait(SB),NOSPLIT,$-8
427+
TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
428+
// This uses pwait instead of wait, because Android O blocks wait.
426429
MOVW epfd+0(FP), R4
427430
MOVV ev+8(FP), R5
428431
MOVW nev+16(FP), R6
429432
MOVW timeout+20(FP), R7
430-
MOVV $SYS_epoll_wait, R2
433+
MOVV $0, R8
434+
MOVV $SYS_epoll_pwait, R2
431435
SYSCALL
432436
MOVW R2, ret+24(FP)
433437
RET

0 commit comments

Comments
 (0)