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