...
Run Format

Source file src/runtime/syscall_solaris.go

Documentation: runtime

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

View as plain text