github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/src/runtime/syscall_aix.go (about)

     1  // Copyright 2018 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  // This file handles some syscalls from the syscall package
    10  // Especially, syscalls use during forkAndExecInChild which must not split the stack
    11  
    12  //go:cgo_import_dynamic libc_chdir chdir "libc.a/shr_64.o"
    13  //go:cgo_import_dynamic libc_chroot chroot "libc.a/shr_64.o"
    14  //go:cgo_import_dynamic libc_dup2 dup2 "libc.a/shr_64.o"
    15  //go:cgo_import_dynamic libc_execve execve "libc.a/shr_64.o"
    16  //go:cgo_import_dynamic libc_fcntl fcntl "libc.a/shr_64.o"
    17  //go:cgo_import_dynamic libc_fork fork "libc.a/shr_64.o"
    18  //go:cgo_import_dynamic libc_ioctl ioctl "libc.a/shr_64.o"
    19  //go:cgo_import_dynamic libc_setgid setgid "libc.a/shr_64.o"
    20  //go:cgo_import_dynamic libc_setgroups setgroups "libc.a/shr_64.o"
    21  //go:cgo_import_dynamic libc_setsid setsid "libc.a/shr_64.o"
    22  //go:cgo_import_dynamic libc_setuid setuid "libc.a/shr_64.o"
    23  //go:cgo_import_dynamic libc_setpgid setpgid "libc.a/shr_64.o"
    24  
    25  //go:linkname libc_chdir libc_chdir
    26  //go:linkname libc_chroot libc_chroot
    27  //go:linkname libc_dup2 libc_dup2
    28  //go:linkname libc_execve libc_execve
    29  //go:linkname libc_fcntl libc_fcntl
    30  //go:linkname libc_fork libc_fork
    31  //go:linkname libc_ioctl libc_ioctl
    32  //go:linkname libc_setgid libc_setgid
    33  //go:linkname libc_setgroups libc_setgroups
    34  //go:linkname libc_setsid libc_setsid
    35  //go:linkname libc_setuid libc_setuid
    36  //go:linkname libc_setpgid libc_setpgid
    37  
    38  var (
    39  	libc_chdir,
    40  	libc_chroot,
    41  	libc_dup2,
    42  	libc_execve,
    43  	libc_fcntl,
    44  	libc_fork,
    45  	libc_ioctl,
    46  	libc_setgid,
    47  	libc_setgroups,
    48  	libc_setsid,
    49  	libc_setuid,
    50  	libc_setpgid libFunc
    51  )
    52  
    53  // In syscall_syscall6 and syscall_rawsyscall6, r2 is always 0
    54  // as it's never used on AIX
    55  // TODO: remove r2 from zsyscall_aix_$GOARCH.go
    56  
    57  // Syscall is needed because some packages (like net) need it too.
    58  // The best way is to return EINVAL and let Golang handles its failure
    59  // If the syscall can't fail, this function can redirect it to a real syscall.
    60  //go:linkname syscall_Syscall syscall.Syscall
    61  //go:nosplit
    62  func syscall_Syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
    63  	return 0, 0, _EINVAL
    64  }
    65  
    66  // This is syscall.RawSyscall, it exists to satisfy some build dependency,
    67  // but it doesn't work.
    68  //go:linkname syscall_RawSyscall syscall.RawSyscall
    69  func syscall_RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
    70  	panic("RawSyscall not available on AIX")
    71  }
    72  
    73  //go:linkname syscall_syscall6 syscall.syscall6
    74  //go:nosplit
    75  func syscall_syscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
    76  	c := getg().m.libcall
    77  	c.fn = uintptr(unsafe.Pointer(fn))
    78  	c.n = nargs
    79  	c.args = uintptr(noescape(unsafe.Pointer(&a1)))
    80  
    81  	entersyscallblock()
    82  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
    83  	exitsyscall()
    84  	return c.r1, 0, c.err
    85  }
    86  
    87  //go:linkname syscall_rawSyscall6 syscall.rawSyscall6
    88  //go:nosplit
    89  func syscall_rawSyscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
    90  	c := getg().m.libcall
    91  	c.fn = uintptr(unsafe.Pointer(fn))
    92  	c.n = nargs
    93  	c.args = uintptr(noescape(unsafe.Pointer(&a1)))
    94  
    95  	asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c))
    96  
    97  	return c.r1, 0, c.err
    98  }
    99  
   100  //go:linkname syscall_chdir syscall.chdir
   101  //go:nosplit
   102  func syscall_chdir(path uintptr) (err uintptr) {
   103  	_, err = syscall1(&libc_chdir, path)
   104  	return
   105  }
   106  
   107  //go:linkname syscall_chroot1 syscall.chroot1
   108  //go:nosplit
   109  func syscall_chroot1(path uintptr) (err uintptr) {
   110  	_, err = syscall1(&libc_chroot, path)
   111  	return
   112  }
   113  
   114  // like close, but must not split stack, for fork.
   115  //go:linkname syscall_close syscall.close
   116  //go:nosplit
   117  func syscall_close(fd int32) int32 {
   118  	_, err := syscall1(&libc_close, uintptr(fd))
   119  	return int32(err)
   120  }
   121  
   122  //go:linkname syscall_dup2child syscall.dup2child
   123  //go:nosplit
   124  func syscall_dup2child(old, new uintptr) (val, err uintptr) {
   125  	val, err = syscall2(&libc_dup2, old, new)
   126  	return
   127  }
   128  
   129  //go:linkname syscall_execve syscall.execve
   130  //go:nosplit
   131  func syscall_execve(path, argv, envp uintptr) (err uintptr) {
   132  	_, err = syscall3(&libc_execve, path, argv, envp)
   133  	return
   134  }
   135  
   136  // like exit, but must not split stack, for fork.
   137  //go:linkname syscall_exit syscall.exit
   138  //go:nosplit
   139  func syscall_exit(code uintptr) {
   140  	syscall1(&libc_exit, code)
   141  }
   142  
   143  //go:linkname syscall_fcntl1 syscall.fcntl1
   144  //go:nosplit
   145  func syscall_fcntl1(fd, cmd, arg uintptr) (val, err uintptr) {
   146  	val, err = syscall3(&libc_fcntl, fd, cmd, arg)
   147  	return
   148  
   149  }
   150  
   151  //go:linkname syscall_forkx syscall.forkx
   152  //go:nosplit
   153  func syscall_forkx(flags uintptr) (pid uintptr, err uintptr) {
   154  	pid, err = syscall1(&libc_fork, flags)
   155  	return
   156  }
   157  
   158  //go:linkname syscall_getpid syscall.getpid
   159  //go:nosplit
   160  func syscall_getpid() (pid, err uintptr) {
   161  	pid, err = syscall0(&libc_getpid)
   162  	return
   163  }
   164  
   165  //go:linkname syscall_ioctl syscall.ioctl
   166  //go:nosplit
   167  func syscall_ioctl(fd, req, arg uintptr) (err uintptr) {
   168  	_, err = syscall3(&libc_ioctl, fd, req, arg)
   169  	return
   170  }
   171  
   172  //go:linkname syscall_setgid syscall.setgid
   173  //go:nosplit
   174  func syscall_setgid(gid uintptr) (err uintptr) {
   175  	_, err = syscall1(&libc_setgid, gid)
   176  	return
   177  }
   178  
   179  //go:linkname syscall_setgroups1 syscall.setgroups1
   180  //go:nosplit
   181  func syscall_setgroups1(ngid, gid uintptr) (err uintptr) {
   182  	_, err = syscall2(&libc_setgroups, ngid, gid)
   183  	return
   184  }
   185  
   186  //go:linkname syscall_setsid syscall.setsid
   187  //go:nosplit
   188  func syscall_setsid() (pid, err uintptr) {
   189  	pid, err = syscall0(&libc_setsid)
   190  	return
   191  }
   192  
   193  //go:linkname syscall_setuid syscall.setuid
   194  //go:nosplit
   195  func syscall_setuid(uid uintptr) (err uintptr) {
   196  	_, err = syscall1(&libc_setuid, uid)
   197  	return
   198  }
   199  
   200  //go:linkname syscall_setpgid syscall.setpgid
   201  //go:nosplit
   202  func syscall_setpgid(pid, pgid uintptr) (err uintptr) {
   203  	_, err = syscall2(&libc_setpgid, pid, pgid)
   204  	return
   205  }
   206  
   207  //go:linkname syscall_write1 syscall.write1
   208  //go:nosplit
   209  func syscall_write1(fd, buf, nbyte uintptr) (n, err uintptr) {
   210  	n, err = syscall3(&libc_write, fd, buf, nbyte)
   211  	return
   212  }