unix: export sizeof consts

Export the sizeof(Ptr|Short|Int|Long|LongLong) consts. This allows users
to get this information (e.g. for alignment purposes) without using cgo
or generating these constants themselves.

Change-Id: I8640482bf67b89c2f2b6e9a116ba7bc268f8135a
Reviewed-on: https://go-review.googlesource.com/c/139617
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tobias Klauser
2018-10-04 14:53:25 +00:00
committed by Tobias Klauser
parent af653ce8b7
commit 8469e31483
41 changed files with 216 additions and 216 deletions
+6 -6
View File
@@ -328,14 +328,14 @@ struct my_blkpg_partition {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
PathMax = C.PATH_MAX PathMax = C.PATH_MAX
) )
+1 -1
View File
@@ -12,7 +12,7 @@ import "unsafe"
// Round the length of a raw sockaddr up to align it properly. // Round the length of a raw sockaddr up to align it properly.
func cmsgAlignOf(salen int) int { func cmsgAlignOf(salen int) int {
salign := sizeofPtr salign := SizeofPtr
// NOTE: It seems like 64-bit Darwin, DragonFly BSD and // NOTE: It seems like 64-bit Darwin, DragonFly BSD and
// Solaris kernels still require 32-bit aligned access to // Solaris kernels still require 32-bit aligned access to
// network subsystem. // network subsystem.
+13 -13
View File
@@ -1122,7 +1122,7 @@ func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err erro
// The ptrace syscall differs from glibc's ptrace. // The ptrace syscall differs from glibc's ptrace.
// Peeks returns the word in *data, not as the return value. // Peeks returns the word in *data, not as the return value.
var buf [sizeofPtr]byte var buf [SizeofPtr]byte
// Leading edge. PEEKTEXT/PEEKDATA don't require aligned // Leading edge. PEEKTEXT/PEEKDATA don't require aligned
// access (PEEKUSER warns that it might), but if we don't // access (PEEKUSER warns that it might), but if we don't
@@ -1130,12 +1130,12 @@ func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err erro
// boundary and not get the bytes leading up to the page // boundary and not get the bytes leading up to the page
// boundary. // boundary.
n := 0 n := 0
if addr%sizeofPtr != 0 { if addr%SizeofPtr != 0 {
err = ptrace(req, pid, addr-addr%sizeofPtr, uintptr(unsafe.Pointer(&buf[0]))) err = ptrace(req, pid, addr-addr%SizeofPtr, uintptr(unsafe.Pointer(&buf[0])))
if err != nil { if err != nil {
return 0, err return 0, err
} }
n += copy(out, buf[addr%sizeofPtr:]) n += copy(out, buf[addr%SizeofPtr:])
out = out[n:] out = out[n:]
} }
@@ -1173,15 +1173,15 @@ func ptracePoke(pokeReq int, peekReq int, pid int, addr uintptr, data []byte) (c
// Leading edge. // Leading edge.
n := 0 n := 0
if addr%sizeofPtr != 0 { if addr%SizeofPtr != 0 {
var buf [sizeofPtr]byte var buf [SizeofPtr]byte
err = ptrace(peekReq, pid, addr-addr%sizeofPtr, uintptr(unsafe.Pointer(&buf[0]))) err = ptrace(peekReq, pid, addr-addr%SizeofPtr, uintptr(unsafe.Pointer(&buf[0])))
if err != nil { if err != nil {
return 0, err return 0, err
} }
n += copy(buf[addr%sizeofPtr:], data) n += copy(buf[addr%SizeofPtr:], data)
word := *((*uintptr)(unsafe.Pointer(&buf[0]))) word := *((*uintptr)(unsafe.Pointer(&buf[0])))
err = ptrace(pokeReq, pid, addr-addr%sizeofPtr, word) err = ptrace(pokeReq, pid, addr-addr%SizeofPtr, word)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@@ -1189,19 +1189,19 @@ func ptracePoke(pokeReq int, peekReq int, pid int, addr uintptr, data []byte) (c
} }
// Interior. // Interior.
for len(data) > sizeofPtr { for len(data) > SizeofPtr {
word := *((*uintptr)(unsafe.Pointer(&data[0]))) word := *((*uintptr)(unsafe.Pointer(&data[0])))
err = ptrace(pokeReq, pid, addr+uintptr(n), word) err = ptrace(pokeReq, pid, addr+uintptr(n), word)
if err != nil { if err != nil {
return n, err return n, err
} }
n += sizeofPtr n += SizeofPtr
data = data[sizeofPtr:] data = data[SizeofPtr:]
} }
// Trailing edge. // Trailing edge.
if len(data) > 0 { if len(data) > 0 {
var buf [sizeofPtr]byte var buf [SizeofPtr]byte
err = ptrace(peekReq, pid, addr+uintptr(n), uintptr(unsafe.Pointer(&buf[0]))) err = ptrace(peekReq, pid, addr+uintptr(n), uintptr(unsafe.Pointer(&buf[0])))
if err != nil { if err != nil {
return n, err return n, err
+4 -4
View File
@@ -22,10 +22,10 @@ var (
) )
const ( const (
darwin64Bit = runtime.GOOS == "darwin" && sizeofPtr == 8 darwin64Bit = runtime.GOOS == "darwin" && SizeofPtr == 8
dragonfly64Bit = runtime.GOOS == "dragonfly" && sizeofPtr == 8 dragonfly64Bit = runtime.GOOS == "dragonfly" && SizeofPtr == 8
netbsd32Bit = runtime.GOOS == "netbsd" && sizeofPtr == 4 netbsd32Bit = runtime.GOOS == "netbsd" && SizeofPtr == 4
solaris64Bit = runtime.GOOS == "solaris" && sizeofPtr == 8 solaris64Bit = runtime.GOOS == "solaris" && SizeofPtr == 8
) )
// Do the interface allocations only once for common // Do the interface allocations only once for common
+6 -6
View File
@@ -59,14 +59,14 @@ struct sockaddr_any {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
PathMax = C.PATH_MAX PathMax = C.PATH_MAX
) )
+6 -6
View File
@@ -70,14 +70,14 @@ struct sockaddr_any {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
) )
// Basic types // Basic types
+6 -6
View File
@@ -65,14 +65,14 @@ struct sockaddr_any {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
) )
// Basic types // Basic types
+6 -6
View File
@@ -154,14 +154,14 @@ struct if_msghdr8 {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
) )
// Basic types // Basic types
+6 -6
View File
@@ -67,14 +67,14 @@ struct sockaddr_any {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
) )
// Basic types // Basic types
+6 -6
View File
@@ -67,14 +67,14 @@ struct sockaddr_any {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
) )
// Basic types // Basic types
+6 -6
View File
@@ -75,14 +75,14 @@ struct sockaddr_any {
*/ */
import "C" import "C"
// Machine characteristics; for internal use. // Machine characteristics
const ( const (
sizeofPtr = C.sizeofPtr SizeofPtr = C.sizeofPtr
sizeofShort = C.sizeof_short SizeofShort = C.sizeof_short
sizeofInt = C.sizeof_int SizeofInt = C.sizeof_int
sizeofLong = C.sizeof_long SizeofLong = C.sizeof_long
sizeofLongLong = C.sizeof_longlong SizeofLongLong = C.sizeof_longlong
PathMax = C.PATH_MAX PathMax = C.PATH_MAX
MaxHostNameLen = C.MAXHOSTNAMELEN MaxHostNameLen = C.MAXHOSTNAMELEN
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x3ff PathMax = 0x3ff
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x3ff PathMax = 0x3ff
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -7,11 +7,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -5,11 +5,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x1000 PathMax = 0x1000
) )
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x4 SizeofPtr = 0x4
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x4 SizeofLong = 0x4
sizeofLongLong = 0x8 SizeofLongLong = 0x8
) )
type ( type (
+5 -5
View File
@@ -6,11 +6,11 @@
package unix package unix
const ( const (
sizeofPtr = 0x8 SizeofPtr = 0x8
sizeofShort = 0x2 SizeofShort = 0x2
sizeofInt = 0x4 SizeofInt = 0x4
sizeofLong = 0x8 SizeofLong = 0x8
sizeofLongLong = 0x8 SizeofLongLong = 0x8
PathMax = 0x400 PathMax = 0x400
MaxHostNameLen = 0x100 MaxHostNameLen = 0x100
) )