Permalink
Browse files

runtime: add symbols for Linux syscall numbers on 386/amd64

Matches other architectures by using names for syscalls instead of
numbers directly.

Fixes #20499.

Change-Id: I63d606b0b1fe6fb517fd994a7542a3f38d80dd54
Reviewed-on: https://go-review.googlesource.com/44213
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information...
cjb authored and ianlancetaylor committed May 25, 2017
1 parent 4641d78 commit 4d269ad1754afa177a590b0dfaff48d8adce2619
Showing with 149 additions and 77 deletions.
  1. +75 −39 src/runtime/sys_linux_386.s
  2. +74 −38 src/runtime/sys_linux_amd64.s
View
@@ -24,22 +24,58 @@
//#define INVOKE_SYSCALL CALL 0x10(GS) // non-portable
#define INVOKE_SYSCALL INT $0x80
#define SYS_exit 1
#define SYS_read 3
#define SYS_write 4
#define SYS_open 5
#define SYS_close 6
#define SYS_getpid 20
#define SYS_access 33
#define SYS_kill 37
#define SYS_brk 45
#define SYS_fcntl 55
#define SYS_munmap 91
#define SYS_socketcall 102
#define SYS_setittimer 104
#define SYS_clone 120
#define SYS_sched_yield 158
#define SYS_rt_sigreturn 173
#define SYS_rt_sigaction 174
#define SYS_rt_sigprocmask 175
#define SYS_sigaltstack 186
#define SYS_ugetrlimit 191
#define SYS_mmap2 192
#define SYS_mincore 218
#define SYS_madvise 219
#define SYS_gettid 224
#define SYS_tkill 238
#define SYS_futex 240
#define SYS_sched_getaffinity 242
#define SYS_set_thread_area 243
#define SYS_exit_group 252
#define SYS_epoll_create 254
#define SYS_epoll_ctl 255
#define SYS_epoll_wait 256
#define SYS_clock_gettime 265
#define SYS_pselect6 308
#define SYS_epoll_create1 329
TEXT runtime·exit(SB),NOSPLIT,$0
MOVL $252, AX // syscall number
MOVL $SYS_exit_group, AX
MOVL code+0(FP), BX
INVOKE_SYSCALL
INT $3 // not reached
RET
TEXT runtime·exit1(SB),NOSPLIT,$0
MOVL $1, AX // exit - exit the current os thread
MOVL $SYS_exit, AX
MOVL code+0(FP), BX
INVOKE_SYSCALL
INT $3 // not reached
RET
TEXT runtime·open(SB),NOSPLIT,$0
MOVL $5, AX // syscall - open
MOVL $SYS_open, AX
MOVL name+0(FP), BX
MOVL mode+4(FP), CX
MOVL perm+8(FP), DX
@@ -51,7 +87,7 @@ TEXT runtime·open(SB),NOSPLIT,$0
RET
TEXT runtime·closefd(SB),NOSPLIT,$0
MOVL $6, AX // syscall - close
MOVL $SYS_close, AX
MOVL fd+0(FP), BX
INVOKE_SYSCALL
CMPL AX, $0xfffff001
@@ -61,7 +97,7 @@ TEXT runtime·closefd(SB),NOSPLIT,$0
RET
TEXT runtime·write(SB),NOSPLIT,$0
MOVL $4, AX // syscall - write
MOVL $SYS_write, AX
MOVL fd+0(FP), BX
MOVL p+4(FP), CX
MOVL n+8(FP), DX
@@ -73,7 +109,7 @@ TEXT runtime·write(SB),NOSPLIT,$0
RET
TEXT runtime·read(SB),NOSPLIT,$0
MOVL $3, AX // syscall - read
MOVL $SYS_read, AX
MOVL fd+0(FP), BX
MOVL p+4(FP), CX
MOVL n+8(FP), DX
@@ -85,7 +121,7 @@ TEXT runtime·read(SB),NOSPLIT,$0
RET
TEXT runtime·getrlimit(SB),NOSPLIT,$0
MOVL $191, AX // syscall - ugetrlimit
MOVL $SYS_ugetrlimit, AX
MOVL kind+0(FP), BX
MOVL limit+4(FP), CX
INVOKE_SYSCALL
@@ -103,7 +139,7 @@ TEXT runtime·usleep(SB),NOSPLIT,$8
MOVL AX, 4(SP)
// pselect6(0, 0, 0, 0, &ts, 0)
MOVL $308, AX
MOVL $SYS_pselect6, AX
MOVL $0, BX
MOVL $0, CX
MOVL $0, DX
@@ -114,39 +150,39 @@ TEXT runtime·usleep(SB),NOSPLIT,$8
RET
TEXT runtime·gettid(SB),NOSPLIT,$0-4
MOVL $224, AX // syscall - gettid
MOVL $SYS_gettid, AX
INVOKE_SYSCALL
MOVL AX, ret+0(FP)
RET
TEXT runtime·raise(SB),NOSPLIT,$12
MOVL $224, AX // syscall - gettid
MOVL $SYS_gettid, AX
INVOKE_SYSCALL
MOVL AX, BX // arg 1 tid
MOVL sig+0(FP), CX // arg 2 signal
MOVL $238, AX // syscall - tkill
MOVL $SYS_tkill, AX
INVOKE_SYSCALL
RET
TEXT runtime·raiseproc(SB),NOSPLIT,$12
MOVL $20, AX // syscall - getpid
MOVL $SYS_getpid, AX
INVOKE_SYSCALL
MOVL AX, BX // arg 1 pid
MOVL sig+0(FP), CX // arg 2 signal
MOVL $37, AX // syscall - kill
MOVL $SYS_kill, AX
INVOKE_SYSCALL
RET
TEXT runtime·setitimer(SB),NOSPLIT,$0-12
MOVL $104, AX // syscall - setitimer
MOVL $SYS_setittimer, AX
MOVL mode+0(FP), BX
MOVL new+4(FP), CX
MOVL old+8(FP), DX
INVOKE_SYSCALL
RET
TEXT runtime·mincore(SB),NOSPLIT,$0-16
MOVL $218, AX // syscall - mincore
MOVL $SYS_mincore, AX
MOVL addr+0(FP), BX
MOVL n+4(FP), CX
MOVL dst+8(FP), DX
@@ -156,7 +192,7 @@ TEXT runtime·mincore(SB),NOSPLIT,$0-16
// func walltime() (sec int64, nsec int32)
TEXT runtime·walltime(SB), NOSPLIT, $32
MOVL $265, AX // syscall - clock_gettime
MOVL $SYS_clock_gettime, AX
MOVL $0, BX // CLOCK_REALTIME
LEAL 8(SP), CX
MOVL $0, DX
@@ -173,7 +209,7 @@ TEXT runtime·walltime(SB), NOSPLIT, $32
// int64 nanotime(void) so really
// void nanotime(int64 *nsec)
TEXT runtime·nanotime(SB), NOSPLIT, $32
MOVL $265, AX // syscall - clock_gettime
MOVL $SYS_clock_gettime, AX
MOVL $1, BX // CLOCK_MONOTONIC
LEAL 8(SP), CX
MOVL $0, DX
@@ -193,7 +229,7 @@ TEXT runtime·nanotime(SB), NOSPLIT, $32
RET
TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0
MOVL $175, AX // syscall entry
MOVL $SYS_rt_sigprocmask, AX
MOVL how+0(FP), BX
MOVL new+4(FP), CX
MOVL old+8(FP), DX
@@ -205,7 +241,7 @@ TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0
RET
TEXT runtime·rt_sigaction(SB),NOSPLIT,$0
MOVL $174, AX // syscall - rt_sigaction
MOVL $SYS_rt_sigaction, AX
MOVL sig+0(FP), BX
MOVL new+4(FP), CX
MOVL old+8(FP), DX
@@ -258,15 +294,15 @@ TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
JMP runtime·sigtramp(SB)
TEXT runtime·sigreturn(SB),NOSPLIT,$0
MOVL $173, AX // rt_sigreturn
MOVL $SYS_rt_sigreturn, AX
// Sigreturn expects same SP as signal handler,
// so cannot CALL 0x10(GS) here.
INT $0x80
INT $3 // not reached
RET
TEXT runtime·mmap(SB),NOSPLIT,$0
MOVL $192, AX // mmap2
MOVL $SYS_mmap2, AX
MOVL addr+0(FP), BX
MOVL n+4(FP), CX
MOVL prot+8(FP), DX
@@ -283,7 +319,7 @@ TEXT runtime·mmap(SB),NOSPLIT,$0
RET
TEXT runtime·munmap(SB),NOSPLIT,$0
MOVL $91, AX // munmap
MOVL $SYS_munmap, AX
MOVL addr+0(FP), BX
MOVL n+4(FP), CX
INVOKE_SYSCALL
@@ -293,7 +329,7 @@ TEXT runtime·munmap(SB),NOSPLIT,$0
RET
TEXT runtime·madvise(SB),NOSPLIT,$0
MOVL $219, AX // madvise
MOVL $SYS_madvise, AX
MOVL addr+0(FP), BX
MOVL n+4(FP), CX
MOVL flags+8(FP), DX
@@ -304,7 +340,7 @@ TEXT runtime·madvise(SB),NOSPLIT,$0
// int32 futex(int32 *uaddr, int32 op, int32 val,
// struct timespec *timeout, int32 *uaddr2, int32 val2);
TEXT runtime·futex(SB),NOSPLIT,$0
MOVL $240, AX // futex
MOVL $SYS_futex, AX
MOVL addr+0(FP), BX
MOVL op+4(FP), CX
MOVL val+8(FP), DX
@@ -317,7 +353,7 @@ TEXT runtime·futex(SB),NOSPLIT,$0
// int32 clone(int32 flags, void *stack, M *mp, G *gp, void (*fn)(void));
TEXT runtime·clone(SB),NOSPLIT,$0
MOVL $120, AX // clone
MOVL $SYS_clone, AX
MOVL flags+0(FP), BX
MOVL stk+4(FP), CX
MOVL $0, DX // parent tid ptr
@@ -351,7 +387,7 @@ TEXT runtime·clone(SB),NOSPLIT,$0
INT $3
// Initialize AX to Linux tid
MOVL $224, AX
MOVL $SYS_gettid, AX
INVOKE_SYSCALL
MOVL 0(SP), BX // m
@@ -400,7 +436,7 @@ nog:
MOVL $0x1234, 0x1005
TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
MOVL $186, AX // sigaltstack
MOVL $SYS_sigaltstack, AX
MOVL new+0(FP), BX
MOVL old+4(FP), CX
INVOKE_SYSCALL
@@ -483,7 +519,7 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
// call set_thread_area
MOVL AX, BX // user_desc
MOVL $243, AX // syscall - set_thread_area
MOVL $SYS_set_thread_area, AX
// We can't call this via 0x10(GS) because this is called from setldt0 to set that up.
INT $0x80
@@ -509,12 +545,12 @@ TEXT runtime·setldt(SB),NOSPLIT,$32
RET
TEXT runtime·osyield(SB),NOSPLIT,$0
MOVL $158, AX
MOVL $SYS_sched_yield, AX
INVOKE_SYSCALL
RET
TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0
MOVL $242, AX // syscall - sched_getaffinity
MOVL $SYS_sched_getaffinity, AX
MOVL pid+0(FP), BX
MOVL len+4(FP), CX
MOVL buf+8(FP), DX
@@ -524,23 +560,23 @@ TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0
// int32 runtime·epollcreate(int32 size);
TEXT runtime·epollcreate(SB),NOSPLIT,$0
MOVL $254, AX
MOVL $SYS_epoll_create, AX
MOVL size+0(FP), BX
INVOKE_SYSCALL
MOVL AX, ret+4(FP)
RET
// int32 runtime·epollcreate1(int32 flags);
TEXT runtime·epollcreate1(SB),NOSPLIT,$0
MOVL $329, AX
MOVL $SYS_epoll_create1, AX
MOVL flags+0(FP), BX
INVOKE_SYSCALL
MOVL AX, ret+4(FP)
RET
// func epollctl(epfd, op, fd int32, ev *epollEvent) int
TEXT runtime·epollctl(SB),NOSPLIT,$0
MOVL $255, AX
MOVL $SYS_epoll_ctl, AX
MOVL epfd+0(FP), BX
MOVL op+4(FP), CX
MOVL fd+8(FP), DX
@@ -551,7 +587,7 @@ TEXT runtime·epollctl(SB),NOSPLIT,$0
// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
TEXT runtime·epollwait(SB),NOSPLIT,$0
MOVL $256, AX
MOVL $SYS_epoll_wait, AX
MOVL epfd+0(FP), BX
MOVL ev+4(FP), CX
MOVL nev+8(FP), DX
@@ -562,7 +598,7 @@ TEXT runtime·epollwait(SB),NOSPLIT,$0
// void runtime·closeonexec(int32 fd);
TEXT runtime·closeonexec(SB),NOSPLIT,$0
MOVL $55, AX // fcntl
MOVL $SYS_fcntl, AX
MOVL fd+0(FP), BX // fd
MOVL $2, CX // F_SETFD
MOVL $1, DX // FD_CLOEXEC
@@ -571,7 +607,7 @@ TEXT runtime·closeonexec(SB),NOSPLIT,$0
// int access(const char *name, int mode)
TEXT runtime·access(SB),NOSPLIT,$0
MOVL $33, AX // syscall - access
MOVL $SYS_access, AX
MOVL name+0(FP), BX
MOVL mode+4(FP), CX
INVOKE_SYSCALL
@@ -582,7 +618,7 @@ TEXT runtime·access(SB),NOSPLIT,$0
TEXT runtime·connect(SB),NOSPLIT,$0-16
// connect is implemented as socketcall(NR_socket, 3, *(rest of args))
// stack already should have fd, addr, addrlen.
MOVL $102, AX // syscall - socketcall
MOVL $SYS_socketcall, AX
MOVL $3, BX // connect
LEAL fd+0(FP), CX
INVOKE_SYSCALL
@@ -593,7 +629,7 @@ TEXT runtime·connect(SB),NOSPLIT,$0-16
TEXT runtime·socket(SB),NOSPLIT,$0-16
// socket is implemented as socketcall(NR_socket, 1, *(rest of args))
// stack already should have domain, type, protocol.
MOVL $102, AX // syscall - socketcall
MOVL $SYS_socketcall, AX
MOVL $1, BX // socket
LEAL domain+0(FP), CX
INVOKE_SYSCALL
@@ -603,7 +639,7 @@ TEXT runtime·socket(SB),NOSPLIT,$0-16
// func sbrk0() uintptr
TEXT runtime·sbrk0(SB),NOSPLIT,$0-4
// Implemented as brk(NULL).
MOVL $45, AX // syscall - brk
MOVL $SYS_brk, AX
MOVL $0, BX // NULL
INVOKE_SYSCALL
MOVL AX, ret+0(FP)
Oops, something went wrong.

0 comments on commit 4d269ad

Please sign in to comment.