ReactOS  0.4.12-dev-918-g6c6e7b8
w32knapi.c
Go to the documentation of this file.
1 #include "w32knapi.h"
2 
6 
7 static
10 {
11  PTEB pTeb = NtCurrentTeb();
12  PPEB pPeb = pTeb->ProcessEnvironmentBlock;
13  return pPeb->GdiSharedHandleTable;
14 }
15 
16 BOOL
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 
32 PVOID
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 
49 static DWORD WINAPI
50 IntSyscall(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 
89 DWORD
90 Syscall(LPWSTR pszFunction, int cParams, void* pParams)
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 }
105 
106 BOOL
108 {
109  char szFunctionName[MAX_PATH];
110  sprintf(szFunctionName, "%ls", lpszFunction);
111  return (GetProcAddress(g_hModule, szFunctionName) != NULL);
112 }
113 
114 int 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 
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 }
BOOL IsHandleValid(HGDIOBJ hobj)
Definition: w32knapi.c:17
HINSTANCE g_hInstance
Definition: w32knapi.c:3
PVOID UserData
Definition: gdi.h:6
#define TRUE
Definition: types.h:120
PPEB ProcessEnvironmentBlock
Definition: ntddk_ex.h:337
HMODULE g_hModule
Definition: w32knapi.c:4
static DWORD WINAPI IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
Definition: w32knapi.c:50
USHORT FullUnique
Definition: ntgdihdl.h:219
static HANDLE proc()
Definition: pdb.c:32
char * LPSTR
Definition: xmlstorage.h:182
PVOID GetHandleUserData(HGDIOBJ hobj)
Definition: w32knapi.c:33
#define sprintf(buf, format,...)
Definition: sprintf.c:55
PVOID GdiSharedHandleTable
Definition: ntddk_ex.h:292
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Definition: w32knapi.c:115
#define FreeLibrary(x)
Definition: compat.h:405
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
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:8
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT g_OsIdx
Definition: osver.c:4
static const WCHAR L[]
Definition: oid.c:1250
BOOL InitOsVersion()
Definition: osver.c:17
Definition: gdi.h:1
Definition: compat.h:484
static PGDI_TABLE_ENTRY MyGdiQueryTable()
Definition: w32knapi.c:9
FORCEINLINE struct _TEB * NtCurrentTeb(VOID)
Definition: psfuncs.h:420
unsigned short USHORT
Definition: pedump.c:61
BOOL IsFunctionPresent(LPWSTR lpszFunction)
Definition: w32knapi.c:107
PVOID KernelData
Definition: gdi.h:3
unsigned int UINT
Definition: ndis.h:50
#define ULONG_PTR
Definition: config.h:101
#define GetProcAddress(x, y)
Definition: compat.h:410
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD Syscall(LPWSTR pszFunction, int cParams, void *pParams)
Definition: w32knapi.c:90
int(* FARPROC)()
Definition: compat.h:28
#define APIENTRY
Definition: api.h:79
PGDI_TABLE_ENTRY GdiHandleTable
Definition: w32knapi.c:5
#define printf
Definition: config.h:203