4 HMODULE g_hModule
= NULL
;
6 PSYSCALL_ENTRY g_SyscallTable
;
14 osv
.dwOSVersionInfoSize
= sizeof(osv
);
16 pszRos
= osv
.szCSDVersion
+ wcslen(osv
.szCSDVersion
) + 1;
17 /* make sure the string is zero terminated */
18 osv
.szCSDVersion
[127] = 0;
20 if (wcsstr(pszRos
, L
"ReactOS") != NULL
)
22 printf("Running on %ls\n", pszRos
);
23 g_hModule
= LoadLibraryW(L
"w32kdll.dll");
26 printf("w32kdll.dll not found!\n");
33 if (osv
.dwPlatformId
!= VER_PLATFORM_WIN32_NT
)
35 printf("Unsupported OS\n");
39 if (osv
.dwMajorVersion
== 5 && osv
.dwMinorVersion
== 1 && osv
.dwBuildNumber
== 2600)
41 printf("Running on Windows XP, build 2600\n");
43 g_SyscallTable
= SyscallTable_XP_2600
;
47 if (osv
.dwMajorVersion
== 5 && osv
.dwMinorVersion
== 0 && osv
.dwBuildNumber
== 2195)
49 printf("Running on Windows 2000, build 2195\n");
51 g_SyscallTable
= SyscallTable_2K_2195
;
55 printf("Unsupported OS\n");
61 GetSyscallEntry(LPWSTR lpszFunction
)
65 for (i
= 0; g_SyscallTable
[i
].lpszFunction
!= NULL
; i
++)
67 if (wcscmp(g_SyscallTable
[i
].lpszFunction
, lpszFunction
) == 0)
69 return &g_SyscallTable
[i
];
76 WinSyscall(INT nSyscalNum
, PVOID pFirstParam
)
79 asm volatile ("int $0x2e\n" : "=a"(ret
): "a" (nSyscalNum
), "d" (pFirstParam
));
84 RosSyscall(FARPROC proc
, UINT cParams
, PVOID pFirstParam
)
90 "pushfl;" // Save flags
92 "shl $2, %%eax;" // Calculate param size
93 "subl %%eax, %%esp;" // Calculate new stack pos
94 "movl %%esp, %%edi;" // Destination is stackpointer
95 "cld;" // Clear direction flag
96 "rep movsd;" // Copy params to the stack
97 "call *%%edx;" // Call function
98 "popfl;" // Restore flags
100 : "S" (pFirstParam
), "c" (cParams
), "d"(proc
)
108 Syscall(LPWSTR pszFunction
, int cParams
, void* pParams
)
110 if (g_nOs
== OS_REACTOS
)
112 char szFunctionName
[MAX_PATH
];
114 sprintf(szFunctionName
, "%ls", pszFunction
);
115 FARPROC proc
= (FARPROC
)GetProcAddress(g_hModule
, szFunctionName
);
118 printf("Couldn't find proc: %s\n", szFunctionName
);
122 return RosSyscall(proc
, cParams
, pParams
);
126 PSYSCALL_ENTRY pEntry
= GetSyscallEntry(pszFunction
);
127 return WinSyscall(pEntry
->nSyscallNum
, pParams
);
132 IsFunctionPresent(LPWSTR lpszFunction
)
134 if (g_nOs
== OS_REACTOS
)
136 char szFunctionName
[MAX_PATH
];
137 sprintf(szFunctionName
, "%ls", lpszFunction
);
138 return (GetProcAddress(g_hModule
, szFunctionName
) != NULL
);
141 return (GetSyscallEntry(lpszFunction
) != NULL
);
145 WinMain(HINSTANCE hInstance
,
146 HINSTANCE hPrevInstance
,
150 g_hInstance
= hInstance
;
153 printf("Win32k native API test\n");
155 /* Convert to gui thread */
158 if (!InitOsVersion())
165 return TestMain(L
"w32knapi", L
"win32k.sys Nt-Api");