os_plan9.go 2.5 KB

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