github.com/zach-klippenstein/go@v0.0.0-20150108044943-fcfbeb3adf58/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) int32
    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  //go:linkname os_sigpipe os.sigpipe
    57  func os_sigpipe() {
    58  	throw("too many writes on closed pipe")
    59  }
    60  
    61  func sigpanic() {
    62  	g := getg()
    63  	if !canpanic(g) {
    64  		throw("unexpected signal during runtime execution")
    65  	}
    66  
    67  	note := gostringnocopy((*byte)(unsafe.Pointer(g.m.notesig)))
    68  	switch g.sig {
    69  	case _SIGRFAULT, _SIGWFAULT:
    70  		addr := note[index(note, "addr=")+5:]
    71  		g.sigcode1 = uintptr(atolwhex(addr))
    72  		if g.sigcode1 < 0x1000 || g.paniconfault {
    73  			panicmem()
    74  		}
    75  		print("unexpected fault address ", hex(g.sigcode1), "\n")
    76  		throw("fault")
    77  	case _SIGTRAP:
    78  		if g.paniconfault {
    79  			panicmem()
    80  		}
    81  		throw(note)
    82  	case _SIGINTDIV:
    83  		panicdivide()
    84  	case _SIGFLOAT:
    85  		panicfloat()
    86  	default:
    87  		panic(errorString(note))
    88  	}
    89  }
    90  
    91  func atolwhex(p string) int64 {
    92  	for hasprefix(p, " ") || hasprefix(p, "\t") {
    93  		p = p[1:]
    94  	}
    95  	neg := false
    96  	if hasprefix(p, "-") || hasprefix(p, "+") {
    97  		neg = p[0] == '-'
    98  		p = p[1:]
    99  		for hasprefix(p, " ") || hasprefix(p, "\t") {
   100  			p = p[1:]
   101  		}
   102  	}
   103  	var n int64
   104  	switch {
   105  	case hasprefix(p, "0x"), hasprefix(p, "0X"):
   106  		p = p[2:]
   107  		for ; len(p) > 0; p = p[1:] {
   108  			if '0' <= p[0] && p[0] <= '9' {
   109  				n = n*16 + int64(p[0]-'0')
   110  			} else if 'a' <= p[0] && p[0] <= 'f' {
   111  				n = n*16 + int64(p[0]-'a'+10)
   112  			} else if 'A' <= p[0] && p[0] <= 'F' {
   113  				n = n*16 + int64(p[0]-'A'+10)
   114  			} else {
   115  				break
   116  			}
   117  		}
   118  	case hasprefix(p, "0"):
   119  		for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] {
   120  			n = n*8 + int64(p[0]-'0')
   121  		}
   122  	default:
   123  		for ; len(p) > 0 && '0' <= p[0] && p[0] <= '9'; p = p[1:] {
   124  			n = n*10 + int64(p[0]-'0')
   125  		}
   126  	}
   127  	if neg {
   128  		n = -n
   129  	}
   130  	return n
   131  }