-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_intel.go
69 lines (56 loc) · 1.18 KB
/
common_intel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
// +build 386 amd64 amd64p32
package socket_tracer
import (
"errors"
"unsafe"
)
var errBadSize = errors.New("bad size for integer")
func copyInt(dst unsafe.Pointer, src unsafe.Pointer, len uint8) error {
switch len {
case 1:
*(*uint8)(dst) = *(*uint8)(src)
case 2:
*(*uint16)(dst) = *(*uint16)(src)
case 4:
*(*uint32)(dst) = *(*uint32)(src)
case 8:
*(*uint64)(dst) = *(*uint64)(src)
default:
return errBadSize
}
return nil
}
func readInt(ptr unsafe.Pointer, len uint8, signed bool) (value interface{}, err error) {
switch len {
case 1:
if signed {
value = *(*int8)(ptr)
} else {
value = *(*uint8)(ptr)
}
case 2:
if signed {
value = *(*int16)(ptr)
} else {
value = *(*uint16)(ptr)
}
case 4:
if signed {
value = *(*int32)(ptr)
} else {
value = *(*uint32)(ptr)
}
case 8:
if signed {
value = *(*int64)(ptr)
} else {
value = *(*uint64)(ptr)
}
default:
return nil, errBadSize
}
return
}