gopkg.in/ro-ag/posix.v1@v1.0.6/posix_darwin.go (about) 1 package posix 2 3 import ( 4 "unsafe" 5 ) 6 7 type Timespec struct { 8 Sec int64 9 Nsec int64 10 } 11 12 type ModeT uint16 13 type DevT int32 14 15 type Stat_t struct { 16 Dev DevT 17 Mode ModeT 18 Nlink uint16 19 Ino uint64 20 Uid uint32 21 Gid uint32 22 Rdev DevT 23 Atim Timespec 24 Mtim Timespec 25 Ctim Timespec 26 Btim Timespec 27 Size int64 28 Blocks int64 29 Blksize int32 30 Flags uint32 31 Gen uint32 32 Lspare int32 33 Qspare [2]int64 34 } 35 36 /* -------------------------------------------------------------------------------------------------------------------*/ 37 func madvise(b []byte, behav int) (err error) { 38 var _p0 unsafe.Pointer 39 if len(b) > 0 { 40 _p0 = unsafe.Pointer(&b[0]) 41 } else { 42 _p0 = unsafe.Pointer(&_zero) 43 } 44 _, _, e1 := syscall_syscall(libc_madvise_trampoline_addr, uintptr(_p0), uintptr(len(b)), uintptr(behav)) 45 if e1 != 0 { 46 err = errnoErr(e1) 47 } 48 return 49 } 50 51 var libc_madvise_trampoline_addr uintptr 52 53 //go:cgo_import_dynamic libc_madvise madvise "/usr/lib/libSystem.B.dylib" 54 55 /* -------------------------------------------------------------------------------------------------------------------*/ 56 57 func mlock(b []byte, size int) (err error) { 58 var _p0 unsafe.Pointer 59 if len(b) > 0 { 60 _p0 = unsafe.Pointer(&b[0]) 61 } else { 62 _p0 = unsafe.Pointer(&_zero) 63 } 64 _, _, e1 := syscall_syscall(libc_mlock_trampoline_addr, uintptr(_p0), uintptr(size), 0) 65 if e1 != 0 { 66 err = errnoErr(e1) 67 } 68 return 69 } 70 71 var libc_mlock_trampoline_addr uintptr 72 73 //go:cgo_import_dynamic libc_mlock mlock "/usr/lib/libSystem.B.dylib" 74 75 /* -------------------------------------------------------------------------------------------------------------------*/ 76 77 func mlockall(flags int) (err error) { 78 _, _, e1 := syscall_syscall(libc_mlockall_trampoline_addr, uintptr(flags), 0, 0) 79 if e1 != 0 { 80 err = errnoErr(e1) 81 } 82 return 83 } 84 85 var libc_mlockall_trampoline_addr uintptr 86 87 //go:cgo_import_dynamic libc_mlockall mlockall "/usr/lib/libSystem.B.dylib" 88 89 /* -------------------------------------------------------------------------------------------------------------------*/ 90 91 func munlock(b []byte, size int) (err error) { 92 var _p0 unsafe.Pointer 93 if len(b) > 0 { 94 _p0 = unsafe.Pointer(&b[0]) 95 } else { 96 _p0 = unsafe.Pointer(&_zero) 97 } 98 _, _, e1 := syscall_syscall(libc_munlock_trampoline_addr, uintptr(_p0), uintptr(size), 0) 99 if e1 != 0 { 100 err = errnoErr(e1) 101 } 102 return 103 } 104 105 var libc_munlock_trampoline_addr uintptr 106 107 //go:cgo_import_dynamic libc_munlock munlock "/usr/lib/libSystem.B.dylib" 108 109 /* -------------------------------------------------------------------------------------------------------------------*/ 110 111 func munlockall() (err error) { 112 _, _, e1 := syscall_syscall(libc_munlockall_trampoline_addr, 0, 0, 0) 113 if e1 != 0 { 114 err = errnoErr(e1) 115 } 116 return 117 } 118 119 var libc_munlockall_trampoline_addr uintptr 120 121 //go:cgo_import_dynamic libc_munlockall munlockall "/usr/lib/libSystem.B.dylib" 122 123 /* -------------------------------------------------------------------------------------------------------------------*/ 124 func mprotect(b []byte, prot int) (err error) { 125 var _p0 unsafe.Pointer 126 if len(b) > 0 { 127 _p0 = unsafe.Pointer(&b[0]) 128 } else { 129 _p0 = unsafe.Pointer(&_zero) 130 } 131 _, _, e1 := syscall_syscall(libc_mprotect_trampoline_addr, uintptr(_p0), uintptr(len(b)), uintptr(prot)) 132 if e1 != 0 { 133 err = errnoErr(e1) 134 } 135 return 136 } 137 138 var libc_mprotect_trampoline_addr uintptr 139 140 //go:cgo_import_dynamic libc_mprotect mprotect "/usr/lib/libSystem.B.dylib" 141 142 /* -------------------------------------------------------------------------------------------------------------------*/ 143 func mmap(addr uintptr, length uintptr, prot int, flag int, fd int, pos int64) (ret uintptr, err error) { 144 r0, _, e1 := syscall_syscall6(libc_mmap_trampoline_addr, 145 uintptr(addr), uintptr(length), uintptr(prot), 146 uintptr(flag), uintptr(fd), uintptr(pos)) 147 ret = uintptr(r0) 148 if e1 != 0 { 149 err = errnoErr(e1) 150 } 151 return 152 } 153 154 var libc_mmap_trampoline_addr uintptr 155 156 //go:cgo_import_dynamic libc_mmap mmap "/usr/lib/libSystem.B.dylib" 157 158 /* -------------------------------------------------------------------------------------------------------------------*/ 159 func munmap(addr uintptr, length uintptr) (err error) { 160 _, _, e1 := syscall_syscall(libc_munmap_trampoline_addr, uintptr(addr), uintptr(length), 0) 161 if e1 != 0 { 162 err = errnoErr(e1) 163 } 164 return 165 } 166 167 var libc_munmap_trampoline_addr uintptr 168 169 //go:cgo_import_dynamic libc_munmap munmap "/usr/lib/libSystem.B.dylib" 170 171 /* -------------------------------------------------------------------------------------------------------------------*/ 172 func closeFd(fd int) (err error) { 173 _, _, e1 := syscall_syscall(libc_close_trampoline_addr, uintptr(fd), 0, 0) 174 if e1 != 0 { 175 err = errnoErr(e1) 176 } 177 return 178 } 179 180 var libc_close_trampoline_addr uintptr 181 182 //go:cgo_import_dynamic libc_close close "/usr/lib/libSystem.B.dylib" 183 184 /* -------------------------------------------------------------------------------------------------------------------*/ 185 186 func fcntl(fd int, cmd int, arg int) (val int, err error) { 187 r0, _, e1 := syscall_syscall(libc_fcntl_trampoline_addr, uintptr(fd), uintptr(cmd), uintptr(arg)) 188 val = int(r0) 189 if e1 != 0 { 190 err = errnoErr(e1) 191 } 192 return 193 } 194 195 var libc_fcntl_trampoline_addr uintptr 196 197 //go:cgo_import_dynamic libc_fcntl fcntl "/usr/lib/libSystem.B.dylib" 198 199 /* -------------------------------------------------------------------------------------------------------------------*/ 200 201 func ftruncate(fd int, length int) (err error) { 202 _, _, e1 := syscall_syscall(libc_ftruncate_trampoline_addr, uintptr(fd), uintptr(length), 0) 203 if e1 != 0 { 204 err = errnoErr(e1) 205 } 206 return 207 } 208 209 var libc_ftruncate_trampoline_addr uintptr 210 211 //go:cgo_import_dynamic libc_ftruncate ftruncate "/usr/lib/libSystem.B.dylib" 212 213 /* -------------------------------------------------------------------------------------------------------------------*/ 214 215 func fstat(fd int, stat *Stat_t) (err error) { 216 _, _, e1 := syscall_syscall(libc_fstat64_trampoline_addr, uintptr(fd), uintptr(unsafe.Pointer(stat)), 0) 217 if e1 != 0 { 218 err = errnoErr(e1) 219 } 220 return 221 } 222 223 var libc_fstat64_trampoline_addr uintptr 224 225 //go:cgo_import_dynamic libc_fstat64 fstat64 "/usr/lib/libSystem.B.dylib" 226 227 /* -------------------------------------------------------------------------------------------------------------------*/ 228 229 func fchown(fd int, uid int, gid int) (err error) { 230 if uid <= 0 && gid <= 0 { 231 return errnoErr(EINVAL) 232 } 233 _, _, e1 := syscall_syscall(libc_fchown_trampoline_addr, uintptr(fd), uintptr(uid), uintptr(gid)) 234 if e1 != 0 { 235 err = errnoErr(e1) 236 } 237 return 238 } 239 240 var libc_fchown_trampoline_addr uintptr 241 242 //go:cgo_import_dynamic libc_fchown fchown "/usr/lib/libSystem.B.dylib" 243 244 /* -------------------------------------------------------------------------------------------------------------------*/ 245 246 func fchmod(fd int, mode int) (err error) { 247 _, _, e1 := syscall_syscall(libc_fchmod_trampoline_addr, uintptr(fd), uintptr(mode), 0) 248 if e1 != 0 { 249 err = errnoErr(e1) 250 } 251 return 252 } 253 254 var libc_fchmod_trampoline_addr uintptr 255 256 //go:cgo_import_dynamic libc_fchmod fchmod "/usr/lib/libSystem.B.dylib" 257 258 /* -------------------------------------------------------------------------------------------------------------------*/ 259 260 func msync(b []byte, flags int) (err error) { 261 var _p0 unsafe.Pointer 262 if len(b) > 0 { 263 _p0 = unsafe.Pointer(&b[0]) 264 } else { 265 _p0 = unsafe.Pointer(&_zero) 266 } 267 _, _, e1 := syscall_syscall(libc_msync_trampoline_addr, uintptr(_p0), uintptr(len(b)), uintptr(flags)) 268 if e1 != 0 { 269 err = errnoErr(e1) 270 } 271 return 272 } 273 274 var libc_msync_trampoline_addr uintptr 275 276 //go:cgo_import_dynamic libc_msync msync "/usr/lib/libSystem.B.dylib" 277 278 /* -------------------------------------------------------------------------------------------------------------------*/ 279 // Implemented in the runtime package (runtime/sys_darwin.go) 280 func syscall_syscall(fn, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) 281 func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) 282 283 //go:linkname syscall_syscall syscall.syscall 284 //go:linkname syscall_syscall6 syscall.syscall6