summaryrefslogtreecommitdiff
path: root/vendor/github.com/cilium/ebpf/internal/ptr.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/cilium/ebpf/internal/ptr.go')
-rw-r--r--vendor/github.com/cilium/ebpf/internal/ptr.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/github.com/cilium/ebpf/internal/ptr.go b/vendor/github.com/cilium/ebpf/internal/ptr.go
new file mode 100644
index 000000000..a7f12b2db
--- /dev/null
+++ b/vendor/github.com/cilium/ebpf/internal/ptr.go
@@ -0,0 +1,30 @@
+package internal
+
+import "unsafe"
+
+// 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 {
+ if str == "" {
+ return Pointer{}
+ }
+
+ // The kernel expects strings to be zero terminated
+ buf := make([]byte, len(str)+1)
+ copy(buf, str)
+
+ return Pointer{ptr: unsafe.Pointer(&buf[0])}
+}