Skip to content

Commit

Permalink
move mmap funciton into mmap package
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Feb 7, 2022
1 parent d0f80f0 commit 5cc2629
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mmap_linux_amd64.go → mmap/mmap_linux_amd64.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build linux && amd64
// +build linux,amd64

package goloader
package mmap

import (
"os"
Expand Down
3 changes: 2 additions & 1 deletion mmap_unix.go → mmap/mmap_unix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build darwin || dragonfly || freebsd || (linux && !amd64) || openbsd || solaris || netbsd
// +build darwin dragonfly freebsd linux,!amd64 openbsd solaris netbsd

package goloader
package mmap

import (
"os"
Expand Down
10 changes: 9 additions & 1 deletion mmap_windows.go → mmap/mmap_windows.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
//go:build windows
// +build windows

package goloader
package mmap

import (
"os"
"syscall"
"unsafe"
)

// See reflect/value.go sliceHeader
type sliceHeader struct {
Data uintptr
Len int
Cap int
}

func Mmap(size int) ([]byte, error) {

sizelo := uint32(size >> 32)
Expand Down
10 changes: 10 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"strconv"
"unsafe"

"github.com/pkujhd/goloader/mmap"
)

//go:linkname add runtime.add
Expand Down Expand Up @@ -98,6 +100,14 @@ func getArch(archName string) *sys.Arch {
return arch
}

func Mmap(size int) ([]byte, error) {
return mmap.Mmap(size)
}

func Munmap(b []byte) (err error) {
return mmap.Munmap(b)
}

//see $GOROOT/src/cmd/internal/loader/loader.go:preprocess
func ispreprocesssymbol(name string) bool {
if len(name) > 5 {
Expand Down

0 comments on commit 5cc2629

Please sign in to comment.