summaryrefslogtreecommitdiffhomepage
path: root/pkg/binary
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/binary')
-rw-r--r--pkg/binary/BUILD6
-rw-r--r--pkg/binary/binary.go10
2 files changed, 12 insertions, 4 deletions
diff --git a/pkg/binary/BUILD b/pkg/binary/BUILD
index 543fb54bf..7ca2fda90 100644
--- a/pkg/binary/BUILD
+++ b/pkg/binary/BUILD
@@ -1,12 +1,10 @@
-load("//tools/go_stateify:defs.bzl", "go_library")
-load("@io_bazel_rules_go//go:def.bzl", "go_test")
+load("//tools:defs.bzl", "go_library", "go_test")
package(licenses = ["notice"])
go_library(
name = "binary",
srcs = ["binary.go"],
- importpath = "gvisor.dev/gvisor/pkg/binary",
visibility = ["//:sandbox"],
)
@@ -14,5 +12,5 @@ go_test(
name = "binary_test",
size = "small",
srcs = ["binary_test.go"],
- embed = [":binary"],
+ library = ":binary",
)
diff --git a/pkg/binary/binary.go b/pkg/binary/binary.go
index 631785f7b..25065aef9 100644
--- a/pkg/binary/binary.go
+++ b/pkg/binary/binary.go
@@ -254,3 +254,13 @@ func WriteUint64(w io.Writer, order binary.ByteOrder, num uint64) error {
_, err := w.Write(buf)
return err
}
+
+// AlignUp rounds a length up to an alignment. align must be a power of 2.
+func AlignUp(length int, align uint) int {
+ return (length + int(align) - 1) & ^(int(align) - 1)
+}
+
+// AlignDown rounds a length down to an alignment. align must be a power of 2.
+func AlignDown(length int, align uint) int {
+ return length & ^(int(align) - 1)
+}