aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/ifuzz/xed.go
diff options
context:
space:
mode:
authorAlexey Kardashevskiy <aik@linux.ibm.com>2020-09-02 18:11:22 +1000
committerDmitry Vyukov <dvyukov@google.com>2020-11-20 15:31:42 +0100
commite72f8f11e096d36aefc41a35c718dced97c45dea (patch)
tree6619d0089d8ac172c64853c76c0b1acc9485d192 /pkg/ifuzz/xed.go
parent740ff4615a9ced4a8a016365aa44674b9b0e807d (diff)
pkg/ifuzz: reorganize files to allow other architectures
At the moment ifuzz only generates x86 instructions. In order to support instruction fuzzing for others (ARM, POWERPC), some separation of the common and arch layers is needed. This adds 2 packages: 1. "x86" where x86 instruction generator goes to 2. "ifuzzimpl which contains some common code. The goal was to keep changes to the rand.go to the minimum. The next patch will use this when adding PPC64. This should cause no behavioural change. Signed-off-by: Alexey Kardashevskiy <aik@linux.ibm.com>
Diffstat (limited to 'pkg/ifuzz/xed.go')
-rw-r--r--pkg/ifuzz/xed.go67
1 files changed, 0 insertions, 67 deletions
diff --git a/pkg/ifuzz/xed.go b/pkg/ifuzz/xed.go
deleted file mode 100644
index dfc66d82a..000000000
--- a/pkg/ifuzz/xed.go
+++ /dev/null
@@ -1,67 +0,0 @@
-// 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.
-
-// XedDecode is required for tests, but it requires Intel XED library installed, so it is disabled by default.
-// To run full tests, check out and build github.com/intelxed/xed, then run:
-// INTELXED=/path/to/intelxed CGO_CFLAGS="-I $INTELXED/xed/include/public \
-// -I $INTELXED/build/obj" CGO_LDFLAGS="$INTELXED/build/obj/libxed.a" \
-// go test -v -tags xed
-
-// +build xed
-
-package ifuzz
-
-/*
-#include "xed-interface.h"
-
-int xedDecode(int mode, int addrsize, void* text, int size, const char** error) {
- xed_decoded_inst_t xedd;
- xed_decoded_inst_zero(&xedd);
- xed_decoded_inst_set_mode(&xedd, mode, addrsize);
- xed_error_enum_t err = xed_decode(&xedd, text, size);
- if (err != XED_ERROR_NONE) {
- if (error)
- *error = xed_error_enum_t2str(err);
- return 0;
- }
- return xed_decoded_inst_get_length(&xedd);
-}
-*/
-import "C"
-
-import (
- "errors"
- "unsafe"
-)
-
-func init() {
- C.xed_tables_init()
- XedDecode = xedDecode
-}
-
-func xedDecode(mode int, text []byte) (int, error) {
- xedMode := 0
- xedAddr := 0
- switch mode {
- case ModeLong64:
- xedMode = C.XED_MACHINE_MODE_LONG_64
- xedAddr = C.XED_ADDRESS_WIDTH_64b
- case ModeProt32:
- xedMode = C.XED_MACHINE_MODE_LONG_COMPAT_32
- xedAddr = C.XED_ADDRESS_WIDTH_32b
- case ModeProt16:
- xedMode = C.XED_MACHINE_MODE_LONG_COMPAT_16
- xedAddr = C.XED_ADDRESS_WIDTH_16b
- case ModeReal16:
- xedMode = C.XED_MACHINE_MODE_REAL_16
- xedAddr = C.XED_ADDRESS_WIDTH_16b
- default:
- panic("bad mode")
- }
- var errorStr *C.char
- res := C.xedDecode(C.int(xedMode), C.int(xedAddr), unsafe.Pointer(&text[0]), C.int(len(text)), &errorStr)
- if res == 0 {
- return 0, errors.New(C.GoString(errorStr))
- }
- return int(res), nil
-}