unix: defer Getpagesize() to runtime
In general, page size is not a function of the archetecture. This was
addressed in the Go standard library here:
https://go-review.googlesource.com/25051
This change simply defers to the standard library "syscall" package,
which in turn defers to the runtime. This helps in addressing golang/go#10180 and
also fixes a bug on ppc64.
Currently, we return 65536 as the page size on ppc64, but the kernel
supports 4k and 64k sizes, see here:
http://elixir.free-electrons.com/linux/v4.13/source/arch/powerpc/include/asm/page.h#L24
Now that various page size calculations are not needed, various
components are now dead code and can also be removed. This CL reverts:
https://go-review.googlesource.com/14483
and part of:
https://go-review.googlesource.com/30755
Change-Id: I9d7a2d96359054e0dca9c985b026c8072b2eeaf3
Reviewed-on: https://go-review.googlesource.com/62111
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/unix/gccgo_linux_sparc64.go b/unix/gccgo_linux_sparc64.go
deleted file mode 100644
index 5633269..0000000
--- a/unix/gccgo_linux_sparc64.go
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2016 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build gccgo,linux,sparc64
-
-package unix
-
-import "syscall"
-
-//extern sysconf
-func realSysconf(name int) int64
-
-func sysconf(name int) (n int64, err syscall.Errno) {
- r := realSysconf(name)
- if r < 0 {
- return 0, syscall.GetErrno()
- }
- return r, 0
-}
diff --git a/unix/linux/types.go b/unix/linux/types.go
index 0c381eb..426be5e 100644
--- a/unix/linux/types.go
+++ b/unix/linux/types.go
@@ -535,10 +535,6 @@
const PERF_IOC_FLAG_GROUP = C.PERF_IOC_FLAG_GROUP
-// sysconf information
-
-const _SC_PAGESIZE = C._SC_PAGESIZE
-
// Terminal handling
type Termios C.termios_t
diff --git a/unix/pagesize_unix.go b/unix/pagesize_unix.go
new file mode 100644
index 0000000..45afcf7
--- /dev/null
+++ b/unix/pagesize_unix.go
@@ -0,0 +1,15 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build darwin dragonfly freebsd linux netbsd openbsd solaris
+
+// For Unix, get the pagesize from the runtime.
+
+package unix
+
+import "syscall"
+
+func Getpagesize() int {
+ return syscall.Getpagesize()
+}
diff --git a/unix/syscall_darwin_386.go b/unix/syscall_darwin_386.go
index c172a3d..76634f7 100644
--- a/unix/syscall_darwin_386.go
+++ b/unix/syscall_darwin_386.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_darwin_amd64.go b/unix/syscall_darwin_amd64.go
index c6c99c1..7be02da 100644
--- a/unix/syscall_darwin_amd64.go
+++ b/unix/syscall_darwin_amd64.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_darwin_arm.go b/unix/syscall_darwin_arm.go
index d286cf4..26b6697 100644
--- a/unix/syscall_darwin_arm.go
+++ b/unix/syscall_darwin_arm.go
@@ -9,8 +9,6 @@
"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) {
diff --git a/unix/syscall_darwin_arm64.go b/unix/syscall_darwin_arm64.go
index c33905c..4d67a87 100644
--- a/unix/syscall_darwin_arm64.go
+++ b/unix/syscall_darwin_arm64.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_dragonfly_amd64.go b/unix/syscall_dragonfly_amd64.go
index da7cb79..6d8952d 100644
--- a/unix/syscall_dragonfly_amd64.go
+++ b/unix/syscall_dragonfly_amd64.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_freebsd_386.go b/unix/syscall_freebsd_386.go
index 6a0cd80..4cf5f45 100644
--- a/unix/syscall_freebsd_386.go
+++ b/unix/syscall_freebsd_386.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_freebsd_amd64.go b/unix/syscall_freebsd_amd64.go
index e142540..b8036e7 100644
--- a/unix/syscall_freebsd_amd64.go
+++ b/unix/syscall_freebsd_amd64.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_freebsd_arm.go b/unix/syscall_freebsd_arm.go
index 5504cb1..5a3bb6a 100644
--- a/unix/syscall_freebsd_arm.go
+++ b/unix/syscall_freebsd_arm.go
@@ -11,8 +11,6 @@
"unsafe"
)
-func Getpagesize() int { return 4096 }
-
func TimespecToNsec(ts Timespec) int64 { return ts.Sec*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_linux_386.go b/unix/syscall_linux_386.go
index 2b881b9..f4c826a 100644
--- a/unix/syscall_linux_386.go
+++ b/unix/syscall_linux_386.go
@@ -14,8 +14,6 @@
"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) {
diff --git a/unix/syscall_linux_amd64.go b/unix/syscall_linux_amd64.go
index 9516a3f..0715200 100644
--- a/unix/syscall_linux_amd64.go
+++ b/unix/syscall_linux_amd64.go
@@ -69,8 +69,6 @@
return nil
}
-func Getpagesize() int { return 4096 }
-
func Time(t *Time_t) (tt Time_t, err error) {
var tv Timeval
errno := gettimeofday(&tv)
diff --git a/unix/syscall_linux_arm.go b/unix/syscall_linux_arm.go
index 71d8702..2b79c84 100644
--- a/unix/syscall_linux_arm.go
+++ b/unix/syscall_linux_arm.go
@@ -11,8 +11,6 @@
"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) {
diff --git a/unix/syscall_linux_arm64.go b/unix/syscall_linux_arm64.go
index 4a13639..68cc975 100644
--- a/unix/syscall_linux_arm64.go
+++ b/unix/syscall_linux_arm64.go
@@ -66,8 +66,6 @@
//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 TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
diff --git a/unix/syscall_linux_mips64x.go b/unix/syscall_linux_mips64x.go
index 73318e5..977df44 100644
--- a/unix/syscall_linux_mips64x.go
+++ b/unix/syscall_linux_mips64x.go
@@ -55,8 +55,6 @@
//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) {
diff --git a/unix/syscall_linux_mipsx.go b/unix/syscall_linux_mipsx.go
index b83d93f..25a5a0d 100644
--- a/unix/syscall_linux_mipsx.go
+++ b/unix/syscall_linux_mipsx.go
@@ -235,5 +235,3 @@
}
return poll(&fds[0], len(fds), timeout)
}
-
-func Getpagesize() int { return 4096 }
diff --git a/unix/syscall_linux_ppc64x.go b/unix/syscall_linux_ppc64x.go
index 60770f6..28b7f35 100644
--- a/unix/syscall_linux_ppc64x.go
+++ b/unix/syscall_linux_ppc64x.go
@@ -61,8 +61,6 @@
//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)
diff --git a/unix/syscall_linux_s390x.go b/unix/syscall_linux_s390x.go
index 1708a4b..3845fc9 100644
--- a/unix/syscall_linux_s390x.go
+++ b/unix/syscall_linux_s390x.go
@@ -46,8 +46,6 @@
//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) {
diff --git a/unix/syscall_linux_sparc64.go b/unix/syscall_linux_sparc64.go
index 20b7454..bd9de3e 100644
--- a/unix/syscall_linux_sparc64.go
+++ b/unix/syscall_linux_sparc64.go
@@ -6,11 +6,6 @@
package unix
-import (
- "sync/atomic"
- "syscall"
-)
-
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error)
//sys Dup2(oldfd int, newfd int) (err error)
//sys Fchown(fd int, uid int, gid int) (err error)
@@ -63,21 +58,6 @@
//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 sysconf(name int) (n int64, err syscall.Errno)
-
-// pageSize caches the value of Getpagesize, since it can't change
-// once the system is booted.
-var pageSize int64 // accessed atomically
-
-func Getpagesize() int {
- n := atomic.LoadInt64(&pageSize)
- if n == 0 {
- n, _ = sysconf(_SC_PAGESIZE)
- atomic.StoreInt64(&pageSize, n)
- }
- return int(n)
-}
-
func Ioperm(from int, num int, on int) (err error) {
return ENOSYS
}
diff --git a/unix/syscall_netbsd_386.go b/unix/syscall_netbsd_386.go
index afaca09..baefa41 100644
--- a/unix/syscall_netbsd_386.go
+++ b/unix/syscall_netbsd_386.go
@@ -6,8 +6,6 @@
package unix
-func Getpagesize() int { return 4096 }
-
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_netbsd_amd64.go b/unix/syscall_netbsd_amd64.go
index a6ff04c..59c2ab7 100644
--- a/unix/syscall_netbsd_amd64.go
+++ b/unix/syscall_netbsd_amd64.go
@@ -6,8 +6,6 @@
package unix
-func Getpagesize() int { return 4096 }
-
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_netbsd_arm.go b/unix/syscall_netbsd_arm.go
index 68a6969..7208108 100644
--- a/unix/syscall_netbsd_arm.go
+++ b/unix/syscall_netbsd_arm.go
@@ -6,8 +6,6 @@
package unix
-func Getpagesize() int { return 4096 }
-
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_openbsd_386.go b/unix/syscall_openbsd_386.go
index a66ddc5..d3809b4 100644
--- a/unix/syscall_openbsd_386.go
+++ b/unix/syscall_openbsd_386.go
@@ -6,8 +6,6 @@
package unix
-func Getpagesize() int { return 4096 }
-
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_openbsd_amd64.go b/unix/syscall_openbsd_amd64.go
index 0776c1f..9a9dfce 100644
--- a/unix/syscall_openbsd_amd64.go
+++ b/unix/syscall_openbsd_amd64.go
@@ -6,8 +6,6 @@
package unix
-func Getpagesize() int { return 4096 }
-
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_openbsd_arm.go b/unix/syscall_openbsd_arm.go
index 14ddaf3..ba86490 100644
--- a/unix/syscall_openbsd_arm.go
+++ b/unix/syscall_openbsd_arm.go
@@ -6,10 +6,6 @@
package unix
-import "syscall"
-
-func Getpagesize() int { return syscall.Getpagesize() }
-
func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) }
func NsecToTimespec(nsec int64) (ts Timespec) {
diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go
index 0d4e5c4..dbb166e 100644
--- a/unix/syscall_solaris.go
+++ b/unix/syscall_solaris.go
@@ -13,7 +13,6 @@
package unix
import (
- "sync/atomic"
"syscall"
"unsafe"
)
@@ -699,18 +698,3 @@
func Munmap(b []byte) (err error) {
return mapper.Munmap(b)
}
-
-//sys sysconf(name int) (n int64, err error)
-
-// pageSize caches the value of Getpagesize, since it can't change
-// once the system is booted.
-var pageSize int64 // accessed atomically
-
-func Getpagesize() int {
- n := atomic.LoadInt64(&pageSize)
- if n == 0 {
- n, _ = sysconf(_SC_PAGESIZE)
- atomic.StoreInt64(&pageSize, n)
- }
- return int(n)
-}
diff --git a/unix/types_solaris.go b/unix/types_solaris.go
index 393c7f0..6d74614 100644
--- a/unix/types_solaris.go
+++ b/unix/types_solaris.go
@@ -256,10 +256,6 @@
type BpfHdr C.struct_bpf_hdr
-// sysconf information
-
-const _SC_PAGESIZE = C._SC_PAGESIZE
-
// Terminal handling
type Termios C.struct_termios
diff --git a/unix/zsyscall_solaris_amd64.go b/unix/zsyscall_solaris_amd64.go
index 4287133..32b0209 100644
--- a/unix/zsyscall_solaris_amd64.go
+++ b/unix/zsyscall_solaris_amd64.go
@@ -129,7 +129,6 @@
//go:cgo_import_dynamic libc_getpeername getpeername "libsocket.so"
//go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so"
//go:cgo_import_dynamic libc_recvfrom recvfrom "libsocket.so"
-//go:cgo_import_dynamic libc_sysconf sysconf "libc.so"
//go:linkname procpipe libc_pipe
//go:linkname procgetsockname libc_getsockname
@@ -250,7 +249,6 @@
//go:linkname procgetpeername libc_getpeername
//go:linkname procsetsockopt libc_setsockopt
//go:linkname procrecvfrom libc_recvfrom
-//go:linkname procsysconf libc_sysconf
var (
procpipe,
@@ -371,8 +369,7 @@
proc__xnet_getsockopt,
procgetpeername,
procsetsockopt,
- procrecvfrom,
- procsysconf syscallFunc
+ procrecvfrom syscallFunc
)
func pipe(p *[2]_C_int) (n int, err error) {
@@ -1589,12 +1586,3 @@
}
return
}
-
-func sysconf(name int) (n int64, err error) {
- r0, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procsysconf)), 1, uintptr(name), 0, 0, 0, 0, 0)
- n = int64(r0)
- if e1 != 0 {
- err = e1
- }
- return
-}
diff --git a/unix/ztypes_linux_386.go b/unix/ztypes_linux_386.go
index 01e6573..8b30c69 100644
--- a/unix/ztypes_linux_386.go
+++ b/unix/ztypes_linux_386.go
@@ -673,8 +673,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_amd64.go b/unix/ztypes_linux_amd64.go
index 7843f44..cf03589 100644
--- a/unix/ztypes_linux_amd64.go
+++ b/unix/ztypes_linux_amd64.go
@@ -691,8 +691,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_arm.go b/unix/ztypes_linux_arm.go
index a7b88b7..8ef7d85 100644
--- a/unix/ztypes_linux_arm.go
+++ b/unix/ztypes_linux_arm.go
@@ -662,8 +662,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_arm64.go b/unix/ztypes_linux_arm64.go
index 2d6e1d7..3110268 100644
--- a/unix/ztypes_linux_arm64.go
+++ b/unix/ztypes_linux_arm64.go
@@ -670,8 +670,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_mips.go b/unix/ztypes_linux_mips.go
index 5b64750..d2c1bc2 100644
--- a/unix/ztypes_linux_mips.go
+++ b/unix/ztypes_linux_mips.go
@@ -667,8 +667,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_mips64.go b/unix/ztypes_linux_mips64.go
index 17c942d..ec7a0cd 100644
--- a/unix/ztypes_linux_mips64.go
+++ b/unix/ztypes_linux_mips64.go
@@ -672,8 +672,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_mips64le.go b/unix/ztypes_linux_mips64le.go
index eee3bce..bbe08d7 100644
--- a/unix/ztypes_linux_mips64le.go
+++ b/unix/ztypes_linux_mips64le.go
@@ -672,8 +672,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_mipsle.go b/unix/ztypes_linux_mipsle.go
index 47aded5..75ee05a 100644
--- a/unix/ztypes_linux_mipsle.go
+++ b/unix/ztypes_linux_mipsle.go
@@ -667,8 +667,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_ppc64.go b/unix/ztypes_linux_ppc64.go
index 2c5caad..30a257f 100644
--- a/unix/ztypes_linux_ppc64.go
+++ b/unix/ztypes_linux_ppc64.go
@@ -680,8 +680,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_ppc64le.go b/unix/ztypes_linux_ppc64le.go
index 60d82b0..bebed6f 100644
--- a/unix/ztypes_linux_ppc64le.go
+++ b/unix/ztypes_linux_ppc64le.go
@@ -680,8 +680,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32
diff --git a/unix/ztypes_linux_s390x.go b/unix/ztypes_linux_s390x.go
index c29138e..286661b 100644
--- a/unix/ztypes_linux_s390x.go
+++ b/unix/ztypes_linux_s390x.go
@@ -697,8 +697,6 @@
const PERF_IOC_FLAG_GROUP = 0x1
-const _SC_PAGESIZE = 0x1e
-
type Termios struct {
Iflag uint32
Oflag uint32