mirror of
https://github.com/awnumar/memguard.git
synced 2026-02-06 17:59:49 +00:00
26 lines
546 B
Go
26 lines
546 B
Go
package core
|
|
|
|
import (
|
|
"os"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
// Ascertain and store the system memory page size.
|
|
pageSize = os.Getpagesize()
|
|
)
|
|
|
|
// Round a length to a multiple of the system page size.
|
|
func roundToPageSize(length int) int {
|
|
return (length + (pageSize - 1)) & (^(pageSize - 1))
|
|
}
|
|
|
|
// Convert a pointer and length to a byte slice that describes that memory.
|
|
func getBytes(ptr *byte, len int) []byte {
|
|
var sl = struct {
|
|
addr uintptr
|
|
len int
|
|
cap int
|
|
}{uintptr(unsafe.Pointer(ptr)), len, len}
|
|
return *(*[]byte)(unsafe.Pointer(&sl))
|
|
}
|