github.com/comwrg/go/src@v0.0.0-20220319063731-c238d0440370/runtime/sys_openbsd2.go (about)

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