github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/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:nosplit 61 func syscall_Syscall(fn, a1, a2, a3 uintptr) (r1, r2, err uintptr) { 62 return 0, 0, _EINVAL 63 } 64 65 // This is syscall.RawSyscall, it exists to satisfy some build dependency, 66 // but it doesn't work. 67 func syscall_RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) { 68 panic("RawSyscall not available on AIX") 69 } 70 71 //go:nosplit 72 func syscall_syscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) { 73 c := getg().m.libcall 74 c.fn = uintptr(unsafe.Pointer(fn)) 75 c.n = nargs 76 c.args = uintptr(noescape(unsafe.Pointer(&a1))) 77 78 entersyscallblock() 79 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c)) 80 exitsyscall() 81 return c.r1, 0, c.err 82 } 83 84 //go:nosplit 85 func syscall_rawSyscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) { 86 c := getg().m.libcall 87 c.fn = uintptr(unsafe.Pointer(fn)) 88 c.n = nargs 89 c.args = uintptr(noescape(unsafe.Pointer(&a1))) 90 91 asmcgocall(unsafe.Pointer(&asmsyscall6), unsafe.Pointer(&c)) 92 93 return c.r1, 0, c.err 94 } 95 96 //go:linkname syscall_chdir syscall.chdir 97 //go:nosplit 98 func syscall_chdir(path uintptr) (err uintptr) { 99 _, err = syscall1(&libc_chdir, path) 100 return 101 } 102 103 //go:linkname syscall_chroot1 syscall.chroot1 104 //go:nosplit 105 func syscall_chroot1(path uintptr) (err uintptr) { 106 _, err = syscall1(&libc_chroot, path) 107 return 108 } 109 110 // like close, but must not split stack, for fork. 111 //go:linkname syscall_close syscall.close 112 //go:nosplit 113 func syscall_close(fd int32) int32 { 114 _, err := syscall1(&libc_close, uintptr(fd)) 115 return int32(err) 116 } 117 118 //go:linkname syscall_dup2child syscall.dup2child 119 //go:nosplit 120 func syscall_dup2child(old, new uintptr) (val, err uintptr) { 121 val, err = syscall2(&libc_dup2, old, new) 122 return 123 } 124 125 //go:linkname syscall_execve syscall.execve 126 //go:nosplit 127 func syscall_execve(path, argv, envp uintptr) (err uintptr) { 128 _, err = syscall3(&libc_execve, path, argv, envp) 129 return 130 } 131 132 // like exit, but must not split stack, for fork. 133 //go:linkname syscall_exit syscall.exit 134 //go:nosplit 135 func syscall_exit(code uintptr) { 136 syscall1(&libc_exit, code) 137 } 138 139 //go:linkname syscall_fcntl1 syscall.fcntl1 140 //go:nosplit 141 func syscall_fcntl1(fd, cmd, arg uintptr) (val, err uintptr) { 142 val, err = syscall3(&libc_fcntl, fd, cmd, arg) 143 return 144 145 } 146 147 //go:linkname syscall_forkx syscall.forkx 148 //go:nosplit 149 func syscall_forkx(flags uintptr) (pid uintptr, err uintptr) { 150 pid, err = syscall1(&libc_fork, flags) 151 return 152 } 153 154 //go:linkname syscall_getpid syscall.getpid 155 //go:nosplit 156 func syscall_getpid() (pid, err uintptr) { 157 pid, err = syscall0(&libc_getpid) 158 return 159 } 160 161 //go:linkname syscall_ioctl syscall.ioctl 162 //go:nosplit 163 func syscall_ioctl(fd, req, arg uintptr) (err uintptr) { 164 _, err = syscall3(&libc_ioctl, fd, req, arg) 165 return 166 } 167 168 //go:linkname syscall_setgid syscall.setgid 169 //go:nosplit 170 func syscall_setgid(gid uintptr) (err uintptr) { 171 _, err = syscall1(&libc_setgid, gid) 172 return 173 } 174 175 //go:linkname syscall_setgroups1 syscall.setgroups1 176 //go:nosplit 177 func syscall_setgroups1(ngid, gid uintptr) (err uintptr) { 178 _, err = syscall2(&libc_setgroups, ngid, gid) 179 return 180 } 181 182 //go:linkname syscall_setsid syscall.setsid 183 //go:nosplit 184 func syscall_setsid() (pid, err uintptr) { 185 pid, err = syscall0(&libc_setsid) 186 return 187 } 188 189 //go:linkname syscall_setuid syscall.setuid 190 //go:nosplit 191 func syscall_setuid(uid uintptr) (err uintptr) { 192 _, err = syscall1(&libc_setuid, uid) 193 return 194 } 195 196 //go:linkname syscall_setpgid syscall.setpgid 197 //go:nosplit 198 func syscall_setpgid(pid, pgid uintptr) (err uintptr) { 199 _, err = syscall2(&libc_setpgid, pid, pgid) 200 return 201 } 202 203 //go:linkname syscall_write1 syscall.write1 204 //go:nosplit 205 func syscall_write1(fd, buf, nbyte uintptr) (n, err uintptr) { 206 n, err = syscall3(&libc_write, fd, buf, nbyte) 207 return 208 }