i#1063: implement file time routines

Fixed a bug in convert_millis_to_date(): Jan 1, 1601 was a Monday, not a Sunday.

Added convert_date_to_millis(), convert_system_time_to_100ns(), and
convert_100ns_to_system_time().

Implemented redirection for FileTimeToLocalFileTime(),
LocalFileTimeToFileTime(), FileTimeToSystemTime(),
SystemTimeToFileTime(), GetSystemTimeAsFileTime(), GetFileTime(), and
SetFileTime().  GetFileTime() was not on the original import list, but
implementing it made it easier to test the others.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1892 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Added convert_to_NT_file_path_wide() for two reasons: to avoid the double
conversion in the wide kernel32 redir routines, and to avoid imposing a
MAX_PATH limit which should not be there for wide paths already in NT
format.  Changed redirect_CreateDirectoryW(), redirect_CreateFileW(), and
redirect_DeleteFileW() to use the new routine.

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

Relax data_sections_enclose_region() to allow for arbitrary section
ordering.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1894 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fix typo in doxygen comment

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1895 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#911: win8 console printing

Add a check that dr_using_console() is never true on win8.
No other direct changes are needed for win8 console support.
Separate changes will disable kernel32 init when loaded for other reasons
than dr_enable_console_printing().

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1896 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#1063: implement FindFirstFile iterator

Implemented redirection routines for FindClose(), FindFirstFileA(),
FindFirstFileW(), FindNextFileA(), and FindNextFileW().  Added several
tests of these routines.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1897 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#1063: file flushing routines

Implemented FlushViewOfFile() and FlushFileBuffers() redirection.

Refactored kernel32 unit test file mapping code into test_file_mapping().

Renamed flush_file_buffers() to nt_flush_file_buffers() and it now
returns NTSTATUS for more flexible usage and sharing between DR and
redirection.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1898 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#1063: RemoveDirectory

Implemented RemoveDirectory{A,W}()

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1899 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#1063: current directory redirection

Implemented redirection for {Get,Set}CurrentDirectory{A,W}().
Setting does not support relative paths: waiting for GetFullPathName().

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1900 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Scan PLT relocations to hook and unhook native exec interception stubs

This allows us to intercept calls out of modules that are already partially or
wholly bound when we initialize.  Also cleans up stubs created lazily by
dynamorio_fixup().

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

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1901 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#1063: implement redirection for ReadFile() and WriteFile().

Added tests for both synch and asynch operation.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1902 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
make advapi32 registry test less flaky

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1903 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Fixes to get VS2005 build working with latest changes

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1904 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Add dbghelp_imports.lib to support using recent wide-char dbghelp
routines and still building with VS2005.  This is for Dr. Memory
i#1127 as well as DRi#943.

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

Construct BaseNamedObjects path on win8 where the ReadOnlyStaticServerData
is above 4GB and has a more complex structure.

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1906 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Update TEB and PEB based on Windows 8 symbols

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1907 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
fix memory leak in FindFile redirection

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1908 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
i#978: Take control back from native ELF modules at cross-module PLT calls

This behavior is controlled by -native_exec_retakeover.  When returning to a
native module with this option set, we trust that it will return control back
to DR.  We generate special bbs that jump directly back into the module on such
returns.

Only one level of native execution is currently supported.  We assert on nested
calls into native modules.

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

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1909 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
Consider the ELF e_entry point to be a gateway

For non-static ELFs, the loader clears the stack after doing its initialization
and jumps indirectly to the exe's e_entry function, which is usually _start
from crt0.o.  There is no retaddr on the stack, so _start can never return.
Therefore we can just go native directly without putting a return address on
the stack.

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

git-svn-id: https://dynamorio.googlecode.com/svn/trunk@1910 49cc7528-f6fd-11dd-9d1a-b59b2e1864b6
native_exec: handle eagerly resolved ELF modules

If DT_BIND_NOW or its equivalents are set, then the resolver will be
NULL and the module fully relocated.  We don't need to replace it, and
we can't use it to check if we've already hooked the module or not.

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

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