Changeset View
Changeset View
Standalone View
Standalone View
sys/cddl/dev/dtrace/x86/instr_size.c
| Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | |||||
| #include <vm/seg_enum.h> | #include <vm/seg_enum.h> | ||||
| #include <sys/privregs.h> | #include <sys/privregs.h> | ||||
| #else | #else | ||||
| #include <sys/cred.h> | #include <sys/cred.h> | ||||
| #include <cddl/dev/dtrace/dtrace_cddl.h> | #include <cddl/dev/dtrace/dtrace_cddl.h> | ||||
| typedef u_int model_t; | typedef u_int model_t; | ||||
| #define DATAMODEL_NATIVE 0 | #define DATAMODEL_NATIVE 0 | ||||
| int dtrace_instr_size(uchar_t *); | int dtrace_instr_size(uint8_t *); | ||||
| int dtrace_instr_size_isa(uchar_t *, model_t, int *); | int dtrace_instr_size_isa(uint8_t *, model_t, int *); | ||||
| #endif | #endif | ||||
| #include <dis_tables.h> | #include <dis_tables.h> | ||||
| /* | /* | ||||
| * This subsystem (with the minor exception of the instr_size() function) is | * This subsystem (with the minor exception of the instr_size() function) is | ||||
| * is called from DTrace probe context. This imposes several requirements on | * is called from DTrace probe context. This imposes several requirements on | ||||
| * the implementation: | * the implementation: | ||||
| Show All 16 Lines | |||||
| /* | /* | ||||
| * get a byte from instruction stream | * get a byte from instruction stream | ||||
| */ | */ | ||||
| static int | static int | ||||
| dtrace_dis_get_byte(void *p) | dtrace_dis_get_byte(void *p) | ||||
| { | { | ||||
| int ret; | int ret; | ||||
| uchar_t **instr = p; | uint8_t **instr = p; | ||||
| ret = **instr; | ret = **instr; | ||||
| *instr += 1; | *instr += 1; | ||||
| return (ret); | return (ret); | ||||
| } | } | ||||
| /* | /* | ||||
| * Returns either the size of a given instruction, in bytes, or the size of that | * Returns either the size of a given instruction, in bytes, or the size of that | ||||
| * instruction's memory access (if any), depending on the value of `which'. | * instruction's memory access (if any), depending on the value of `which'. | ||||
| * If a programming error in the tables is detected, the system will panic to | * If a programming error in the tables is detected, the system will panic to | ||||
| * ease diagnosis. Invalid instructions will not be flagged. They will appear | * ease diagnosis. Invalid instructions will not be flagged. They will appear | ||||
| * to have an instruction size between 1 and the actual size, and will be | * to have an instruction size between 1 and the actual size, and will be | ||||
| * reported as having no memory impact. | * reported as having no memory impact. | ||||
| */ | */ | ||||
| /* ARGSUSED2 */ | /* ARGSUSED2 */ | ||||
| static int | static int | ||||
| dtrace_dis_isize(uchar_t *instr, dis_isize_t which, model_t model, int *rmindex) | dtrace_dis_isize(uint8_t *instr, dis_isize_t which, model_t model, int *rmindex) | ||||
| { | { | ||||
| int sz; | int sz; | ||||
| dis86_t x; | dis86_t x; | ||||
| uint_t mode = SIZE32; | uint_t mode = SIZE32; | ||||
| mode = (model == DATAMODEL_LP64) ? SIZE64 : SIZE32; | mode = (model == DATAMODEL_LP64) ? SIZE64 : SIZE32; | ||||
| x.d86_data = (void **)&instr; | x.d86_data = (void **)&instr; | ||||
| Show All 9 Lines | else | ||||
| sz = x.d86_memsize; /* length of memory operand */ | sz = x.d86_memsize; /* length of memory operand */ | ||||
| if (rmindex != NULL) | if (rmindex != NULL) | ||||
| *rmindex = x.d86_rmindex; | *rmindex = x.d86_rmindex; | ||||
| return (sz); | return (sz); | ||||
| } | } | ||||
| int | int | ||||
| dtrace_instr_size_isa(uchar_t *instr, model_t model, int *rmindex) | dtrace_instr_size_isa(uint8_t *instr, model_t model, int *rmindex) | ||||
| { | { | ||||
| return (dtrace_dis_isize(instr, DIS_ISIZE_INSTR, model, rmindex)); | return (dtrace_dis_isize(instr, DIS_ISIZE_INSTR, model, rmindex)); | ||||
| } | } | ||||
| int | int | ||||
| dtrace_instr_size(uchar_t *instr) | dtrace_instr_size(uint8_t *instr) | ||||
| { | { | ||||
| return (dtrace_dis_isize(instr, DIS_ISIZE_INSTR, DATAMODEL_NATIVE, | return (dtrace_dis_isize(instr, DIS_ISIZE_INSTR, DATAMODEL_NATIVE, | ||||
| NULL)); | NULL)); | ||||
| } | } | ||||