...
Run Format

Text file src/runtime/sys_linux_amd64.s

Documentation: runtime

     1	// Copyright 2009 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	//
     6	// System calls and other sys.stuff for AMD64, Linux
     7	//
     8	
     9	#include "go_asm.h"
    10	#include "go_tls.h"
    11	#include "textflag.h"
    12	
    13	#define AT_FDCWD -100
    14	
    15	#define SYS_read		0
    16	#define SYS_write		1
    17	#define SYS_close		3
    18	#define SYS_mmap		9
    19	#define SYS_munmap		11
    20	#define SYS_brk 		12
    21	#define SYS_rt_sigaction	13
    22	#define SYS_rt_sigprocmask	14
    23	#define SYS_rt_sigreturn	15
    24	#define SYS_sched_yield 	24
    25	#define SYS_mincore		27
    26	#define SYS_madvise		28
    27	#define SYS_setittimer		38
    28	#define SYS_getpid		39
    29	#define SYS_socket		41
    30	#define SYS_connect		42
    31	#define SYS_clone		56
    32	#define SYS_exit		60
    33	#define SYS_kill		62
    34	#define SYS_fcntl		72
    35	#define SYS_getrlimit		97
    36	#define SYS_sigaltstack 	131
    37	#define SYS_arch_prctl		158
    38	#define SYS_gettid		186
    39	#define SYS_tkill		200
    40	#define SYS_futex		202
    41	#define SYS_sched_getaffinity	204
    42	#define SYS_epoll_create	213
    43	#define SYS_exit_group		231
    44	#define SYS_epoll_ctl		233
    45	#define SYS_openat		257
    46	#define SYS_faccessat		269
    47	#define SYS_pselect6		270
    48	#define SYS_epoll_pwait		281
    49	#define SYS_epoll_create1	291
    50	
    51	TEXT runtime·exit(SB),NOSPLIT,$0-4
    52		MOVL	code+0(FP), DI
    53		MOVL	$SYS_exit_group, AX
    54		SYSCALL
    55		RET
    56	
    57	// func exitThread(wait *uint32)
    58	TEXT runtime·exitThread(SB),NOSPLIT,$0-8
    59		MOVQ	wait+0(FP), AX
    60		// We're done using the stack.
    61		MOVL	$0, (AX)
    62		MOVL	$0, DI	// exit code
    63		MOVL	$SYS_exit, AX
    64		SYSCALL
    65		// We may not even have a stack any more.
    66		INT	$3
    67		JMP	0(PC)
    68	
    69	TEXT runtime·open(SB),NOSPLIT,$0-20
    70		// This uses openat instead of open, because Android O blocks open.
    71		MOVL	$AT_FDCWD, DI // AT_FDCWD, so this acts like open
    72		MOVQ	name+0(FP), SI
    73		MOVL	mode+8(FP), DX
    74		MOVL	perm+12(FP), R10
    75		MOVL	$SYS_openat, AX
    76		SYSCALL
    77		CMPQ	AX, $0xfffffffffffff001
    78		JLS	2(PC)
    79		MOVL	$-1, AX
    80		MOVL	AX, ret+16(FP)
    81		RET
    82	
    83	TEXT runtime·closefd(SB),NOSPLIT,$0-12
    84		MOVL	fd+0(FP), DI
    85		MOVL	$SYS_close, AX
    86		SYSCALL
    87		CMPQ	AX, $0xfffffffffffff001
    88		JLS	2(PC)
    89		MOVL	$-1, AX
    90		MOVL	AX, ret+8(FP)
    91		RET
    92	
    93	TEXT runtime·write(SB),NOSPLIT,$0-28
    94		MOVQ	fd+0(FP), DI
    95		MOVQ	p+8(FP), SI
    96		MOVL	n+16(FP), DX
    97		MOVL	$SYS_write, AX
    98		SYSCALL
    99		CMPQ	AX, $0xfffffffffffff001
   100		JLS	2(PC)
   101		MOVL	$-1, AX
   102		MOVL	AX, ret+24(FP)
   103		RET
   104	
   105	TEXT runtime·read(SB),NOSPLIT,$0-28
   106		MOVL	fd+0(FP), DI
   107		MOVQ	p+8(FP), SI
   108		MOVL	n+16(FP), DX
   109		MOVL	$SYS_read, AX
   110		SYSCALL
   111		CMPQ	AX, $0xfffffffffffff001
   112		JLS	2(PC)
   113		MOVL	$-1, AX
   114		MOVL	AX, ret+24(FP)
   115		RET
   116	
   117	TEXT runtime·getrlimit(SB),NOSPLIT,$0-20
   118		MOVL	kind+0(FP), DI
   119		MOVQ	limit+8(FP), SI
   120		MOVL	$SYS_getrlimit, AX
   121		SYSCALL
   122		MOVL	AX, ret+16(FP)
   123		RET
   124	
   125	TEXT runtime·usleep(SB),NOSPLIT,$16
   126		MOVL	$0, DX
   127		MOVL	usec+0(FP), AX
   128		MOVL	$1000000, CX
   129		DIVL	CX
   130		MOVQ	AX, 0(SP)
   131		MOVL	$1000, AX	// usec to nsec
   132		MULL	DX
   133		MOVQ	AX, 8(SP)
   134	
   135		// pselect6(0, 0, 0, 0, &ts, 0)
   136		MOVL	$0, DI
   137		MOVL	$0, SI
   138		MOVL	$0, DX
   139		MOVL	$0, R10
   140		MOVQ	SP, R8
   141		MOVL	$0, R9
   142		MOVL	$SYS_pselect6, AX
   143		SYSCALL
   144		RET
   145	
   146	TEXT runtime·gettid(SB),NOSPLIT,$0-4
   147		MOVL	$SYS_gettid, AX
   148		SYSCALL
   149		MOVL	AX, ret+0(FP)
   150		RET
   151	
   152	TEXT runtime·raise(SB),NOSPLIT,$0
   153		MOVL	$SYS_gettid, AX
   154		SYSCALL
   155		MOVL	AX, DI	// arg 1 tid
   156		MOVL	sig+0(FP), SI	// arg 2
   157		MOVL	$SYS_tkill, AX
   158		SYSCALL
   159		RET
   160	
   161	TEXT runtime·raiseproc(SB),NOSPLIT,$0
   162		MOVL	$SYS_getpid, AX
   163		SYSCALL
   164		MOVL	AX, DI	// arg 1 pid
   165		MOVL	sig+0(FP), SI	// arg 2
   166		MOVL	$SYS_kill, AX
   167		SYSCALL
   168		RET
   169	
   170	TEXT runtime·setitimer(SB),NOSPLIT,$0-24
   171		MOVL	mode+0(FP), DI
   172		MOVQ	new+8(FP), SI
   173		MOVQ	old+16(FP), DX
   174		MOVL	$SYS_setittimer, AX
   175		SYSCALL
   176		RET
   177	
   178	TEXT runtime·mincore(SB),NOSPLIT,$0-28
   179		MOVQ	addr+0(FP), DI
   180		MOVQ	n+8(FP), SI
   181		MOVQ	dst+16(FP), DX
   182		MOVL	$SYS_mincore, AX
   183		SYSCALL
   184		MOVL	AX, ret+24(FP)
   185		RET
   186	
   187	// func walltime() (sec int64, nsec int32)
   188	TEXT runtime·walltime(SB),NOSPLIT,$0-12
   189		// We don't know how much stack space the VDSO code will need,
   190		// so switch to g0.
   191		// In particular, a kernel configured with CONFIG_OPTIMIZE_INLINING=n
   192		// and hardening can use a full page of stack space in gettime_sym
   193		// due to stack probes inserted to avoid stack/heap collisions.
   194		// See issue #20427.
   195	
   196		MOVQ	SP, BP	// Save old SP; BP unchanged by C code.
   197	
   198		get_tls(CX)
   199		MOVQ	g(CX), AX
   200		MOVQ	g_m(AX), CX
   201		MOVQ	m_curg(CX), DX
   202	
   203		CMPQ	AX, DX		// Only switch if on curg.
   204		JNE	noswitch
   205	
   206		MOVQ	m_g0(CX), DX
   207		MOVQ	(g_sched+gobuf_sp)(DX), SP	// Set SP to g0 stack
   208	
   209	noswitch:
   210		SUBQ	$16, SP		// Space for results
   211		ANDQ	$~15, SP	// Align for C code
   212	
   213		MOVQ	runtime·__vdso_clock_gettime_sym(SB), AX
   214		CMPQ	AX, $0
   215		JEQ	fallback
   216		MOVL	$0, DI // CLOCK_REALTIME
   217		LEAQ	0(SP), SI
   218		CALL	AX
   219		MOVQ	0(SP), AX	// sec
   220		MOVQ	8(SP), DX	// nsec
   221		MOVQ	BP, SP		// Restore real SP
   222		MOVQ	AX, sec+0(FP)
   223		MOVL	DX, nsec+8(FP)
   224		RET
   225	fallback:
   226		LEAQ	0(SP), DI
   227		MOVQ	$0, SI
   228		MOVQ	runtime·__vdso_gettimeofday_sym(SB), AX
   229		CALL	AX
   230		MOVQ	0(SP), AX	// sec
   231		MOVL	8(SP), DX	// usec
   232		IMULQ	$1000, DX
   233		MOVQ	BP, SP		// Restore real SP
   234		MOVQ	AX, sec+0(FP)
   235		MOVL	DX, nsec+8(FP)
   236		RET
   237	
   238	TEXT runtime·nanotime(SB),NOSPLIT,$0-8
   239		// Switch to g0 stack. See comment above in runtime·walltime.
   240	
   241		MOVQ	SP, BP	// Save old SP; BX unchanged by C code.
   242	
   243		get_tls(CX)
   244		MOVQ	g(CX), AX
   245		MOVQ	g_m(AX), CX
   246		MOVQ	m_curg(CX), DX
   247	
   248		CMPQ	AX, DX		// Only switch if on curg.
   249		JNE	noswitch
   250	
   251		MOVQ	m_g0(CX), DX
   252		MOVQ	(g_sched+gobuf_sp)(DX), SP	// Set SP to g0 stack
   253	
   254	noswitch:
   255		SUBQ	$16, SP		// Space for results
   256		ANDQ	$~15, SP	// Align for C code
   257	
   258		MOVQ	runtime·__vdso_clock_gettime_sym(SB), AX
   259		CMPQ	AX, $0
   260		JEQ	fallback
   261		MOVL	$1, DI // CLOCK_MONOTONIC
   262		LEAQ	0(SP), SI
   263		CALL	AX
   264		MOVQ	0(SP), AX	// sec
   265		MOVQ	8(SP), DX	// nsec
   266		MOVQ	BP, SP		// Restore real SP
   267		// sec is in AX, nsec in DX
   268		// return nsec in AX
   269		IMULQ	$1000000000, AX
   270		ADDQ	DX, AX
   271		MOVQ	AX, ret+0(FP)
   272		RET
   273	fallback:
   274		LEAQ	0(SP), DI
   275		MOVQ	$0, SI
   276		MOVQ	runtime·__vdso_gettimeofday_sym(SB), AX
   277		CALL	AX
   278		MOVQ	0(SP), AX	// sec
   279		MOVL	8(SP), DX	// usec
   280		MOVQ	BP, SP		// Restore real SP
   281		IMULQ	$1000, DX
   282		// sec is in AX, nsec in DX
   283		// return nsec in AX
   284		IMULQ	$1000000000, AX
   285		ADDQ	DX, AX
   286		MOVQ	AX, ret+0(FP)
   287		RET
   288	
   289	TEXT runtime·rtsigprocmask(SB),NOSPLIT,$0-28
   290		MOVL	how+0(FP), DI
   291		MOVQ	new+8(FP), SI
   292		MOVQ	old+16(FP), DX
   293		MOVL	size+24(FP), R10
   294		MOVL	$SYS_rt_sigprocmask, AX
   295		SYSCALL
   296		CMPQ	AX, $0xfffffffffffff001
   297		JLS	2(PC)
   298		MOVL	$0xf1, 0xf1  // crash
   299		RET
   300	
   301	TEXT runtime·sysSigaction(SB),NOSPLIT,$0-36
   302		MOVQ	sig+0(FP), DI
   303		MOVQ	new+8(FP), SI
   304		MOVQ	old+16(FP), DX
   305		MOVQ	size+24(FP), R10
   306		MOVL	$SYS_rt_sigaction, AX
   307		SYSCALL
   308		MOVL	AX, ret+32(FP)
   309		RET
   310	
   311	// Call the function stored in _cgo_sigaction using the GCC calling convention.
   312	TEXT runtime·callCgoSigaction(SB),NOSPLIT,$16
   313		MOVQ	sig+0(FP), DI
   314		MOVQ	new+8(FP), SI
   315		MOVQ	old+16(FP), DX
   316		MOVQ	_cgo_sigaction(SB), AX
   317		MOVQ	SP, BX	// callee-saved
   318		ANDQ	$~15, SP	// alignment as per amd64 psABI
   319		CALL	AX
   320		MOVQ	BX, SP
   321		MOVL	AX, ret+24(FP)
   322		RET
   323	
   324	TEXT runtime·sigfwd(SB),NOSPLIT,$0-32
   325		MOVQ	fn+0(FP),    AX
   326		MOVL	sig+8(FP),   DI
   327		MOVQ	info+16(FP), SI
   328		MOVQ	ctx+24(FP),  DX
   329		PUSHQ	BP
   330		MOVQ	SP, BP
   331		ANDQ	$~15, SP     // alignment for x86_64 ABI
   332		CALL	AX
   333		MOVQ	BP, SP
   334		POPQ	BP
   335		RET
   336	
   337	TEXT runtime·sigtramp(SB),NOSPLIT,$72
   338		// Save callee-saved C registers, since the caller may be a C signal handler.
   339		MOVQ	BX,  bx-8(SP)
   340		MOVQ	BP,  bp-16(SP)  // save in case GOEXPERIMENT=noframepointer is set
   341		MOVQ	R12, r12-24(SP)
   342		MOVQ	R13, r13-32(SP)
   343		MOVQ	R14, r14-40(SP)
   344		MOVQ	R15, r15-48(SP)
   345		// We don't save mxcsr or the x87 control word because sigtrampgo doesn't
   346		// modify them.
   347	
   348		MOVQ	DX, ctx-56(SP)
   349		MOVQ	SI, info-64(SP)
   350		MOVQ	DI, signum-72(SP)
   351		MOVQ	$runtime·sigtrampgo(SB), AX
   352		CALL AX
   353	
   354		MOVQ	r15-48(SP), R15
   355		MOVQ	r14-40(SP), R14
   356		MOVQ	r13-32(SP), R13
   357		MOVQ	r12-24(SP), R12
   358		MOVQ	bp-16(SP),  BP
   359		MOVQ	bx-8(SP),   BX
   360		RET
   361	
   362	// Used instead of sigtramp in programs that use cgo.
   363	// Arguments from kernel are in DI, SI, DX.
   364	TEXT runtime·cgoSigtramp(SB),NOSPLIT,$0
   365		// If no traceback function, do usual sigtramp.
   366		MOVQ	runtime·cgoTraceback(SB), AX
   367		TESTQ	AX, AX
   368		JZ	sigtramp
   369	
   370		// If no traceback support function, which means that
   371		// runtime/cgo was not linked in, do usual sigtramp.
   372		MOVQ	_cgo_callers(SB), AX
   373		TESTQ	AX, AX
   374		JZ	sigtramp
   375	
   376		// Figure out if we are currently in a cgo call.
   377		// If not, just do usual sigtramp.
   378		get_tls(CX)
   379		MOVQ	g(CX),AX
   380		TESTQ	AX, AX
   381		JZ	sigtrampnog     // g == nil
   382		MOVQ	g_m(AX), AX
   383		TESTQ	AX, AX
   384		JZ	sigtramp        // g.m == nil
   385		MOVL	m_ncgo(AX), CX
   386		TESTL	CX, CX
   387		JZ	sigtramp        // g.m.ncgo == 0
   388		MOVQ	m_curg(AX), CX
   389		TESTQ	CX, CX
   390		JZ	sigtramp        // g.m.curg == nil
   391		MOVQ	g_syscallsp(CX), CX
   392		TESTQ	CX, CX
   393		JZ	sigtramp        // g.m.curg.syscallsp == 0
   394		MOVQ	m_cgoCallers(AX), R8
   395		TESTQ	R8, R8
   396		JZ	sigtramp        // g.m.cgoCallers == nil
   397		MOVL	m_cgoCallersUse(AX), CX
   398		TESTL	CX, CX
   399		JNZ	sigtramp	// g.m.cgoCallersUse != 0
   400	
   401		// Jump to a function in runtime/cgo.
   402		// That function, written in C, will call the user's traceback
   403		// function with proper unwind info, and will then call back here.
   404		// The first three arguments, and the fifth, are already in registers.
   405		// Set the two remaining arguments now.
   406		MOVQ	runtime·cgoTraceback(SB), CX
   407		MOVQ	$runtime·sigtramp(SB), R9
   408		MOVQ	_cgo_callers(SB), AX
   409		JMP	AX
   410	
   411	sigtramp:
   412		JMP	runtime·sigtramp(SB)
   413	
   414	sigtrampnog:
   415		// Signal arrived on a non-Go thread. If this is SIGPROF, get a
   416		// stack trace.
   417		CMPL	DI, $27 // 27 == SIGPROF
   418		JNZ	sigtramp
   419	
   420		// Lock sigprofCallersUse.
   421		MOVL	$0, AX
   422		MOVL	$1, CX
   423		MOVQ	$runtime·sigprofCallersUse(SB), R11
   424		LOCK
   425		CMPXCHGL	CX, 0(R11)
   426		JNZ	sigtramp  // Skip stack trace if already locked.
   427	
   428		// Jump to the traceback function in runtime/cgo.
   429		// It will call back to sigprofNonGo, which will ignore the
   430		// arguments passed in registers.
   431		// First three arguments to traceback function are in registers already.
   432		MOVQ	runtime·cgoTraceback(SB), CX
   433		MOVQ	$runtime·sigprofCallers(SB), R8
   434		MOVQ	$runtime·sigprofNonGo(SB), R9
   435		MOVQ	_cgo_callers(SB), AX
   436		JMP	AX
   437	
   438	// For cgo unwinding to work, this function must look precisely like
   439	// the one in glibc.  The glibc source code is:
   440	// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/x86_64/sigaction.c
   441	// The code that cares about the precise instructions used is:
   442	// https://gcc.gnu.org/viewcvs/gcc/trunk/libgcc/config/i386/linux-unwind.h?revision=219188&view=markup
   443	TEXT runtime·sigreturn(SB),NOSPLIT,$0
   444		MOVQ	$SYS_rt_sigreturn, AX
   445		SYSCALL
   446		INT $3	// not reached
   447	
   448	TEXT runtime·sysMmap(SB),NOSPLIT,$0
   449		MOVQ	addr+0(FP), DI
   450		MOVQ	n+8(FP), SI
   451		MOVL	prot+16(FP), DX
   452		MOVL	flags+20(FP), R10
   453		MOVL	fd+24(FP), R8
   454		MOVL	off+28(FP), R9
   455	
   456		MOVL	$SYS_mmap, AX
   457		SYSCALL
   458		CMPQ	AX, $0xfffffffffffff001
   459		JLS	ok
   460		NOTQ	AX
   461		INCQ	AX
   462		MOVQ	$0, p+32(FP)
   463		MOVQ	AX, err+40(FP)
   464		RET
   465	ok:
   466		MOVQ	AX, p+32(FP)
   467		MOVQ	$0, err+40(FP)
   468		RET
   469	
   470	// Call the function stored in _cgo_mmap using the GCC calling convention.
   471	// This must be called on the system stack.
   472	TEXT runtime·callCgoMmap(SB),NOSPLIT,$16
   473		MOVQ	addr+0(FP), DI
   474		MOVQ	n+8(FP), SI
   475		MOVL	prot+16(FP), DX
   476		MOVL	flags+20(FP), CX
   477		MOVL	fd+24(FP), R8
   478		MOVL	off+28(FP), R9
   479		MOVQ	_cgo_mmap(SB), AX
   480		MOVQ	SP, BX
   481		ANDQ	$~15, SP	// alignment as per amd64 psABI
   482		MOVQ	BX, 0(SP)
   483		CALL	AX
   484		MOVQ	0(SP), SP
   485		MOVQ	AX, ret+32(FP)
   486		RET
   487	
   488	TEXT runtime·sysMunmap(SB),NOSPLIT,$0
   489		MOVQ	addr+0(FP), DI
   490		MOVQ	n+8(FP), SI
   491		MOVQ	$SYS_munmap, AX
   492		SYSCALL
   493		CMPQ	AX, $0xfffffffffffff001
   494		JLS	2(PC)
   495		MOVL	$0xf1, 0xf1  // crash
   496		RET
   497	
   498	// Call the function stored in _cgo_munmap using the GCC calling convention.
   499	// This must be called on the system stack.
   500	TEXT runtime·callCgoMunmap(SB),NOSPLIT,$16-16
   501		MOVQ	addr+0(FP), DI
   502		MOVQ	n+8(FP), SI
   503		MOVQ	_cgo_munmap(SB), AX
   504		MOVQ	SP, BX
   505		ANDQ	$~15, SP	// alignment as per amd64 psABI
   506		MOVQ	BX, 0(SP)
   507		CALL	AX
   508		MOVQ	0(SP), SP
   509		RET
   510	
   511	TEXT runtime·madvise(SB),NOSPLIT,$0
   512		MOVQ	addr+0(FP), DI
   513		MOVQ	n+8(FP), SI
   514		MOVL	flags+16(FP), DX
   515		MOVQ	$SYS_madvise, AX
   516		SYSCALL
   517		// ignore failure - maybe pages are locked
   518		RET
   519	
   520	// int64 futex(int32 *uaddr, int32 op, int32 val,
   521	//	struct timespec *timeout, int32 *uaddr2, int32 val2);
   522	TEXT runtime·futex(SB),NOSPLIT,$0
   523		MOVQ	addr+0(FP), DI
   524		MOVL	op+8(FP), SI
   525		MOVL	val+12(FP), DX
   526		MOVQ	ts+16(FP), R10
   527		MOVQ	addr2+24(FP), R8
   528		MOVL	val3+32(FP), R9
   529		MOVL	$SYS_futex, AX
   530		SYSCALL
   531		MOVL	AX, ret+40(FP)
   532		RET
   533	
   534	// int32 clone(int32 flags, void *stk, M *mp, G *gp, void (*fn)(void));
   535	TEXT runtime·clone(SB),NOSPLIT,$0
   536		MOVL	flags+0(FP), DI
   537		MOVQ	stk+8(FP), SI
   538		MOVQ	$0, DX
   539		MOVQ	$0, R10
   540	
   541		// Copy mp, gp, fn off parent stack for use by child.
   542		// Careful: Linux system call clobbers CX and R11.
   543		MOVQ	mp+16(FP), R8
   544		MOVQ	gp+24(FP), R9
   545		MOVQ	fn+32(FP), R12
   546	
   547		MOVL	$SYS_clone, AX
   548		SYSCALL
   549	
   550		// In parent, return.
   551		CMPQ	AX, $0
   552		JEQ	3(PC)
   553		MOVL	AX, ret+40(FP)
   554		RET
   555	
   556		// In child, on new stack.
   557		MOVQ	SI, SP
   558	
   559		// If g or m are nil, skip Go-related setup.
   560		CMPQ	R8, $0    // m
   561		JEQ	nog
   562		CMPQ	R9, $0    // g
   563		JEQ	nog
   564	
   565		// Initialize m->procid to Linux tid
   566		MOVL	$SYS_gettid, AX
   567		SYSCALL
   568		MOVQ	AX, m_procid(R8)
   569	
   570		// Set FS to point at m->tls.
   571		LEAQ	m_tls(R8), DI
   572		CALL	runtime·settls(SB)
   573	
   574		// In child, set up new stack
   575		get_tls(CX)
   576		MOVQ	R8, g_m(R9)
   577		MOVQ	R9, g(CX)
   578		CALL	runtime·stackcheck(SB)
   579	
   580	nog:
   581		// Call fn
   582		CALL	R12
   583	
   584		// It shouldn't return. If it does, exit that thread.
   585		MOVL	$111, DI
   586		MOVL	$SYS_exit, AX
   587		SYSCALL
   588		JMP	-3(PC)	// keep exiting
   589	
   590	TEXT runtime·sigaltstack(SB),NOSPLIT,$-8
   591		MOVQ	new+0(FP), DI
   592		MOVQ	old+8(FP), SI
   593		MOVQ	$SYS_sigaltstack, AX
   594		SYSCALL
   595		CMPQ	AX, $0xfffffffffffff001
   596		JLS	2(PC)
   597		MOVL	$0xf1, 0xf1  // crash
   598		RET
   599	
   600	// set tls base to DI
   601	TEXT runtime·settls(SB),NOSPLIT,$32
   602	#ifdef GOOS_android
   603		// Same as in sys_darwin_386.s:/ugliness, different constant.
   604		// DI currently holds m->tls, which must be fs:0x1d0.
   605		// See cgo/gcc_android_amd64.c for the derivation of the constant.
   606		SUBQ	$0x1d0, DI  // In android, the tls base
   607	#else
   608		ADDQ	$8, DI	// ELF wants to use -8(FS)
   609	#endif
   610		MOVQ	DI, SI
   611		MOVQ	$0x1002, DI	// ARCH_SET_FS
   612		MOVQ	$SYS_arch_prctl, AX
   613		SYSCALL
   614		CMPQ	AX, $0xfffffffffffff001
   615		JLS	2(PC)
   616		MOVL	$0xf1, 0xf1  // crash
   617		RET
   618	
   619	TEXT runtime·osyield(SB),NOSPLIT,$0
   620		MOVL	$SYS_sched_yield, AX
   621		SYSCALL
   622		RET
   623	
   624	TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0
   625		MOVQ	pid+0(FP), DI
   626		MOVQ	len+8(FP), SI
   627		MOVQ	buf+16(FP), DX
   628		MOVL	$SYS_sched_getaffinity, AX
   629		SYSCALL
   630		MOVL	AX, ret+24(FP)
   631		RET
   632	
   633	// int32 runtime·epollcreate(int32 size);
   634	TEXT runtime·epollcreate(SB),NOSPLIT,$0
   635		MOVL    size+0(FP), DI
   636		MOVL    $SYS_epoll_create, AX
   637		SYSCALL
   638		MOVL	AX, ret+8(FP)
   639		RET
   640	
   641	// int32 runtime·epollcreate1(int32 flags);
   642	TEXT runtime·epollcreate1(SB),NOSPLIT,$0
   643		MOVL	flags+0(FP), DI
   644		MOVL	$SYS_epoll_create1, AX
   645		SYSCALL
   646		MOVL	AX, ret+8(FP)
   647		RET
   648	
   649	// func epollctl(epfd, op, fd int32, ev *epollEvent) int
   650	TEXT runtime·epollctl(SB),NOSPLIT,$0
   651		MOVL	epfd+0(FP), DI
   652		MOVL	op+4(FP), SI
   653		MOVL	fd+8(FP), DX
   654		MOVQ	ev+16(FP), R10
   655		MOVL	$SYS_epoll_ctl, AX
   656		SYSCALL
   657		MOVL	AX, ret+24(FP)
   658		RET
   659	
   660	// int32 runtime·epollwait(int32 epfd, EpollEvent *ev, int32 nev, int32 timeout);
   661	TEXT runtime·epollwait(SB),NOSPLIT,$0
   662		// This uses pwait instead of wait, because Android O blocks wait.
   663		MOVL	epfd+0(FP), DI
   664		MOVQ	ev+8(FP), SI
   665		MOVL	nev+16(FP), DX
   666		MOVL	timeout+20(FP), R10
   667		MOVQ	$0, R8
   668		MOVL	$SYS_epoll_pwait, AX
   669		SYSCALL
   670		MOVL	AX, ret+24(FP)
   671		RET
   672	
   673	// void runtime·closeonexec(int32 fd);
   674	TEXT runtime·closeonexec(SB),NOSPLIT,$0
   675		MOVL    fd+0(FP), DI  // fd
   676		MOVQ    $2, SI  // F_SETFD
   677		MOVQ    $1, DX  // FD_CLOEXEC
   678		MOVL	$SYS_fcntl, AX
   679		SYSCALL
   680		RET
   681	
   682	
   683	// int access(const char *name, int mode)
   684	TEXT runtime·access(SB),NOSPLIT,$0
   685		// This uses faccessat instead of access, because Android O blocks access.
   686		MOVL	$AT_FDCWD, DI // AT_FDCWD, so this acts like access
   687		MOVQ	name+0(FP), SI
   688		MOVL	mode+8(FP), DX
   689		MOVL	$0, R10
   690		MOVL	$SYS_faccessat, AX
   691		SYSCALL
   692		MOVL	AX, ret+16(FP)
   693		RET
   694	
   695	// int connect(int fd, const struct sockaddr *addr, socklen_t addrlen)
   696	TEXT runtime·connect(SB),NOSPLIT,$0-28
   697		MOVL	fd+0(FP), DI
   698		MOVQ	addr+8(FP), SI
   699		MOVL	len+16(FP), DX
   700		MOVL	$SYS_connect, AX
   701		SYSCALL
   702		MOVL	AX, ret+24(FP)
   703		RET
   704	
   705	// int socket(int domain, int type, int protocol)
   706	TEXT runtime·socket(SB),NOSPLIT,$0-20
   707		MOVL	domain+0(FP), DI
   708		MOVL	typ+4(FP), SI
   709		MOVL	prot+8(FP), DX
   710		MOVL	$SYS_socket, AX
   711		SYSCALL
   712		MOVL	AX, ret+16(FP)
   713		RET
   714	
   715	// func sbrk0() uintptr
   716	TEXT runtime·sbrk0(SB),NOSPLIT,$0-8
   717		// Implemented as brk(NULL).
   718		MOVQ	$0, DI
   719		MOVL	$SYS_brk, AX
   720		SYSCALL
   721		MOVQ	AX, ret+0(FP)
   722		RET

View as plain text