github.com/hbdrawn/golang@v0.0.0-20141214014649-6b835209aba2/src/runtime/os_plan9.go (about) 1 // Copyright 2014 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 package runtime 6 7 import "unsafe" 8 9 //go:noescape 10 func pread(fd int32, buf unsafe.Pointer, nbytes int32, offset int64) int32 11 12 //go:noescape 13 func pwrite(fd int32, buf unsafe.Pointer, nbytes int32, offset int64) int32 14 15 func seek(fd int32, offset int64, whence int32) int64 16 17 //go:noescape 18 func exits(msg *byte) 19 20 //go:noescape 21 func brk_(addr unsafe.Pointer) uintptr 22 23 func sleep(ms int32) int32 24 25 func rfork(flags int32) int32 26 27 //go:noescape 28 func plan9_semacquire(addr *uint32, block int32) int32 29 30 //go:noescape 31 func plan9_tsemacquire(addr *uint32, ms int32) int32 32 33 //go:noescape 34 func plan9_semrelease(addr *uint32, count int32) int32 35 36 //go:noescape 37 func notify(fn unsafe.Pointer) int32 38 39 func noted(mode int32) int32 40 41 //go:noescape 42 func nsec(*int64) int64 43 44 //go:noescape 45 func sigtramp(ureg, msg unsafe.Pointer) 46 47 func setfpmasks() 48 49 //go:noescape 50 func tstart_plan9(newm *m) 51 52 func errstr() string 53 54 type _Plink uintptr 55 56 func os_sigpipe() { 57 gothrow("too many writes on closed pipe") 58 } 59 60 func sigpanic() { 61 g := getg() 62 if !canpanic(g) { 63 gothrow("unexpected signal during runtime execution") 64 } 65 66 note := gostringnocopy((*byte)(unsafe.Pointer(g.m.notesig))) 67 switch g.sig { 68 case _SIGRFAULT, _SIGWFAULT: 69 addr := note[index(note, "addr=")+5:] 70 g.sigcode1 = uintptr(atolwhex(addr)) 71 if g.sigcode1 < 0x1000 || g.paniconfault { 72 panicmem() 73 } 74 print("unexpected fault address ", hex(g.sigcode1), "\n") 75 gothrow("fault") 76 case _SIGTRAP: 77 if g.paniconfault { 78 panicmem() 79 } 80 gothrow(note) 81 case _SIGINTDIV: 82 panicdivide() 83 case _SIGFLOAT: 84 panicfloat() 85 default: 86 panic(errorString(note)) 87 } 88 } 89 90 func atolwhex(p string) int64 { 91 for hasprefix(p, " ") || hasprefix(p, "\t") { 92 p = p[1:] 93 } 94 neg := false 95 if hasprefix(p, "-") || hasprefix(p, "+") { 96 neg = p[0] == '-' 97 p = p[1:] 98 for hasprefix(p, " ") || hasprefix(p, "\t") { 99 p = p[1:] 100 } 101 } 102 var n int64 103 switch { 104 case hasprefix(p, "0x"), hasprefix(p, "0X"): 105 p = p[2:] 106 for ; len(p) > 0; p = p[1:] { 107 if '0' <= p[0] && p[0] <= '9' { 108 n = n*16 + int64(p[0]-'0') 109 } else if 'a' <= p[0] && p[0] <= 'f' { 110 n = n*16 + int64(p[0]-'a'+10) 111 } else if 'A' <= p[0] && p[0] <= 'F' { 112 n = n*16 + int64(p[0]-'A'+10) 113 } else { 114 break 115 } 116 } 117 case hasprefix(p, "0"): 118 for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] { 119 n = n*8 + int64(p[0]-'0') 120 } 121 default: 122 for ; len(p) > 0 && '0' <= p[0] && p[0] <= '9'; p = p[1:] { 123 n = n*10 + int64(p[0]-'0') 124 } 125 } 126 if neg { 127 n = -n 128 } 129 return n 130 }