libc64.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2020 The Libc 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. //go:build (!linux && !(386 || arm)) || mips64le
  5. package libc // import "modernc.org/libc"
  6. import (
  7. "unsafe"
  8. "modernc.org/libc/limits"
  9. "modernc.org/libc/sys/types"
  10. )
  11. const (
  12. heapSize = 2 << 30 // Adjust for your debugging session requirements and system RAM size.
  13. )
  14. type (
  15. // RawMem represents the biggest byte array the runtime can handle
  16. RawMem [1<<50 - 1]byte
  17. // 48-5*8 = 8 bytes left to pad
  18. stackHeaderPadding struct {
  19. a uintptr
  20. }
  21. )
  22. type bits []int
  23. func newBits(n int) (r bits) { return make(bits, (n+63)>>6) }
  24. func (b bits) has(n int) bool { return b != nil && b[n>>6]&(1<<uint(n&63)) != 0 }
  25. func (b bits) set(n int) { b[n>>6] |= 1 << uint(n&63) }
  26. func Xstrchrnul(tls *TLS, s uintptr, c int32) (r uintptr) {
  27. if __ccgo_strace {
  28. trc("tls=%v s=%v c=%v, (%v:)", tls, s, c, origin(2))
  29. defer func() { trc("-> %v", r) }()
  30. }
  31. var k types.Size_t
  32. var w uintptr
  33. _, _ = k, w
  34. c = int32(uint8(c))
  35. if !(c != 0) {
  36. return s + uintptr(Xstrlen(tls, s))
  37. }
  38. for {
  39. if !(uint64(s)%Uint64FromInt64(8) != 0) {
  40. break
  41. }
  42. if !(*(*int8)(unsafe.Pointer(s)) != 0) || int32(*(*uint8)(unsafe.Pointer(s))) == c {
  43. return s
  44. }
  45. goto _1
  46. _1:
  47. s++
  48. }
  49. k = uint64(-Int32FromInt32(1)) / Uint64FromInt32(limits.UCHAR_MAX) * uint64(c)
  50. w = s
  51. for {
  52. if !(!((*(*uint64)(unsafe.Pointer(w))-uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)) & ^*(*uint64)(unsafe.Pointer(w)) & (uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)*uint64(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0) && !((*(*uint64)(unsafe.Pointer(w))^k-uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)) & ^(*(*uint64)(unsafe.Pointer(w))^k) & (uint64(-Int32FromInt32(1))/Uint64FromInt32(limits.UCHAR_MAX)*uint64(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0)) {
  53. break
  54. }
  55. goto _2
  56. _2:
  57. w += 8
  58. }
  59. s = w
  60. for {
  61. if !(*(*int8)(unsafe.Pointer(s)) != 0 && int32(*(*uint8)(unsafe.Pointer(s))) != c) {
  62. break
  63. }
  64. goto _3
  65. _3:
  66. s++
  67. }
  68. return s
  69. }