mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-10-31 15:38:57 +08:00 
			
		
		
		
	mdbx-windows: rework workaround for Wine.
Resolves https://github.com/erthink/libmdbx/issues/83 in accordance with https://bugs.winehq.org/show_bug.cgi?id=48620 Change-Id: Ieb4385efdcd86c865184a783363cf6e90da14f61
This commit is contained in:
		| @@ -733,7 +733,47 @@ MDBX_ReclaimVirtualMemory mdbx_ReclaimVirtualMemory; | ||||
| #endif /* MDBX_ALLOY */ | ||||
|  | ||||
| static void mdbx_winnt_import(void) { | ||||
|   const HINSTANCE hNtdll = GetModuleHandleA("ntdll.dll"); | ||||
|  | ||||
| #define GET_PROC_ADDR(dll, ENTRY)                                              \ | ||||
|   mdbx_##ENTRY = (MDBX_##ENTRY)GetProcAddress(dll, #ENTRY) | ||||
|  | ||||
|   if (GetProcAddress(hNtdll, "wine_get_version")) { | ||||
|     assert(mdbx_RunningUnderWine()); | ||||
|   } else { | ||||
|     GET_PROC_ADDR(hNtdll, NtFsControlFile); | ||||
|     GET_PROC_ADDR(hNtdll, NtExtendSection); | ||||
|     assert(!mdbx_RunningUnderWine()); | ||||
|   } | ||||
|  | ||||
|   const HINSTANCE hKernel32dll = GetModuleHandleA("kernel32.dll"); | ||||
|   GET_PROC_ADDR(hKernel32dll, GetFileInformationByHandleEx); | ||||
|   GET_PROC_ADDR(hKernel32dll, SetFileInformationByHandle); | ||||
|   GET_PROC_ADDR(hKernel32dll, GetTickCount64); | ||||
|   if (!mdbx_GetTickCount64) | ||||
|     mdbx_GetTickCount64 = stub_GetTickCount64; | ||||
|   if (!mdbx_RunningUnderWine()) { | ||||
|     GET_PROC_ADDR(hKernel32dll, GetVolumeInformationByHandleW); | ||||
|     GET_PROC_ADDR(hKernel32dll, GetFinalPathNameByHandleW); | ||||
|     GET_PROC_ADDR(hKernel32dll, PrefetchVirtualMemory); | ||||
|   } | ||||
|  | ||||
| #if 0  /* LY: unused for now */ | ||||
|   if (!mdbx_RunningUnderWine()) { | ||||
|     GET_PROC_ADDR(hKernel32dll, DiscardVirtualMemory); | ||||
|     GET_PROC_ADDR(hKernel32dll, OfferVirtualMemory); | ||||
|     GET_PROC_ADDR(hKernel32dll, ReclaimVirtualMemory); | ||||
|   } | ||||
|   if (!mdbx_DiscardVirtualMemory) | ||||
|     mdbx_DiscardVirtualMemory = stub_DiscardVirtualMemory; | ||||
|   if (!mdbx_OfferVirtualMemory) | ||||
|     mdbx_OfferVirtualMemory = stub_OfferVirtualMemory; | ||||
|   if (!mdbx_ReclaimVirtualMemory) | ||||
|     mdbx_ReclaimVirtualMemory = stub_ReclaimVirtualMemory; | ||||
| #endif /* unused for now */ | ||||
|  | ||||
| #undef GET_PROC_ADDR | ||||
|  | ||||
|   const MDBX_srwlock_function init = | ||||
|       (MDBX_srwlock_function)GetProcAddress(hKernel32dll, "InitializeSRWLock"); | ||||
|   if (init != NULL) { | ||||
| @@ -753,29 +793,4 @@ static void mdbx_winnt_import(void) { | ||||
|     mdbx_srwlock_AcquireExclusive = stub_srwlock_AcquireExclusive; | ||||
|     mdbx_srwlock_ReleaseExclusive = stub_srwlock_ReleaseExclusive; | ||||
|   } | ||||
|  | ||||
| #define GET_KERNEL32_PROC(ENTRY)                                               \ | ||||
|   mdbx_##ENTRY = (MDBX_##ENTRY)GetProcAddress(hKernel32dll, #ENTRY) | ||||
|   GET_KERNEL32_PROC(GetFileInformationByHandleEx); | ||||
|   GET_KERNEL32_PROC(GetVolumeInformationByHandleW); | ||||
|   GET_KERNEL32_PROC(GetFinalPathNameByHandleW); | ||||
|   GET_KERNEL32_PROC(SetFileInformationByHandle); | ||||
|   GET_KERNEL32_PROC(PrefetchVirtualMemory); | ||||
|   GET_KERNEL32_PROC(GetTickCount64); | ||||
|   if (!mdbx_GetTickCount64) | ||||
|     mdbx_GetTickCount64 = stub_GetTickCount64; | ||||
| #if 0  /* LY: unused for now */ | ||||
|   GET_KERNEL32_PROC(DiscardVirtualMemory); | ||||
|   if (!mdbx_DiscardVirtualMemory) | ||||
|     mdbx_DiscardVirtualMemory = stub_DiscardVirtualMemory; | ||||
|   GET_KERNEL32_PROC(OfferVirtualMemory); | ||||
|   GET_KERNEL32_PROC(ReclaimVirtualMemory); | ||||
| #endif /* unused for now */ | ||||
| #undef GET_KERNEL32_PROC | ||||
|  | ||||
|   const HINSTANCE hNtdll = GetModuleHandleA("ntdll.dll"); | ||||
|   mdbx_NtFsControlFile = | ||||
|       (MDBX_NtFsControlFile)GetProcAddress(hNtdll, "NtFsControlFile"); | ||||
|   mdbx_NtExtendSection = | ||||
|       (MDBX_NtExtendSection)GetProcAddress(hNtdll, "NtExtendSection"); | ||||
| } | ||||
|   | ||||
| @@ -985,6 +985,9 @@ MDBX_INTERNAL_FUNC int mdbx_check_fs_rdonly(mdbx_filehandle_t handle, | ||||
|  | ||||
| static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) { | ||||
| #if defined(_WIN32) || defined(_WIN64) | ||||
|   if (mdbx_RunningUnderWine() && !(flags & MDBX_EXCLUSIVE)) | ||||
|     return ERROR_NOT_CAPABLE /* workaround for Wine */; | ||||
|  | ||||
|   if (GetFileType(handle) != FILE_TYPE_DISK) | ||||
|     return ERROR_FILE_OFFLINE; | ||||
|  | ||||
|   | ||||
| @@ -760,6 +760,7 @@ MDBX_INTERNAL_FUNC int mdbx_rpid_clear(MDBX_env *env); | ||||
| MDBX_INTERNAL_FUNC int mdbx_rpid_check(MDBX_env *env, uint32_t pid); | ||||
|  | ||||
| #if defined(_WIN32) || defined(_WIN64) | ||||
|  | ||||
| typedef union MDBX_srwlock { | ||||
|   struct { | ||||
|     long volatile readerCount; | ||||
| @@ -855,6 +856,10 @@ typedef NTSTATUS(NTAPI *MDBX_NtExtendSection)(IN HANDLE SectionHandle, | ||||
|                                               IN PLARGE_INTEGER NewSectionSize); | ||||
| MDBX_INTERNAL_VAR MDBX_NtExtendSection mdbx_NtExtendSection; | ||||
|  | ||||
| static __inline bool mdbx_RunningUnderWine(void) { | ||||
|   return !mdbx_NtExtendSection; | ||||
| } | ||||
|  | ||||
| #endif /* Windows */ | ||||
|  | ||||
| /*----------------------------------------------------------------------------*/ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user