ReactOS  0.4.14-dev-831-gef8c9239
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 }
PVOID UserData
Definition: gdi.h:6
USHORT FullUnique
Definition: ntgdihdl.h:223
smooth NULL
Definition: ftsmooth.c:416
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: gdi.h:1
unsigned short USHORT
Definition: pedump.c:61
PVOID KernelData
Definition: gdi.h:3
#define ULONG_PTR
Definition: config.h:101
PGDI_TABLE_ENTRY GdiHandleTable
Definition: w32knapi.c:5

◆ 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 }
static HANDLE proc()
Definition: pdb.c:32
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx 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 mm1 mm5 paddd mm0 paddd mm4 mm0 mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm0 mm0 packssdw mm0 movd eax movw edi esi edx edi
Definition: synth_sse3d.h:185
unsigned long DWORD
Definition: ntddk_ex.h:95

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 }
HMODULE g_hModule
Definition: w32knapi.c:4
#define sprintf(buf, format,...)
Definition: sprintf.c:55
smooth NULL
Definition: ftsmooth.c:416
#define MAX_PATH
Definition: compat.h:26
#define GetProcAddress(x, y)
Definition: compat.h:418

◆ 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
USHORT FullUnique
Definition: ntgdihdl.h:223
smooth NULL
Definition: ftsmooth.c:416
static const UCHAR Index[8]
Definition: usbohci.c:18
Definition: gdi.h:1
unsigned short USHORT
Definition: pedump.c:61
PVOID KernelData
Definition: gdi.h:3
#define ULONG_PTR
Definition: config.h:101
PGDI_TABLE_ENTRY GdiHandleTable
Definition: w32knapi.c:5

◆ 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 }
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
PVOID GdiSharedHandleTable
Definition: ntddk_ex.h:292
Definition: compat.h:492
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420

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];
93  FARPROC proc;
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 }
HMODULE g_hModule
Definition: w32knapi.c:4
static DWORD WINAPI IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
Definition: w32knapi.c:50
static HANDLE proc()
Definition: pdb.c:32
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define MAX_PATH
Definition: compat.h:26
#define GetProcAddress(x, y)
Definition: compat.h:418
int(* FARPROC)()
Definition: compat.h:28
#define printf
Definition: config.h:203

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 
127  InitOsVersion();
128  printf("g_OsIdx = %d\n", g_OsIdx);
129 
130  g_hModule = LoadLibraryW(L"w32kdll.dll");
131  if (!g_hModule)
132  {
133  printf("w32kdll.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 g_hInstance
Definition: w32knapi.c:3
HMODULE g_hModule
Definition: w32knapi.c:4
HINSTANCE hInstance
Definition: charmap.c:20
#define LoadLibraryW(x)
Definition: compat.h:412
#define FreeLibrary(x)
Definition: compat.h:413
UINT g_OsIdx
Definition: osver.c:4
static const WCHAR L[]
Definition: oid.c:1250
BOOL InitOsVersion()
Definition: osver.c:17
static PGDI_TABLE_ENTRY MyGdiQueryTable()
Definition: w32knapi.c:9
PGDI_TABLE_ENTRY GdiHandleTable
Definition: w32knapi.c:5
#define printf
Definition: config.h:203

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().