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