Commit 1b9499b0 authored by Austin Clements's avatar Austin Clements

syscall: make Getpagesize return page size from runtime

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 #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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 6dda7b2f
...@@ -52,5 +52,8 @@ var argslice []string ...@@ -52,5 +52,8 @@ var argslice []string
//go:linkname syscall_runtime_envs syscall.runtime_envs //go:linkname syscall_runtime_envs syscall.runtime_envs
func syscall_runtime_envs() []string { return append([]string{}, 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 //go:linkname os_runtime_args os.runtime_args
func os_runtime_args() []string { return append([]string{}, argslice...) } func os_runtime_args() []string { return append([]string{}, argslice...) }
...@@ -95,6 +95,10 @@ func (tv *Timeval) Nano() int64 { ...@@ -95,6 +95,10 @@ func (tv *Timeval) Nano() int64 {
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 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. // 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. // Calling use(p) ensures that p is kept live until that point.
// This was needed until Go 1.6 to call syscall.Syscall correctly. // This was needed until Go 1.6 to call syscall.Syscall correctly.
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 16384 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -6,8 +6,6 @@ package syscall ...@@ -6,8 +6,6 @@ package syscall
import "unsafe" import "unsafe"
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -14,8 +14,6 @@ const ( ...@@ -14,8 +14,6 @@ const (
_SYS_getdents = SYS_GETDENTS64 _SYS_getdents = SYS_GETDENTS64
) )
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -72,8 +72,6 @@ func Gettimeofday(tv *Timeval) (err error) { ...@@ -72,8 +72,6 @@ func Gettimeofday(tv *Timeval) (err error) {
return nil return nil
} }
func Getpagesize() int { return 4096 }
func Time(t *Time_t) (tt Time_t, err error) { func Time(t *Time_t) (tt Time_t, err error) {
var tv Timeval var tv Timeval
errno := gettimeofday(&tv) errno := gettimeofday(&tv)
......
...@@ -11,8 +11,6 @@ const ( ...@@ -11,8 +11,6 @@ const (
_SYS_getdents = SYS_GETDENTS64 _SYS_getdents = SYS_GETDENTS64
) )
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -68,8 +68,6 @@ func Lstat(path string, stat *Stat_t) (err error) { ...@@ -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 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) //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 Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error) //sysnb Time(t *Time_t) (tt Time_t, err error)
......
...@@ -65,8 +65,6 @@ const ( ...@@ -65,8 +65,6 @@ const (
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, 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) //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 Gettimeofday(tv *Timeval) (err error)
func Time(t *Time_t) (tt Time_t, err error) { func Time(t *Time_t) (tt Time_t, err error) {
......
...@@ -64,8 +64,6 @@ const ( ...@@ -64,8 +64,6 @@ const (
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, 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) //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 Gettimeofday(tv *Timeval) (err error)
//sysnb Time(t *Time_t) (tt Time_t, err error) //sysnb Time(t *Time_t) (tt Time_t, err error)
......
...@@ -44,8 +44,6 @@ const ( ...@@ -44,8 +44,6 @@ const (
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error) //sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
//sysnb setgroups(n int, list *_Gid_t) (err error) //sysnb setgroups(n int, list *_Gid_t) (err error)
func Getpagesize() int { return 4096 }
//sysnb Gettimeofday(tv *Timeval) (err error) //sysnb Gettimeofday(tv *Timeval) (err error)
func Time(t *Time_t) (tt Time_t, err error) { func Time(t *Time_t) (tt Time_t, err error) {
......
...@@ -292,7 +292,6 @@ func Getegid() int { return 1 } ...@@ -292,7 +292,6 @@ func Getegid() int { return 1 }
func Geteuid() int { return 1 } func Geteuid() int { return 1 }
func Getgid() int { return 1 } func Getgid() int { return 1 }
func Getgroups() ([]int, error) { return []int{1}, nil } func Getgroups() ([]int, error) { return []int{1}, nil }
func Getpagesize() int { return 65536 }
func Getppid() int { return 2 } func Getppid() int { return 2 }
func Getpid() int { return 3 } func Getpid() int { return 3 }
func Gettimeofday(tv *Timeval) error { return ENOSYS } func Gettimeofday(tv *Timeval) error { return ENOSYS }
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -305,8 +305,6 @@ func Gettimeofday(tv *Timeval) error { ...@@ -305,8 +305,6 @@ func Gettimeofday(tv *Timeval) error {
return nil return nil
} }
func Getpagesize() int { return 0x1000 }
func Getegid() (egid int) { return -1 } func Getegid() (egid int) { return -1 }
func Geteuid() (euid int) { return -1 } func Geteuid() (euid int) { return -1 }
func Getgid() (gid int) { return -1 } func Getgid() (gid int) { return -1 }
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
package syscall package syscall
func Getpagesize() int { return 4096 }
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) { func NsecToTimespec(nsec int64) (ts Timespec) {
......
...@@ -74,8 +74,6 @@ func UTF16PtrFromString(s string) (*uint16, error) { ...@@ -74,8 +74,6 @@ func UTF16PtrFromString(s string) (*uint16, error) {
return &a[0], nil return &a[0], nil
} }
func Getpagesize() int { return 4096 }
// Errno is the Windows error number. // Errno is the Windows error number.
type Errno uintptr type Errno uintptr
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment