mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-25 09:52:23 -05:00
dll: refactor library.h into src/shared/minimal.h for reuse
This commit is contained in:
parent
2a69ad6710
commit
dc4109fc22
@ -23,6 +23,7 @@
|
|||||||
<ClInclude Include="..\..\inc\winfsp\fsctl.h" />
|
<ClInclude Include="..\..\inc\winfsp\fsctl.h" />
|
||||||
<ClInclude Include="..\..\inc\winfsp\winfsp.h" />
|
<ClInclude Include="..\..\inc\winfsp\winfsp.h" />
|
||||||
<ClInclude Include="..\..\src\dll\library.h" />
|
<ClInclude Include="..\..\src\dll\library.h" />
|
||||||
|
<ClInclude Include="..\..\src\shared\minimal.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\dll\eventlog.c" />
|
<ClCompile Include="..\..\src\dll\eventlog.c" />
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
<Filter Include="Include\winfsp">
|
<Filter Include="Include\winfsp">
|
||||||
<UniqueIdentifier>{1d6501f4-cebd-4a00-a774-deb782b59fb5}</UniqueIdentifier>
|
<UniqueIdentifier>{1d6501f4-cebd-4a00-a774-deb782b59fb5}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="Include\shared">
|
||||||
|
<UniqueIdentifier>{c7b83307-0aa0-4593-b2d4-26ff2f1edfc6}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\inc\winfsp\fsctl.h">
|
<ClInclude Include="..\..\inc\winfsp\fsctl.h">
|
||||||
@ -23,6 +26,9 @@
|
|||||||
<ClInclude Include="..\..\src\dll\library.h">
|
<ClInclude Include="..\..\src\dll\library.h">
|
||||||
<Filter>Source</Filter>
|
<Filter>Source</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\shared\minimal.h">
|
||||||
|
<Filter>Include\shared</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\dll\library.c">
|
<ClCompile Include="..\..\src\dll\library.c">
|
||||||
|
@ -67,13 +67,11 @@ BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* see comments in library.h */
|
/* see comments in shared/minimal.h */
|
||||||
#if defined(WINFSP_DLL_NODEFAULTLIB)
|
|
||||||
BOOL WINAPI _DllMainCRTStartup(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
BOOL WINAPI _DllMainCRTStartup(HINSTANCE Instance, DWORD Reason, PVOID Reserved)
|
||||||
{
|
{
|
||||||
return DllMain(Instance, Reason, Reserved);
|
return DllMain(Instance, Reason, Reserved);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
HRESULT WINAPI DllRegisterServer(VOID)
|
HRESULT WINAPI DllRegisterServer(VOID)
|
||||||
{
|
{
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
#define WINFSP_DLL_LIBRARY_H_INCLUDED
|
#define WINFSP_DLL_LIBRARY_H_INCLUDED
|
||||||
|
|
||||||
#define WINFSP_DLL_INTERNAL
|
#define WINFSP_DLL_INTERNAL
|
||||||
#define WINFSP_DLL_NODEFAULTLIB
|
|
||||||
#include <winfsp/winfsp.h>
|
#include <winfsp/winfsp.h>
|
||||||
|
#include <shared/minimal.h>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
|
||||||
#define LIBRARY_NAME "WinFsp"
|
#define LIBRARY_NAME "WinFsp"
|
||||||
@ -36,73 +36,6 @@
|
|||||||
#define DEBUGLOGSD(fmt, SD) ((void)0)
|
#define DEBUGLOGSD(fmt, SD) ((void)0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline PVOID MemAlloc(SIZE_T Size)
|
|
||||||
{
|
|
||||||
extern HANDLE ProcessHeap;
|
|
||||||
return HeapAlloc(ProcessHeap, 0, Size);
|
|
||||||
}
|
|
||||||
static inline VOID MemFree(PVOID Pointer)
|
|
||||||
{
|
|
||||||
extern HANDLE ProcessHeap;
|
|
||||||
if (0 != Pointer)
|
|
||||||
HeapFree(ProcessHeap, 0, Pointer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Define WINFSP_DLL_NODEFAULTLIB to eliminate dependency on the MSVCRT libraries.
|
|
||||||
*
|
|
||||||
* For this to work the following project settings must be set:
|
|
||||||
* - "C/C++ > General > SDL checks" must be empty (not "Yes" or "No").
|
|
||||||
* - "C/C++ > Code Generation > Basic Runtime Checks" must be set to "Default"
|
|
||||||
* - "C/C++ > Code Generation > Security Check" must be disabled (/GS-).
|
|
||||||
* - "Linker > Input > Ignore All Default Libraries" must be "Yes".
|
|
||||||
*/
|
|
||||||
#if defined(WINFSP_DLL_NODEFAULTLIB)
|
|
||||||
#undef RtlFillMemory
|
|
||||||
#undef RtlMoveMemory
|
|
||||||
NTSYSAPI VOID NTAPI RtlFillMemory(VOID *Destination, DWORD Length, BYTE Fill);
|
|
||||||
NTSYSAPI VOID NTAPI RtlMoveMemory(VOID *Destination, CONST VOID *Source, DWORD Length);
|
|
||||||
|
|
||||||
#pragma function(memcpy)
|
|
||||||
#pragma function(memset)
|
|
||||||
static inline
|
|
||||||
void *memcpy(void *dst, const void *src, size_t siz)
|
|
||||||
{
|
|
||||||
RtlMoveMemory(dst, src, (DWORD)siz);
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
static inline
|
|
||||||
void *memset(void *dst, int val, size_t siz)
|
|
||||||
{
|
|
||||||
RtlFillMemory(dst, (DWORD)siz, val);
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static FORCEINLINE
|
|
||||||
VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
|
|
||||||
{
|
|
||||||
PLIST_ENTRY Blink;
|
|
||||||
|
|
||||||
Blink = ListHead->Blink;
|
|
||||||
Entry->Flink = ListHead;
|
|
||||||
Entry->Blink = Blink;
|
|
||||||
Blink->Flink = Entry;
|
|
||||||
ListHead->Blink = Entry;
|
|
||||||
}
|
|
||||||
static FORCEINLINE
|
|
||||||
BOOLEAN RemoveEntryList(PLIST_ENTRY Entry)
|
|
||||||
{
|
|
||||||
PLIST_ENTRY Blink;
|
|
||||||
PLIST_ENTRY Flink;
|
|
||||||
|
|
||||||
Flink = Entry->Flink;
|
|
||||||
Blink = Entry->Blink;
|
|
||||||
Blink->Flink = Flink;
|
|
||||||
Flink->Blink = Blink;
|
|
||||||
return Flink == Blink;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID FspNtStatusInitialize(BOOLEAN Dynamic);
|
VOID FspNtStatusInitialize(BOOLEAN Dynamic);
|
||||||
VOID FspNtStatusFinalize(BOOLEAN Dynamic);
|
VOID FspNtStatusFinalize(BOOLEAN Dynamic);
|
||||||
VOID FspEventLogInitialize(BOOLEAN Dynamic);
|
VOID FspEventLogInitialize(BOOLEAN Dynamic);
|
||||||
|
87
src/shared/minimal.h
Normal file
87
src/shared/minimal.h
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/**
|
||||||
|
* @file shared/minimal.h
|
||||||
|
*
|
||||||
|
* @copyright 2015-2016 Bill Zissimopoulos
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of WinFsp.
|
||||||
|
*
|
||||||
|
* You can redistribute it and/or modify it under the terms of the
|
||||||
|
* GNU Affero General Public License version 3 as published by the
|
||||||
|
* Free Software Foundation.
|
||||||
|
*
|
||||||
|
* Licensees holding a valid commercial license may use this file in
|
||||||
|
* accordance with the commercial license agreement provided with the
|
||||||
|
* software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WINFSP_SHARED_MINIMAL_H_INCLUDED
|
||||||
|
#define WINFSP_SHARED_MINIMAL_H_INCLUDED
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Eliminate dependency on the MSVCRT libraries.
|
||||||
|
*
|
||||||
|
* For this to work the following project settings must be set:
|
||||||
|
* - "C/C++ > General > SDL checks" must be empty (not "Yes" or "No").
|
||||||
|
* - "C/C++ > Code Generation > Basic Runtime Checks" must be set to "Default"
|
||||||
|
* - "C/C++ > Code Generation > Security Check" must be disabled (/GS-).
|
||||||
|
* - "Linker > Input > Ignore All Default Libraries" must be "Yes".
|
||||||
|
*/
|
||||||
|
|
||||||
|
#undef RtlFillMemory
|
||||||
|
#undef RtlMoveMemory
|
||||||
|
NTSYSAPI VOID NTAPI RtlFillMemory(VOID *Destination, DWORD Length, BYTE Fill);
|
||||||
|
NTSYSAPI VOID NTAPI RtlMoveMemory(VOID *Destination, CONST VOID *Source, DWORD Length);
|
||||||
|
|
||||||
|
#pragma function(memcpy)
|
||||||
|
#pragma function(memset)
|
||||||
|
static inline
|
||||||
|
void *memcpy(void *dst, const void *src, size_t siz)
|
||||||
|
{
|
||||||
|
RtlMoveMemory(dst, src, (DWORD)siz);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
static inline
|
||||||
|
void *memset(void *dst, int val, size_t siz)
|
||||||
|
{
|
||||||
|
RtlFillMemory(dst, (DWORD)siz, val);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline PVOID MemAlloc(SIZE_T Size)
|
||||||
|
{
|
||||||
|
extern HANDLE ProcessHeap;
|
||||||
|
return HeapAlloc(ProcessHeap, 0, Size);
|
||||||
|
}
|
||||||
|
static inline VOID MemFree(PVOID Pointer)
|
||||||
|
{
|
||||||
|
extern HANDLE ProcessHeap;
|
||||||
|
if (0 != Pointer)
|
||||||
|
HeapFree(ProcessHeap, 0, Pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
static FORCEINLINE
|
||||||
|
VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry)
|
||||||
|
{
|
||||||
|
PLIST_ENTRY Blink;
|
||||||
|
|
||||||
|
Blink = ListHead->Blink;
|
||||||
|
Entry->Flink = ListHead;
|
||||||
|
Entry->Blink = Blink;
|
||||||
|
Blink->Flink = Entry;
|
||||||
|
ListHead->Blink = Entry;
|
||||||
|
}
|
||||||
|
static FORCEINLINE
|
||||||
|
BOOLEAN RemoveEntryList(PLIST_ENTRY Entry)
|
||||||
|
{
|
||||||
|
PLIST_ENTRY Blink;
|
||||||
|
PLIST_ENTRY Flink;
|
||||||
|
|
||||||
|
Flink = Entry->Flink;
|
||||||
|
Blink = Entry->Blink;
|
||||||
|
Blink->Flink = Flink;
|
||||||
|
Flink->Blink = Blink;
|
||||||
|
return Flink == Blink;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user