Skip to content

Commit

Permalink
Fixing ntext compilation, and changing FLS fucntions to adapt to Wind…
Browse files Browse the repository at this point in the history
…ows XP/2003.
  • Loading branch information
Skulltrail192 committed Feb 15, 2022
1 parent 4273235 commit 18cad0e
Show file tree
Hide file tree
Showing 28 changed files with 2,335 additions and 648 deletions.
83 changes: 29 additions & 54 deletions wrappers/base/kernelbase_wrapper/dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,83 +22,58 @@ Revision History:

WINE_DEFAULT_DEBUG_CHANNEL(kernel32);

static BOOL (WINAPI *pGetProcessDEPPolicy)(HANDLE, LPDWORD, PBOOL);
static BOOL (WINAPI *pSetProcessDEPPolicy)(DWORD);
static DEP_SYSTEM_POLICY_TYPE (WINAPI *pGetSystemDEPPolicy)();

DEP_SYSTEM_POLICY_TYPE WINAPI
GetSystemDEPPolicy(void)
{
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");

pGetSystemDEPPolicy = (void *)GetProcAddress(hkernel32, "GetSystemDEPPolicy");
if(pGetSystemDEPPolicy){
return pGetSystemDEPPolicy();
}else{
return SharedUserData->NXSupportPolicy;
}
return SharedUserData->NXSupportPolicy;
}

BOOL
WINAPI
GetProcessDEPPolicy(HANDLE ProcessInformation, LPDWORD lpFlags, PBOOL lpPermanent)
{
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
NTSTATUS status;
ULONG dep_flags;
NTSTATUS Status;
ULONG depFlags;

pGetProcessDEPPolicy = (void *)GetProcAddress(hkernel32, "GetProcessDEPPolicy");
if(pGetProcessDEPPolicy){
return pGetProcessDEPPolicy(ProcessInformation, lpFlags, lpPermanent);
}else{

status = NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
&dep_flags, sizeof(dep_flags), NULL );
if (!status)
Status = NtQueryInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
&depFlags, sizeof(depFlags), NULL );
if (!Status)
{
if (lpFlags)
{
if (lpFlags)
{
*lpFlags = 0;
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE)
*lpFlags |= PROCESS_DEP_ENABLE;
if (dep_flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
*lpFlags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
*lpFlags = 0;
if (depFlags & MEM_EXECUTE_OPTION_DISABLE)
*lpFlags |= PROCESS_DEP_ENABLE;
if (depFlags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
*lpFlags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
}

if (lpPermanent)
*lpPermanent = (dep_flags & MEM_EXECUTE_OPTION_PERMANENT) != 0;

}
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
*lpPermanent = (depFlags & MEM_EXECUTE_OPTION_PERMANENT) != 0;
}
if (Status)
SetLastError( RtlNtStatusToDosError(Status) );
return !Status;
}

BOOL
WINAPI
SetProcessDEPPolicy(DWORD dwFlags)
{
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
NTSTATUS status;
NTSTATUS Status;
ULONG depFlags = 0;

pSetProcessDEPPolicy = (void *)GetProcAddress(hkernel32, "SetProcessDEPPolicy");
if(pSetProcessDEPPolicy){
return pSetProcessDEPPolicy(dwFlags);
}else{
if (dwFlags & PROCESS_DEP_ENABLE)
depFlags |= MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT;
if (dwFlags & PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION)
depFlags |= MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION;

status = NtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
&depFlags, sizeof(depFlags) );
if (dwFlags & PROCESS_DEP_ENABLE)
depFlags |= MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT;
if (dwFlags & PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION)
depFlags |= MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION;

if(NT_SUCCESS(status)){
return TRUE;
}else{
BaseSetLastNTError(status);
return FALSE;
}
Status = NtSetInformationProcess( GetCurrentProcess(), ProcessExecuteFlags,
&depFlags, sizeof(depFlags) );
if(NT_SUCCESS(Status)){
return TRUE;
}else{
BaseSetLastNTError(Status);
return FALSE;
}
}
29 changes: 11 additions & 18 deletions wrappers/base/kernelbase_wrapper/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,19 @@ FilenameA2W(
*/
BOOL WINAPI SetFileCompletionNotificationModes( HANDLE handle, UCHAR flags )
{
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
NTSTATUS Status;

pSetFileCompletionNotificationModes = (void *)GetProcAddress(hkernel32, "SetFileCompletionNotificationModes");

if(pSetFileCompletionNotificationModes){
return pSetFileCompletionNotificationModes(handle, flags);
}else{
FILE_IO_COMPLETION_NOTIFICATION_INFORMATION info;
IO_STATUS_BLOCK io;
FILE_IO_COMPLETION_NOTIFICATION_INFORMATION info;
IO_STATUS_BLOCK io;

info.Flags = flags;
Status = NtSetInformationFile( handle, &io, &info, sizeof(info),
FileIoCompletionNotificationInformation );
info.Flags = flags;
Status = NtSetInformationFile( handle, &io, &info, sizeof(info),
FileIoCompletionNotificationInformation );

if(NT_SUCCESS(Status)){
return TRUE;
}else{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
}
if(NT_SUCCESS(Status)){
return TRUE;
}else{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
}
12 changes: 6 additions & 6 deletions wrappers/base/kernelbase_wrapper/kernelbase.spec
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@
@ stdcall Wow64RevertWow64FsRedirection(ptr)
@ stdcall ReOpenFile(ptr long long long)
@ stdcall GetNLSVersion(long long ptr)
@ stdcall IsNLSDefinedString(long long ptr long long) kernel32.IsNLSDefinedString
@ stdcall -stub IsNLSDefinedString(long long ptr long long)
@ stdcall SetFileCompletionNotificationModes(ptr long)

#Missing on XP and 2003 RTM
Expand Down Expand Up @@ -1007,12 +1007,12 @@
@ stdcall CreateProcessInternalA(ptr str str ptr ptr long long ptr str ptr ptr long) CreateProcessInternalExA
@ stdcall CreateProcessInternalW(ptr wstr wstr ptr ptr long long ptr wstr ptr ptr long) CreateProcessInternalExW
@ stdcall CreateProcessW(wstr wstr ptr ptr long long ptr wstr ptr ptr) CreateProcessExW
@ stdcall GetModuleHandleA(str) GetModuleHandleInternalA
@ stdcall GetModuleHandleW(wstr) GetModuleHandleInternalW
@ stdcall GetProcAddress(long str) GetProcAddressInternal
@ stdcall GetModuleHandleA(str)
@ stdcall GetModuleHandleW(wstr)
@ stdcall GetProcAddress(long str)
@ stdcall IsProcessorFeaturePresent(long) IsProcessorFeaturePresentInternal
@ stdcall LoadLibraryA(str) LoadLibraryInternalA
@ stdcall LoadLibraryW(wstr) LoadLibraryInternalW
@ stdcall LoadLibraryA(str)
@ stdcall LoadLibraryW(wstr)
@ stdcall LoadLibraryExA( str long long) LoadLibraryExInternalA
@ stdcall LoadLibraryExW(wstr long long) LoadLibraryExInternalW
@ stdcall SetFileApisToANSI() SetpFileApisToANSI
Expand Down
16 changes: 1 addition & 15 deletions wrappers/base/kernelbase_wrapper/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ static RTL_CRITICAL_SECTION cache_section;

WINE_DEFAULT_DEBUG_CHANNEL(locale);

typedef BOOL (WINAPI *pGetNLSVersion)(
NLS_FUNCTION,
LCID,
LPNLSVERSIONINFO);

struct sortguid
{
GUID id; /* sort GUID */
Expand Down Expand Up @@ -1801,16 +1796,7 @@ GetNLSVersion(
LCID lcid,
LPNLSVERSIONINFO info)
{
pGetNLSVersion nlsVersion;
WCHAR locale[LOCALE_NAME_MAX_LENGTH];

nlsVersion = (pGetNLSVersion) GetProcAddress(
GetModuleHandleW(L"kernel32"),
"GetNLSVersion");

if(nlsVersion!=NULL){
return nlsVersion(func, lcid, info);
}
WCHAR locale[LOCALE_NAME_MAX_LENGTH];

if (info->dwNLSVersionInfoSize < offsetof( NLSVERSIONINFO, dwNLSVersionInfoSize ))
{
Expand Down
71 changes: 7 additions & 64 deletions wrappers/base/kernelbase_wrapper/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,73 +374,16 @@ BOOL WINAPI DECLSPEC_HOTPATCH SetDefaultDllDirectories( DWORD flags )
*/
BOOL WINAPI SetSearchPathMode( DWORD flags )
{
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
NTSTATUS Status;

pSetSearchPathMode = (void *)GetProcAddress(hkernel32, "SetSearchPathMode");
if(pSetSearchPathMode){
return pSetSearchPathMode(flags);
}else{
Status = RtlSetSearchPathMode( flags );
Status = RtlSetSearchPathMode( flags );

if(NT_SUCCESS(Status)){
return TRUE;
}else{
SetLastError(Status);
return FALSE;
}
}
}

FARPROC
WINAPI
GetProcAddressInternal(
_In_ HMODULE hModule,
_In_ LPCSTR lpProcName
)
{
//DbgPrint("GetProcAddress::Function name: %s\n", lpProcName);
return GetProcAddress(hModule, lpProcName);
}

HMODULE
WINAPI
GetModuleHandleInternalA(
_In_opt_ LPCTSTR lpModuleName
)
{
//DbgPrint("GetModuleHandleA::Module name: %s\n", lpModuleName);
return GetModuleHandleA(lpModuleName);
}

HMODULE
WINAPI
GetModuleHandleInternalW(
_In_opt_ LPCWSTR lpModuleName
)
{
//DbgPrint("GetModuleHandleW::Module name: %ws\n", lpModuleName);
return GetModuleHandleW(lpModuleName);
}

HMODULE
WINAPI
LoadLibraryInternalA(
_In_ LPCTSTR lpFileName
)
{
//DbgPrint("LoadLibraryA::File name: %s\n", lpFileName);
return LoadLibraryA(lpFileName);
}

HMODULE
WINAPI
LoadLibraryInternalW(
_In_ LPCWSTR lpFileName
)
{
//DbgPrint("LoadLibraryW::File name: %ws\n", lpFileName);
return LoadLibraryW(lpFileName);
if(NT_SUCCESS(Status)){
return TRUE;
}else{
SetLastError(Status);
return FALSE;
}
}

WCHAR szAppInit[KEY_LENGTH];
Expand Down
31 changes: 12 additions & 19 deletions wrappers/base/kernelbase_wrapper/numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,23 @@ GetNumaNodeProcessorMask(
NTSTATUS Status;
ULONG ReturnedSize;
SYSTEM_NUMA_INFORMATION Map;
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");

pGetNumaNodeProcessorMask = (void *)GetProcAddress(hkernel32, "GetNumaNodeProcessorMask");
if(pGetNumaNodeProcessorMask){
return pGetNumaNodeProcessorMask(Node, ProcessorMask);
}else{
Status = NtQuerySystemInformation(SystemNumaProcessorMap,

Status = NtQuerySystemInformation(SystemNumaProcessorMap,
&Map,
sizeof(Map),
&ReturnedSize);
if (!NT_SUCCESS(Status)) {

BaseSetLastNTError(Status);
return FALSE;
}
if (!NT_SUCCESS(Status)) {
BaseSetLastNTError(Status);
return FALSE;
}

if (Node > Map.HighestNodeNumber) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (Node > Map.HighestNodeNumber) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}

*ProcessorMask = Map.ActiveProcessorsAffinityMask[Node];
return TRUE;
}
*ProcessorMask = Map.ActiveProcessorsAffinityMask[Node];
return TRUE;
}

BOOL
Expand Down
36 changes: 17 additions & 19 deletions wrappers/base/kernelbase_wrapper/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,23 @@ SetSystemFileCacheSize(
int Flags
)
{
HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
NTSTATUS status;
NTSTATUS Status;
BOOL result;
char SystemInformation;
SYSTEM_FILECACHE_INFORMATION SystemInformation;

pSetSystemFileCacheSize = (void *)GetProcAddress(hkernel32, "SetSystemFileCacheSize");
if(pSetSystemFileCacheSize){
return pSetSystemFileCacheSize(MinimumFileCacheSize, MaximumFileCacheSize, Flags);
}else{
status = NtSetSystemInformation(SystemObjectInformation|0x40, &SystemInformation, 0x24u);
if ( !NT_SUCCESS(status) )
{
BaseSetLastNTError(status);
result = FALSE;
}
else
{
result = TRUE;
}
return result;
}
SystemInformation.MinimumWorkingSet = MinimumFileCacheSize;
SystemInformation.MaximumWorkingSet = MaximumFileCacheSize;
SystemInformation.Flags = Flags;

Status = NtSetSystemInformation(SystemFileCacheInformationEx, &SystemInformation, sizeof(SYSTEM_FILECACHE_INFORMATION));
if ( !NT_SUCCESS(Status) )
{
BaseSetLastNTError(Status);
result = FALSE;
}
else
{
result = TRUE;
}
return result;
}
Loading

0 comments on commit 18cad0e

Please sign in to comment.