diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2015-10-12 10:16:57 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2015-10-12 10:16:57 +0200 |
| commit | 874c5754bb22dbf77d6b600ff91f0f4f1fc5073a (patch) | |
| tree | 0075fbd088046ad5c86e6e972235701d68b3ce7c /sys/decl.go | |
initial commit
Diffstat (limited to 'sys/decl.go')
| -rw-r--r-- | sys/decl.go | 270 |
1 files changed, 270 insertions, 0 deletions
diff --git a/sys/decl.go b/sys/decl.go new file mode 100644 index 000000000..31f7febc3 --- /dev/null +++ b/sys/decl.go @@ -0,0 +1,270 @@ +// Copyright 2015 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +//go:generate go install github.com/google/syzkaller/sysgen +//go:generate sysgen sys.txt + +package sys + +type Call struct { + ID int + CallID int + Name string + CallName string + Args []Type + Ret Type +} + +type Type interface { + Name() string + Optional() bool + Default() uintptr +} + +type TypeCommon struct { + TypeName string + IsOptional bool +} + +func (t TypeCommon) Name() string { + return t.TypeName +} + +func (t TypeCommon) Optional() bool { + return t.IsOptional +} + +func (t TypeCommon) Default() uintptr { + return 0 +} + +type ( + ResourceKind int + ResourceSubkind int +) + +const ( + ResFD ResourceKind = iota + ResIOCtx + ResIPC + ResKey + ResInotifyDesc + ResPid + ResUid + ResGid + ResTimerid +) + +const ( + ResAny ResourceSubkind = iota + FdFile + FdSock + FdPipe + FdSignal + FdEvent + FdTimer + FdEpoll + FdDir + FdMq + FdInotify + FdFanotify + + IPCMsq + IPCSem + IPCShm +) + +const ( + InvalidFD = ^uintptr(0) + BogusFD = uintptr(100000 - 1) +) + +type ResourceType struct { + TypeCommon + Kind ResourceKind + Subkind ResourceSubkind +} + +func (t ResourceType) Default() uintptr { + switch t.Kind { + case ResFD: + return InvalidFD + case ResIOCtx: + return 0 + case ResIPC: + return 0 + case ResKey: + return 0 + case ResInotifyDesc: + return 0 + case ResPid: + return 0 + case ResUid: + return 0 + case ResGid: + return 0 + case ResTimerid: + return 0 + default: + panic("unknown resource type") + } +} + +func (t ResourceType) SpecialValues() []uintptr { + switch t.Kind { + case ResFD: + return []uintptr{InvalidFD, BogusFD} + case ResIOCtx: + return []uintptr{0} + case ResIPC: + return []uintptr{0, ^uintptr(0)} + case ResKey: + return []uintptr{0} + case ResInotifyDesc: + return []uintptr{0} + case ResPid: + return []uintptr{0, ^uintptr(0)} + case ResUid: + return []uintptr{0, ^uintptr(0)} + case ResGid: + return []uintptr{0, ^uintptr(0)} + case ResTimerid: + return []uintptr{0} + default: + panic("unknown resource kind") + } +} + +func (t ResourceType) Size() uintptr { + switch t.Kind { + case ResFD: + return 4 + case ResIOCtx: + return 8 + case ResIPC: + return 4 + case ResKey: + return 4 + case ResInotifyDesc: + return 4 + case ResPid: + return 4 + case ResUid: + return 4 + case ResGid: + return 4 + case ResTimerid: + return 4 + default: + panic("unknown resource kind") + } +} + +func (t ResourceType) SubKinds() []ResourceSubkind { + switch t.Kind { + case ResFD: + return []ResourceSubkind{FdFile, FdSock, FdPipe, FdSignal, FdEvent, FdTimer, FdEpoll, FdDir, FdMq, FdInotify, FdFanotify} + case ResIPC: + return []ResourceSubkind{IPCMsq, IPCSem, IPCShm} + case ResIOCtx, ResKey, ResInotifyDesc, ResPid, ResUid, ResGid, ResTimerid: + return []ResourceSubkind{ResAny} + default: + panic("unknown resource kind") + } +} + +type FileoffType struct { + TypeCommon + TypeSize uintptr + File string +} + +type AddrType struct { + TypeCommon +} + +type BufferKind int + +const ( + BufferBlob BufferKind = iota + BufferString + BufferSockaddr +) + +type BufferType struct { + TypeCommon + Kind BufferKind +} + +type VmaType struct { + TypeCommon +} + +type LenType struct { + TypeCommon + TypeSize uintptr + Buf string +} + +type FlagsType struct { + TypeCommon + TypeSize uintptr + Vals []uintptr +} + +type IntType struct { + TypeCommon + TypeSize uintptr + Limit uintptr +} + +type FilenameType struct { + TypeCommon +} + +type ArrayType struct { + TypeCommon + Type Type +} + +type PtrType struct { + TypeCommon + Type Type + Dir Dir +} + +type StructType struct { + TypeCommon + Fields []Type +} + +type Dir int + +const ( + DirIn Dir = iota + DirOut + DirInOut +) + +var ( + CallCount int + CallMap = make(map[string]*Call) + CallID = make(map[string]int) +) + +func init() { + for _, c := range Calls { + if CallMap[c.Name] != nil { + println(c.Name) + panic("duplicate syscall") + } + id, ok := CallID[c.CallName] + if !ok { + id = len(CallID) + CallID[c.CallName] = id + } + c.CallID = id + CallMap[c.Name] = c + } + CallCount = len(CallID) +} |
