Skip to content

Commit

Permalink
export DEP stuff for firefox 54
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFire01 committed Sep 15, 2023
1 parent 2451116 commit 7352756
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 4 deletions.
1 change: 1 addition & 0 deletions dll/win32/kernel32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ list(APPEND SOURCE
client/atom.c
client/compname.c
client/debugger.c
client/dep.c
client/dosdev.c
client/dllmain.c
client/environ.c
Expand Down
153 changes: 153 additions & 0 deletions dll/win32/kernel32/client/dep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* PROJECT: ReactOS system libraries
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* FILE: dll/win32/kernel32/client/dep.c
* PURPOSE: ReactOS Data Execution Prevention (DEP) functions
* COPYRIGHT: Copyright 2021 Oleg Dubinskiy ([email protected])
*/

/* INCLUDES *******************************************************************/

#include <k32.h>

#define NDEBUG
#include <debug.h>
#define PROCESS_DEP_ENABLE 0x00000001
#define PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION 0x00000002
typedef enum _DEP_SYSTEM_POLICY_TYPE {
DEPPolicyAlwaysOff = 0,
DEPPolicyAlwaysOn,
DEPPolicyOptIn,
DEPPolicyOptOut,
DEPTotalPolicyCount
} DEP_SYSTEM_POLICY_TYPE;
/* PUBLIC FUNCTIONS ***********************************************************/

/**
* @brief Retrieves the data execution prevention (DEP) and thunk emulation (DEP-ATL)
* settings for the process.
*
* On Windows XP SP3, the current process is handled.
* On Vista and newer, the process specified in hProcess parameter is handled.
*
* @param [in] hProcess
* A handle to a process with PROCESS_QUERY_INFORMATION privilege.
* Ignored on Windows XP SP3.
*
* @param [out] lpFlags
* Pointer to a variable that receives the flags:
* 0 - DEP is disabled.
* PROCESS_DEP_ENABLE - DEP is enabled.
* PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION - DEP-ATL is disabled.
*
* @param [out] lpPermanent
* Pointer to a variable that specifies whether DEP is enabled or disabled permanently.
*
* @return
* TRUE on success, FALSE on failure.
*
* @remarks
* Supported for 32-bit processes only. Returns ERROR_NOT_SUPPORTED for 64-bit processes.
*
*/
BOOL
WINAPI
GetProcessDEPPolicy(_In_ HANDLE hProcess,
_Out_ LPDWORD lpFlags,
_Out_ PBOOL lpPermanent)
{
ULONG Flags;
NTSTATUS Status;

Status = NtQueryInformationProcess(GetCurrentProcess(),
ProcessExecuteFlags,
&Flags,
sizeof(Flags),
NULL);
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return FALSE;
}

if (lpFlags)
{
*lpFlags = 0;
if (Flags & MEM_EXECUTE_OPTION_DISABLE)
*lpFlags |= PROCESS_DEP_ENABLE;
if (Flags & MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION)
*lpFlags |= PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION;
}

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

return TRUE;
}

/**
* @brief Sets the data execution prevention (DEP) and thunk emulation (DEP-ATL)
* settings for the current process.
*
* @param [in] dwFlags
* Variable that specifies the flags to set:
* 0 - disables DEP;
* PROCESS_DEP_ENABLE - enables DEP permanently.
* PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION - disables DEP-ATL. Can be specified
* only with PROCESS_DEP_ENABLE.
*
* @return
* TRUE on success, FALSE on failure.
*
* @remarks
* Supported for 32-bit processes only. Returns ERROR_NOT_SUPPORTED for 64-bit processes.
*
*/
BOOL
WINAPI
SetProcessDEPPolicy(_In_ DWORD dwFlags)
{
ULONG Flags = 0;
NTSTATUS Status;

if (dwFlags & PROCESS_DEP_ENABLE)
Flags |= MEM_EXECUTE_OPTION_DISABLE | MEM_EXECUTE_OPTION_PERMANENT;
if (dwFlags & PROCESS_DEP_DISABLE_ATL_THUNK_EMULATION)
Flags |= MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION;

Status = NtSetInformationProcess(GetCurrentProcess(),
ProcessExecuteFlags,
&Flags,
sizeof(Flags));
if (!NT_SUCCESS(Status))
{
BaseSetLastNTError(Status);
return FALSE;
}

return TRUE;
}

/**
* @brief Retrieves the system data execution prevention (DEP) and thunk emulation (DEP-ATL)
* settings.
*
* @return
* One of DEP_SYSTEM_POLICY_TYPE enumeration values:
* AlwaysOff - DEP is always disabled system-wide.
* AlwaysOn - DEP is always enabled system-wide.
* OptIn - DEP is enabled only for system components.
* Default for client Windows versions.
* OptOut - DEP is enabled for system components and processes.
* Default for server Windows versions.
*
* @remarks
* Supported for 32-bit processes only.
*
*/
DEP_SYSTEM_POLICY_TYPE
WINAPI
GetSystemDEPPolicy(VOID)
{
return SharedUserData->NXSupportPolicy;
}
10 changes: 6 additions & 4 deletions dll/win32/kernel32/kernel32.spec
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@
@ stdcall GetPrivateProfileStructW(wstr wstr ptr long wstr)
@ stdcall GetProcAddress(long str)
@ stdcall GetProcessAffinityMask(long ptr ptr)
@ stub -version=0x600+ GetProcessDEPPolicy
@ stdcall GetProcessDEPPolicy(ptr ptr ptr)
@ stdcall GetProcessHandleCount(long ptr)
@ stdcall -norelay GetProcessHeap()
@ stdcall GetProcessHeaps(long ptr)
Expand Down Expand Up @@ -590,7 +590,7 @@
@ stdcall GetStringTypeExA(long long str long ptr)
@ stdcall GetStringTypeExW(long long wstr long ptr)
@ stdcall GetStringTypeW(long wstr long ptr)
@ stub -version=0x600+ GetSystemDEPPolicy
@ stdcall GetSystemDEPPolicy()
@ stdcall GetSystemDefaultLCID()
@ stdcall GetSystemDefaultLangID()
@ stdcall -stub -version=0x600+ GetSystemDefaultLocaleName(ptr long)
Expand Down Expand Up @@ -1056,7 +1056,7 @@
@ stdcall SetPriorityClass(long long)
@ stdcall SetProcessAffinityMask(long long)
@ stub -version=0x600+ SetProcessAffinityUpdateMode
@ stub -version=0x600+ SetProcessDEPPolicy
@ stdcall SetProcessDEPPolicy(long)
@ stdcall SetProcessPriorityBoost(long long)
@ stdcall SetProcessShutdownParameters(long long)
@ stdcall SetProcessWorkingSetSize(long long long)
Expand Down Expand Up @@ -1290,4 +1290,6 @@
@ stdcall -version=0x600+ K32GetPerformanceInfo(ptr long)
@ stdcall -version=0x600+ K32QueryWorkingSet(ptr ptr long)
@ stdcall -version=0x600+ K32QueryWorkingSetEx(ptr ptr long)
@ stdcall -version=0x600+ K32GetMappedFileNameW(ptr ptr ptr long)
@ stdcall -version=0x600+ K32GetMappedFileNameW(ptr ptr ptr long)
@ stdcall -stub -version=0x600+ K32GetProcessImageFileNameW(ptr ptr long)

0 comments on commit 7352756

Please sign in to comment.