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