aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-11-20 19:28:53 +0100
committerDmitry Vyukov <dvyukov@google.com>2020-11-21 08:46:20 +0100
commit418476ecb925e5d58ba9c22928a4e37dc30909df (patch)
tree702468b5ca1b0df89a83d861b18eaff9ae2237c5 /pkg
parente1dea42221c13dabdf9d4938428f1ef91863b813 (diff)
pkg/ifuzz/iset: rename ifuzzimpl to iset
ifuzzimpl is too lenghty and too clumsy on my taste (nm/vmimpl worked better b/c it's shorter and used less). I've tried to come up with something shorter and nicer. We could use "insn" as a common name for "instruction" in ifuzz, but it's a commonly used name already so would cause lots of conflicts. "iset" is somewhat descriptive, short and nice.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/ifuzz/ifuzz.go34
-rw-r--r--pkg/ifuzz/ifuzz_test.go22
-rw-r--r--pkg/ifuzz/iset/iset.go (renamed from pkg/ifuzz/ifuzzimpl/ifuzzimpl.go)3
-rw-r--r--pkg/ifuzz/powerpc/powerpc.go24
-rw-r--r--pkg/ifuzz/powerpc/pseudo.go12
-rw-r--r--pkg/ifuzz/x86/decode.go16
-rw-r--r--pkg/ifuzz/x86/encode.go18
-rw-r--r--pkg/ifuzz/x86/gen/gen.go16
-rw-r--r--pkg/ifuzz/x86/pseudo.go84
-rw-r--r--pkg/ifuzz/x86/x86.go24
10 files changed, 127 insertions, 126 deletions
diff --git a/pkg/ifuzz/ifuzz.go b/pkg/ifuzz/ifuzz.go
index 45082834d..01137b6ea 100644
--- a/pkg/ifuzz/ifuzz.go
+++ b/pkg/ifuzz/ifuzz.go
@@ -6,24 +6,24 @@ package ifuzz
import (
"math/rand"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
_ "github.com/google/syzkaller/pkg/ifuzz/powerpc/generated" // pull in generated instruction descriptions
_ "github.com/google/syzkaller/pkg/ifuzz/x86/generated" // pull in generated instruction descriptions
)
type (
- Config = ifuzzimpl.Config
- MemRegion = ifuzzimpl.MemRegion
- Mode = ifuzzimpl.Mode
+ Config = iset.Config
+ MemRegion = iset.MemRegion
+ Mode = iset.Mode
)
const (
- ArchX86 = ifuzzimpl.ArchX86
- ArchPowerPC = ifuzzimpl.ArchPowerPC
- ModeLong64 = ifuzzimpl.ModeLong64
- ModeProt32 = ifuzzimpl.ModeProt32
- ModeProt16 = ifuzzimpl.ModeProt16
- ModeReal16 = ifuzzimpl.ModeReal16
+ ArchX86 = iset.ArchX86
+ ArchPowerPC = iset.ArchPowerPC
+ ModeLong64 = iset.ModeLong64
+ ModeProt32 = iset.ModeProt32
+ ModeProt16 = iset.ModeProt16
+ ModeReal16 = iset.ModeReal16
)
func Generate(cfg *Config, r *rand.Rand) []byte {
@@ -99,21 +99,21 @@ func Mutate(cfg *Config, r *rand.Rand, text []byte) []byte {
return text
}
-func randInsn(cfg *Config, r *rand.Rand) ifuzzimpl.Insn {
- insnset := ifuzzimpl.Arches[cfg.Arch]
- var insns []ifuzzimpl.Insn
+func randInsn(cfg *Config, r *rand.Rand) iset.Insn {
+ insnset := iset.Arches[cfg.Arch]
+ var insns []iset.Insn
if cfg.Priv && cfg.Exec {
- insns = insnset.GetInsns(cfg.Mode, ifuzzimpl.Type(r.Intn(3)))
+ insns = insnset.GetInsns(cfg.Mode, iset.Type(r.Intn(3)))
} else if cfg.Priv {
- insns = insnset.GetInsns(cfg.Mode, ifuzzimpl.Type(r.Intn(2)))
+ insns = insnset.GetInsns(cfg.Mode, iset.Type(r.Intn(2)))
} else {
- insns = insnset.GetInsns(cfg.Mode, ifuzzimpl.TypeUser)
+ insns = insnset.GetInsns(cfg.Mode, iset.TypeUser)
}
return insns[r.Intn(len(insns))]
}
func split(cfg *Config, text []byte) [][]byte {
- insnset := ifuzzimpl.Arches[cfg.Arch]
+ insnset := iset.Arches[cfg.Arch]
text = append([]byte{}, text...)
var insns [][]byte
var bad []byte
diff --git a/pkg/ifuzz/ifuzz_test.go b/pkg/ifuzz/ifuzz_test.go
index edee05c9a..eee8afe00 100644
--- a/pkg/ifuzz/ifuzz_test.go
+++ b/pkg/ifuzz/ifuzz_test.go
@@ -10,7 +10,7 @@ import (
"testing"
"time"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
var allArches = []string{ArchX86, ArchPowerPC}
@@ -24,8 +24,8 @@ func TestMode(t *testing.T) {
}
func testMode(t *testing.T, arch string) {
- all := make(map[ifuzzimpl.Insn]bool)
- for mode := ifuzzimpl.Mode(0); mode < ifuzzimpl.ModeLast; mode++ {
+ all := make(map[iset.Insn]bool)
+ for mode := iset.Mode(0); mode < iset.ModeLast; mode++ {
for priv := 0; priv < 2; priv++ {
for exec := 0; exec < 2; exec++ {
insns := allInsns(arch, mode, priv != 0, exec != 0)
@@ -48,7 +48,7 @@ func TestDecode(t *testing.T) {
}
func testDecode(t *testing.T, arch string) {
- insnset := ifuzzimpl.Arches[arch]
+ insnset := iset.Arches[arch]
xedEnabled := false
if _, err := insnset.DecodeExt(0, nil); err == nil {
xedEnabled = true
@@ -61,8 +61,8 @@ func testDecode(t *testing.T, arch string) {
r := rand.New(rand.NewSource(seed))
for repeat := 0; repeat < 10; repeat++ {
- for mode := ifuzzimpl.Mode(0); mode < ifuzzimpl.ModeLast; mode++ {
- cfg := &ifuzzimpl.Config{
+ for mode := iset.Mode(0); mode < iset.ModeLast; mode++ {
+ cfg := &iset.Config{
Mode: mode,
Priv: true,
Exec: true,
@@ -122,13 +122,13 @@ func testDecode(t *testing.T, arch string) {
}
}
-func allInsns(arch string, mode ifuzzimpl.Mode, priv, exec bool) []ifuzzimpl.Insn {
- insnset := ifuzzimpl.Arches[arch]
- insns := insnset.GetInsns(mode, ifuzzimpl.TypeUser)
+func allInsns(arch string, mode iset.Mode, priv, exec bool) []iset.Insn {
+ insnset := iset.Arches[arch]
+ insns := insnset.GetInsns(mode, iset.TypeUser)
if priv {
- insns = append(insns, insnset.GetInsns(mode, ifuzzimpl.TypePriv)...)
+ insns = append(insns, insnset.GetInsns(mode, iset.TypePriv)...)
if exec {
- insns = append(insns, insnset.GetInsns(mode, ifuzzimpl.TypeExec)...)
+ insns = append(insns, insnset.GetInsns(mode, iset.TypeExec)...)
}
}
return insns
diff --git a/pkg/ifuzz/ifuzzimpl/ifuzzimpl.go b/pkg/ifuzz/iset/iset.go
index 32f285250..46c42537d 100644
--- a/pkg/ifuzz/ifuzzimpl/ifuzzimpl.go
+++ b/pkg/ifuzz/iset/iset.go
@@ -1,7 +1,8 @@
// Copyright 2017 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.
-package ifuzzimpl
+// Package iset ("instruction set") provides base and helper types for ifuzz arch implementations.
+package iset
import (
"math/rand"
diff --git a/pkg/ifuzz/powerpc/powerpc.go b/pkg/ifuzz/powerpc/powerpc.go
index a78e0a251..bee20850d 100644
--- a/pkg/ifuzz/powerpc/powerpc.go
+++ b/pkg/ifuzz/powerpc/powerpc.go
@@ -18,7 +18,7 @@ import (
"fmt"
"math/rand"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
type InsnBits struct {
@@ -35,20 +35,20 @@ type Insn struct {
Opcode uint32
Mask uint32
- generator func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte
+ generator func(cfg *iset.Config, r *rand.Rand) []byte
}
type InsnSet struct {
Insns []*Insn
- modeInsns ifuzzimpl.ModeInsns
+ modeInsns iset.ModeInsns
insnMap map[string]*Insn
}
-func (insnset *InsnSet) GetInsns(mode ifuzzimpl.Mode, typ ifuzzimpl.Type) []ifuzzimpl.Insn {
+func (insnset *InsnSet) GetInsns(mode iset.Mode, typ iset.Type) []iset.Insn {
return insnset.modeInsns[mode][typ]
}
-func (insnset *InsnSet) Decode(mode ifuzzimpl.Mode, text []byte) (int, error) {
+func (insnset *InsnSet) Decode(mode iset.Mode, text []byte) (int, error) {
if len(text) < 4 {
return 0, errors.New("must be at least 4 bytes")
}
@@ -61,7 +61,7 @@ func (insnset *InsnSet) Decode(mode ifuzzimpl.Mode, text []byte) (int, error) {
return 0, fmt.Errorf("unrecognised instruction %08x", insn32)
}
-func (insnset *InsnSet) DecodeExt(mode ifuzzimpl.Mode, text []byte) (int, error) {
+func (insnset *InsnSet) DecodeExt(mode iset.Mode, text []byte) (int, error) {
return 0, fmt.Errorf("no external decoder")
}
@@ -85,7 +85,7 @@ func (insn *Insn) EncodeParam(v map[string]uint, r *rand.Rand) []byte {
return ret
}
-func (insn Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+func (insn Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {
if insn.Pseudo {
return insn.generator(cfg, r)
}
@@ -108,16 +108,16 @@ func Register(insns []*Insn) {
for _, insn := range insnset.Insns {
insnset.modeInsns.Add(insn)
}
- ifuzzimpl.Arches[ifuzzimpl.ArchPowerPC] = insnset
+ iset.Arches[iset.ArchPowerPC] = insnset
}
-func (insn *Insn) Info() (string, ifuzzimpl.Mode, bool, bool) {
+func (insn *Insn) Info() (string, iset.Mode, bool, bool) {
return insn.Name, insn.mode(), insn.Pseudo, insn.Priv
}
-func (insn Insn) mode() ifuzzimpl.Mode {
+func (insn Insn) mode() iset.Mode {
if insn.M64 {
- return (1 << ifuzzimpl.ModeLong64)
+ return (1 << iset.ModeLong64)
}
- return (1 << ifuzzimpl.ModeLong64) | (1 << ifuzzimpl.ModeProt32)
+ return (1 << iset.ModeLong64) | (1 << iset.ModeProt32)
}
diff --git a/pkg/ifuzz/powerpc/pseudo.go b/pkg/ifuzz/powerpc/pseudo.go
index 495e0f935..f300eec0f 100644
--- a/pkg/ifuzz/powerpc/pseudo.go
+++ b/pkg/ifuzz/powerpc/pseudo.go
@@ -6,7 +6,7 @@ package powerpc
import (
"math/rand"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
// nolint:dupl
@@ -15,7 +15,7 @@ func (insnset *InsnSet) initPseudo() {
Name: "PSEUDO_hypercall",
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(insnset, cfg, r)
gen.sc(1)
return gen.text
@@ -25,7 +25,7 @@ func (insnset *InsnSet) initPseudo() {
Name: "PSEUDO_syscall",
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(insnset, cfg, r)
gen.sc(0)
return gen.text
@@ -35,7 +35,7 @@ func (insnset *InsnSet) initPseudo() {
Name: "PSEUDO_ultracall",
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(insnset, cfg, r)
gen.sc(2)
return gen.text
@@ -45,12 +45,12 @@ func (insnset *InsnSet) initPseudo() {
type generator struct {
imap map[string]*Insn
- mode ifuzzimpl.Mode
+ mode iset.Mode
r *rand.Rand
text []byte
}
-func makeGen(insnset *InsnSet, cfg *ifuzzimpl.Config, r *rand.Rand) *generator {
+func makeGen(insnset *InsnSet, cfg *iset.Config, r *rand.Rand) *generator {
return &generator{
imap: insnset.insnMap,
mode: cfg.Mode,
diff --git a/pkg/ifuzz/x86/decode.go b/pkg/ifuzz/x86/decode.go
index a40643a6b..1306f40db 100644
--- a/pkg/ifuzz/x86/decode.go
+++ b/pkg/ifuzz/x86/decode.go
@@ -6,26 +6,26 @@ package x86
import (
"fmt"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
// Decode decodes instruction length for the given mode.
// It can have falsely decode incorrect instructions,
// but should not fail to decode correct instructions.
// nolint: gocyclo, nestif, gocognit, funlen
-func (insnset *InsnSet) Decode(mode ifuzzimpl.Mode, text []byte) (int, error) {
+func (insnset *InsnSet) Decode(mode iset.Mode, text []byte) (int, error) {
if len(text) == 0 {
return 0, fmt.Errorf("zero-length instruction")
}
prefixes := prefixes32
var operSize, immSize, dispSize, addrSize int
switch mode {
- case ifuzzimpl.ModeLong64:
+ case iset.ModeLong64:
operSize, immSize, dispSize, addrSize = 4, 4, 4, 8
prefixes = prefixes64
- case ifuzzimpl.ModeProt32:
+ case iset.ModeProt32:
operSize, immSize, dispSize, addrSize = 4, 4, 4, 4
- case ifuzzimpl.ModeProt16, ifuzzimpl.ModeReal16:
+ case iset.ModeProt16, iset.ModeReal16:
operSize, immSize, dispSize, addrSize = 2, 2, 2, 2
default:
panic("bad mode")
@@ -36,7 +36,7 @@ func (insnset *InsnSet) Decode(mode ifuzzimpl.Mode, text []byte) (int, error) {
if len(text) > 1 {
// There are only 2 32-bit instructions that look like VEX-prefixed but are actually not: LDS, LES.
// They always reference memory (mod!=3), but all VEX instructions have "mod=3" where LDS/LES would have mod.
- if (text[0] == 0xc4 || text[0] == 0xc5) && (mode == ifuzzimpl.ModeLong64 || text[1]&0xc0 == 0xc0) {
+ if (text[0] == 0xc4 || text[0] == 0xc5) && (mode == iset.ModeLong64 || text[1]&0xc0 == 0xc0) {
vex = true
}
// There is only one instruction that looks like XOP-prefixed but is actually not: POP.
@@ -208,7 +208,7 @@ nextInsn:
return 0, fmt.Errorf("unknown instruction")
}
-var XedDecode func(mode ifuzzimpl.Mode, text []byte) (int, error)
+var XedDecode func(mode iset.Mode, text []byte) (int, error)
var (
prefixes32 = map[byte]bool{
@@ -226,7 +226,7 @@ var (
}
)
-func (insnset *InsnSet) DecodeExt(mode ifuzzimpl.Mode, text []byte) (int, error) {
+func (insnset *InsnSet) DecodeExt(mode iset.Mode, text []byte) (int, error) {
if XedDecode != nil && text != nil && len(text) > 0 {
return XedDecode(mode, text)
}
diff --git a/pkg/ifuzz/x86/encode.go b/pkg/ifuzz/x86/encode.go
index 9203d51c3..59b9a294a 100644
--- a/pkg/ifuzz/x86/encode.go
+++ b/pkg/ifuzz/x86/encode.go
@@ -10,11 +10,11 @@ package x86
import (
"math/rand"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
// nolint: gocyclo, nestif, gocognit, funlen
-func (insn *Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+func (insn *Insn) Encode(cfg *iset.Config, r *rand.Rand) []byte {
if !cfg.IsCompatible(insn) {
panic("instruction is not suitable for this mode")
}
@@ -24,11 +24,11 @@ func (insn *Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
var operSize, immSize, dispSize, addrSize int
switch cfg.Mode {
- case ifuzzimpl.ModeLong64:
+ case iset.ModeLong64:
operSize, immSize, dispSize, addrSize = 4, 4, 4, 8
- case ifuzzimpl.ModeProt32:
+ case iset.ModeProt32:
operSize, immSize, dispSize, addrSize = 4, 4, 4, 4
- case ifuzzimpl.ModeProt16, ifuzzimpl.ModeReal16:
+ case iset.ModeProt16, iset.ModeReal16:
operSize, immSize, dispSize, addrSize = 2, 2, 2, 2
default:
panic("bad mode")
@@ -54,7 +54,7 @@ func (insn *Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
if !insn.No66Prefix {
prefixes = append(prefixes, 0x66) // operand size
}
- if cfg.Mode == ifuzzimpl.ModeLong64 || !insn.Mem32 {
+ if cfg.Mode == iset.ModeLong64 || !insn.Mem32 {
prefixes = append(prefixes, 0x67) // address size
}
if !insn.NoRepPrefix {
@@ -71,7 +71,7 @@ func (insn *Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
// REX
var rex byte
- if cfg.Mode == ifuzzimpl.ModeLong64 && r.Intn(2) == 0 {
+ if cfg.Mode == iset.ModeLong64 && r.Intn(2) == 0 {
// bit 0 - B
// bit 1 - X
// bit 2 - R
@@ -119,7 +119,7 @@ func (insn *Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
code = append(code, insn.Vex)
vexR = byte(1)
vexX = byte(1)
- if cfg.Mode == ifuzzimpl.ModeLong64 {
+ if cfg.Mode == iset.ModeLong64 {
vexR = byte(r.Intn(2))
vexX = byte(r.Intn(2))
}
@@ -147,7 +147,7 @@ func (insn *Insn) Encode(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
code = append(code, vexR<<7|vexX<<6|vexB<<5|insn.VexMap)
code = append(code, W<<7|vvvv<<3|L<<2|pp)
// TODO: short encoding
- if cfg.Mode != ifuzzimpl.ModeLong64 {
+ if cfg.Mode != iset.ModeLong64 {
vvvv |= 8
}
}
diff --git a/pkg/ifuzz/x86/gen/gen.go b/pkg/ifuzz/x86/gen/gen.go
index 3622ba248..284ea9033 100644
--- a/pkg/ifuzz/x86/gen/gen.go
+++ b/pkg/ifuzz/x86/gen/gen.go
@@ -13,7 +13,7 @@ import (
"strconv"
"strings"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
"github.com/google/syzkaller/pkg/ifuzz/x86"
"github.com/google/syzkaller/pkg/serializer"
)
@@ -102,7 +102,7 @@ func main() {
insn.Extension = vals[0]
switch insn.Extension {
case "FMA", "AVX2", "AVX", "F16C", "BMI2", "BMI", "XOP", "FMA4", "AVXAES", "BMI1", "AVX2GATHER":
- insn.Mode = 1<<ifuzzimpl.ModeLong64 | 1<<ifuzzimpl.ModeProt32
+ insn.Mode = 1<<iset.ModeLong64 | 1<<iset.ModeProt32
}
insn.Avx2Gather = insn.Extension == "AVX2GATHER"
case "PATTERN":
@@ -201,7 +201,7 @@ func parsePattern(insn *x86.Insn, vals []string) error {
return errSkip("")
}
if insn.Mode == 0 {
- insn.Mode = 1<<ifuzzimpl.ModeLast - 1
+ insn.Mode = 1<<iset.ModeLast - 1
}
insn.Mod = -100
insn.Reg = -100
@@ -314,7 +314,7 @@ func parsePattern(insn *x86.Insn, vals []string) error {
// VOP/VEX
case v == "XOPV":
insn.Vex = 0x8f
- insn.Mode &^= 1 << ifuzzimpl.ModeReal16
+ insn.Mode &^= 1 << iset.ModeReal16
case v == "EVV":
insn.Vex = 0xc4
case v == "VV1":
@@ -355,13 +355,13 @@ func parsePattern(insn *x86.Insn, vals []string) error {
// Modes.
case v == "mode64":
- insn.Mode &= 1 << ifuzzimpl.ModeLong64
+ insn.Mode &= 1 << iset.ModeLong64
case v == "not64":
- insn.Mode &^= 1 << ifuzzimpl.ModeLong64
+ insn.Mode &^= 1 << iset.ModeLong64
case v == "mode32":
- insn.Mode &= 1 << ifuzzimpl.ModeProt32
+ insn.Mode &= 1 << iset.ModeProt32
case v == "mode16":
- insn.Mode &= 1<<ifuzzimpl.ModeProt16 | 1<<ifuzzimpl.ModeReal16
+ insn.Mode &= 1<<iset.ModeProt16 | 1<<iset.ModeReal16
case v == "eamode64",
v == "eamode32",
v == "eamode16",
diff --git a/pkg/ifuzz/x86/pseudo.go b/pkg/ifuzz/x86/pseudo.go
index e11ace0cc..9e6f31204 100644
--- a/pkg/ifuzz/x86/pseudo.go
+++ b/pkg/ifuzz/x86/pseudo.go
@@ -6,16 +6,16 @@ package x86
import (
"math/rand"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
var pseudo = []*Insn{
{
Name: "PSEUDO_RDMSR",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
msr := msrs[r.Intn(len(msrs))]
gen.mov32(regECX, msr)
@@ -25,10 +25,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_WRMSR",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
msr := msrs[r.Intn(len(msrs))]
v := generateInt(cfg, r, 8)
@@ -41,10 +41,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_PCI_READ",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
addr, port, size := pciAddrPort(r)
gen.out32(0xcf8, addr)
@@ -54,10 +54,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_PCI_WRITE",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
addr, port, size := pciAddrPort(r)
val := generateInt(cfg, r, 4)
@@ -68,10 +68,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_PORT_READ",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
port := ports[r.Intn(len(ports))]
gen.in(port, r.Intn(3))
@@ -80,10 +80,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_PORT_WRITE",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
port := ports[r.Intn(len(ports))]
val := generateInt(cfg, r, 4)
@@ -93,10 +93,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_XOR_CR",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
cr := controlRegisters[r.Intn(len(controlRegisters))]
var v uint32
@@ -114,10 +114,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_XOR_EFER",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
gen.mov32(regECX, eferMSR)
gen.byte(0x0f, 0x32) // rdmsr
@@ -129,16 +129,16 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_SET_BREAK",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
br := uint8(r.Intn(4))
loc := uint32(r.Intn(4))
typ := uint32(r.Intn(16))
addr := generateInt(cfg, r, 8)
- if cfg.Mode == ifuzzimpl.ModeLong64 {
+ if cfg.Mode == iset.ModeLong64 {
gen.mov64(regRAX, addr)
} else {
gen.mov32(regEAX, uint32(addr))
@@ -152,13 +152,13 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_LOAD_SEG",
- Mode: 1<<ifuzzimpl.ModeLast - 1,
+ Mode: 1<<iset.ModeLast - 1,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
sel := randSelector(r)
- if cfg.Mode == ifuzzimpl.ModeReal16 {
+ if cfg.Mode == iset.ModeReal16 {
sel = uint16(generateInt(cfg, r, 8)) >> 4
}
reg := uint8(r.Intn(6))
@@ -169,14 +169,14 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_FAR_JMP",
- Mode: 1<<ifuzzimpl.ModeLong64 | 1<<ifuzzimpl.ModeProt32 | 1<<ifuzzimpl.ModeProt16,
+ Mode: 1<<iset.ModeLong64 | 1<<iset.ModeProt32 | 1<<iset.ModeProt16,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
sel := randSelector(r)
off := generateInt(cfg, r, 4)
- if cfg.Mode == ifuzzimpl.ModeLong64 {
+ if cfg.Mode == iset.ModeLong64 {
gen.mov32toSPaddr(uint32(sel), 0)
gen.mov32toSPaddr(uint32(off), 2)
if r.Intn(2) == 0 {
@@ -190,7 +190,7 @@ var pseudo = []*Insn{
} else {
gen.byte(0x9a) // lcall $imm16, $imm16/32
}
- if cfg.Mode == ifuzzimpl.ModeProt16 {
+ if cfg.Mode == iset.ModeProt16 {
gen.imm16(uint16(off))
} else {
gen.imm32(uint32(off))
@@ -202,10 +202,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_LTR_LLDT",
- Mode: 1<<ifuzzimpl.ModeLong64 | 1<<ifuzzimpl.ModeProt32 | 1<<ifuzzimpl.ModeProt16,
+ Mode: 1<<iset.ModeLong64 | 1<<iset.ModeProt32 | 1<<iset.ModeProt16,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
sel := randSelector(r)
gen.mov16(regAX, sel)
@@ -219,10 +219,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_LGIDT",
- Mode: 1<<ifuzzimpl.ModeLong64 | 1<<ifuzzimpl.ModeProt32 | 1<<ifuzzimpl.ModeProt16,
+ Mode: 1<<iset.ModeLong64 | 1<<iset.ModeProt32 | 1<<iset.ModeProt16,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
limit := uint32(generateInt(cfg, r, 2))
base := uint32(generateInt(cfg, r, 4))
@@ -240,10 +240,10 @@ var pseudo = []*Insn{
},
{
Name: "PSEUDO_HYPERCALL",
- Mode: 1<<ifuzzimpl.ModeLong64 | 1<<ifuzzimpl.ModeProt32 | 1<<ifuzzimpl.ModeProt16,
+ Mode: 1<<iset.ModeLong64 | 1<<iset.ModeProt32 | 1<<iset.ModeProt16,
Priv: true,
Pseudo: true,
- generator: func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte {
+ generator: func(cfg *iset.Config, r *rand.Rand) []byte {
gen := makeGen(cfg, r)
switch r.Intn(2) {
case 0:
@@ -280,12 +280,12 @@ const (
)
type generator struct {
- mode ifuzzimpl.Mode
+ mode iset.Mode
r *rand.Rand
text []byte
}
-func makeGen(cfg *ifuzzimpl.Config, r *rand.Rand) *generator {
+func makeGen(cfg *iset.Config, r *rand.Rand) *generator {
return &generator{
mode: cfg.Mode,
r: r,
@@ -311,9 +311,9 @@ func (gen *generator) imm64(v uint64) {
func (gen *generator) operand16() {
switch gen.mode {
- case ifuzzimpl.ModeLong64, ifuzzimpl.ModeProt32:
+ case iset.ModeLong64, iset.ModeProt32:
gen.byte(0x66)
- case ifuzzimpl.ModeProt16, ifuzzimpl.ModeReal16:
+ case iset.ModeProt16, iset.ModeReal16:
default:
panic("bad mode")
}
@@ -321,8 +321,8 @@ func (gen *generator) operand16() {
func (gen *generator) operand32() {
switch gen.mode {
- case ifuzzimpl.ModeLong64, ifuzzimpl.ModeProt32:
- case ifuzzimpl.ModeProt16, ifuzzimpl.ModeReal16:
+ case iset.ModeLong64, iset.ModeProt32:
+ case iset.ModeProt16, iset.ModeReal16:
gen.byte(0x66)
default:
panic("bad mode")
@@ -331,8 +331,8 @@ func (gen *generator) operand32() {
func (gen *generator) addr32() {
switch gen.mode {
- case ifuzzimpl.ModeLong64, ifuzzimpl.ModeProt32:
- case ifuzzimpl.ModeProt16, ifuzzimpl.ModeReal16:
+ case iset.ModeLong64, iset.ModeProt32:
+ case iset.ModeProt16, iset.ModeReal16:
gen.byte(0x67)
default:
panic("bad mode")
@@ -384,7 +384,7 @@ func (gen *generator) mov32(reg int, v uint32) {
}
func (gen *generator) mov64(reg int, v uint64) {
- if gen.mode != ifuzzimpl.ModeLong64 {
+ if gen.mode != iset.ModeLong64 {
panic("bad mode")
}
gen.byte(0x48)
diff --git a/pkg/ifuzz/x86/x86.go b/pkg/ifuzz/x86/x86.go
index 51623aa2f..25d01fd36 100644
--- a/pkg/ifuzz/x86/x86.go
+++ b/pkg/ifuzz/x86/x86.go
@@ -9,16 +9,16 @@ package x86
import (
"math/rand"
- "github.com/google/syzkaller/pkg/ifuzz/ifuzzimpl"
+ "github.com/google/syzkaller/pkg/ifuzz/iset"
)
type Insn struct {
Name string
Extension string
- Mode ifuzzimpl.Mode // bitmask of compatible modes
- Priv bool // CPL=0
- Pseudo bool // pseudo instructions can consist of several real instructions
+ Mode iset.Mode // bitmask of compatible modes
+ Priv bool // CPL=0
+ Pseudo bool // pseudo instructions can consist of several real instructions
Opcode []byte
Prefix []byte
@@ -44,11 +44,11 @@ type Insn struct {
VexP int8
Avx2Gather bool
- generator func(cfg *ifuzzimpl.Config, r *rand.Rand) []byte // for pseudo instructions
+ generator func(cfg *iset.Config, r *rand.Rand) []byte // for pseudo instructions
}
type InsnSet struct {
- modeInsns ifuzzimpl.ModeInsns
+ modeInsns iset.ModeInsns
Insns []*Insn
}
@@ -62,18 +62,18 @@ func Register(insns []*Insn) {
for _, insn := range insnset.Insns {
insnset.modeInsns.Add(insn)
}
- ifuzzimpl.Arches[ifuzzimpl.ArchX86] = insnset
+ iset.Arches[iset.ArchX86] = insnset
}
-func (insnset *InsnSet) GetInsns(mode ifuzzimpl.Mode, typ ifuzzimpl.Type) []ifuzzimpl.Insn {
+func (insnset *InsnSet) GetInsns(mode iset.Mode, typ iset.Type) []iset.Insn {
return insnset.modeInsns[mode][typ]
}
-func (insn *Insn) Info() (string, ifuzzimpl.Mode, bool, bool) {
+func (insn *Insn) Info() (string, iset.Mode, bool, bool) {
return insn.Name, insn.Mode, insn.Pseudo, insn.Priv
}
-func generateArg(cfg *ifuzzimpl.Config, r *rand.Rand, size int) []byte {
+func generateArg(cfg *iset.Config, r *rand.Rand, size int) []byte {
v := generateInt(cfg, r, size)
arg := make([]byte, size)
for i := 0; i < size; i++ {
@@ -83,7 +83,7 @@ func generateArg(cfg *ifuzzimpl.Config, r *rand.Rand, size int) []byte {
return arg
}
-func generateInt(cfg *ifuzzimpl.Config, r *rand.Rand, size int) uint64 {
+func generateInt(cfg *iset.Config, r *rand.Rand, size int) uint64 {
if size != 1 && size != 2 && size != 4 && size != 8 {
panic("bad arg size")
}
@@ -98,7 +98,7 @@ func generateInt(cfg *ifuzzimpl.Config, r *rand.Rand, size int) uint64 {
case x < 30:
v = uint64(r.Int63())
case x < 40:
- v = ifuzzimpl.SpecialNumbers[r.Intn(len(ifuzzimpl.SpecialNumbers))]
+ v = iset.SpecialNumbers[r.Intn(len(iset.SpecialNumbers))]
if r.Intn(5) == 0 {
v += uint64(r.Intn(33)) - 16
}