Skip to content

Commit

Permalink
hitsumabushi: add PageSize
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
hajimehoshi committed Aug 12, 2023
1 parent 5ef7a51 commit 4dddf85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 0 additions & 4 deletions 1.20_linux/runtime/runtime1.go.patch
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ func args(c int32, v **byte) {
}
//--to
func args(c int32, v **byte) {
// Malloc is not defined yet and getting an address of a global variable might fail here.
// Overwrite goargs later.

physPageSize = 4096
}
//--append
// Expose the entry point for some special environments.
Expand Down
26 changes: 23 additions & 3 deletions overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type config struct {
overlayDir string
os string
args []string
pageSize int
clockGettimeName string
futexName string
replaceDLLs []replaceString
Expand Down Expand Up @@ -67,7 +68,7 @@ func Args(args ...string) Option {
// If name is an empty string, the function is not replaced.
// This is useful for special environments where `clock_gettime` doesn't work correctly.
//
// ReplaceClockGettime works only for Linux with Go 1.18 and older.
// ReplaceClockGettime works only for Linux.
// For Go 1.19 and newer, use Overlay and ClockFilePath.
func ReplaceClockGettime(name string) Option {
return func(cfg *config) {
Expand All @@ -79,7 +80,7 @@ func ReplaceClockGettime(name string) Option {
// If name is an empty string, a pseudo futex implementation is used.
// This is useful for special environments where the pseudo `futex` doesn't work correctly.
//
// ReplaceFutex works only for Linux with Go 1.18 and older.
// ReplaceFutex works only for Linux.
// For Go 1.19 and newer, use Overlay and FutexFilePath.
func ReplaceFutex(name string) Option {
return func(cfg *config) {
Expand All @@ -95,6 +96,16 @@ func GOOS(os string) Option {
}
}

// PageSize specifies the page size.
// The deafult value is 4096.
//
// This works only for Linux.
func PageSize(pageSize int) Option {
return func(cfg *config) {
cfg.pageSize = pageSize
}
}

// ReplaceDLL replaces a DLL file name loaded at LoadLibraryW and LoadLibraryExW.
//
// This works only for Windows.
Expand Down Expand Up @@ -139,7 +150,8 @@ func GenOverlayJSON(options ...Option) ([]byte, error) {
}

cfg := config{
os: runtime.GOOS,
os: runtime.GOOS,
pageSize: 4096,
}
for _, op := range options {
op(&cfg)
Expand Down Expand Up @@ -301,6 +313,14 @@ func goargs() {
}
}

{
old := `var physPageSize uintptr`
new := fmt.Sprintf(`var physPageSize uintptr = %d`, cfg.pageSize)
if err := replace(tmpDir, replaces, "runtime", "malloc.go", old, new, cfg.os); err != nil {
return nil, err
}
}

// Replace clock_gettime.
if cfg.clockGettimeName != "" {
old := "#define clock_gettime clock_gettime"
Expand Down

0 comments on commit 4dddf85

Please sign in to comment.