Path: blob/master/arch/x86/mm/kmemcheck/selftest.c
10818 views
#include <linux/kernel.h>12#include "opcode.h"3#include "selftest.h"45struct selftest_opcode {6unsigned int expected_size;7const uint8_t *insn;8const char *desc;9};1011static const struct selftest_opcode selftest_opcodes[] = {12/* REP MOVS */13{1, "\xf3\xa4", "rep movsb <mem8>, <mem8>"},14{4, "\xf3\xa5", "rep movsl <mem32>, <mem32>"},1516/* MOVZX / MOVZXD */17{1, "\x66\x0f\xb6\x51\xf8", "movzwq <mem8>, <reg16>"},18{1, "\x0f\xb6\x51\xf8", "movzwq <mem8>, <reg32>"},1920/* MOVSX / MOVSXD */21{1, "\x66\x0f\xbe\x51\xf8", "movswq <mem8>, <reg16>"},22{1, "\x0f\xbe\x51\xf8", "movswq <mem8>, <reg32>"},2324#ifdef CONFIG_X86_6425/* MOVZX / MOVZXD */26{1, "\x49\x0f\xb6\x51\xf8", "movzbq <mem8>, <reg64>"},27{2, "\x49\x0f\xb7\x51\xf8", "movzbq <mem16>, <reg64>"},2829/* MOVSX / MOVSXD */30{1, "\x49\x0f\xbe\x51\xf8", "movsbq <mem8>, <reg64>"},31{2, "\x49\x0f\xbf\x51\xf8", "movsbq <mem16>, <reg64>"},32{4, "\x49\x63\x51\xf8", "movslq <mem32>, <reg64>"},33#endif34};3536static bool selftest_opcode_one(const struct selftest_opcode *op)37{38unsigned size;3940kmemcheck_opcode_decode(op->insn, &size);4142if (size == op->expected_size)43return true;4445printk(KERN_WARNING "kmemcheck: opcode %s: expected size %d, got %d\n",46op->desc, op->expected_size, size);47return false;48}4950static bool selftest_opcodes_all(void)51{52bool pass = true;53unsigned int i;5455for (i = 0; i < ARRAY_SIZE(selftest_opcodes); ++i)56pass = pass && selftest_opcode_one(&selftest_opcodes[i]);5758return pass;59}6061bool kmemcheck_selftest(void)62{63bool pass = true;6465pass = pass && selftest_opcodes_all();6667return pass;68}697071