Skip to content

Commit

Permalink
syscall: make Getpagesize return page size from runtime
Browse files Browse the repository at this point in the history
syscall.Getpagesize currently returns hard-coded page sizes on all
architectures (some of which are probably always wrong, and some of
which are definitely not always right). The runtime now has this
information, queried from the OS during runtime init, so make
syscall.Getpagesize return the page size that the runtime knows.

Updates golang#10180.

Change-Id: I4daa6fbc61a2193eb8fa9e7878960971205ac346
Reviewed-on: https://go-review.googlesource.com/25051
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
  • Loading branch information
aclements authored and tmm1 committed Nov 9, 2016
1 parent 7ae2610 commit fa510bf
Show file tree
Hide file tree
Showing 27 changed files with 7 additions and 49 deletions.
3 changes: 3 additions & 0 deletions src/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ var argslice []string
//go:linkname syscall_runtime_envs syscall.runtime_envs
func syscall_runtime_envs() []string { return append([]string{}, envs...) }

//go:linkname syscall_Getpagesize syscall.Getpagesize
func syscall_Getpagesize() int { return int(physPageSize) }

//go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string { return append([]string{}, argslice...) }
4 changes: 4 additions & 0 deletions src/syscall/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (tv *Timeval) Nano() int64 {
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
}

// Getpagesize is provided by the runtime.

func Getpagesize() int

// use is a no-op, but the compiler cannot see that it is.
// Calling use(p) ensures that p is kept live until that point.
// This was needed until Go 1.6 to call syscall.Syscall correctly.
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_darwin_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_darwin_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 16384 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_dragonfly_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_freebsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_freebsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_freebsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package syscall

import "unsafe"

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const (
_SYS_getdents = SYS_GETDENTS64
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ func Gettimeofday(tv *Timeval) (err error) {
return nil
}

func Getpagesize() int { return 4096 }

func Time(t *Time_t) (tt Time_t, err error) {
var tv Timeval
errno := gettimeofday(&tv)
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const (
_SYS_getdents = SYS_GETDENTS64
)

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func Lstat(path string, stat *Stat_t) (err error) {
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func Getpagesize() int { return 65536 }

//sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error)

Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_mips64x.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const (
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func Getpagesize() int { return 65536 }

//sysnb Gettimeofday(tv *Timeval) (err error)

func Time(t *Time_t) (tt Time_t, err error) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_ppc64x.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const (
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)

func Getpagesize() int { return 65536 }

//sysnb Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error)

Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_linux_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const (
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error)

func Getpagesize() int { return 4096 }

//sysnb Gettimeofday(tv *Timeval) (err error)

func Time(t *Time_t) (tt Time_t, err error) {
Expand Down
1 change: 0 additions & 1 deletion src/syscall/syscall_nacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ func Getegid() int { return 1 }
func Geteuid() int { return 1 }
func Getgid() int { return 1 }
func Getgroups() ([]int, error) { return []int{1}, nil }
func Getpagesize() int { return 65536 }
func Getppid() int { return 2 }
func Getpid() int { return 3 }
func Getuid() int { return 1 }
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_netbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_netbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_netbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_openbsd_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_openbsd_arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ func Gettimeofday(tv *Timeval) error {
return nil
}

func Getpagesize() int { return 0x1000 }

func Getegid() (egid int) { return -1 }
func Geteuid() (euid int) { return -1 }
func Getgid() (gid int) { return -1 }
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_solaris_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

package syscall

func Getpagesize() int { return 4096 }

func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }

func NsecToTimespec(nsec int64) (ts Timespec) {
Expand Down
2 changes: 0 additions & 2 deletions src/syscall/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ func UTF16PtrFromString(s string) (*uint16, error) {
return &a[0], nil
}

func Getpagesize() int { return 4096 }

// Errno is the Windows error number.
type Errno uintptr

Expand Down

0 comments on commit fa510bf

Please sign in to comment.