Skip to content

Commit

Permalink
issue 34: REG_* enum conflict with sys/ucontext.h
Browse files Browse the repository at this point in the history
* renamed to DR_REG_ and DR_SEG_* in all client-exposed headers
* added set of compatibility defines if DR_REG_ENUM_COMPATIBILITY is set,
  which it is for the core to avoid changing the rest of the core
* added client var DynamoRIO_REG_COMPATIBILITY for requesting compatibility
* if client requests 2.0.0 or earlier, automatically use old constants
* added error message if compat is requested and ucontext.h included before DR
* added genapi.pl check for exposing non-DR_ constants which is the
  danger of a half-replace like this
* turned on REG_ compatibility for suite/ tests

SVN-Revision: 469
  • Loading branch information
derekbruening committed Oct 22, 2010
1 parent 2f623e3 commit 96cfabc
Show file tree
Hide file tree
Showing 15 changed files with 838 additions and 485 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ set(CMAKE_BUILD_TYPE "" CACHE INTERNAL
# resources when packaging
# N.B.: once VERSION_NUMBER crosses 3.x we'll need to update the
# symlink loop in core/CMakeLists.txt
set(VERSION_NUMBER_DEFAULT "2.0.0")
set(VERSION_NUMBER_DEFAULT "2.1.0")
# do not store the default VERSION_NUMBER in the cache to prevent a stale one
# from preventing future version updates in a pre-existing build dir
set(VERSION_NUMBER "" CACHE STRING "Version number: leave empty for default")
Expand Down
7 changes: 6 additions & 1 deletion api/docs/release.dox
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ are not backward compatible: see below for details.
The changes between version 2.1.0 and 2.0.0 are:

- Added Windows 7 support
- Added DR_TRY_EXCEPT() (Issue 52)
- Added DR_TRY_EXCEPT() (Issue 51)
- Added dr_client_thread_set_suspendable()
- Added dr_get_random_value(), dr_set_random_seed(), and dr_get_random_seed()
- Added dr_file_exists() and dr_directory_exists() for Linux
Expand All @@ -126,6 +126,11 @@ The changes between version 2.1.0 and 2.0.0 are:
- Added drsym_enumerate_symbols() to the \p drsyms Extension
- Added limited support for printing to the cmd window (Issue 261) via the
\p drsyms Extension: drsym_write_to_console() and drsym_using_console()
- Renamed the REG_ constants to DR_REG_ to avoid conflicts with system
headers (Issue 34). \Clients should set(DynamoRIO_REG_COMPATIBILITY ON)
prior to configure_DynamoRIO_client() to use the old constants and avoid
any source changes; this will happen automatically if the \client
targets version 2.0 or earlier. Binary compatibility is unaffected.
- Deprecated dr_request_synchronized_exit() and replaced it with
dr_set_process_exit_behavior(). Now a full thread synch is performed
at exit time in release build if a process exit event or thread exit
Expand Down
8 changes: 4 additions & 4 deletions api/samples/countcalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ insert_counter_update(void *drcontext, instrlist_t *bb, instr_t *where, int offs
/* We spill xbx to use a scratch register (we could do a liveness
* analysis to try and find a dead register to use). Note that xax
* is currently holding the saved eflags. */
dr_save_reg(drcontext, bb, where, REG_XBX, SPILL_SLOT_2);
dr_insert_read_tls_field(drcontext, bb, where, REG_XBX);
dr_save_reg(drcontext, bb, where, DR_REG_XBX, SPILL_SLOT_2);
dr_insert_read_tls_field(drcontext, bb, where, DR_REG_XBX);
instrlist_meta_preinsert(bb, where,
INSTR_CREATE_inc(drcontext, OPND_CREATE_MEM32(REG_XBX, offset)));
dr_restore_reg(drcontext, bb, where, REG_XBX, SPILL_SLOT_2);
INSTR_CREATE_inc(drcontext, OPND_CREATE_MEM32(DR_REG_XBX, offset)));
dr_restore_reg(drcontext, bb, where, DR_REG_XBX, SPILL_SLOT_2);
}

/* restore flags */
Expand Down
10 changes: 5 additions & 5 deletions api/samples/memtrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ code_cache_init(void)
ilist = instrlist_create(drcontext);
/* The lean procecure simply performs a clean call, and then jump back */
/* jump back to the DR's code cache */
where = INSTR_CREATE_jmp_ind(drcontext, opnd_create_reg(REG_XCX));
where = INSTR_CREATE_jmp_ind(drcontext, opnd_create_reg(DR_REG_XCX));
instrlist_meta_append(ilist, where);
/* clean call */
dr_insert_clean_call(drcontext, ilist, where, (void *)clean_call, false, 0);
Expand Down Expand Up @@ -344,8 +344,8 @@ instrument_mem(void *drcontext, instrlist_t *ilist, instr_t *where,
{
instr_t *instr, *call, *restore;
opnd_t ref, opnd1, opnd2;
reg_id_t reg1 = REG_XBX; /* We can optimize it by picking dead reg */
reg_id_t reg2 = REG_XCX; /* reg2 must be ECX or RCX for jecxz */
reg_id_t reg1 = DR_REG_XBX; /* We can optimize it by picking dead reg */
reg_id_t reg2 = DR_REG_XCX; /* reg2 must be ECX or RCX for jecxz */
per_thread_t *data;

data = dr_get_tls_field(drcontext);
Expand Down Expand Up @@ -409,7 +409,7 @@ instrument_mem(void *drcontext, instrlist_t *ilist, instr_t *where,

/* Increment reg value by pointer size using lea instr */
opnd1 = opnd_create_reg(reg2);
opnd2 = opnd_create_base_disp(reg2, REG_NULL, 0,
opnd2 = opnd_create_base_disp(reg2, DR_REG_NULL, 0,
sizeof(mem_ref_t),
OPSZ_lea);
instr = INSTR_CREATE_lea(drcontext, opnd1, opnd2);
Expand Down Expand Up @@ -453,7 +453,7 @@ instrument_mem(void *drcontext, instrlist_t *ilist, instr_t *where,
* clean call invocation. This is to reduce the code cache size.
*/
instrlist_meta_preinsert(ilist, where, call);
/* mov restore REG_XCX */
/* mov restore DR_REG_XCX */
opnd1 = opnd_create_reg(reg2);
/* this is the return address for jumping back from lean procedure */
opnd2 = opnd_create_instr(restore);
Expand Down
2 changes: 1 addition & 1 deletion api/samples/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ insert_inc(void *drcontext, instrlist_t *bb, instr_t *where,
immed = OPND_CREATE_INT8(incby);
else /* unlikely but possible */
immed = OPND_CREATE_INT32(incby);
inc = INSTR_CREATE_add(drcontext, OPND_CREATE_MEM32(REG_NULL, (int)addr), immed);
inc = INSTR_CREATE_add(drcontext, OPND_CREATE_MEM32(DR_REG_NULL, (int)addr), immed);
/* make it thread-safe (only works if it doesn't straddle a cache line) */
instr_set_prefix_flag(inc, PREFIX_LOCK);
DR_ASSERT((((ptr_uint_t)addr) & 0x3) == 0); /* 4-aligned => single cache line */
Expand Down
5 changes: 5 additions & 0 deletions api/samples/stl_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
#include <list>
#include <map>

#ifdef LINUX
/* included as a test of i#34 */
# include <signal.h>
#endif

using namespace std;


Expand Down
2 changes: 1 addition & 1 deletion api/samples/strace.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ decode_syscall_num(byte *entry)
}
/* Note that we'll failed if somebody has hooked the wrapper */
if (opc == OP_mov_imm && opnd_is_reg(instr_get_dst(&instr, 0)) &&
opnd_get_reg(instr_get_dst(&instr, 0)) == REG_EAX) {
opnd_get_reg(instr_get_dst(&instr, 0)) == DR_REG_EAX) {
DR_ASSERT(opnd_is_immed_int(instr_get_src(&instr, 0)));
num = (int) opnd_get_immed_int(instr_get_src(&instr, 0));
break;
Expand Down
19 changes: 16 additions & 3 deletions core/lib/genapi.pl
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ ($)
if ($_ =~ /\r$/) { chop; };
$l = $_;

if ($output_routine || $output_directly || $output_verbatim) {
# Enforce the rename to DR_REG_ and DR_SEG_
if (($l =~ /[^_]REG_/ || $l =~ /[^_]SEG_/) &&
# We have certain exceptions
($l !~ /^# define [RS]EG_/ &&
$l !~ /DR_REG_ENUM_COMPATIBILITY/ &&
$l !~ /conflict/ &&
$l !~ /compatibility/ &&
$l !~ /weird errors/)) {
die "Error: update to DR_{REG,SEG} constants:\n$l\n";
}
}

if ($l =~ /^DR_API/) {
$output_routine = 1;
$did_output_something = 1;
Expand Down Expand Up @@ -450,10 +463,10 @@ ($)
# remove pointers into decode tables
$l =~ s/(OP_[a-zA-Z0-9_]*,) *\/\*[^\*]*\*\/(.*)/\1\2/;
}
# PR 227381: auto-insert doxygen comments for REG_ enum lines without any
# PR 227381: auto-insert doxygen comments for DR_REG_ enum lines w/o any
if ($file =~ "/instr.h" &&
$l =~ /^ *[RS]EG_/ && $l !~ /\/\*\*</) {
$l =~ s|([RS]EG_)(\w+), *|\1\2, /**< The "\L\2" register. */\n |g;
$l =~ /^ *DR_[RS]EG_/ && $l !~ /\/\*\*</) {
$l =~ s|(DR_[RS]EG_)(\w+), *|\1\2, /**< The "\L\2" register. */\n |g;
}
# Strip out FIXME comments
$l =~ s/\/\* FIXME.*\*\///;
Expand Down
6 changes: 3 additions & 3 deletions core/x86/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,15 @@ enum {
/* DR_API EXPORT BEGIN */

/* Memory operand sizes (with Intel's corresponding size names noted).
* For register operands, the REG_ constants are used, which implicitly
* state a size (e.g., REG_CX is 2 bytes).
* For register operands, the DR_REG_ constants are used, which implicitly
* state a size (e.g., DR_REG_CX is 2 bytes).
* Use the type opnd_size_t for these values (we avoid typedef-ing the
* enum, as its storage size is compiler-specific). opnd_size_t is a
* byte, so the largest value here needs to be <= 255.
*/
enum {
/* register enum values are used for TYPE_*REG */
OPSZ_NA = REG_LAST_ENUM+1, /**< Sentinel value: not a valid size. */ /* = 139 */
OPSZ_NA = DR_REG_LAST_ENUM+1, /**< Sentinel value: not a valid size. */ /* = 139 */
OPSZ_0, /**< Intel 'm': "sizeless": used for both start addresses
* (lea, invlpg) and implicit constants (rol, fldl2e, etc.) */
OPSZ_1, /**< Intel 'b': 1 byte */
Expand Down
Loading

0 comments on commit 96cfabc

Please sign in to comment.