harmless changes in preparation for moving to unicode
ia32: fix: ia32_GetCallTarget wasn't always initializing target x86_x64: use macro implementation for rdtsc to reduce timing overhead This was SVN commit r7160.
This commit is contained in:
parent
e6f9d25925
commit
a46f3432f3
@ -160,7 +160,7 @@ namespace detail
|
||||
*
|
||||
* @param expression that is expected to evaluate to non-zero at compile-time.
|
||||
**/
|
||||
#define cassert2(expr) extern char CASSERT_FAILURE[1][(expr)]
|
||||
#define cassert2(expr) extern u8 CASSERT_FAILURE[1][(expr)]
|
||||
|
||||
|
||||
// copied from boost::noncopyable; this definition avoids warnings when
|
||||
|
@ -86,7 +86,7 @@ const size_t GiB = size_t(1) << 30;
|
||||
// (function taking a reference to an array and returning a pointer to
|
||||
// an array of characters. it's only declared and never defined; we just
|
||||
// need it to determine n, the size of the array that was passed.)
|
||||
template<typename T, size_t n> char (*ArraySizeDeducer(T (&)[n]))[n];
|
||||
template<typename T, size_t n> u8 (*ArraySizeDeducer(T (&)[n]))[n];
|
||||
|
||||
// (although requiring C++, this method is much better than the standard
|
||||
// sizeof(name) / sizeof(name[0]) because it doesn't compile when a
|
||||
|
@ -90,6 +90,8 @@ need only be renamed (e.g. _open, _stat).
|
||||
#if MSC_VERSION
|
||||
#define strcasecmp stricmp
|
||||
#define strncasecmp strnicmp
|
||||
#define wcscasecmp wcsicmp
|
||||
#define wcsncasecmp wcsnicmp
|
||||
#endif
|
||||
|
||||
#if OS_MACOSX
|
||||
|
@ -32,6 +32,8 @@ static const size_t maxInstructionLength = 15; // IA-32 limitation
|
||||
|
||||
static bool IsCall(void* ret_addr, void*& target)
|
||||
{
|
||||
target = 0; // (not always possible to determine)
|
||||
|
||||
// points to end of the CALL instruction (which is of unknown length)
|
||||
const u8* c = (const u8*)ret_addr;
|
||||
// this would allow for avoiding exceptions when accessing ret_addr
|
||||
|
@ -846,17 +846,17 @@ u8 x86_x64_ApicId()
|
||||
}
|
||||
|
||||
|
||||
#if !MSC_VERSION // replaced by macro
|
||||
u64 x86_x64_rdtsc()
|
||||
{
|
||||
#if MSC_VERSION
|
||||
return (u64)__rdtsc();
|
||||
#elif GCC_VERSION
|
||||
#if GCC_VERSION
|
||||
// GCC supports "portable" assembly for both x86 and x64
|
||||
volatile u32 lo, hi;
|
||||
asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
|
||||
return u64_from_u32(hi, lo);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void x86_x64_DebugBreak()
|
||||
|
@ -26,6 +26,10 @@
|
||||
#error "including x86_x64.h without ARCH_X86_X64=1"
|
||||
#endif
|
||||
|
||||
#if MSC_VERSION
|
||||
#include <intrin.h> // __rdtsc
|
||||
#endif
|
||||
|
||||
/**
|
||||
* registers used/returned by x86_x64_cpuid
|
||||
**/
|
||||
@ -225,13 +229,21 @@ LIB_API u8 x86_x64_ApicId();
|
||||
* @return the current value of the TimeStampCounter (a counter of
|
||||
* CPU cycles since power-on, which is useful for high-resolution timing
|
||||
* but potentially differs between multiple CPUs)
|
||||
*
|
||||
* notes:
|
||||
* - a macro avoids call overhead, which is important for TIMER_ACCRUE.
|
||||
* - x64 RDTSC writes to edx:eax and clears the upper halves of rdx and rax.
|
||||
**/
|
||||
#if MSC_VERSION
|
||||
#define x86_x64_rdtsc __rdtsc
|
||||
#else
|
||||
LIB_API u64 x86_x64_rdtsc();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* trigger a breakpoint inside this function when it is called.
|
||||
**/
|
||||
LIB_API void x86_x64_DebugBreak(void);
|
||||
LIB_API void x86_x64_DebugBreak();
|
||||
|
||||
/**
|
||||
* measure the CPU clock frequency via x86_x64_rdtsc and timer_Time.
|
||||
|
@ -23,7 +23,7 @@ extern LibError sys_clipboard_set(const wchar_t* text);
|
||||
// can be represented as text, otherwise 0.
|
||||
// when it is no longer needed, the returned pointer must be freed via
|
||||
// sys_clipboard_free. (NB: not necessary if zero, but doesn't hurt)
|
||||
extern wchar_t* sys_clipboard_get(void);
|
||||
extern wchar_t* sys_clipboard_get();
|
||||
|
||||
// frees memory used by <copy>, which must have been returned by
|
||||
// sys_clipboard_get. see note above.
|
||||
|
@ -25,7 +25,7 @@
|
||||
#ifndef INCLUDED_AKEN
|
||||
#define INCLUDED_AKEN
|
||||
|
||||
#define AKEN_NAME "Aken"
|
||||
#define AKEN_NAME L"Aken"
|
||||
|
||||
// device type
|
||||
#define FILE_DEVICE_AKEN 53498 // in the "User Defined" range."
|
||||
|
@ -186,7 +186,7 @@ static void UninstallDriver()
|
||||
SC_HANDLE hSCM = OpenServiceControlManager();
|
||||
if(!hSCM)
|
||||
return;
|
||||
SC_HANDLE hService = OpenService(hSCM, AKEN_NAME, SERVICE_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenServiceW(hSCM, AKEN_NAME, SERVICE_ALL_ACCESS);
|
||||
if(!hService)
|
||||
return;
|
||||
|
||||
@ -212,13 +212,13 @@ static void UninstallDriver()
|
||||
}
|
||||
|
||||
|
||||
static void StartDriver(const char* driverPathname)
|
||||
static void StartDriver(const fs::wpath& driverPathname)
|
||||
{
|
||||
const SC_HANDLE hSCM = OpenServiceControlManager();
|
||||
if(!hSCM)
|
||||
return;
|
||||
|
||||
SC_HANDLE hService = OpenService(hSCM, AKEN_NAME, SERVICE_ALL_ACCESS);
|
||||
SC_HANDLE hService = OpenServiceW(hSCM, AKEN_NAME, SERVICE_ALL_ACCESS);
|
||||
|
||||
// during development, we want to ensure the newest build is used, so
|
||||
// unload and re-create the service if it's running/installed.
|
||||
@ -238,10 +238,10 @@ static void StartDriver(const char* driverPathname)
|
||||
// no error is raised if the driver binary doesn't exist etc.)
|
||||
if(!hService)
|
||||
{
|
||||
LPCSTR startName = 0; // LocalSystem
|
||||
hService = CreateService(hSCM, AKEN_NAME, AKEN_NAME,
|
||||
LPCWSTR startName = 0; // LocalSystem
|
||||
hService = CreateServiceW(hSCM, AKEN_NAME, AKEN_NAME,
|
||||
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
|
||||
driverPathname, 0, 0, 0, startName, 0);
|
||||
driverPathname.string().c_str(), 0, 0, 0, startName, 0);
|
||||
debug_assert(hService != 0);
|
||||
}
|
||||
|
||||
@ -274,15 +274,17 @@ static bool Is64BitOs()
|
||||
#endif
|
||||
}
|
||||
|
||||
static void GetDriverPathname(char* driverPathname, size_t maxChars)
|
||||
static fs::wpath DriverPathname()
|
||||
{
|
||||
const char* const bits = Is64BitOs()? "64" : "";
|
||||
const wchar_t* const bits = Is64BitOs()? L"64" : L"";
|
||||
#ifdef NDEBUG
|
||||
const char* const debug = "";
|
||||
const wchar_t* const debug = L"";
|
||||
#else
|
||||
const char* const debug = "d";
|
||||
const wchar_t* const debug = L"d";
|
||||
#endif
|
||||
sprintf_s(driverPathname, maxChars, "%s\\aken%s%s.sys", win_exe_dir, bits, debug);
|
||||
wchar_t filename[PATH_MAX];
|
||||
swprintf_s(filename, ARRAY_SIZE(filename), L"aken%ls%ls.sys", bits, debug);
|
||||
return wutil_ExecutablePath()/filename;
|
||||
}
|
||||
|
||||
|
||||
@ -297,12 +299,11 @@ bool mahaf_Init()
|
||||
if(!ModuleShouldInitialize(&initState))
|
||||
return true;
|
||||
|
||||
if(wutil_HasCommandLineArgument("-wNoMahaf"))
|
||||
if(wutil_HasCommandLineArgument(L"-wNoMahaf"))
|
||||
goto fail;
|
||||
|
||||
{
|
||||
char driverPathname[PATH_MAX];
|
||||
GetDriverPathname(driverPathname, ARRAY_SIZE(driverPathname));
|
||||
const fs::wpath driverPathname = DriverPathname();
|
||||
StartDriver(driverPathname);
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ size_t os_cpu_LargePageSize()
|
||||
|
||||
if(largePageSize == ~(size_t)0)
|
||||
{
|
||||
typedef SIZE_T (WINAPI *PGetLargePageMinimum)(void);
|
||||
typedef SIZE_T (WINAPI *PGetLargePageMinimum)();
|
||||
const HMODULE hKernel32 = GetModuleHandle("kernel32.dll");
|
||||
const PGetLargePageMinimum pGetLargePageMinimum = (PGetLargePageMinimum)GetProcAddress(hKernel32, "GetLargePageMinimum");
|
||||
if(pGetLargePageMinimum)
|
||||
@ -228,7 +228,7 @@ static const DWORD invalidProcessorNumber = (DWORD)-1;
|
||||
|
||||
static DWORD CurrentProcessorNumber()
|
||||
{
|
||||
typedef DWORD (WINAPI *PGetCurrentProcessorNumber)(void);
|
||||
typedef DWORD (WINAPI *PGetCurrentProcessorNumber)();
|
||||
static PGetCurrentProcessorNumber pGetCurrentProcessorNumber;
|
||||
|
||||
static bool initialized;
|
||||
|
Loading…
Reference in New Issue
Block a user