unsafe_link.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package reflect2
  2. import "unsafe"
  3. //go:linkname unsafe_New reflect.unsafe_New
  4. func unsafe_New(rtype unsafe.Pointer) unsafe.Pointer
  5. //go:linkname typedmemmove reflect.typedmemmove
  6. func typedmemmove(rtype unsafe.Pointer, dst, src unsafe.Pointer)
  7. //go:linkname unsafe_NewArray reflect.unsafe_NewArray
  8. func unsafe_NewArray(rtype unsafe.Pointer, length int) unsafe.Pointer
  9. // typedslicecopy copies a slice of elemType values from src to dst,
  10. // returning the number of elements copied.
  11. //go:linkname typedslicecopy reflect.typedslicecopy
  12. //go:noescape
  13. func typedslicecopy(elemType unsafe.Pointer, dst, src sliceHeader) int
  14. //go:linkname mapassign reflect.mapassign
  15. //go:noescape
  16. func mapassign(rtype unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer, val unsafe.Pointer)
  17. //go:linkname mapaccess reflect.mapaccess
  18. //go:noescape
  19. func mapaccess(rtype unsafe.Pointer, m unsafe.Pointer, key unsafe.Pointer) (val unsafe.Pointer)
  20. //go:noescape
  21. //go:linkname mapiternext reflect.mapiternext
  22. func mapiternext(it *hiter)
  23. //go:linkname ifaceE2I reflect.ifaceE2I
  24. func ifaceE2I(rtype unsafe.Pointer, src interface{}, dst unsafe.Pointer)
  25. // A hash iteration structure.
  26. // If you modify hiter, also change cmd/internal/gc/reflect.go to indicate
  27. // the layout of this structure.
  28. type hiter struct {
  29. key unsafe.Pointer
  30. value unsafe.Pointer
  31. t unsafe.Pointer
  32. h unsafe.Pointer
  33. buckets unsafe.Pointer
  34. bptr unsafe.Pointer
  35. overflow *[]unsafe.Pointer
  36. oldoverflow *[]unsafe.Pointer
  37. startBucket uintptr
  38. offset uint8
  39. wrapped bool
  40. B uint8
  41. i uint8
  42. bucket uintptr
  43. checkBucket uintptr
  44. }
  45. // add returns p+x.
  46. //
  47. // The whySafe string is ignored, so that the function still inlines
  48. // as efficiently as p+x, but all call sites should use the string to
  49. // record why the addition is safe, which is to say why the addition
  50. // does not cause x to advance to the very end of p's allocation
  51. // and therefore point incorrectly at the next block in memory.
  52. func add(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
  53. return unsafe.Pointer(uintptr(p) + x)
  54. }
  55. // arrayAt returns the i-th element of p,
  56. // an array whose elements are eltSize bytes wide.
  57. // The array pointed at by p must have at least i+1 elements:
  58. // it is invalid (but impossible to check here) to pass i >= len,
  59. // because then the result will point outside the array.
  60. // whySafe must explain why i < len. (Passing "i < len" is fine;
  61. // the benefit is to surface this assumption at the call site.)
  62. func arrayAt(p unsafe.Pointer, i int, eltSize uintptr, whySafe string) unsafe.Pointer {
  63. return add(p, uintptr(i)*eltSize, "i < len")
  64. }