@@ -6,33 +6,45 @@ package runtime
6
6
7
7
import "unsafe"
8
8
9
- type ptrAlign struct {
9
+ type ptrAlignError struct {
10
10
ptr unsafe.Pointer
11
11
elem * _type
12
12
n uintptr
13
13
}
14
14
15
+ func (e ptrAlignError ) RuntimeError () {}
16
+
17
+ func (e ptrAlignError ) Error () string {
18
+ return "runtime error: unsafe pointer conversion"
19
+ }
20
+
15
21
func checkptrAlignment (p unsafe.Pointer , elem * _type , n uintptr ) {
16
22
// Check that (*[n]elem)(p) is appropriately aligned.
17
23
// TODO(mdempsky): What about fieldAlign?
18
24
if uintptr (p )& (uintptr (elem .align )- 1 ) != 0 {
19
- panic (ptrAlign {p , elem , n })
25
+ panic (ptrAlignError {p , elem , n })
20
26
}
21
27
22
28
// Check that (*[n]elem)(p) doesn't straddle multiple heap objects.
23
29
if size := n * elem .size ; size > 1 && checkptrBase (p ) != checkptrBase (add (p , size - 1 )) {
24
- panic (ptrAlign {p , elem , n })
30
+ panic (ptrAlignError {p , elem , n })
25
31
}
26
32
}
27
33
28
- type ptrArith struct {
34
+ type ptrArithError struct {
29
35
ptr unsafe.Pointer
30
36
originals []unsafe.Pointer
31
37
}
32
38
39
+ func (e ptrArithError ) RuntimeError () {}
40
+
41
+ func (e ptrArithError ) Error () string {
42
+ return "runtime error: unsafe pointer arithmetic"
43
+ }
44
+
33
45
func checkptrArithmetic (p unsafe.Pointer , originals []unsafe.Pointer ) {
34
46
if 0 < uintptr (p ) && uintptr (p ) < minLegalPointer {
35
- panic (ptrArith {p , originals })
47
+ panic (ptrArithError {p , originals })
36
48
}
37
49
38
50
// Check that if the computed pointer p points into a heap
@@ -49,7 +61,7 @@ func checkptrArithmetic(p unsafe.Pointer, originals []unsafe.Pointer) {
49
61
}
50
62
}
51
63
52
- panic (ptrArith {p , originals })
64
+ panic (ptrArithError {p , originals })
53
65
}
54
66
55
67
func checkptrBase (p unsafe.Pointer ) uintptr {
0 commit comments