i#891: Add dr_get_main_module() to the API

This provides a reliable way for the client to get information about the
main app executable.  The existing pattern for getting the main module
is:

  dr_lookup_module_by_name(dr_get_application_name());

However, the above is unreliable if there are multiple modules with the
same preferred name.  More likely, on Linux, dr_get_application_name()
relies on the proc filesystem, which could be unavailable for various
reasons.  This API is more robust in the face of such corner cases.

Review URL: https://codereview.appspot.com/6492106

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1589 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Re-land "Replace uses of WCHAR with TCHAR in dr_config.c"

Part of issue 840.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1590 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#840: Port the native drconfig tool

Part 3 of porting drconfig and drinject to Linux.

I started with drconfig since it is the smallest tool.  The native
drconfig tool produces a config file similar to the one from the shell
script, but lacking DYNAMORIO_HOME.

To make the drconfig exports cross platform I switched from the .def file to DR_API macros in the header files.

Review URL: https://codereview.appspot.com/6496077

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1591 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fixed a bug in r1570
- remove "0x" used by %x before

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1592 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Clang: Pass xsp in the x86.asm signal trampoline without aliasing

Fixes issue 898.

gcc was eliminating the xsp_unsafe to xsp copy because gcc believed
xsp_unsafe had no aliases.  Instead, we create a new stack frame and
read the arguments to the signal handler through xsp.

Unfortunately this means that ia32 and x64 have different signal handler
prototypes again.

I did an ia32 build with !HAVE_SIGALTSTACK, and the signal tests passed.

Review URL: https://codereview.appspot.com/6527048

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1593 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#893: add /safeseh:no

Added /safeseh:no for the core and for all the tests in order to
avoid errors from VS2012 due to our asm code.
Had to move core unit_tests down below the definition of LD_FLAGS.
Long-term we should make tools.asm SEH-compliant, so not resolving
the issue with this workaround.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1594 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fixes issue 894

Win8 WDK ntdll.lib does not list Ki routines nor string/memory routines so
we make our own .lib.  Because the Ki are stdcall we can't just use a .def
file: we need an .obj file built from stubs w/ the same signatures.

For the string routines, the .def file is sufficient as they're cdecl.
We also have to re-order msvcrt.lib to ensure it's after the new
ntdll_imports.lib.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1595 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fixes issue 895

fix libutil buffer overflow found by VS2012

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1596 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fixes issue 896

VS2012 and Win8 WDK support:

1) locate ntdll.lib in Windows 8 WDK
2) locate uuid.lib
3) PEXCEPTION_REGISTRATION_RECORD rename to avoid conflict
4) use editbin instead of the missing bind.exe
5) eliminate C++ keywords becoming macros
6) eliminate macro redefs

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1597 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fixes issue 897

update winsysnums for proper 64-bit decoding and for win8:
+ honor -ignore_Zw for pdb
+ don't require ecx for wow64
+ don't truncate syscall number
+ build 64-bit and set 64-bit mode for -x64 option
+ build properly w/ latest DynamoRIOConfig.cmake
+ handle win8 call-adjacent wrappers

relaxed asserts in dr_print_{instr,opnd} to allow calling in standalone
mode

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1598 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Make the ninja cmake generator work on Windows

Ninja ends up being a lot faster for incremental builds, but seems to do
worse on clean builds.  I don't know why yet.  I made the suite work
with ninja, but it's not worth using that way yet since the clean builds
are slower.

The clean builds below were builds after completely removing the build
directory and re-configuring, and the incremental times were builds
after touching dynamo.c.

Times:       clean       incremental
---------------------------------------
msbuild:     52.67s      15.89s
ninja:       62.76s      2.41s

Review URL: https://codereview.appspot.com/6534043

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1600 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
+ fix events.h generation race introduced by r1600
+ fix unit_tests ntdll_imports vs libc link order

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1601 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#565 part 1: win8 version update

Updated all places where we store Windows versions:
+ windows_version_init()
+ tools.c get_windows_version()
+ dr_get_os_version()

Except not updating this until win8 support is all done:
+ -max_supported_os_version option

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1603 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#565 part 2: win8 syscall #s

Added the syscall numbers for win8 x86 and x64, and for the first time made
a separate column for wow64 due to the high-order bits being used instead
of ecx.

Reversed the columns so that new numbers are appened rather than inserted
at the beginning.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1604 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#899: new win8 syscalls

Adds numbers for 3 new win8 syscalls the core may need to intercept.
Adds NYI asserts to catch execution so we can go figure them out.

NtUnmapViewOfSectionEx with new arg==0 is let through as it's the same as
NtUnmapViewOfSection.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1605 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#565 part 3: syscall wrapper updates

There are quite a few wrapper differences which end up tripping DR all over
the place due to its many interactions with such wrappers:

+ syscalls_init() up-front syscall type check
+ intercept_syscall_wrapper()
+ clean_syscall_wrapper()
+ syscall param base for app syscall processing
+ add dynamorio_syscall_wow64_noedx which shifts retaddr
  so params are in right spot for calls from DR
+ wow64 post-syscall esp adjust is on win7 but not win8,
  for skipping syscalls and for invoke-another feature
+ win8 wow64 cleanup_and_terminate can't just use edx so I have it storing
  args on wow64_syscall_stack which I claim is safe
+ set_mcontext_for_syscall needs to pass args to an app syscall.
  I have it writing args to the app stack.  I can't clean them up.
  but it's only used for NtRaiseException, where changes
  to regs or even the stack will be unrolled or else the app will exit.

The checks for these are sometimes version checks for win8, and also:
+ added two routines for more general checks than "is it win8?":
  + syscall_uses_wow64_index()
  + !syscall_uses_edx_param_base()

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1606 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#899: handle new win8 syscall NtWow64AllocateVirtualMemory64 which it
turns out is just like NtAllocateVirtualMemory except it has an extra
unused arg inserted in the middle.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1607 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#910: treat _FPE_MULTIPLE_TRAPS as _FPE_ZERODIVIDE to get win32.fpe test to pass

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1608 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fixes issue 917
+ define sfPdb ourselves for VS2005

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1609 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Export doxygen-handling scripts for use by other tools:
http://code.google.com/p/drmemory/issues/detail?id=929

+ export CMake_rundoxygen.cmake as cmake/docs_rundoxygen.cmake
+ add new file CMake_doxyutils.cmake exported as
  cmake/docs_doxyutils.cmake which provides functions for:
  + doxygen version check
  + cygpath conversion
  + doxyfile conversion for header and for navbar
+ updated DR to use this script split

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1610 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6