rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/runtime/syscall_solaris.go (about)

     1  // Copyright 2014 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  package runtime
     6  
     7  import "unsafe"
     8  
     9  var (
    10  	libc_chdir,
    11  	libc_chroot,
    12  	libc_dlopen,
    13  	libc_dlclose,
    14  	libc_dlsym,
    15  	libc_execve,
    16  	libc_fcntl,
    17  	libc_forkx,
    18  	libc_gethostname,
    19  	libc_getpid,
    20  	libc_ioctl,
    21  	libc_pipe,
    22  	libc_setgid,
    23  	libc_setgroups,
    24  	libc_setsid,
    25  	libc_setuid,
    26  	libc_setpgid,
    27  	libc_syscall,
    28  	libc_wait4,
    29  	pipe1 libcFunc
    30  )
    31  
    32  //go:nosplit
    33  func syscall_sysvicall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
    34  	call := libcall{
    35  		fn:   fn,
    36  		n:    nargs,
    37  		args: uintptr(unsafe.Pointer(&a1)),
    38  	}
    39  	entersyscallblock(0)
    40  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
    41  	exitsyscall(0)
    42  	return call.r1, call.r2, call.err
    43  }
    44  
    45  //go:nosplit
    46  func syscall_rawsysvicall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
    47  	call := libcall{
    48  		fn:   fn,
    49  		n:    nargs,
    50  		args: uintptr(unsafe.Pointer(&a1)),
    51  	}
    52  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
    53  	return call.r1, call.r2, call.err
    54  }
    55  
    56  // TODO(aram): Once we remove all instances of C calling sysvicallN, make
    57  // sysvicallN return errors and replace the body of the following functions
    58  // with calls to sysvicallN.
    59  
    60  //go:nosplit
    61  func syscall_chdir(path uintptr) (err uintptr) {
    62  	call := libcall{
    63  		fn:   uintptr(unsafe.Pointer(libc_chdir)),
    64  		n:    1,
    65  		args: uintptr(unsafe.Pointer(&path)),
    66  	}
    67  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
    68  	return call.err
    69  }
    70  
    71  //go:nosplit
    72  func syscall_chroot(path uintptr) (err uintptr) {
    73  	call := libcall{
    74  		fn:   uintptr(unsafe.Pointer(libc_chroot)),
    75  		n:    1,
    76  		args: uintptr(unsafe.Pointer(&path)),
    77  	}
    78  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
    79  	return call.err
    80  }
    81  
    82  // like close, but must not split stack, for forkx.
    83  //go:nosplit
    84  func syscall_close(fd int32) int32 {
    85  	return int32(sysvicall1(libc_close, uintptr(fd)))
    86  }
    87  
    88  func syscall_dlopen(name *byte, mode uintptr) (handle uintptr, err uintptr) {
    89  	call := libcall{
    90  		fn:   uintptr(unsafe.Pointer(libc_dlopen)),
    91  		n:    2,
    92  		args: uintptr(unsafe.Pointer(&name)),
    93  	}
    94  	entersyscallblock(0)
    95  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
    96  	exitsyscall(0)
    97  	if call.r1 == 0 {
    98  		return call.r1, call.err
    99  	}
   100  	return call.r1, 0
   101  }
   102  
   103  func syscall_dlclose(handle uintptr) (err uintptr) {
   104  	call := libcall{
   105  		fn:   uintptr(unsafe.Pointer(libc_dlclose)),
   106  		n:    1,
   107  		args: uintptr(unsafe.Pointer(&handle)),
   108  	}
   109  	entersyscallblock(0)
   110  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   111  	exitsyscall(0)
   112  	return call.r1
   113  }
   114  
   115  func syscall_dlsym(handle uintptr, name *byte) (proc uintptr, err uintptr) {
   116  	call := libcall{
   117  		fn:   uintptr(unsafe.Pointer(libc_dlsym)),
   118  		n:    2,
   119  		args: uintptr(unsafe.Pointer(&handle)),
   120  	}
   121  	entersyscallblock(0)
   122  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   123  	exitsyscall(0)
   124  	if call.r1 == 0 {
   125  		return call.r1, call.err
   126  	}
   127  	return call.r1, 0
   128  }
   129  
   130  //go:nosplit
   131  func syscall_execve(path, argv, envp uintptr) (err uintptr) {
   132  	call := libcall{
   133  		fn:   uintptr(unsafe.Pointer(libc_execve)),
   134  		n:    3,
   135  		args: uintptr(unsafe.Pointer(&path)),
   136  	}
   137  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   138  	return call.err
   139  }
   140  
   141  // like exit, but must not split stack, for forkx.
   142  //go:nosplit
   143  func syscall_exit(code uintptr) {
   144  	sysvicall1(libc_exit, code)
   145  }
   146  
   147  //go:nosplit
   148  func syscall_fcntl(fd, cmd, arg uintptr) (val, err uintptr) {
   149  	call := libcall{
   150  		fn:   uintptr(unsafe.Pointer(libc_fcntl)),
   151  		n:    3,
   152  		args: uintptr(unsafe.Pointer(&fd)),
   153  	}
   154  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   155  	return call.r1, call.err
   156  }
   157  
   158  //go:nosplit
   159  func syscall_forkx(flags uintptr) (pid uintptr, err uintptr) {
   160  	call := libcall{
   161  		fn:   uintptr(unsafe.Pointer(libc_forkx)),
   162  		n:    1,
   163  		args: uintptr(unsafe.Pointer(&flags)),
   164  	}
   165  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   166  	return call.r1, call.err
   167  }
   168  
   169  func syscall_gethostname() (name string, err uintptr) {
   170  	cname := new([_MAXHOSTNAMELEN]byte)
   171  	var args = [2]uintptr{uintptr(unsafe.Pointer(&cname[0])), _MAXHOSTNAMELEN}
   172  	call := libcall{
   173  		fn:   uintptr(unsafe.Pointer(libc_gethostname)),
   174  		n:    2,
   175  		args: uintptr(unsafe.Pointer(&args[0])),
   176  	}
   177  	entersyscallblock(0)
   178  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   179  	exitsyscall(0)
   180  	if call.r1 != 0 {
   181  		return "", call.err
   182  	}
   183  	cname[_MAXHOSTNAMELEN-1] = 0
   184  	return gostringnocopy(&cname[0]), 0
   185  }
   186  
   187  //go:nosplit
   188  func syscall_getpid() (pid, err uintptr) {
   189  	call := libcall{
   190  		fn:   uintptr(unsafe.Pointer(libc_getpid)),
   191  		n:    0,
   192  		args: uintptr(unsafe.Pointer(libc_getpid)), // it's unused but must be non-nil, otherwise crashes
   193  	}
   194  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   195  	return call.r1, call.err
   196  }
   197  
   198  //go:nosplit
   199  func syscall_ioctl(fd, req, arg uintptr) (err uintptr) {
   200  	call := libcall{
   201  		fn:   uintptr(unsafe.Pointer(libc_ioctl)),
   202  		n:    3,
   203  		args: uintptr(unsafe.Pointer(&fd)),
   204  	}
   205  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   206  	return call.err
   207  }
   208  
   209  func syscall_pipe() (r, w, err uintptr) {
   210  	call := libcall{
   211  		fn:   uintptr(unsafe.Pointer(&pipe1)),
   212  		n:    0,
   213  		args: uintptr(unsafe.Pointer(&pipe1)), // it's unused but must be non-nil, otherwise crashes
   214  	}
   215  	entersyscallblock(0)
   216  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   217  	exitsyscall(0)
   218  	return call.r1, call.r2, call.err
   219  }
   220  
   221  // This is syscall.RawSyscall, it exists to satisfy some build dependency,
   222  // but it doesn't work correctly.
   223  //
   224  // DO NOT USE!
   225  //
   226  // TODO(aram): make this panic once we stop calling fcntl(2) in net using it.
   227  func syscall_rawsyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
   228  	call := libcall{
   229  		fn:   uintptr(unsafe.Pointer(libc_syscall)),
   230  		n:    4,
   231  		args: uintptr(unsafe.Pointer(&trap)),
   232  	}
   233  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   234  	return call.r1, call.r2, call.err
   235  }
   236  
   237  //go:nosplit
   238  func syscall_setgid(gid uintptr) (err uintptr) {
   239  	call := libcall{
   240  		fn:   uintptr(unsafe.Pointer(libc_setgid)),
   241  		n:    1,
   242  		args: uintptr(unsafe.Pointer(&gid)),
   243  	}
   244  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   245  	return call.err
   246  }
   247  
   248  //go:nosplit
   249  func syscall_setgroups(ngid, gid uintptr) (err uintptr) {
   250  	call := libcall{
   251  		fn:   uintptr(unsafe.Pointer(libc_setgroups)),
   252  		n:    2,
   253  		args: uintptr(unsafe.Pointer(&ngid)),
   254  	}
   255  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   256  	return call.err
   257  }
   258  
   259  //go:nosplit
   260  func syscall_setsid() (pid, err uintptr) {
   261  	call := libcall{
   262  		fn:   uintptr(unsafe.Pointer(libc_setsid)),
   263  		n:    0,
   264  		args: uintptr(unsafe.Pointer(libc_setsid)), // it's unused but must be non-nil, otherwise crashes
   265  	}
   266  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   267  	return call.r1, call.err
   268  }
   269  
   270  //go:nosplit
   271  func syscall_setuid(uid uintptr) (err uintptr) {
   272  	call := libcall{
   273  		fn:   uintptr(unsafe.Pointer(libc_setuid)),
   274  		n:    1,
   275  		args: uintptr(unsafe.Pointer(&uid)),
   276  	}
   277  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   278  	return call.err
   279  }
   280  
   281  //go:nosplit
   282  func syscall_setpgid(pid, pgid uintptr) (err uintptr) {
   283  	call := libcall{
   284  		fn:   uintptr(unsafe.Pointer(libc_setpgid)),
   285  		n:    2,
   286  		args: uintptr(unsafe.Pointer(&pid)),
   287  	}
   288  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   289  	return call.err
   290  }
   291  
   292  // This is syscall.Syscall, it exists to satisfy some build dependency,
   293  // but it doesn't work correctly.
   294  //
   295  // DO NOT USE!
   296  //
   297  // TODO(aram): make this panic once we stop calling fcntl(2) in net using it.
   298  func syscall_syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
   299  	call := libcall{
   300  		fn:   uintptr(unsafe.Pointer(libc_syscall)),
   301  		n:    4,
   302  		args: uintptr(unsafe.Pointer(&trap)),
   303  	}
   304  	entersyscallblock(0)
   305  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   306  	exitsyscall(0)
   307  	return call.r1, call.r2, call.err
   308  }
   309  
   310  func syscall_wait4(pid uintptr, wstatus *uint32, options uintptr, rusage unsafe.Pointer) (wpid int, err uintptr) {
   311  	call := libcall{
   312  		fn:   uintptr(unsafe.Pointer(libc_wait4)),
   313  		n:    4,
   314  		args: uintptr(unsafe.Pointer(&pid)),
   315  	}
   316  	entersyscallblock(0)
   317  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   318  	exitsyscall(0)
   319  	return int(call.r1), call.err
   320  }
   321  
   322  //go:nosplit
   323  func syscall_write(fd, buf, nbyte uintptr) (n, err uintptr) {
   324  	call := libcall{
   325  		fn:   uintptr(unsafe.Pointer(libc_write)),
   326  		n:    3,
   327  		args: uintptr(unsafe.Pointer(&fd)),
   328  	}
   329  	asmcgocall(unsafe.Pointer(&asmsysvicall6), unsafe.Pointer(&call))
   330  	return call.r1, call.err
   331  }