Implement getpagesize and munmap. For go 1.18.

This commit is contained in:
Dan Kegel
2022-03-17 09:53:28 -07:00
committed by Ron Evans
parent 06b19cde2d
commit cf8f4d65f2
2 changed files with 43 additions and 0 deletions
+20
View File
@@ -226,6 +226,14 @@ func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, e
return (*[1 << 30]byte)(addr)[:length:length], nil
}
func Munmap(b []byte) (err error) {
errCode := libc_munmap(unsafe.Pointer(&b[0]), uintptr(len(b)))
if errCode != 0 {
err = getErrno()
}
return err
}
func Mprotect(b []byte, prot int) (err error) {
errCode := libc_mprotect(unsafe.Pointer(&b[0]), uintptr(len(b)), int32(prot))
if errCode != 0 {
@@ -234,6 +242,10 @@ func Mprotect(b []byte, prot int) (err error) {
return
}
func Getpagesize() int {
return int(libc_getpagesize())
}
func Environ() []string {
// This function combines all the environment into a single allocation.
@@ -343,10 +355,18 @@ func libc_dup(fd int32) int32
//export mmap
func libc_mmap(addr unsafe.Pointer, length uintptr, prot, flags, fd int32, offset uintptr) unsafe.Pointer
// int munmap(void *addr, size_t length);
//export munmap
func libc_munmap(addr unsafe.Pointer, length uintptr) int32
// int mprotect(void *addr, size_t len, int prot);
//export mprotect
func libc_mprotect(addr unsafe.Pointer, len uintptr, prot int32) int32
// int getpagesize();
//export getpagesize
func libc_getpagesize() int32
// int chdir(const char *pathname, mode_t mode);
//export chdir
func libc_chdir(pathname *byte) int32