2018-23-01 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / go / runtime / os_freebsd.go
blob8c3535b893b20c5250453d9c7f942a8293a1185e
1 // Copyright 2011 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.
5 package runtime
7 import (
8 "unsafe"
11 type mOS struct {
12 unused byte
15 //go:noescape
16 //extern _umtx_op
17 func sys_umtx_op(addr *uint32, mode int32, val uint32, uaddr1 uinptr, ts *umtx_time) int32
19 func getPageSize() uintptr {
20 mib := [2]uint32{_CTL_HW, _HW_PAGESIZE}
21 out := uint32(0)
22 nout := unsafe.Sizeof(out)
23 ret := sysctl(&mib[0], 2, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0)
24 if ret >= 0 {
25 return uintptr(out)
27 return 0
30 // FreeBSD's umtx_op syscall is effectively the same as Linux's futex, and
31 // thus the code is largely similar. See Linux implementation
32 // and lock_futex.go for comments.
34 //go:nosplit
35 func futexsleep(addr *uint32, val uint32, ns int64) {
36 systemstack(func() {
37 futexsleep1(addr, val, ns)
41 func futexsleep1(addr *uint32, val uint32, ns int64) {
42 var utp *umtx_time
43 if ns >= 0 {
44 var ut umtx_time
45 ut._clockid = _CLOCK_MONOTONIC
46 ut._timeout.set_sec(int64(timediv(ns, 1000000000, (*int32)(unsafe.Pointer(&ut._timeout.tv_nsec)))))
47 utp = &ut
49 ret := sys_umtx_op(addr, _UMTX_OP_WAIT_UINT_PRIVATE, val, unsafe.Sizeof(*utp), utp)
50 if ret >= 0 || ret == -_EINTR {
51 return
53 print("umtx_wait addr=", addr, " val=", val, " ret=", ret, "\n")
54 *(*int32)(unsafe.Pointer(uintptr(0x1005))) = 0x1005
57 //go:nosplit
58 func futexwakeup(addr *uint32, cnt uint32) {
59 ret := sys_umtx_op(addr, _UMTX_OP_WAKE_PRIVATE, cnt, 0, nil)
60 if ret >= 0 {
61 return
64 systemstack(func() {
65 print("umtx_wake_addr=", addr, " ret=", ret, "\n")