Sync to trunk head(r38096)
[reactos.git] / rostests / apitests / w32knapi / w32knapi.c
1 #include "w32knapi.h"
2
3 HINSTANCE g_hInstance;
4 HMODULE g_hModule = NULL;
5 PGDI_TABLE_ENTRY GdiHandleTable;
6
7 static
8 PGDI_TABLE_ENTRY
9 MyGdiQueryTable()
10 {
11 PTEB pTeb = NtCurrentTeb();
12 PPEB pPeb = pTeb->ProcessEnvironmentBlock;
13 return pPeb->GdiSharedHandleTable;
14 }
15
16 static DWORD STDCALL
17 IntSyscall(FARPROC proc, UINT cParams, PVOID pFirstParam)
18 {
19 DWORD ret;
20
21 asm volatile
22 (
23 "pushfl;" // Save flags
24 "movl %%ecx, %%eax;"
25 "shl $2, %%eax;" // Calculate param size
26 "subl %%eax, %%esp;" // Calculate new stack pos
27 "movl %%esp, %%edi;" // Destination is stackpointer
28 "cld;" // Clear direction flag
29 "rep movsd;" // Copy params to the stack
30 "call *%%edx;" // Call function
31 "popfl;" // Restore flags
32 : "=a" (ret)
33 : "S" (pFirstParam), "c" (cParams), "d"(proc)
34 : "%edi"
35 );
36
37 return ret;
38 }
39
40 DWORD
41 Syscall(LPWSTR pszFunction, int cParams, void* pParams)
42 {
43 char szFunctionName[MAX_PATH];
44
45 sprintf(szFunctionName, "%ls", pszFunction);
46 FARPROC proc = (FARPROC)GetProcAddress(g_hModule, szFunctionName);
47 if (!proc)
48 {
49 printf("Couldn't find proc: %s\n", szFunctionName);
50 return FALSE;
51 }
52
53 return IntSyscall(proc, cParams, pParams);
54 }
55
56 BOOL
57 IsFunctionPresent(LPWSTR lpszFunction)
58 {
59 char szFunctionName[MAX_PATH];
60 sprintf(szFunctionName, "%ls", lpszFunction);
61 return (GetProcAddress(g_hModule, szFunctionName) != NULL);
62 }
63
64 int APIENTRY
65 WinMain(HINSTANCE hInstance,
66 HINSTANCE hPrevInstance,
67 LPSTR lpCmdLine,
68 int nCmdShow)
69 {
70 g_hInstance = hInstance;
71
72 printf("Win32k native API test\n");
73
74 /* Convert to gui thread */
75 // IsGUIThread(TRUE); <- does not exists on win2k
76
77 InitOsVersion();
78 printf("g_OsIdx = %d\n", g_OsIdx);
79
80 g_hModule = LoadLibraryW(L"w32kdll.dll");
81 if (!g_hModule)
82 {
83 printf("w32kdll.dll not found!\n");
84 return -1;
85 }
86
87 GdiHandleTable = MyGdiQueryTable();
88 if(!GdiHandleTable)
89 {
90 FreeLibrary(g_hModule);
91 printf("GdiHandleTable not found!\n");
92 return -1;
93 }
94
95 printf("\n");
96
97 return TestMain(L"w32knapi", L"win32k.sys Nt-Api");
98 }