1 // Copyright 2009 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.
11 // For C code to call:
18 // Called to initialize a new m (including the bootstrap m).
19 // Called on the parent thread (main thread in case of bootstrap), can allocate memory.
20 func mpreinit(mp *m) {
21 mp.gsignal = malg(true, true, &mp.gsignalstack, &mp.gsignalstacksize)
25 // minit is called to initialize a new m (including the bootstrap m).
26 // Called on the new thread, cannot allocate memory.
30 // FIXME: only works on linux for now.
31 getg().m.procid = uint64(gettid())
34 // Called from dropm to undo the effect of an minit.
36 //go:nowritebarrierrec
41 var urandom_dev = []byte("/dev/urandom\x00")
43 func getRandomData(r []byte) {
44 if startupRandomData != nil {
45 n := copy(r, startupRandomData)
49 fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0)
50 n := read(fd, unsafe.Pointer(&r[0]), int32(len(r)))
52 extendRandom(r, int(n))
57 func libcPipe(*[2]int32) int32
59 func pipe() (r, w int32, e int32) {
70 func libcPipe2(*[2]int32, int32) int32
72 func pipe2(flags int32) (r, w int32, e int32) {
74 res := libcPipe2(&p, flags)
81 //extern __go_fcntl_uintptr
82 func fcntlUintptr(fd, cmd, arg uintptr) (uintptr, uintptr)
85 func closeonexec(fd int32) {
86 fcntlUintptr(uintptr(fd), _F_SETFD, _FD_CLOEXEC)
90 func setNonblock(fd int32) {
91 flags, errno := fcntlUintptr(uintptr(fd), _F_GETFL, 0)
93 fcntlUintptr(uintptr(fd), _F_SETFL, flags|_O_NONBLOCK)