ReactOS 0.4.15-dev-7934-g1dc8d80
w32knapi.c
Go to the documentation of this file.
1#include "w32knapi.h"
2
6
7static
10{
11 PTEB pTeb = NtCurrentTeb();
12 PPEB pPeb = pTeb->ProcessEnvironmentBlock;
13 return pPeb->GdiSharedHandleTable;
14}
15
16BOOL
18{
19 USHORT Index = (ULONG_PTR)hobj;
21
22 if (pentry->KernelData == NULL ||
23 pentry->KernelData < (PVOID)0x80000000 ||
24 (USHORT)pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16))
25 {
26 return FALSE;
27 }
28
29 return TRUE;
30}
31
34{
35 USHORT Index = (ULONG_PTR)hobj;
37
38 if (pentry->KernelData == NULL ||
39 pentry->KernelData < (PVOID)0x80000000 ||
40 (USHORT)pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16))
41 {
42 return NULL;
43 }
44
45 return pentry->UserData;
46}
47
48
49static DWORD WINAPI
50IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
51{
52 DWORD retval;
53
54#ifdef __GNUC__
55 asm volatile
56 (
57 "pushfl;" // Save flags
58 "movl %%ecx, %%eax;"
59 "shl $2, %%eax;" // Calculate param size
60 "subl %%eax, %%esp;" // Calculate new stack pos
61 "movl %%esp, %%edi;" // Destination is stackpointer
62 "cld;" // Clear direction flag
63 "rep movsd;" // Copy params to the stack
64 "call *%%edx;" // Call function
65 "popfl;" // Restore flags
66 : "=a" (retval)
67 : "S" (pFirstParam), "c" (cParams), "d"(proc)
68 : "%edi"
69 );
70#else
71 __asm
72 {
73 pushf
74 mov eax, cParams
75 shl eax, 2
76 sub esp, eax
77 mov edi, esp
78 cld
79 rep movsd
80 call proc
81 mov retval, eax
82 popf
83 };
84#endif
85
86 return retval;
87}
88
90Syscall(LPWSTR pszFunction, int cParams, void* pParams)
91{
92 char szFunctionName[MAX_PATH];
94
95 sprintf(szFunctionName, "%ls", pszFunction);
96 proc = (FARPROC)GetProcAddress(g_hModule, szFunctionName);
97 if (!proc)
98 {
99 printf("Couldn't find proc: %s\n", szFunctionName);
100 return FALSE;
101 }
102
103 return IntSyscall(proc, cParams, pParams);
104}
105
106BOOL
108{
109 char szFunctionName[MAX_PATH];
110 sprintf(szFunctionName, "%ls", lpszFunction);
111 return (GetProcAddress(g_hModule, szFunctionName) != NULL);
112}
113
114int APIENTRY
116 HINSTANCE hPrevInstance,
117 LPSTR lpCmdLine,
118 int nCmdShow)
119{
121
122 printf("Win32k native API test\n");
123
124 /* Convert to gui thread */
125 // IsGUIThread(TRUE); <- does not exists on win2k
126
128 printf("g_OsIdx = %d\n", g_OsIdx);
129
130 g_hModule = LoadLibraryW(L"win32u.dll");
131 if (!g_hModule)
132 {
133 printf("win32u.dll not found!\n");
134 return -1;
135 }
136
138 if(!GdiHandleTable)
139 {
141 printf("GdiHandleTable not found!\n");
142 return -1;
143 }
144
145 printf("\n");
146
147 return TestMain(L"w32knapi", L"win32k.sys Nt-Api");
148}
HINSTANCE hInstance
Definition: charmap.c:19
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
int(* FARPROC)()
Definition: compat.h:36
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define LoadLibraryW(x)
Definition: compat.h:747
#define ULONG_PTR
Definition: config.h:101
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:97
#define NtCurrentTeb
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
BOOL InitOsVersion()
Definition: osver.c:17
UINT g_OsIdx
Definition: osver.c:4
static HANDLE proc()
Definition: pdb.c:34
unsigned short USHORT
Definition: pedump.c:61
Definition: gdi.h:2
PVOID KernelData
Definition: gdi.h:3
USHORT FullUnique
Definition: ntgdihdl.h:210
PVOID UserData
Definition: gdi.h:6
PVOID GdiSharedHandleTable
Definition: ntddk_ex.h:292
Definition: compat.h:836
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx testl eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx shrl ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 psrlq mm1 psrlq mm5 paddd mm0 paddd mm4 psrad mm0 psrad mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx andl ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 psrlq mm1 paddd mm0 psrad mm0 packssdw mm0 movd eax movw edi esi edx edi
Definition: synth_sse3d.h:185
ecx edi movl ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
PGDI_TABLE_ENTRY GdiHandleTable
Definition: w32knapi.c:5
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Definition: w32knapi.c:115
BOOL IsFunctionPresent(LPWSTR lpszFunction)
Definition: w32knapi.c:107
static DWORD WINAPI IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
Definition: w32knapi.c:50
PVOID GetHandleUserData(HGDIOBJ hobj)
Definition: w32knapi.c:33
BOOL IsHandleValid(HGDIOBJ hobj)
Definition: w32knapi.c:17
HMODULE g_hModule
Definition: w32knapi.c:4
DWORD Syscall(LPWSTR pszFunction, int cParams, void *pParams)
Definition: w32knapi.c:90
static PGDI_TABLE_ENTRY MyGdiQueryTable()
Definition: w32knapi.c:9
HINSTANCE g_hInstance
Definition: w32knapi.c:3
_In_ WDFCOLLECTION _In_ ULONG Index
#define WINAPI
Definition: msvc.h:6
char * LPSTR
Definition: xmlstorage.h:182
WCHAR * LPWSTR
Definition: xmlstorage.h:184