-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
# Gopkg.toml example | ||
# | ||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
|
||
|
||
[[constraint]] | ||
branch = "master" | ||
name = "golang.org/x/sys" |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// +build freebsd | ||
|
||
package memcall | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// Lock is a wrapper for unix.Mlock(), with extra precautions. | ||
func Lock(b []byte) { | ||
// Advise the kernel not to dump. Ignore failure. | ||
unix.Madvise(b, unix.MADV_DONTDUMP) | ||
|
||
// Call mlock. | ||
if err := unix.Mlock(b); err != nil { | ||
panic(fmt.Sprintf("memguard.memcall.Lock(): could not acquire lock on %p, limit reached? [Err: %s]", &b[0], err)) | ||
} | ||
} | ||
|
||
// Unlock is a wrapper for unix.Munlock(). | ||
func Unlock(b []byte) { | ||
if err := unix.Munlock(b); err != nil { | ||
panic(fmt.Sprintf("memguard.memcall.Unlock(): could not free lock on %p [Err: %s]", &b[0], err)) | ||
} | ||
} | ||
|
||
// Alloc allocates a byte slice of length n and returns it. | ||
func Alloc(n int) []byte { | ||
// Allocate the memory. | ||
b, err := unix.Mmap(-1, 0, n, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_PRIVATE|unix.MAP_ANONYMOUS|unix.MAP_NOCORE) | ||
if err != nil { | ||
panic(fmt.Sprintf("memguard.memcall.Alloc(): could not allocate [Err: %s]", err)) | ||
} | ||
|
||
// Fill memory with weird bytes in order to help catch bugs due to uninitialized data. | ||
for i := 0; i < n; i++ { | ||
b[i] = byte(0xdb) | ||
} | ||
|
||
// Return the allocated memory. | ||
return b | ||
} | ||
|
||
// Free unallocates the byte slice specified. | ||
func Free(b []byte) { | ||
if err := unix.Munmap(b); err != nil { | ||
panic(fmt.Sprintf("memguard.memcall.Free(): could not unallocate %p [Err: %s]", &b[0], err)) | ||
} | ||
} | ||
|
||
// Protect modifies the PROT_ flags for a specified byte slice. | ||
func Protect(b []byte, read, write bool) { | ||
// Ascertain protection value from arguments. | ||
var prot int | ||
if read && write { | ||
prot = unix.PROT_READ | unix.PROT_WRITE | ||
} else if read { | ||
prot = unix.PROT_READ | ||
} else if write { | ||
prot = unix.PROT_WRITE | ||
} else { | ||
prot = unix.PROT_NONE | ||
} | ||
|
||
// Change the protection value of the byte slice. | ||
if err := unix.Mprotect(b, prot); err != nil { | ||
panic(fmt.Sprintf("memguard.memcall.Protect(): could not set %d on %p [Err: %s]", prot, &b[0], err)) | ||
} | ||
} | ||
|
||
// DisableCoreDumps disables core dumps on Unix systems. | ||
func DisableCoreDumps() { | ||
// Disable core dumps. | ||
if err := unix.Setrlimit(unix.RLIMIT_CORE, &unix.Rlimit{Cur: 0, Max: 0}); err != nil { | ||
panic(fmt.Sprintf("memguard.memcall.DisableCoreDumps(): could not set rlimit [Err: %s]", err)) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.