2020-08-10 17:43:49 +00:00
|
|
|
package internal
|
|
|
|
|
2021-04-14 18:11:13 +00:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/cilium/ebpf/internal/unix"
|
|
|
|
)
|
2020-08-10 17:43:49 +00:00
|
|
|
|
|
|
|
// NewPointer creates a 64-bit pointer from an unsafe Pointer.
|
|
|
|
func NewPointer(ptr unsafe.Pointer) Pointer {
|
|
|
|
return Pointer{ptr: ptr}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewSlicePointer creates a 64-bit pointer from a byte slice.
|
|
|
|
func NewSlicePointer(buf []byte) Pointer {
|
|
|
|
if len(buf) == 0 {
|
|
|
|
return Pointer{}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Pointer{ptr: unsafe.Pointer(&buf[0])}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewStringPointer creates a 64-bit pointer from a string.
|
|
|
|
func NewStringPointer(str string) Pointer {
|
2021-04-14 18:11:13 +00:00
|
|
|
p, err := unix.BytePtrFromString(str)
|
|
|
|
if err != nil {
|
|
|
|
return Pointer{}
|
|
|
|
}
|
2020-08-10 17:43:49 +00:00
|
|
|
|
2021-04-14 18:11:13 +00:00
|
|
|
return Pointer{ptr: unsafe.Pointer(p)}
|
2020-08-10 17:43:49 +00:00
|
|
|
}
|