...

Source file src/runtime/sys_openbsd2.go

Documentation: runtime

		 1  // Copyright 2020 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  //go:build openbsd
		 6  // +build openbsd
		 7  
		 8  package runtime
		 9  
		10  import "unsafe"
		11  
		12  // This is exported via linkname to assembly in runtime/cgo.
		13  //go:linkname exit
		14  //go:nosplit
		15  //go:cgo_unsafe_args
		16  func exit(code int32) {
		17  	libcCall(unsafe.Pointer(funcPC(exit_trampoline)), unsafe.Pointer(&code))
		18  }
		19  func exit_trampoline()
		20  
		21  //go:nosplit
		22  //go:cgo_unsafe_args
		23  func getthrid() (tid int32) {
		24  	libcCall(unsafe.Pointer(funcPC(getthrid_trampoline)), unsafe.Pointer(&tid))
		25  	return
		26  }
		27  func getthrid_trampoline()
		28  
		29  //go:nosplit
		30  //go:cgo_unsafe_args
		31  func raiseproc(sig uint32) {
		32  	libcCall(unsafe.Pointer(funcPC(raiseproc_trampoline)), unsafe.Pointer(&sig))
		33  }
		34  func raiseproc_trampoline()
		35  
		36  //go:nosplit
		37  //go:cgo_unsafe_args
		38  func thrkill(tid int32, sig int) {
		39  	// TODO(jsing): sig should really be uint32 rather than a Go int,
		40  	// which switches between int32 and int64 depending on arch.
		41  	libcCall(unsafe.Pointer(funcPC(thrkill_trampoline)), unsafe.Pointer(&tid))
		42  }
		43  func thrkill_trampoline()
		44  
		45  // mmap is used to do low-level memory allocation via mmap. Don't allow stack
		46  // splits, since this function (used by sysAlloc) is called in a lot of low-level
		47  // parts of the runtime and callers often assume it won't acquire any locks.
		48  // go:nosplit
		49  func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uint32) (unsafe.Pointer, int) {
		50  	args := struct {
		51  		addr						unsafe.Pointer
		52  		n							 uintptr
		53  		prot, flags, fd int32
		54  		off						 uint32
		55  		ret1						unsafe.Pointer
		56  		ret2						int
		57  	}{addr, n, prot, flags, fd, off, nil, 0}
		58  	libcCall(unsafe.Pointer(funcPC(mmap_trampoline)), unsafe.Pointer(&args))
		59  	KeepAlive(addr) // Just for consistency. Hopefully addr is not a Go address.
		60  	return args.ret1, args.ret2
		61  }
		62  func mmap_trampoline()
		63  
		64  //go:nosplit
		65  //go:cgo_unsafe_args
		66  func munmap(addr unsafe.Pointer, n uintptr) {
		67  	libcCall(unsafe.Pointer(funcPC(munmap_trampoline)), unsafe.Pointer(&addr))
		68  	KeepAlive(addr) // Just for consistency. Hopefully addr is not a Go address.
		69  }
		70  func munmap_trampoline()
		71  
		72  //go:nosplit
		73  //go:cgo_unsafe_args
		74  func madvise(addr unsafe.Pointer, n uintptr, flags int32) {
		75  	libcCall(unsafe.Pointer(funcPC(madvise_trampoline)), unsafe.Pointer(&addr))
		76  	KeepAlive(addr) // Just for consistency. Hopefully addr is not a Go address.
		77  }
		78  func madvise_trampoline()
		79  
		80  //go:nosplit
		81  //go:cgo_unsafe_args
		82  func open(name *byte, mode, perm int32) (ret int32) {
		83  	ret = libcCall(unsafe.Pointer(funcPC(open_trampoline)), unsafe.Pointer(&name))
		84  	KeepAlive(name)
		85  	return
		86  }
		87  func open_trampoline()
		88  
		89  //go:nosplit
		90  //go:cgo_unsafe_args
		91  func closefd(fd int32) int32 {
		92  	return libcCall(unsafe.Pointer(funcPC(close_trampoline)), unsafe.Pointer(&fd))
		93  }
		94  func close_trampoline()
		95  
		96  //go:nosplit
		97  //go:cgo_unsafe_args
		98  func read(fd int32, p unsafe.Pointer, n int32) int32 {
		99  	ret := libcCall(unsafe.Pointer(funcPC(read_trampoline)), unsafe.Pointer(&fd))
	 100  	KeepAlive(p)
	 101  	return ret
	 102  }
	 103  func read_trampoline()
	 104  
	 105  //go:nosplit
	 106  //go:cgo_unsafe_args
	 107  func write1(fd uintptr, p unsafe.Pointer, n int32) int32 {
	 108  	ret := libcCall(unsafe.Pointer(funcPC(write_trampoline)), unsafe.Pointer(&fd))
	 109  	KeepAlive(p)
	 110  	return ret
	 111  }
	 112  func write_trampoline()
	 113  
	 114  func pipe() (r, w int32, errno int32) {
	 115  	return pipe2(0)
	 116  }
	 117  
	 118  func pipe2(flags int32) (r, w int32, errno int32) {
	 119  	var p [2]int32
	 120  	args := struct {
	 121  		p		 unsafe.Pointer
	 122  		flags int32
	 123  	}{noescape(unsafe.Pointer(&p)), flags}
	 124  	errno = libcCall(unsafe.Pointer(funcPC(pipe2_trampoline)), unsafe.Pointer(&args))
	 125  	return p[0], p[1], errno
	 126  }
	 127  func pipe2_trampoline()
	 128  
	 129  //go:nosplit
	 130  //go:cgo_unsafe_args
	 131  func setitimer(mode int32, new, old *itimerval) {
	 132  	libcCall(unsafe.Pointer(funcPC(setitimer_trampoline)), unsafe.Pointer(&mode))
	 133  	KeepAlive(new)
	 134  	KeepAlive(old)
	 135  }
	 136  func setitimer_trampoline()
	 137  
	 138  //go:nosplit
	 139  //go:cgo_unsafe_args
	 140  func usleep(usec uint32) {
	 141  	libcCall(unsafe.Pointer(funcPC(usleep_trampoline)), unsafe.Pointer(&usec))
	 142  }
	 143  func usleep_trampoline()
	 144  
	 145  //go:nosplit
	 146  //go:cgo_unsafe_args
	 147  func usleep_no_g(usec uint32) {
	 148  	asmcgocall_no_g(unsafe.Pointer(funcPC(usleep_trampoline)), unsafe.Pointer(&usec))
	 149  }
	 150  
	 151  //go:nosplit
	 152  //go:cgo_unsafe_args
	 153  func sysctl(mib *uint32, miblen uint32, out *byte, size *uintptr, dst *byte, ndst uintptr) int32 {
	 154  	ret := libcCall(unsafe.Pointer(funcPC(sysctl_trampoline)), unsafe.Pointer(&mib))
	 155  	KeepAlive(mib)
	 156  	KeepAlive(out)
	 157  	KeepAlive(size)
	 158  	KeepAlive(dst)
	 159  	return ret
	 160  }
	 161  func sysctl_trampoline()
	 162  
	 163  //go:nosplit
	 164  //go:cgo_unsafe_args
	 165  func fcntl(fd, cmd, arg int32) int32 {
	 166  	return libcCall(unsafe.Pointer(funcPC(fcntl_trampoline)), unsafe.Pointer(&fd))
	 167  }
	 168  func fcntl_trampoline()
	 169  
	 170  //go:nosplit
	 171  func nanotime1() int64 {
	 172  	var ts timespec
	 173  	args := struct {
	 174  		clock_id int32
	 175  		tp			 unsafe.Pointer
	 176  	}{_CLOCK_MONOTONIC, unsafe.Pointer(&ts)}
	 177  	libcCall(unsafe.Pointer(funcPC(clock_gettime_trampoline)), unsafe.Pointer(&args))
	 178  	return ts.tv_sec*1e9 + int64(ts.tv_nsec)
	 179  }
	 180  func clock_gettime_trampoline()
	 181  
	 182  //go:nosplit
	 183  func walltime() (int64, int32) {
	 184  	var ts timespec
	 185  	args := struct {
	 186  		clock_id int32
	 187  		tp			 unsafe.Pointer
	 188  	}{_CLOCK_REALTIME, unsafe.Pointer(&ts)}
	 189  	libcCall(unsafe.Pointer(funcPC(clock_gettime_trampoline)), unsafe.Pointer(&args))
	 190  	return ts.tv_sec, int32(ts.tv_nsec)
	 191  }
	 192  
	 193  //go:nosplit
	 194  //go:cgo_unsafe_args
	 195  func kqueue() int32 {
	 196  	return libcCall(unsafe.Pointer(funcPC(kqueue_trampoline)), nil)
	 197  }
	 198  func kqueue_trampoline()
	 199  
	 200  //go:nosplit
	 201  //go:cgo_unsafe_args
	 202  func kevent(kq int32, ch *keventt, nch int32, ev *keventt, nev int32, ts *timespec) int32 {
	 203  	ret := libcCall(unsafe.Pointer(funcPC(kevent_trampoline)), unsafe.Pointer(&kq))
	 204  	KeepAlive(ch)
	 205  	KeepAlive(ev)
	 206  	KeepAlive(ts)
	 207  	return ret
	 208  }
	 209  func kevent_trampoline()
	 210  
	 211  //go:nosplit
	 212  //go:cgo_unsafe_args
	 213  func sigaction(sig uint32, new *sigactiont, old *sigactiont) {
	 214  	libcCall(unsafe.Pointer(funcPC(sigaction_trampoline)), unsafe.Pointer(&sig))
	 215  	KeepAlive(new)
	 216  	KeepAlive(old)
	 217  }
	 218  func sigaction_trampoline()
	 219  
	 220  //go:nosplit
	 221  //go:cgo_unsafe_args
	 222  func sigprocmask(how uint32, new *sigset, old *sigset) {
	 223  	// sigprocmask is called from sigsave, which is called from needm.
	 224  	// As such, we have to be able to run with no g here.
	 225  	asmcgocall_no_g(unsafe.Pointer(funcPC(sigprocmask_trampoline)), unsafe.Pointer(&how))
	 226  	KeepAlive(new)
	 227  	KeepAlive(old)
	 228  }
	 229  func sigprocmask_trampoline()
	 230  
	 231  //go:nosplit
	 232  //go:cgo_unsafe_args
	 233  func sigaltstack(new *stackt, old *stackt) {
	 234  	libcCall(unsafe.Pointer(funcPC(sigaltstack_trampoline)), unsafe.Pointer(&new))
	 235  	KeepAlive(new)
	 236  	KeepAlive(old)
	 237  }
	 238  func sigaltstack_trampoline()
	 239  
	 240  // Not used on OpenBSD, but must be defined.
	 241  func exitThread(wait *uint32) {
	 242  }
	 243  
	 244  //go:nosplit
	 245  func closeonexec(fd int32) {
	 246  	fcntl(fd, _F_SETFD, _FD_CLOEXEC)
	 247  }
	 248  
	 249  //go:nosplit
	 250  func setNonblock(fd int32) {
	 251  	flags := fcntl(fd, _F_GETFL, 0)
	 252  	fcntl(fd, _F_SETFL, flags|_O_NONBLOCK)
	 253  }
	 254  
	 255  // Tell the linker that the libc_* functions are to be found
	 256  // in a system library, with the libc_ prefix missing.
	 257  
	 258  //go:cgo_import_dynamic libc_errno __errno "libc.so"
	 259  //go:cgo_import_dynamic libc_exit exit "libc.so"
	 260  //go:cgo_import_dynamic libc_getthrid getthrid "libc.so"
	 261  //go:cgo_import_dynamic libc_sched_yield sched_yield "libc.so"
	 262  //go:cgo_import_dynamic libc_thrkill thrkill "libc.so"
	 263  
	 264  //go:cgo_import_dynamic libc_mmap mmap "libc.so"
	 265  //go:cgo_import_dynamic libc_munmap munmap "libc.so"
	 266  //go:cgo_import_dynamic libc_madvise madvise "libc.so"
	 267  
	 268  //go:cgo_import_dynamic libc_open open "libc.so"
	 269  //go:cgo_import_dynamic libc_close close "libc.so"
	 270  //go:cgo_import_dynamic libc_read read "libc.so"
	 271  //go:cgo_import_dynamic libc_write write "libc.so"
	 272  //go:cgo_import_dynamic libc_pipe2 pipe2 "libc.so"
	 273  
	 274  //go:cgo_import_dynamic libc_clock_gettime clock_gettime "libc.so"
	 275  //go:cgo_import_dynamic libc_setitimer setitimer "libc.so"
	 276  //go:cgo_import_dynamic libc_usleep usleep "libc.so"
	 277  //go:cgo_import_dynamic libc_sysctl sysctl "libc.so"
	 278  //go:cgo_import_dynamic libc_fcntl fcntl "libc.so"
	 279  //go:cgo_import_dynamic libc_getpid getpid "libc.so"
	 280  //go:cgo_import_dynamic libc_kill kill "libc.so"
	 281  //go:cgo_import_dynamic libc_kqueue kqueue "libc.so"
	 282  //go:cgo_import_dynamic libc_kevent kevent "libc.so"
	 283  
	 284  //go:cgo_import_dynamic libc_sigaction sigaction "libc.so"
	 285  //go:cgo_import_dynamic libc_sigaltstack sigaltstack "libc.so"
	 286  
	 287  //go:cgo_import_dynamic _ _ "libc.so"
	 288  

View as plain text