Index: sandbox/win/src/app_container.cc |
=================================================================== |
--- sandbox/win/src/app_container.cc (revision 223979) |
+++ sandbox/win/src/app_container.cc (working copy) |
@@ -23,6 +23,17 @@ |
return local_sid; |
} |
+template <typename T> |
+T BindFunction(const char* name) { |
+ HMODULE module = GetModuleHandle(sandbox::kKerneldllName); |
+ void* function = GetProcAddress(module, name); |
+ if (!function) { |
+ module = GetModuleHandle(sandbox::kKernelBasedllName); |
+ function = GetProcAddress(module, name); |
+ } |
+ return reinterpret_cast<T>(function); |
+} |
+ |
} // namespace |
namespace sandbox { |
@@ -94,9 +105,8 @@ |
static AppContainerRegisterSidPtr AppContainerRegisterSid = NULL; |
if (!AppContainerRegisterSid) { |
- HMODULE module = GetModuleHandle(kKerneldllName); |
- AppContainerRegisterSid = reinterpret_cast<AppContainerRegisterSidPtr>( |
- GetProcAddress(module, "AppContainerRegisterSid")); |
+ AppContainerRegisterSid = |
+ BindFunction<AppContainerRegisterSidPtr>("AppContainerRegisterSid"); |
} |
ResultCode operation_result = SBOX_ERROR_GENERIC; |
@@ -120,9 +130,8 @@ |
static AppContainerUnregisterSidPtr AppContainerUnregisterSid = NULL; |
if (!AppContainerUnregisterSid) { |
- HMODULE module = GetModuleHandle(kKerneldllName); |
- AppContainerUnregisterSid = reinterpret_cast<AppContainerUnregisterSidPtr>( |
- GetProcAddress(module, "AppContainerUnregisterSid")); |
+ AppContainerUnregisterSid = |
+ BindFunction<AppContainerUnregisterSidPtr>("AppContainerUnregisterSid"); |
} |
ResultCode operation_result = SBOX_ERROR_GENERIC; |
@@ -150,11 +159,10 @@ |
static AppContainerFreeMemoryPtr AppContainerFreeMemory = NULL; |
if (!AppContainerLookupMoniker || !AppContainerFreeMemory) { |
- HMODULE module = GetModuleHandle(kKerneldllName); |
- AppContainerLookupMoniker = reinterpret_cast<AppContainerLookupMonikerPtr>( |
- GetProcAddress(module, "AppContainerLookupMoniker")); |
- AppContainerFreeMemory = reinterpret_cast<AppContainerFreeMemoryPtr>( |
- GetProcAddress(module, "AppContainerFreeMemory")); |
+ AppContainerLookupMoniker = |
+ BindFunction<AppContainerLookupMonikerPtr>("AppContainerLookupMoniker"); |
+ AppContainerFreeMemory = |
+ BindFunction<AppContainerFreeMemoryPtr>("AppContainerFreeMemory"); |
} |
if (!AppContainerLookupMoniker || !AppContainerFreeMemory) |