libc32.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 && (arm || 386)
  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 = 1 << 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<<31 - 1]byte
  17. // 32-5*4 = 12 bytes left to pad
  18. stackHeaderPadding struct {
  19. a uintptr
  20. b uintptr
  21. c uintptr
  22. }
  23. )
  24. type bits []int
  25. func newBits(n int) (r bits) { return make(bits, (n+31)>>5) }
  26. func (b bits) has(n int) bool { return b != nil && b[n>>5]&(1<<uint(n&31)) != 0 }
  27. func (b bits) set(n int) { b[n>>5] |= 1 << uint(n&31) }
  28. func Xstrchrnul(tls *TLS, s uintptr, c int32) (r uintptr) {
  29. return x___strchrnul(tls, s, c)
  30. }
  31. func x___strchrnul(tls *TLS, s uintptr, c int32) (r uintptr) {
  32. var k types.Size_t
  33. var w uintptr
  34. _, _ = k, w
  35. c = int32(uint8(c))
  36. if !(c != 0) {
  37. return s + uintptr(Xstrlen(tls, s))
  38. }
  39. for {
  40. if !(uint32(s)%Uint32FromInt64(4) != 0) {
  41. break
  42. }
  43. if !(*(*int8)(unsafe.Pointer(s)) != 0) || int32(*(*uint8)(unsafe.Pointer(s))) == c {
  44. return s
  45. }
  46. goto _1
  47. _1:
  48. s++
  49. }
  50. k = uint32(-Int32FromInt32(1)) / Uint32FromInt32(limits.UCHAR_MAX) * uint32(c)
  51. w = s
  52. for {
  53. if !(!((*(*uint32)(unsafe.Pointer(w))-uint32(-Int32FromInt32(1))/Uint32FromInt32(limits.UCHAR_MAX)) & ^*(*uint32)(unsafe.Pointer(w)) & (uint32(-Int32FromInt32(1))/Uint32FromInt32(limits.UCHAR_MAX)*uint32(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0) && !((*(*uint32)(unsafe.Pointer(w))^k-uint32(-Int32FromInt32(1))/Uint32FromInt32(limits.UCHAR_MAX)) & ^(*(*uint32)(unsafe.Pointer(w))^k) & (uint32(-Int32FromInt32(1))/Uint32FromInt32(limits.UCHAR_MAX)*uint32(Int32FromInt32(limits.UCHAR_MAX)/Int32FromInt32(2)+Int32FromInt32(1))) != 0)) {
  54. break
  55. }
  56. goto _2
  57. _2:
  58. w += 4
  59. }
  60. s = w
  61. for {
  62. if !(*(*int8)(unsafe.Pointer(s)) != 0 && int32(*(*uint8)(unsafe.Pointer(s))) != c) {
  63. break
  64. }
  65. goto _3
  66. _3:
  67. s++
  68. }
  69. return s
  70. }