Skip to content

Commit

Permalink
i#1848: auto-generate a syscall file on a new OS (#2155)
Browse files Browse the repository at this point in the history
Moves the default syscall file location into logs/symbols instead of the
bin/ directory, as we need a writable location.  Adds a new option
-syscall_number_path to allow specifying a custom location.

Adds functionality to drsyscall to fetch debug info for system libraries
and parse every symbol in each library looking for syscall wrappers.  Two
interfaces are added: drsys_find_sysnum_dlls() and
drsys_generate_sysnum_file().  Includes usercall identification support via
a list of target wrappers for key usercalls plus interpolation between
known numbers to include speculative results for all usercalls.  The
syscall wrapper parsing code is based on DR's winsysnums.c, expanded to
support 64-bit.

The resulting syscall file only supports the current machine, unlike the
general files we have posted for downloading.

Adds auto-triggering of the new functionality when an unknown OS version is
detected.  A special exit code is used, and when the frontend sees it, it
invokes the drsyscall functions for generating a syscall file.  If that is
successful, it re-launches the app.

Adds new options -vv and -vvv to support raising verbosity for the
drsyscall code invoked directly from the frontend.

Changes the existing mksystable.pl-based test to test the new auto-gen
functionality.

Fixes #1848
  • Loading branch information
derekbruening committed Feb 24, 2019
1 parent 8bcd285 commit 313de07
Show file tree
Hide file tree
Showing 20 changed files with 1,311 additions and 182 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Expand Up @@ -1376,7 +1376,8 @@ if (USE_DRSYMS)
set(DynamoRIO_RPATH ON)
configure_DynamoRIO_standalone(${toolname})
set(DynamoRIO_RPATH ${old_rpath})
target_link_libraries(${toolname} drinjectlib drconfiglib drfrontendlib)
target_link_libraries(${toolname} drinjectlib drconfiglib drfrontendlib
drsyscall_static)
if (WIN32)
set_target_properties(${toolname} PROPERTIES
VERSION ${TOOL_VERSION_NUMBER}
Expand Down
2 changes: 1 addition & 1 deletion common/utils.c
Expand Up @@ -45,7 +45,7 @@
/* globals that affect NOTIFY* and *LOG* macros */
int tls_idx_util = -1;
bool op_print_stderr = true;
uint op_verbose_level;
int op_verbose_level;
bool op_pause_at_assert;
bool op_pause_via_loop;
bool op_ignore_asserts;
Expand Down
29 changes: 23 additions & 6 deletions common/utils.h
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2010-2017 Google, Inc. All rights reserved.
* Copyright (c) 2010-2018 Google, Inc. All rights reserved.
* Copyright (c) 2007-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -193,10 +193,12 @@ extern "C" {
#define CROSSES_ALIGNMENT(addr, size, alignment) \
(ALIGN_MOD(addr, size, alignment) < (size)-1)

#define TEST(mask, var) (((mask) & (var)) != 0)
#define TESTANY TEST
#define TESTALL(mask, var) (((mask) & (var)) == (mask))
#define TESTONE(mask, var) test_one_bit_set((mask) & (var))
#ifndef TESTANY
# define TEST(mask, var) (((mask) & (var)) != 0)
# define TESTANY TEST
# define TESTALL(mask, var) (((mask) & (var)) == (mask))
# define TESTONE(mask, var) test_one_bit_set((mask) & (var))
#endif

#define IS_POWER_OF_2(x) ((x) != 0 && ((x) & ((x)-1)) == 0)

Expand Down Expand Up @@ -302,7 +304,7 @@ extern "C" {

/* globals that affect NOTIFY* and *LOG* macros */
extern bool op_print_stderr;
extern uint op_verbose_level;
extern int op_verbose_level;
extern bool op_pause_at_assert;
extern bool op_pause_via_loop;
extern bool op_ignore_asserts;
Expand Down Expand Up @@ -389,6 +391,13 @@ print_prefix_to_console(void);
PRINT_CONSOLE(__VA_ARGS__); \
} \
} while (0)
#define NOTIFY_VERBOSE(level, ...) do { \
ELOG(0, __VA_ARGS__); \
if (op_verbose_level >= level && op_print_stderr) { \
print_prefix_to_console(); \
PRINT_CONSOLE(__VA_ARGS__); \
} \
} while (0)
#define NOTIFY_NO_PREFIX(...) do { \
ELOG(0, __VA_ARGS__); \
if (op_print_stderr) { \
Expand Down Expand Up @@ -861,6 +870,14 @@ cast_to_func(void *p)
#ifdef WINDOWS
# include "windefs.h"

/* i#1908: we support loading numbers from a file */
# define SYSNUM_FILE IF_X64_ELSE("syscalls_x64.txt", "syscalls_x86.txt")
# define SYSNUM_FILE_WOW64 "syscalls_wow64.txt"

# ifndef STATUS_INVALID_KERNEL_INFO_VERSION
# define STATUS_INVALID_KERNEL_INFO_VERSION 0xc000a004
# endif

TEB *
get_TEB(void);

Expand Down

0 comments on commit 313de07

Please sign in to comment.