aboutsummaryrefslogtreecommitdiffstats
path: root/api/adapter.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-03 02:09:00 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-03 02:25:57 +0100
commit1201c9f346f1e9b2bc00b0a9854fc6e182e851ef (patch)
tree7a404f1a14c3fbb258bb11b464c72dcb15f319d3 /api/adapter.c
parentapi: begin to separate rundll32 jumps (diff)
downloadwintun-1201c9f346f1e9b2bc00b0a9854fc6e182e851ef.tar.xz
wintun-1201c9f346f1e9b2bc00b0a9854fc6e182e851ef.zip
api: ensure more code compiles by using dead code elimination
It'd be nicer to do this via if (is_defined(HAVE_WHATEVER)) But MSVC won't work with the linux kernel macros for this. Ongoing research. Nevertheless, this makes most of the program always pass through the compiler's type checker, only to have dead code removed later. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api/adapter.c')
-rw-r--r--api/adapter.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 0579e8b..642f842 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -340,7 +340,8 @@ EnableAllOurAdapters(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA_LIST *AdaptersT
void
AdapterInit(void)
{
-#ifdef MAYBE_WOW64
+ if (!MAYBE_WOW64)
+ return;
typedef BOOL(WINAPI * IsWow64Process2_t)(
_In_ HANDLE hProcess, _Out_ USHORT * pProcessMachine, _Out_opt_ USHORT * pNativeMachine);
HANDLE Kernel32;
@@ -354,7 +355,6 @@ AdapterInit(void)
NativeMachine =
IsWow64Process(GetCurrentProcess(), &IsWoW64) && IsWoW64 ? IMAGE_FILE_MACHINE_AMD64 : IMAGE_FILE_PROCESS;
}
-#endif
}
static BOOL
@@ -801,13 +801,13 @@ RtlGetNtVersionNumbers(_Out_opt_ DWORD *MajorVersion, _Out_opt_ DWORD *MinorVers
static BOOL
HaveWHQL(void)
{
-#if defined(HAVE_WHQL)
- DWORD MajorVersion;
- RtlGetNtVersionNumbers(&MajorVersion, NULL, NULL);
- return MajorVersion >= 10;
-#else
+ if (HAVE_WHQL)
+ {
+ DWORD MajorVersion;
+ RtlGetNtVersionNumbers(&MajorVersion, NULL, NULL);
+ return MajorVersion >= 10;
+ }
return FALSE;
-#endif
}
static WINTUN_STATUS
@@ -1682,15 +1682,10 @@ WintunCreateAdapter(
RebootRequired = &DummyRebootRequired;
*RebootRequired = FALSE;
DWORD Result;
-#ifdef MAYBE_WOW64
- if (NativeMachine != IMAGE_FILE_PROCESS)
- {
+ if (MAYBE_WOW64 && NativeMachine != IMAGE_FILE_PROCESS)
Result = CreateAdapterViaRundll32(Pool, Name, RequestedGUID, Adapter, RebootRequired);
- RevertToSelf();
- return Result;
- }
-#endif
- Result = CreateAdapter(Pool, Name, RequestedGUID, Adapter, RebootRequired);
+ else
+ Result = CreateAdapter(Pool, Name, RequestedGUID, Adapter, RebootRequired);
RevertToSelf();
return Result;
}
@@ -1706,14 +1701,12 @@ WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _In_ BOOL ForceCloseSess
RebootRequired = &DummyRebootRequired;
*RebootRequired = FALSE;
DWORD Result;
-#ifdef MAYBE_WOW64
- if (NativeMachine != IMAGE_FILE_PROCESS)
+ if (MAYBE_WOW64 && NativeMachine != IMAGE_FILE_PROCESS)
{
Result = DeleteAdapterViaRundll32(Adapter, ForceCloseSessions, RebootRequired);
RevertToSelf();
return Result;
}
-#endif
HDEVINFO DevInfo;
SP_DEVINFO_DATA DevInfoData;
@@ -1796,14 +1789,12 @@ WintunDeleteDriver(void)
DWORD Result = ERROR_SUCCESS;
-#ifdef MAYBE_WOW64
- if (NativeMachine != IMAGE_FILE_PROCESS)
+ if (MAYBE_WOW64 && NativeMachine != IMAGE_FILE_PROCESS)
{
Result = DeleteDriverViaRundll32();
RevertToSelf();
return Result;
}
-#endif
/* DeleteAllOurAdapters(); */
HANDLE DriverInstallationLock = NamespaceTakeDriverInstallationMutex();