ReactOS 0.4.15-dev-8100-g1887773
w32knapi.c File Reference
#include "w32knapi.h"
Include dependency graph for w32knapi.c:

Go to the source code of this file.

Functions

static PGDI_TABLE_ENTRY MyGdiQueryTable ()
 
BOOL IsHandleValid (HGDIOBJ hobj)
 
PVOID GetHandleUserData (HGDIOBJ hobj)
 
static DWORD WINAPI IntSyscall (FARPROC proc, UINT cParams, PVOID pFirstParam)
 
DWORD Syscall (LPWSTR pszFunction, int cParams, void *pParams)
 
BOOL IsFunctionPresent (LPWSTR lpszFunction)
 
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 

Variables

HINSTANCE g_hInstance
 
HMODULE g_hModule = NULL
 
PGDI_TABLE_ENTRY GdiHandleTable
 

Function Documentation

◆ GetHandleUserData()

PVOID GetHandleUserData ( HGDIOBJ  hobj)

Definition at line 33 of file w32knapi.c.

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}
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
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
PGDI_TABLE_ENTRY GdiHandleTable
Definition: w32knapi.c:5
_In_ WDFCOLLECTION _In_ ULONG Index

◆ IntSyscall()

static DWORD WINAPI IntSyscall ( FARPROC  proc,
UINT  cParams,
PVOID  pFirstParam 
)
static

Definition at line 50 of file w32knapi.c.

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}
unsigned long DWORD
Definition: ntddk_ex.h:95
static HANDLE proc()
Definition: pdb.c:34
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

Referenced by Syscall().

◆ IsFunctionPresent()

BOOL IsFunctionPresent ( LPWSTR  lpszFunction)

Definition at line 107 of file w32knapi.c.

108{
109 char szFunctionName[MAX_PATH];
110 sprintf(szFunctionName, "%ls", lpszFunction);
111 return (GetProcAddress(g_hModule, szFunctionName) != NULL);
112}
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
#define sprintf(buf, format,...)
Definition: sprintf.c:55
HMODULE g_hModule
Definition: w32knapi.c:4

◆ IsHandleValid()

BOOL IsHandleValid ( HGDIOBJ  hobj)

Definition at line 17 of file w32knapi.c.

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}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117

◆ MyGdiQueryTable()

static PGDI_TABLE_ENTRY MyGdiQueryTable ( )
static

Definition at line 9 of file w32knapi.c.

10{
11 PTEB pTeb = NtCurrentTeb();
12 PPEB pPeb = pTeb->ProcessEnvironmentBlock;
13 return pPeb->GdiSharedHandleTable;
14}
#define NtCurrentTeb
PVOID GdiSharedHandleTable
Definition: ntddk_ex.h:292
Definition: compat.h:836
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337

Referenced by WinMain().

◆ Syscall()

DWORD Syscall ( LPWSTR  pszFunction,
int  cParams,
void pParams 
)

Definition at line 90 of file w32knapi.c.

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}
int(* FARPROC)()
Definition: compat.h:36
#define printf
Definition: freeldr.h:97
static DWORD WINAPI IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
Definition: w32knapi.c:50

Referenced by NtUserEnumDisplayMonitors1().

◆ WinMain()

int APIENTRY WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPSTR  lpCmdLine,
int  nCmdShow 
)

Definition at line 115 of file w32knapi.c.

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 FreeLibrary(x)
Definition: compat.h:748
#define LoadLibraryW(x)
Definition: compat.h:747
#define L(x)
Definition: ntvdm.h:50
BOOL InitOsVersion()
Definition: osver.c:17
UINT g_OsIdx
Definition: osver.c:4
static PGDI_TABLE_ENTRY MyGdiQueryTable()
Definition: w32knapi.c:9
HINSTANCE g_hInstance
Definition: w32knapi.c:3

Variable Documentation

◆ g_hInstance

HINSTANCE g_hInstance

Definition at line 3 of file w32knapi.c.

Referenced by WinMain().

◆ g_hModule

HMODULE g_hModule = NULL

Definition at line 4 of file w32knapi.c.

Referenced by IsFunctionPresent(), Syscall(), and WinMain().

◆ GdiHandleTable

PGDI_TABLE_ENTRY GdiHandleTable

Definition at line 5 of file w32knapi.c.

Referenced by GetHandleUserData(), IsHandleValid(), and WinMain().