Skip to content

Commit 1b9499b

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 6dda7b2 commit 1b9499b

27 files changed

+7
-49
lines changed

src/runtime/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,8 @@ var argslice []string
5252
//go:linkname syscall_runtime_envs syscall.runtime_envs
5353
func syscall_runtime_envs() []string { return append([]string{}, envs...) }
5454

55+
//go:linkname syscall_Getpagesize syscall.Getpagesize
56+
func syscall_Getpagesize() int { return int(physPageSize) }
57+
5558
//go:linkname os_runtime_args os.runtime_args
5659
func os_runtime_args() []string { return append([]string{}, argslice...) }

src/syscall/syscall.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ func (tv *Timeval) Nano() int64 {
9595
return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
9696
}
9797

98+
// Getpagesize is provided by the runtime.
99+
100+
func Getpagesize() int
101+
98102
// use is a no-op, but the compiler cannot see that it is.
99103
// Calling use(p) ensures that p is kept live until that point.
100104
// This was needed until Go 1.6 to call syscall.Syscall correctly.

src/syscall/syscall_darwin_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_darwin_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_darwin_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_darwin_arm64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 16384 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_dragonfly_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_freebsd_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_freebsd_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_freebsd_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ package syscall
66

77
import "unsafe"
88

9-
func Getpagesize() int { return 4096 }
10-
119
func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }
1210

1311
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_linux_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ const (
1414
_SYS_getdents = SYS_GETDENTS64
1515
)
1616

17-
func Getpagesize() int { return 4096 }
18-
1917
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
2018

2119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_linux_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ func Gettimeofday(tv *Timeval) (err error) {
7272
return nil
7373
}
7474

75-
func Getpagesize() int { return 4096 }
76-
7775
func Time(t *Time_t) (tt Time_t, err error) {
7876
var tv Timeval
7977
errno := gettimeofday(&tv)

src/syscall/syscall_linux_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ const (
1111
_SYS_getdents = SYS_GETDENTS64
1212
)
1313

14-
func Getpagesize() int { return 4096 }
15-
1614
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
1715

1816
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_linux_arm64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ func Lstat(path string, stat *Stat_t) (err error) {
6868
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6969
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
7070

71-
func Getpagesize() int { return 65536 }
72-
7371
//sysnb Gettimeofday(tv *Timeval) (err error)
7472
//sysnb Time(t *Time_t) (tt Time_t, err error)
7573

src/syscall/syscall_linux_mips64x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ const (
6565
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6666
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
6767

68-
func Getpagesize() int { return 65536 }
69-
7068
//sysnb Gettimeofday(tv *Timeval) (err error)
7169

7270
func Time(t *Time_t) (tt Time_t, err error) {

src/syscall/syscall_linux_ppc64x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ const (
6464
//sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
6565
//sys mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error)
6666

67-
func Getpagesize() int { return 65536 }
68-
6967
//sysnb Gettimeofday(tv *Timeval) (err error)
7068
//sysnb Time(t *Time_t) (tt Time_t, err error)
7169

src/syscall/syscall_linux_s390x.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ const (
4444
//sysnb getgroups(n int, list *_Gid_t) (nn int, err error)
4545
//sysnb setgroups(n int, list *_Gid_t) (err error)
4646

47-
func Getpagesize() int { return 4096 }
48-
4947
//sysnb Gettimeofday(tv *Timeval) (err error)
5048

5149
func Time(t *Time_t) (tt Time_t, err error) {

src/syscall/syscall_nacl.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ func Getegid() int { return 1 }
292292
func Geteuid() int { return 1 }
293293
func Getgid() int { return 1 }
294294
func Getgroups() ([]int, error) { return []int{1}, nil }
295-
func Getpagesize() int { return 65536 }
296295
func Getppid() int { return 2 }
297296
func Getpid() int { return 3 }
298297
func Gettimeofday(tv *Timeval) error { return ENOSYS }

src/syscall/syscall_netbsd_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_netbsd_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_netbsd_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_openbsd_386.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_openbsd_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_openbsd_arm.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_plan9.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ func Gettimeofday(tv *Timeval) error {
305305
return nil
306306
}
307307

308-
func Getpagesize() int { return 0x1000 }
309-
310308
func Getegid() (egid int) { return -1 }
311309
func Geteuid() (euid int) { return -1 }
312310
func Getgid() (gid int) { return -1 }

src/syscall/syscall_solaris_amd64.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
package syscall
66

7-
func Getpagesize() int { return 4096 }
8-
97
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
108

119
func NsecToTimespec(nsec int64) (ts Timespec) {

src/syscall/syscall_windows.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ func UTF16PtrFromString(s string) (*uint16, error) {
7474
return &a[0], nil
7575
}
7676

77-
func Getpagesize() int { return 4096 }
78-
7977
// Errno is the Windows error number.
8078
type Errno uintptr
8179

0 commit comments

Comments
 (0)