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

View as plain text