sys, prog: switch values to to uint64

We currently use uintptr for all values.
This won't work for 32-bit archs.
Moreover in some cases we use uintptr but assume
that it is always 64-bits (e.g. in encodingexec).
Switch everything to uint64.

Update #324
This commit is contained in:
Dmitry Vyukov 2017-08-19 09:46:43 +02:00
parent 33b9e777cb
commit 838e336594
17 changed files with 13259 additions and 13261 deletions

View File

@ -259,13 +259,13 @@ func generateTestFunc(w io.Writer, opts Options, calls []string, name string) {
}
func generateCalls(exec []byte, opts Options) ([]string, int) {
read := func() uintptr {
read := func() uint64 {
if len(exec) < 8 {
panic("exec program overflow")
}
v := *(*uint64)(unsafe.Pointer(&exec[0]))
exec = exec[8:]
return uintptr(v)
return v
}
resultRef := func() string {
arg := read()
@ -332,8 +332,8 @@ loop:
case prog.ExecArgCsumInet:
fmt.Fprintf(w, "\tstruct csum_inet csum_%d;\n", n)
fmt.Fprintf(w, "\tcsum_inet_init(&csum_%d);\n", n)
csum_chunks_num := read()
for i := uintptr(0); i < csum_chunks_num; i++ {
csumChunksNum := read()
for i := uint64(0); i < csumChunksNum; i++ {
chunk_kind := read()
chunk_value := read()
chunk_size := read()
@ -383,7 +383,7 @@ loop:
}
}
nargs := read()
for i := uintptr(0); i < nargs; i++ {
for i := uint64(0); i < nargs; i++ {
typ := read()
size := read()
_ = size

View File

@ -99,11 +99,11 @@ func (s *state) analyze(c *Call) {
func (s *state) addressable(addr *PointerArg, size *ConstArg, ok bool) {
sizePages := size.Val / pageSize
if addr.PageIndex+sizePages > uintptr(len(s.pages)) {
if addr.PageIndex+sizePages > uint64(len(s.pages)) {
panic(fmt.Sprintf("address is out of bounds: page=%v len=%v bound=%v\naddr: %+v\nsize: %+v",
addr.PageIndex, sizePages, len(s.pages), addr, size))
}
for i := uintptr(0); i < sizePages; i++ {
for i := uint64(0); i < sizePages; i++ {
s.pages[addr.PageIndex+i] = ok
}
}
@ -149,13 +149,13 @@ func foreachArg(c *Call, f func(arg, base Arg, parent *[]Arg)) {
foreachArgArray(&c.Args, nil, f)
}
func foreachSubargOffset(arg Arg, f func(arg Arg, offset uintptr)) {
var rec func(Arg, uintptr) uintptr
rec = func(arg1 Arg, offset uintptr) uintptr {
func foreachSubargOffset(arg Arg, f func(arg Arg, offset uint64)) {
var rec func(Arg, uint64) uint64
rec = func(arg1 Arg, offset uint64) uint64 {
switch a := arg1.(type) {
case *GroupArg:
f(arg1, offset)
var totalSize uintptr
var totalSize uint64
for _, arg2 := range a.Inner {
size := rec(arg2, offset)
if arg2.Type().BitfieldLength() == 0 || arg2.Type().BitfieldLast() {
@ -250,7 +250,7 @@ func sanitizeCall(c *Call) {
// PTRACE_TRACEME leads to unkillable processes, see:
// https://groups.google.com/forum/#!topic/syzkaller/uGzwvhlCXAw
if req.Val == sys.PTRACE_TRACEME {
req.Val = ^uintptr(0)
req.Val = ^uint64(0)
}
case "exit", "exit_group":
code := c.Args[0].(*ConstArg)

View File

@ -29,9 +29,9 @@ type CsumInfo struct {
type CsumChunk struct {
Kind CsumChunkKind
Arg Arg // for CsumChunkArg
Value uintptr // for CsumChunkConst
Size uintptr // for CsumChunkConst
Arg Arg // for CsumChunkArg
Value uint64 // for CsumChunkConst
Size uint64 // for CsumChunkConst
}
func getFieldByName(arg Arg, name string) Arg {
@ -71,8 +71,8 @@ func composePseudoCsumIPv4(tcpPacket, srcAddr, dstAddr Arg, protocol uint8, pid
info := CsumInfo{Kind: CsumInet}
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkArg, srcAddr, 0, 0})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkArg, dstAddr, 0, 0})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uintptr(swap16(uint16(protocol))), 2})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uintptr(swap16(uint16(tcpPacket.Size()))), 2})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uint64(swap16(uint16(protocol))), 2})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uint64(swap16(uint16(tcpPacket.Size()))), 2})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkArg, tcpPacket, 0, 0})
return info
}
@ -81,8 +81,8 @@ func composePseudoCsumIPv6(tcpPacket, srcAddr, dstAddr Arg, protocol uint8, pid
info := CsumInfo{Kind: CsumInet}
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkArg, srcAddr, 0, 0})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkArg, dstAddr, 0, 0})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uintptr(swap32(uint32(tcpPacket.Size()))), 4})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uintptr(swap32(uint32(protocol))), 4})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uint64(swap32(uint32(tcpPacket.Size()))), 4})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkConst, nil, uint64(swap32(uint32(protocol))), 4})
info.Chunks = append(info.Chunks, CsumChunk{CsumChunkArg, tcpPacket, 0, 0})
return info
}

View File

@ -213,9 +213,9 @@ func parseArg(typ sys.Type, p *parser, vars map[string]Arg) (Arg, error) {
}
switch typ.(type) {
case *sys.ConstType, *sys.IntType, *sys.FlagsType, *sys.ProcType, *sys.LenType, *sys.CsumType:
arg = constArg(typ, uintptr(v))
arg = constArg(typ, v)
case *sys.ResourceType:
arg = resultArg(typ, nil, uintptr(v))
arg = resultArg(typ, nil, v)
case *sys.PtrType:
arg = pointerArg(typ, 0, 0, 0, nil)
case *sys.VmaType:
@ -237,7 +237,7 @@ func parseArg(typ sys.Type, p *parser, vars map[string]Arg) (Arg, error) {
if err != nil {
return nil, fmt.Errorf("wrong result div op: '%v'", op)
}
arg.(*ResultArg).OpDiv = uintptr(v)
arg.(*ResultArg).OpDiv = v
}
if p.Char() == '+' {
p.Parse('+')
@ -246,7 +246,7 @@ func parseArg(typ sys.Type, p *parser, vars map[string]Arg) (Arg, error) {
if err != nil {
return nil, fmt.Errorf("wrong result add op: '%v'", op)
}
arg.(*ResultArg).OpAdd = uintptr(v)
arg.(*ResultArg).OpAdd = v
}
case '&':
var typ1 sys.Type
@ -383,9 +383,8 @@ const (
)
func serializeAddr(arg Arg) string {
var pageIndex uintptr
var pageIndex, pagesNum uint64
var pageOffset int
var pagesNum uintptr
switch a := arg.(type) {
case *PointerArg:
pageIndex = a.PageIndex
@ -414,7 +413,7 @@ func serializeAddr(arg Arg) string {
return fmt.Sprintf("(0x%x%v%v)", page, soff, ssize)
}
func parseAddr(p *parser, base bool) (uintptr, int, uintptr, error) {
func parseAddr(p *parser, base bool) (uint64, int, uint64, error) {
p.Parse('(')
pstr := p.Ident()
page, err := strconv.ParseUint(pstr, 0, 64)
@ -461,7 +460,7 @@ func parseAddr(p *parser, base bool) (uintptr, int, uintptr, error) {
p.Parse(')')
page /= encodingPageSize
size /= encodingPageSize
return uintptr(page), int(off), uintptr(size), nil
return page, int(off), size, nil
}
type parser struct {

View File

@ -14,24 +14,24 @@ import (
)
const (
ExecInstrEOF = ^uintptr(iota)
ExecInstrEOF = ^uint64(iota)
ExecInstrCopyin
ExecInstrCopyout
)
const (
ExecArgConst = uintptr(iota)
ExecArgConst = uint64(iota)
ExecArgResult
ExecArgData
ExecArgCsum
)
const (
ExecArgCsumInet = uintptr(iota)
ExecArgCsumInet = uint64(iota)
)
const (
ExecArgCsumChunkData = uintptr(iota)
ExecArgCsumChunkData = uint64(iota)
ExecArgCsumChunkConst
)
@ -70,7 +70,7 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
panic(fmt.Errorf("serializing invalid program: %v", err))
}
}
var instrSeq uintptr
instrSeq := 0
w := &execContext{
buf: buffer,
eof: false,
@ -97,7 +97,7 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
// Generate copyin instructions that fill in data into pointer arguments.
foreachArg(c, func(arg, _ Arg, _ *[]Arg) {
if a, ok := arg.(*PointerArg); ok && a.Res != nil {
foreachSubargOffset(a.Res, func(arg1 Arg, offset uintptr) {
foreachSubargOffset(a.Res, func(arg1 Arg, offset uint64) {
used, ok := arg1.(ArgUsed)
if (ok && len(*used.Used()) != 0) || csumUses[arg1] {
w.args[arg1] = argInfo{Addr: physicalAddr(arg) + offset}
@ -140,7 +140,7 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
switch csumMap[arg].Kind {
case CsumInet:
w.write(ExecArgCsumInet)
w.write(uintptr(len(csumMap[arg].Chunks)))
w.write(uint64(len(csumMap[arg].Chunks)))
for _, chunk := range csumMap[arg].Chunks {
switch chunk.Kind {
case CsumChunkArg:
@ -162,8 +162,8 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
}
}
// Generate the call itself.
w.write(uintptr(c.Meta.ID))
w.write(uintptr(len(c.Args)))
w.write(uint64(c.Meta.ID))
w.write(uint64(len(c.Args)))
for _, arg := range c.Args {
w.writeArg(arg, pid, csumMap)
}
@ -203,16 +203,16 @@ func (p *Prog) SerializeForExec(buffer []byte, pid int) error {
return nil
}
func physicalAddr(arg Arg) uintptr {
func physicalAddr(arg Arg) uint64 {
a, ok := arg.(*PointerArg)
if !ok {
panic("physicalAddr: bad arg kind")
}
addr := a.PageIndex*pageSize + dataOffset
if a.PageOffset >= 0 {
addr += uintptr(a.PageOffset)
addr += uint64(a.PageOffset)
} else {
addr += pageSize - uintptr(-a.PageOffset)
addr += pageSize - uint64(-a.PageOffset)
}
return addr
}
@ -224,11 +224,11 @@ type execContext struct {
}
type argInfo struct {
Addr uintptr // physical addr
Idx uintptr // instruction index
Addr uint64 // physical addr
Idx int // instruction index
}
func (w *execContext) write(v uintptr) {
func (w *execContext) write(v uint64) {
if len(w.buf) < 8 {
w.eof = true
return
@ -262,7 +262,7 @@ func (w *execContext) writeArg(arg Arg, pid int, csumMap map[Arg]CsumInfo) {
} else {
w.write(ExecArgResult)
w.write(a.Size())
w.write(w.args[a.Res].Idx)
w.write(uint64(w.args[a.Res].Idx))
w.write(a.OpDiv)
w.write(a.OpAdd)
}
@ -274,7 +274,7 @@ func (w *execContext) writeArg(arg Arg, pid int, csumMap map[Arg]CsumInfo) {
w.write(0) // bit field length
case *DataArg:
w.write(ExecArgData)
w.write(uintptr(len(a.Data)))
w.write(uint64(len(a.Data)))
padded := len(a.Data)
if pad := 8 - len(a.Data)%8; pad != 8 {
padded += pad

View File

@ -5,7 +5,6 @@ package prog
import (
"fmt"
"math"
"math/rand"
"unsafe"
@ -71,7 +70,7 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
}
idx := r.Intn(len(args))
arg, base := args[idx], bases[idx]
var baseSize uintptr
var baseSize uint64
if base != nil {
b, ok := base.(*PointerArg)
if !ok || b.Res == nil {
@ -88,11 +87,11 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
} else {
switch {
case r.nOutOf(1, 3):
a.Val += uintptr(r.Intn(4)) + 1
a.Val += uint64(r.Intn(4)) + 1
case r.nOutOf(1, 2):
a.Val -= uintptr(r.Intn(4)) + 1
a.Val -= uint64(r.Intn(4)) + 1
default:
a.Val ^= 1 << uintptr(r.Intn(64))
a.Val ^= 1 << uint64(r.Intn(64))
}
}
case *sys.ResourceType, *sys.VmaType, *sys.ProcType:
@ -104,20 +103,20 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
case sys.BufferBlobRand, sys.BufferBlobRange:
var data []byte
data = append([]byte{}, a.Data...)
minLen := int(0)
maxLen := math.MaxInt32
var minLen uint64
maxLen := ^uint64(0)
if t.Kind == sys.BufferBlobRange {
minLen = int(t.RangeBegin)
maxLen = int(t.RangeEnd)
minLen = t.RangeBegin
maxLen = t.RangeEnd
}
a.Data = mutateData(r, data, minLen, maxLen)
case sys.BufferString:
if r.bin() {
minLen := int(0)
maxLen := math.MaxInt32
var minLen uint64
maxLen := ^uint64(0)
if t.Length != 0 {
minLen = int(t.Length)
maxLen = int(t.Length)
minLen = t.Length
maxLen = t.Length
}
a.Data = mutateData(r, append([]byte{}, a.Data...), minLen, maxLen)
} else {
@ -132,23 +131,23 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
}
case *sys.ArrayType:
a := arg.(*GroupArg)
count := uintptr(0)
count := uint64(0)
switch t.Kind {
case sys.ArrayRandLen:
for count == uintptr(len(a.Inner)) {
for count == uint64(len(a.Inner)) {
count = r.randArrayLen()
}
case sys.ArrayRangeLen:
if t.RangeBegin == t.RangeEnd {
panic("trying to mutate fixed length array")
}
for count == uintptr(len(a.Inner)) {
count = r.randRange(int(t.RangeBegin), int(t.RangeEnd))
for count == uint64(len(a.Inner)) {
count = r.randRange(t.RangeBegin, t.RangeEnd)
}
}
if count > uintptr(len(a.Inner)) {
if count > uint64(len(a.Inner)) {
var calls []*Call
for count > uintptr(len(a.Inner)) {
for count > uint64(len(a.Inner)) {
arg1, calls1 := r.generateArg(s, t.Type)
a.Inner = append(a.Inner, arg1)
for _, c1 := range calls1 {
@ -161,7 +160,7 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
}
sanitizeCall(c)
p.insertBefore(c, calls)
} else if count < uintptr(len(a.Inner)) {
} else if count < uint64(len(a.Inner)) {
for _, arg := range a.Inner[count:] {
p.removeArg(c, arg)
}
@ -174,7 +173,7 @@ func (p *Prog) Mutate(rs rand.Source, ncalls int, ct *ChoiceTable, corpus []*Pro
break
}
// TODO: we don't know size for out args
size := uintptr(1)
size := uint64(1)
if a.Res != nil {
size = a.Res.Size()
}
@ -294,7 +293,7 @@ func Minimize(p0 *Prog, callIndex0 int, pred func(*Prog, int) bool, crash bool)
}
}
// Prepend uber-mmap.
mmap := createMmapCall(uintptr(lo), uintptr(hi-lo)+1)
mmap := createMmapCall(uint64(lo), uint64(hi-lo)+1)
p.Calls = append([]*Call{mmap}, p.Calls...)
if callIndex != -1 {
callIndex++
@ -581,7 +580,7 @@ func swap64(v uint64) uint64 {
return v
}
func mutateData(r *randGen, data []byte, minLen, maxLen int) []byte {
func mutateData(r *randGen, data []byte, minLen, maxLen uint64) []byte {
const maxInc = 35
retry := false
loop:
@ -590,14 +589,14 @@ loop:
switch r.Intn(13) {
case 0:
// Append byte.
if len(data) >= maxLen {
if uint64(len(data)) >= maxLen {
retry = true
continue loop
}
data = append(data, byte(r.rand(256)))
case 1:
// Remove byte.
if len(data) == 0 || len(data) <= minLen {
if len(data) == 0 || uint64(len(data)) <= minLen {
retry = true
continue loop
}
@ -683,7 +682,7 @@ loop:
}
i := r.Intn(len(data) - 7)
p := (*uint64)(unsafe.Pointer(&data[i]))
delta := uint64(r.rand(2*maxInc+1) - maxInc)
delta := r.rand(2*maxInc+1) - maxInc
if delta == 0 {
delta = 1
}
@ -730,7 +729,7 @@ loop:
continue loop
}
i := r.Intn(len(data) - 7)
value := uint64(r.randInt())
value := r.randInt()
if r.bin() {
value = swap64(value)
}

View File

@ -21,7 +21,7 @@ type Call struct {
type Arg interface {
Type() sys.Type
Size() uintptr
Size() uint64
}
type ArgCommon struct {
@ -35,15 +35,15 @@ func (arg *ArgCommon) Type() sys.Type {
// Used for ConstType, IntType, FlagsType, LenType, ProcType and CsumType.
type ConstArg struct {
ArgCommon
Val uintptr
Val uint64
}
func (arg *ConstArg) Size() uintptr {
func (arg *ConstArg) Size() uint64 {
return arg.typ.Size()
}
// Returns value taking endianness and executor pid into consideration.
func (arg *ConstArg) Value(pid int) uintptr {
func (arg *ConstArg) Value(pid int) uint64 {
switch typ := (*arg).Type().(type) {
case *sys.IntType:
return encodeValue(arg.Val, typ.Size(), typ.BigEndian)
@ -63,7 +63,7 @@ func (arg *ConstArg) Value(pid int) uintptr {
panic(fmt.Sprintf("bad base type for a resource: %v", t))
}
case *sys.ProcType:
val := uintptr(typ.ValuesStart) + uintptr(typ.ValuesPerProc)*uintptr(pid) + arg.Val
val := typ.ValuesStart + typ.ValuesPerProc*uint64(pid) + arg.Val
return encodeValue(val, typ.Size(), typ.BigEndian)
}
return arg.Val
@ -74,13 +74,13 @@ func (arg *ConstArg) Value(pid int) uintptr {
// type because they are represented in an abstract (base+page+offset) form.
type PointerArg struct {
ArgCommon
PageIndex uintptr
PageOffset int // offset within a page
PagesNum uintptr // number of available pages
Res Arg // pointee
PageIndex uint64
PageOffset int // offset within a page
PagesNum uint64 // number of available pages
Res Arg // pointee
}
func (arg *PointerArg) Size() uintptr {
func (arg *PointerArg) Size() uint64 {
return arg.typ.Size()
}
@ -90,8 +90,8 @@ type DataArg struct {
Data []byte
}
func (arg *DataArg) Size() uintptr {
return uintptr(len(arg.Data))
func (arg *DataArg) Size() uint64 {
return uint64(len(arg.Data))
}
// Used for StructType and ArrayType.
@ -101,10 +101,10 @@ type GroupArg struct {
Inner []Arg
}
func (arg *GroupArg) Size() uintptr {
func (arg *GroupArg) Size() uint64 {
switch typ := (*arg).Type().(type) {
case *sys.StructType:
var size uintptr
var size uint64
for _, fld := range arg.Inner {
if fld.Type().BitfieldLength() == 0 || fld.Type().BitfieldLast() {
size += fld.Size()
@ -120,7 +120,7 @@ func (arg *GroupArg) Size() uintptr {
}
return size
case *sys.ArrayType:
var size uintptr
var size uint64
for _, in := range arg.Inner {
size += in.Size()
}
@ -137,7 +137,7 @@ type UnionArg struct {
OptionType sys.Type
}
func (arg *UnionArg) Size() uintptr {
func (arg *UnionArg) Size() uint64 {
if !arg.Type().Varlen() {
return arg.Type().Size()
} else {
@ -150,13 +150,13 @@ func (arg *UnionArg) Size() uintptr {
type ResultArg struct {
ArgCommon
Res Arg // reference to arg which we use
OpDiv uintptr // divide result (executed before OpAdd)
OpAdd uintptr // add to result
Val uintptr // value used if Res is nil
OpDiv uint64 // divide result (executed before OpAdd)
OpAdd uint64 // add to result
Val uint64 // value used if Res is nil
uses map[Arg]bool // ArgResult args that use this arg
}
func (arg *ResultArg) Size() uintptr {
func (arg *ResultArg) Size() uint64 {
return arg.typ.Size()
}
@ -167,7 +167,7 @@ type ReturnArg struct {
uses map[Arg]bool // ArgResult args that use this arg
}
func (arg *ReturnArg) Size() uintptr {
func (arg *ReturnArg) Size() uint64 {
panic("not called")
}
@ -209,27 +209,27 @@ func InnerArg(arg Arg) Arg {
return arg // Not a pointer.
}
func encodeValue(value, size uintptr, bigEndian bool) uintptr {
func encodeValue(value uint64, size uint64, bigEndian bool) uint64 {
if !bigEndian {
return value
}
switch size {
case 2:
return uintptr(swap16(uint16(value)))
return uint64(swap16(uint16(value)))
case 4:
return uintptr(swap32(uint32(value)))
return uint64(swap32(uint32(value)))
case 8:
return uintptr(swap64(uint64(value)))
return swap64(value)
default:
panic(fmt.Sprintf("bad size %v for value %v", size, value))
}
}
func constArg(t sys.Type, v uintptr) Arg {
func constArg(t sys.Type, v uint64) Arg {
return &ConstArg{ArgCommon: ArgCommon{typ: t}, Val: v}
}
func resultArg(t sys.Type, r Arg, v uintptr) Arg {
func resultArg(t sys.Type, r Arg, v uint64) Arg {
arg := &ResultArg{ArgCommon: ArgCommon{typ: t}, Res: r, Val: v}
if r == nil {
return arg
@ -250,7 +250,7 @@ func dataArg(t sys.Type, data []byte) Arg {
return &DataArg{ArgCommon: ArgCommon{typ: t}, Data: append([]byte{}, data...)}
}
func pointerArg(t sys.Type, page uintptr, off int, npages uintptr, obj Arg) Arg {
func pointerArg(t sys.Type, page uint64, off int, npages uint64, obj Arg) Arg {
return &PointerArg{ArgCommon: ArgCommon{typ: t}, PageIndex: page, PageOffset: off, PagesNum: npages, Res: obj}
}

View File

@ -96,7 +96,7 @@ func TestVmaType(t *testing.T) {
if len(c.Args) != 6 {
t.Fatalf("generated wrong number of args %v", len(c.Args))
}
check := func(v, l Arg, min, max uintptr) {
check := func(v, l Arg, min, max uint64) {
va, ok := v.(*PointerArg)
if !ok {
t.Fatalf("vma has bad type: %v", v)

View File

@ -15,7 +15,7 @@ import (
"github.com/google/syzkaller/sys"
)
var pageStartPool = sync.Pool{New: func() interface{} { return new([]uintptr) }}
var pageStartPool = sync.Pool{New: func() interface{} { return new([]uint64) }}
type randGen struct {
*rand.Rand
@ -27,12 +27,12 @@ func newRand(rs rand.Source) *randGen {
return &randGen{rand.New(rs), false, make(map[sys.Type]int)}
}
func (r *randGen) rand(n int) uintptr {
return uintptr(r.Intn(n))
func (r *randGen) rand(n int) uint64 {
return uint64(r.Intn(n))
}
func (r *randGen) randRange(begin int, end int) uintptr {
return uintptr(begin + r.Intn(end-begin+1))
func (r *randGen) randRange(begin, end uint64) uint64 {
return begin + uint64(r.Intn(int(end-begin+1)))
}
func (r *randGen) bin() bool {
@ -43,8 +43,8 @@ func (r *randGen) oneOf(n int) bool {
return r.Intn(n) == 0
}
func (r *randGen) rand64() uintptr {
v := uintptr(r.Int63())
func (r *randGen) rand64() uint64 {
v := uint64(r.Int63())
if r.bin() {
v |= 1 << 63
}
@ -52,7 +52,7 @@ func (r *randGen) rand64() uintptr {
}
// Some potentially interesting integers.
var specialInts = []uintptr{
var specialInts = []uint64{
0, 1, 31, 32, 63, 64, 127, 128,
129, 255, 256, 257, 511, 512,
1023, 1024, 1025, 2047, 2048, 4095, 4096,
@ -62,7 +62,7 @@ var specialInts = []uintptr{
(1 << 32) - 1, (1 << 32), (1 << 32) + 1,
}
func (r *randGen) randInt() uintptr {
func (r *randGen) randInt() uint64 {
v := r.rand64()
switch {
case r.nOutOf(100, 182):
@ -81,18 +81,18 @@ func (r *randGen) randInt() uintptr {
switch {
case r.nOutOf(100, 107):
case r.nOutOf(5, 7):
v = uintptr(-int(v))
v = uint64(-int64(v))
default:
v <<= uint(r.Intn(63))
}
return v
}
func (r *randGen) randRangeInt(begin int64, end int64) uintptr {
func (r *randGen) randRangeInt(begin uint64, end uint64) uint64 {
if r.oneOf(100) {
return r.randInt()
}
return uintptr(begin + r.Int63n(end-begin+1))
return begin + uint64(r.Int63n(int64(end-begin+1)))
}
// biasedRand returns a random int in range [0..n),
@ -104,14 +104,14 @@ func (r *randGen) biasedRand(n, k int) int {
return int(bf)
}
func (r *randGen) randArrayLen() uintptr {
func (r *randGen) randArrayLen() uint64 {
const maxLen = 10
// biasedRand produces: 10, 9, ..., 1, 0,
// we want: 1, 2, ..., 9, 10, 0
return uintptr(maxLen-r.biasedRand(maxLen+1, 10)+1) % (maxLen + 1)
return uint64(maxLen-r.biasedRand(maxLen+1, 10)+1) % (maxLen + 1)
}
func (r *randGen) randBufLen() (n uintptr) {
func (r *randGen) randBufLen() (n uint64) {
switch {
case r.nOutOf(50, 56):
n = r.rand(256)
@ -121,7 +121,7 @@ func (r *randGen) randBufLen() (n uintptr) {
return
}
func (r *randGen) randPageCount() (n uintptr) {
func (r *randGen) randPageCount() (n uint64) {
switch {
case r.nOutOf(100, 106):
n = r.rand(4) + 1
@ -133,7 +133,7 @@ func (r *randGen) randPageCount() (n uintptr) {
return
}
func (r *randGen) flags(vv []uintptr) (v uintptr) {
func (r *randGen) flags(vv []uint64) (v uint64) {
switch {
case r.nOutOf(90, 111):
for stop := false; !stop; stop = r.bin() {
@ -255,7 +255,7 @@ func (r *randGen) timespec(s *state, typ *sys.StructType, usec bool) (arg Arg, c
})
case r.nOutOf(1, 3):
// few ms ahead for relative, past for absolute
nsec := uintptr(10 * 1e6)
nsec := uint64(10 * 1e6)
if usec {
nsec /= 1e3
}
@ -303,7 +303,7 @@ func (r *randGen) timespec(s *state, typ *sys.StructType, usec bool) (arg Arg, c
}
// createMmapCall creates a "normal" mmap call that maps [start, start+npages) page range.
func createMmapCall(start, npages uintptr) *Call {
func createMmapCall(start, npages uint64) *Call {
meta := sys.CallMap["mmap"]
mmap := &Call{
Meta: meta,
@ -320,7 +320,7 @@ func createMmapCall(start, npages uintptr) *Call {
return mmap
}
func (r *randGen) addr1(s *state, typ sys.Type, size uintptr, data Arg) (Arg, []*Call) {
func (r *randGen) addr1(s *state, typ sys.Type, size uint64, data Arg) (Arg, []*Call) {
npages := (size + pageSize - 1) / pageSize
if npages == 0 {
npages = 1
@ -328,9 +328,9 @@ func (r *randGen) addr1(s *state, typ sys.Type, size uintptr, data Arg) (Arg, []
if r.bin() {
return r.randPageAddr(s, typ, npages, data, false), nil
}
for i := uintptr(0); i < maxPages-npages; i++ {
for i := uint64(0); i < maxPages-npages; i++ {
free := true
for j := uintptr(0); j < npages; j++ {
for j := uint64(0); j < npages; j++ {
if s.pages[i+j] {
free = false
break
@ -345,7 +345,7 @@ func (r *randGen) addr1(s *state, typ sys.Type, size uintptr, data Arg) (Arg, []
return r.randPageAddr(s, typ, npages, data, false), nil
}
func (r *randGen) addr(s *state, typ sys.Type, size uintptr, data Arg) (Arg, []*Call) {
func (r *randGen) addr(s *state, typ sys.Type, size uint64, data Arg) (Arg, []*Call) {
arg, calls := r.addr1(s, typ, size, data)
a, ok := arg.(*PointerArg)
if !ok {
@ -366,12 +366,12 @@ func (r *randGen) addr(s *state, typ sys.Type, size uintptr, data Arg) (Arg, []*
return arg, calls
}
func (r *randGen) randPageAddr(s *state, typ sys.Type, npages uintptr, data Arg, vma bool) Arg {
poolPtr := pageStartPool.Get().(*[]uintptr)
func (r *randGen) randPageAddr(s *state, typ sys.Type, npages uint64, data Arg, vma bool) Arg {
poolPtr := pageStartPool.Get().(*[]uint64)
starts := (*poolPtr)[:0]
for i := uintptr(0); i < maxPages-npages; i++ {
for i := uint64(0); i < maxPages-npages; i++ {
busy := true
for j := uintptr(0); j < npages; j++ {
for j := uint64(0); j < npages; j++ {
if !s.pages[i+j] {
busy = false
break
@ -384,7 +384,7 @@ func (r *randGen) randPageAddr(s *state, typ sys.Type, npages uintptr, data Arg,
}
starts = append(starts, i)
}
var page uintptr
var page uint64
if len(starts) != 0 {
page = starts[r.rand(len(starts))]
} else {
@ -664,7 +664,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg Arg, calls []*Call) {
case sys.BufferBlobRand, sys.BufferBlobRange:
sz := r.randBufLen()
if a.Kind == sys.BufferBlobRange {
sz = r.randRange(int(a.RangeBegin), int(a.RangeEnd))
sz = r.randRange(a.RangeBegin, a.RangeEnd)
}
data := make([]byte, sz)
if a.Dir() != sys.DirOut {
@ -699,7 +699,7 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg Arg, calls []*Call) {
case *sys.VmaType:
npages := r.randPageCount()
if a.RangeBegin != 0 || a.RangeEnd != 0 {
npages = uintptr(int(a.RangeBegin) + r.Intn(int(a.RangeEnd-a.RangeBegin+1)))
npages = a.RangeBegin + uint64(r.Intn(int(a.RangeEnd-a.RangeBegin+1)))
}
arg := r.randPageAddr(s, a, npages, nil, true)
return arg, nil
@ -728,16 +728,16 @@ func (r *randGen) generateArg(s *state, typ sys.Type) (arg Arg, calls []*Call) {
case *sys.ProcType:
return constArg(a, r.rand(int(a.ValuesPerProc))), nil
case *sys.ArrayType:
count := uintptr(0)
var count uint64
switch a.Kind {
case sys.ArrayRandLen:
count = r.randArrayLen()
case sys.ArrayRangeLen:
count = r.randRange(int(a.RangeBegin), int(a.RangeEnd))
count = r.randRange(a.RangeBegin, a.RangeEnd)
}
var inner []Arg
var calls []*Call
for i := uintptr(0); i < count; i++ {
for i := uint64(0); i < count; i++ {
arg1, calls1 := r.generateArg(s, a.Type)
inner = append(inner, arg1)
calls = append(calls, calls1...)

View File

@ -24,7 +24,7 @@ func generateSize(arg Arg, lenType *sys.LenType) Arg {
if lenType.ByteSize != 0 {
return constArg(lenType, a.Size()/lenType.ByteSize)
} else {
return constArg(lenType, uintptr(len(a.Inner)))
return constArg(lenType, uint64(len(a.Inner)))
}
default:
if lenType.ByteSize != 0 {

View File

@ -113,7 +113,7 @@ func (c *Call) validate(ctx *validCtx) error {
case *sys.ProcType:
switch a := arg.(type) {
case *ConstArg:
if a.Val >= uintptr(typ1.ValuesPerProc) {
if a.Val >= typ1.ValuesPerProc {
return fmt.Errorf("syscall %v: per proc arg '%v' has bad value '%v'", c.Meta.Name, a.Type().Name(), a.Val)
}
default:

View File

@ -37,7 +37,7 @@ func initAlign() {
}
}
func setBitfieldOffset(t Type, offset uintptr, last bool) {
func setBitfieldOffset(t Type, offset uint64, last bool) {
switch t1 := t.(type) {
case *IntType:
t1.BitfieldOff = offset
@ -60,7 +60,7 @@ func setBitfieldOffset(t Type, offset uintptr, last bool) {
}
func markBitfields(t *StructType) {
var bfOffset uintptr
var bfOffset uint64
for i, f := range t.Fields {
if f.BitfieldLength() == 0 {
continue
@ -87,7 +87,7 @@ func addAlignment(t *StructType) {
return
}
var fields []Type
var off uintptr
var off uint64
align := t.align
for i, f := range t.Fields {
a := f.Align()
@ -120,7 +120,7 @@ func addAlignment(t *StructType) {
t.Fields = fields
}
func makePad(sz uintptr) Type {
func makePad(sz uint64) Type {
return &ConstType{
IntTypeCommon: IntTypeCommon{
TypeCommon: TypeCommon{TypeName: "pad", IsOptional: false},

View File

@ -32,12 +32,12 @@ type Type interface {
FieldName() string
Dir() Dir
Optional() bool
Default() uintptr
Default() uint64
Varlen() bool
Size() uintptr
Align() uintptr
BitfieldOffset() uintptr
BitfieldLength() uintptr
Size() uint64
Align() uint64
BitfieldOffset() uint64
BitfieldLength() uint64
BitfieldLast() bool
}
@ -67,7 +67,7 @@ func (t *TypeCommon) Optional() bool {
return t.IsOptional
}
func (t *TypeCommon) Default() uintptr {
func (t *TypeCommon) Default() uint64 {
return 0
}
@ -75,11 +75,11 @@ func (t *TypeCommon) Varlen() bool {
return false
}
func (t *TypeCommon) BitfieldOffset() uintptr {
func (t *TypeCommon) BitfieldOffset() uint64 {
return 0
}
func (t *TypeCommon) BitfieldLength() uintptr {
func (t *TypeCommon) BitfieldLength() uint64 {
return 0
}
@ -92,14 +92,14 @@ func (t TypeCommon) Dir() Dir {
}
const (
InvalidFD = ^uintptr(0)
InvalidFD = ^uint64(0)
)
type ResourceDesc struct {
Name string
Type Type
Kind []string
Values []uintptr
Values []uint64
}
type ResourceType struct {
@ -107,44 +107,44 @@ type ResourceType struct {
Desc *ResourceDesc
}
func (t *ResourceType) Default() uintptr {
func (t *ResourceType) Default() uint64 {
return t.Desc.Values[0]
}
func (t *ResourceType) SpecialValues() []uintptr {
func (t *ResourceType) SpecialValues() []uint64 {
return t.Desc.Values
}
func (t *ResourceType) Size() uintptr {
func (t *ResourceType) Size() uint64 {
return t.Desc.Type.Size()
}
func (t *ResourceType) Align() uintptr {
func (t *ResourceType) Align() uint64 {
return t.Desc.Type.Align()
}
type IntTypeCommon struct {
TypeCommon
TypeSize uintptr
TypeSize uint64
BigEndian bool
BitfieldOff uintptr
BitfieldLen uintptr
BitfieldOff uint64
BitfieldLen uint64
BitfieldLst bool
}
func (t *IntTypeCommon) Size() uintptr {
func (t *IntTypeCommon) Size() uint64 {
return t.TypeSize
}
func (t *IntTypeCommon) Align() uintptr {
func (t *IntTypeCommon) Align() uint64 {
return t.Size()
}
func (t *IntTypeCommon) BitfieldOffset() uintptr {
func (t *IntTypeCommon) BitfieldOffset() uint64 {
return t.BitfieldOff
}
func (t *IntTypeCommon) BitfieldLength() uintptr {
func (t *IntTypeCommon) BitfieldLength() uint64 {
return t.BitfieldLen
}
@ -154,7 +154,7 @@ func (t *IntTypeCommon) BitfieldLast() bool {
type ConstType struct {
IntTypeCommon
Val uintptr
Val uint64
IsPad bool
}
@ -170,24 +170,24 @@ const (
type IntType struct {
IntTypeCommon
Kind IntKind
RangeBegin int64
RangeEnd int64
RangeBegin uint64
RangeEnd uint64
}
type FlagsType struct {
IntTypeCommon
Vals []uintptr
Vals []uint64
}
type LenType struct {
IntTypeCommon
ByteSize uintptr // want size in multiple of bytes instead of array size
ByteSize uint64 // want size in multiple of bytes instead of array size
Buf string
}
type ProcType struct {
IntTypeCommon
ValuesStart int64
ValuesStart uint64
ValuesPerProc uint64
}
@ -207,15 +207,15 @@ type CsumType struct {
type VmaType struct {
TypeCommon
RangeBegin int64 // in pages
RangeEnd int64
RangeBegin uint64 // in pages
RangeEnd uint64
}
func (t *VmaType) Size() uintptr {
func (t *VmaType) Size() uint64 {
return ptrSize
}
func (t *VmaType) Align() uintptr {
func (t *VmaType) Align() uint64 {
return t.Size()
}
@ -242,12 +242,12 @@ const (
type BufferType struct {
TypeCommon
Kind BufferKind
RangeBegin uintptr // for BufferBlobRange kind
RangeEnd uintptr // for BufferBlobRange kind
RangeBegin uint64 // for BufferBlobRange kind
RangeEnd uint64 // for BufferBlobRange kind
Text TextKind // for BufferText
SubKind string
Values []string // possible values for BufferString kind
Length uintptr // max string length for BufferString kind
Length uint64 // max string length for BufferString kind
}
func (t *BufferType) Varlen() bool {
@ -267,7 +267,7 @@ func (t *BufferType) Varlen() bool {
}
}
func (t *BufferType) Size() uintptr {
func (t *BufferType) Size() uint64 {
if t.Varlen() {
panic(fmt.Sprintf("buffer size is not statically known: %v", t.Name()))
}
@ -281,7 +281,7 @@ func (t *BufferType) Size() uintptr {
}
}
func (t *BufferType) Align() uintptr {
func (t *BufferType) Align() uint64 {
return 1
}
@ -296,8 +296,8 @@ type ArrayType struct {
TypeCommon
Type Type
Kind ArrayKind
RangeBegin uintptr
RangeEnd uintptr
RangeBegin uint64
RangeEnd uint64
}
func (t *ArrayType) Varlen() bool {
@ -311,7 +311,7 @@ func (t *ArrayType) Varlen() bool {
}
}
func (t *ArrayType) Size() uintptr {
func (t *ArrayType) Size() uint64 {
if t.Varlen() {
panic(fmt.Sprintf("array size is not statically known: %v", t.Name()))
}
@ -323,7 +323,7 @@ func (t *ArrayType) Size() uintptr {
}
}
func (t *ArrayType) Align() uintptr {
func (t *ArrayType) Align() uint64 {
return t.Type.Align()
}
@ -332,11 +332,11 @@ type PtrType struct {
Type Type
}
func (t *PtrType) Size() uintptr {
func (t *PtrType) Size() uint64 {
return ptrSize
}
func (t *PtrType) Align() uintptr {
func (t *PtrType) Align() uint64 {
return t.Size()
}
@ -345,7 +345,7 @@ type StructType struct {
Fields []Type
padded bool
packed bool
align uintptr
align uint64
varlen bool
varlenAssigned bool
}
@ -366,14 +366,14 @@ func (t *StructType) Varlen() bool {
return t.varlen
}
func (t *StructType) Size() uintptr {
func (t *StructType) Size() uint64 {
if t.Varlen() {
panic(fmt.Sprintf("struct size is not statically known: %v", t.Name()))
}
if !t.padded {
panic("struct is not padded yet")
}
var size uintptr
var size uint64
for _, f := range t.Fields {
if f.BitfieldLength() == 0 || f.BitfieldLast() {
size += f.Size()
@ -382,14 +382,14 @@ func (t *StructType) Size() uintptr {
return size
}
func (t *StructType) Align() uintptr {
func (t *StructType) Align() uint64 {
if t.align != 0 {
return t.align // overrided by user attribute
}
if t.packed {
return 1
}
var align uintptr
var align uint64
for _, f := range t.Fields {
if a1 := f.Align(); align < a1 {
align = a1
@ -408,7 +408,7 @@ func (t *UnionType) Varlen() bool {
return t.varlen
}
func (t *UnionType) Size() uintptr {
func (t *UnionType) Size() uint64 {
if t.Varlen() {
panic(fmt.Sprintf("union size is not statically known: %v", t.Name()))
}
@ -421,8 +421,8 @@ func (t *UnionType) Size() uintptr {
return size
}
func (t *UnionType) Align() uintptr {
var align uintptr
func (t *UnionType) Align() uint64 {
var align uint64
for _, opt := range t.Options {
if a1 := opt.Align(); align < a1 {
align = a1

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -463,7 +463,7 @@ func generateResources(desc *Description, consts map[string]uint64, out io.Write
}
fmt.Fprintf(out, "\"%v\"", k)
}
fmt.Fprintf(out, "}, Values: []uintptr{")
fmt.Fprintf(out, "}, Values: []uint64{")
if len(values) == 0 {
values = append(values, "0")
}
@ -779,7 +779,7 @@ func generateArg(
if len(vals) == 0 {
fmt.Fprintf(out, "&IntType{%v}", intCommon(size, bigEndian, bitfieldLen))
} else {
fmt.Fprintf(out, "&FlagsType{%v, Vals: []uintptr{%v}}", intCommon(size, bigEndian, bitfieldLen), strings.Join(vals, ","))
fmt.Fprintf(out, "&FlagsType{%v, Vals: []uint64{%v}}", intCommon(size, bigEndian, bitfieldLen), strings.Join(vals, ","))
}
case "const":
canBeArg = true
@ -805,7 +805,7 @@ func generateArg(
val = "0"
skipSyscall(fmt.Sprintf("missing const %v", a[0]))
}
fmt.Fprintf(out, "&ConstType{%v, Val: uintptr(%v)}", intCommon(size, bigEndian, bitfieldLen), val)
fmt.Fprintf(out, "&ConstType{%v, Val: uint64(%v)}", intCommon(size, bigEndian, bitfieldLen), val)
case "proc":
canBeArg = true
size := uint64(ptrSize)