ReactOS 0.4.17-dev-1247-ge46f4bb
ntuserpfn.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS runtime library
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: NtUser PFN registration
5 * COPYRIGHT: Copyright 2026 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8#include <rtl.h>
9#include <ndk/rtlfuncs.h>
10
11#define NDEBUG
12#include <debug.h>
13
14typedef struct _NTUSER_PFN
15{
16 PVOID WndProcsA[RTLP_NUMBER_OF_NTUSER_WNDPROCS];
17 PVOID WndProcsW[RTLP_NUMBER_OF_NTUSER_WNDPROCS];
18 PVOID WorkerProcs[RTLP_NUMBER_OF_NTUSER_WORKERPROCS];
20
22
23extern const NTUSER_PFN NtDllUserStubs;
24
26
30 _In_reads_bytes_(SizeOfWndProcsA) LPCVOID WndProcsA,
31 _In_ SIZE_T SizeOfWndProcsA,
32 _In_reads_bytes_(SizeOfWndProcsW) LPCVOID WndProcsW,
33 _In_ SIZE_T SizeOfWndProcsW,
34 _In_reads_bytes_(SizeOfWorkerProcs) LPCVOID WorkerProcs,
35 _In_ SIZE_T SizeOfWorkerProcs)
36{
37 ULONG OldProtect;
41
42 /* Validate parameters */
43 if ((SizeOfWndProcsA != sizeof(RtlpNtUserPfns.WndProcsA)) ||
44 (SizeOfWndProcsW != sizeof(RtlpNtUserPfns.WndProcsW)) ||
45 (SizeOfWorkerProcs != sizeof(RtlpNtUserPfns.WorkerProcs)))
46 {
48 }
49
50 /* Check if already initialized */
52 {
54 }
55
56 /* Change page protection, so we can set up the PFNs */
58 RegionSize = sizeof(RtlpNtUserPfns);
63 &OldProtect);
64 if (!NT_SUCCESS(Status))
65 {
66 return Status;
67 }
68
69 RtlCopyMemory((PVOID)RtlpNtUserPfns.WndProcsA, WndProcsA, SizeOfWndProcsA);
70 RtlCopyMemory((PVOID)RtlpNtUserPfns.WndProcsW, WndProcsW, SizeOfWndProcsW);
71 RtlCopyMemory((PVOID)RtlpNtUserPfns.WorkerProcs, WorkerProcs, SizeOfWorkerProcs);
72
73 /* Restore original page protection */
77 OldProtect,
78 &OldProtect);
79 if (!NT_SUCCESS(Status))
80 {
81 return Status;
82 }
83
85
86 return STATUS_SUCCESS;
87}
88
89
93 _Outptr_ const VOID** NtdllWndProcsA,
94 _Outptr_ const VOID** NtdllWndProcsW,
95 _Outptr_ const VOID** NtdllWorkerProcs)
96{
98 {
100 }
101
102 *NtdllWndProcsA = NtDllUserStubs.WndProcsA;
103 *NtdllWndProcsW = NtDllUserStubs.WndProcsW;
104 *NtdllWorkerProcs = NtDllUserStubs.WorkerProcs;
105
106 return STATUS_SUCCESS;
107}
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:24
CONST void * LPCVOID
Definition: minwindef.h:164
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:408
__kernel_entry _Inout_ _Inout_ PSIZE_T RegionSize
Definition: mmfuncs.h:176
#define _In_reads_bytes_(s)
Definition: no_sal2.h:170
#define _Outptr_
Definition: no_sal2.h:262
#define _In_
Definition: no_sal2.h:158
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define NtCurrentProcess()
Definition: nt_native.h:1660
NTSTATUS NTAPI NtProtectVirtualMemory(IN HANDLE ProcessHandle, IN OUT PVOID *UnsafeBaseAddress, IN OUT SIZE_T *UnsafeNumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG UnsafeOldAccessProtection)
Definition: virtual.c:3076
static BOOLEAN NtUserPfnsInitialized
Definition: ntuserpfn.c:25
const NTUSER_PFN NtDllUserStubs
NTSTATUS NTAPI RtlRetrieveNtUserPfn(_Outptr_ const VOID **NtdllWndProcsA, _Outptr_ const VOID **NtdllWndProcsW, _Outptr_ const VOID **NtdllWorkerProcs)
Definition: ntuserpfn.c:92
NTSTATUS NTAPI RtlInitializeNtUserPfn(_In_reads_bytes_(SizeOfWndProcsA) LPCVOID WndProcsA, _In_ SIZE_T SizeOfWndProcsA, _In_reads_bytes_(SizeOfWndProcsW) LPCVOID WndProcsW, _In_ SIZE_T SizeOfWndProcsW, _In_reads_bytes_(SizeOfWorkerProcs) LPCVOID WorkerProcs, _In_ SIZE_T SizeOfWorkerProcs)
Definition: ntuserpfn.c:29
struct _NTUSER_PFN * PNTUSER_PFN
struct _NTUSER_PFN NTUSER_PFN
const NTUSER_PFN RtlpNtUserPfns
Definition: ntuserpfn.c:21
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID WndProcsW[RTLP_NUMBER_OF_NTUSER_WNDPROCS]
Definition: ntuserpfn.c:17
PVOID WorkerProcs[RTLP_NUMBER_OF_NTUSER_WORKERPROCS]
Definition: ntuserpfn.c:18
PVOID WndProcsA[RTLP_NUMBER_OF_NTUSER_WNDPROCS]
Definition: ntuserpfn.c:16
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135