3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS version of ntdll
5 * FILE: iface/native/genntdll.c
6 * PURPOSE: Generates the system call stubs in ntdll
7 * CHANGE HISTORY: Added a '@xx' to deal with stdcall [ Ariadne ]
9 * Four arguments now required; 4th is the file
10 * for ntoskrnl ZwXXX functions (which are merely calls
11 * to twin NtXXX calls, via int 0x2e (x86).
13 * Fixed a bug in function numbers in kernel ZwXXX stubs.
17 /* INCLUDE ******************************************************************/
23 #define PARAMETERIZED_LIBS
27 #define INPUT_BUFFER_SIZE 255
29 #define INDEX 0x1000 /* SSDT index 1 */
32 /* FUNCTIONS ****************************************************************/
34 int makeSystemServiceTable(FILE *in, FILE *out)
36 char line [INPUT_BUFFER_SIZE];
46 fprintf(out,"// Machine generated, don't edit\n");
50 * First we build the Win32k SSDT
52 fprintf(out,"SSDT Win32kSSDT[] = {\n");
54 /* First system call has index zero */
57 /* Go on until EOF or read zero bytes */
58 while ((!feof(in))&& (fgets(line, sizeof line, in) != NULL))
60 if ((s = (char *) strchr(line,'\r')) != NULL)
65 * Skip comments (#) and empty lines.
68 if ((*s) != '#' && (*s) != '\0')
70 /* Extract the NtXXX name */
71 name = (char *)strtok(s," \t");
72 /* Extract the stack size */
73 nr_args = (char *)strtok(NULL," \t");
75 * Remove, if present, the trailing LF.
77 if ((stmp = strchr(nr_args, '\n')) != NULL)
82 printf("%3d \"%s\"\n",sys_call_idx | INDEX,name);
90 * Now write the current system call's name
91 * in the service table.
93 fprintf(out,"\t\t{ (ULONG)%s }",name);
95 /* Next system call index */
99 /* Close the service table (C syntax) */
100 fprintf(out,"\n};\n");
103 * Now we build the Win32k SSPT
107 fprintf(out,"SSPT Win32kSSPT[] = {\n");
109 /* First system call has index zero */
112 /* Go on until EOF or read zero bytes */
113 while ((!feof(in))&& (fgets(line, sizeof line, in) != NULL))
115 if ((s = (char *) strchr(line,'\r')) != NULL)
120 * Skip comments (#) and empty lines.
123 if ((*s) != '#' && (*s) != '\0')
125 /* Extract the NtXXX name */
126 name = (char *)strtok(s," \t");
127 /* Extract the stack size */
128 nr_args = (char *)strtok(NULL," \t");
130 * Remove, if present, the trailing LF.
132 if ((stmp = strchr(nr_args, '\n')) != NULL)
137 printf("%3d \"%s\"\n",sys_call_idx|INDEX,name);
140 if (sys_call_idx > 0)
145 * Now write the current system call's ID
146 * in the service table along with its Parameters Size.
148 fprintf(out,"\t\t{ %d }",atoi(nr_args) * sizeof(void*));
150 /* Next system call index */
155 * Close the service table (C syntax)
157 fprintf(out,"\n};\n");
160 * We write some useful defines
162 fprintf(out, "\n\n#define MIN_SYSCALL_NUMBER 0\n");
163 fprintf(out, "#define MAX_SYSCALL_NUMBER %d\n", sys_call_idx-1);
164 fprintf(out, "#define NUMBER_OF_SYSCALLS %d\n", sys_call_idx);
165 fprintf(out, "ULONG Win32kNumberOfSysCalls = %d;\n", sys_call_idx);
179 char line [INPUT_BUFFER_SIZE];
181 char * name; /* NtXXX name */
182 int sys_call_idx; /* NtXXX index number in the service table */
183 char * nr_args; /* stack_size / machine_word_size */
188 * GDI32 stubs file header
190 fprintf(out1,"// Machine generated, don't edit\n");
191 fprintf(out1,"\n\n");
194 * USER32 stubs file header
196 fprintf(out2,"// Machine generated, don't edit\n");
197 fprintf(out2,"\n\n");
200 * CSRSS stubs file header
202 fprintf(out3,"// Machine generated, don't edit\n");
203 fprintf(out3,"\n\n");
206 * Scan the database. DB is a text file; each line
207 * is a record, which contains data for one system
208 * function. Each record has three columns:
210 * NT_NAME (e.g. NtCreateProcess)
211 * ZW_NAME (e.g. ZwCreateProcess)
212 * STACK_SIZE (in machine words: for x[3456]86
213 * processors a machine word is 4 bytes)
216 /* First system call has index zero */
219 /* Go on until EOF or read zero bytes */
221 && (fgets(line, sizeof line, in) != NULL)
226 * Remove, if present, the trailing CR.
229 if ((s = (char *) strchr(line,'\r')) != NULL)
234 * Skip comments (#) and empty lines.
237 if ((*s) != '#' && (*s) != '\0')
239 /* Extract the NtXXX name */
240 name = (char *)strtok(s," \t");
241 /* Extract the stack size */
242 nr_args = (char *)strtok(NULL," \t");
243 stacksize = atoi(nr_args)*sizeof(void*);
245 * Remove, if present, the trailing LF.
247 if ((stmp = strchr(nr_args, '\n')) != NULL)
252 printf("%3d \"%s\"\n",sys_call_idx | INDEX,name);
256 * Write the GDI32 stub for the current system call.
258 #ifdef PARAMETERIZED_LIBS
259 fprintf(out1,"__asm__(\"\\n\\t.global _%s@%d\\n\\t\"\n",name,stacksize);
260 fprintf(out1,"\"_%s@%d:\\n\\t\"\n",name,stacksize);
262 fprintf(out1,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name);
263 fprintf(out1,"\"_%s:\\n\\t\"\n",name);
265 fprintf(out1,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx | INDEX);
266 fprintf(out1,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
267 fprintf(out1,"\t\"int\t$0x2E\\n\\t\"\n");
268 fprintf(out1,"\t\"ret\t$%d\\n\\t\");\n\n",stacksize);
271 * Write the USER32 stub for the current system call
273 #ifdef PARAMETERIZED_LIBS
274 fprintf(out2,"__asm__(\"\\n\\t.global _%s@%d\\n\\t\"\n",name,stacksize);
275 fprintf(out2,"\"_%s@%d:\\n\\t\"\n",name,stacksize);
277 fprintf(out2,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name);
278 fprintf(out2,"\"_%s:\\n\\t\"\n",name);
280 fprintf(out2,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx | INDEX);
281 fprintf(out2,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
282 fprintf(out2,"\t\"int\t$0x2E\\n\\t\"\n");
283 fprintf(out2,"\t\"ret\t$%d\\n\\t\");\n\n",stacksize);
286 * Write the CSRSS stub for the current system call
288 #ifdef PARAMETERIZED_LIBS
289 fprintf(out3,"__asm__(\"\\n\\t.global _%s@%d\\n\\t\"\n",name,stacksize);
290 fprintf(out3,"\"_%s@%d:\\n\\t\"\n",name,stacksize);
292 fprintf(out3,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name);
293 fprintf(out3,"\"_%s:\\n\\t\"\n",name);
295 fprintf(out3,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx | INDEX);
296 fprintf(out3,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
297 fprintf(out3,"\t\"int\t$0x2E\\n\\t\"\n");
298 fprintf(out3,"\t\"ret\t$%d\\n\\t\");\n\n",stacksize);
300 /* Next system call index */
308 void usage(char * argv0)
310 printf("Usage: %s w32k.lst ssdt.h win32k.c win32k.c\n"
311 " w32k.lst system functions database\n"
312 " ssdt.h WIN32K service table\n"
313 " win32k.c GDI32 stubs\n"
314 " win32k.c USER32 stubs\n",
319 int main(int argc, char* argv[])
321 FILE * in; /* System calls database */
322 FILE * out1; /* SERVICE_TABLE */
323 FILE * out2; /* GDI32 stubs */
324 FILE * out3; /* USER32 stubs */
325 FILE * out4; /* CSRSS stubs */
334 in = fopen(argv[1],"rb");
337 perror("Failed to open input file (system calls database)");
341 out1 = fopen(argv[2],"wb");
344 perror("Failed to open output file (WIN32K service table)");
348 out2 = fopen(argv[3],"wb");
351 perror("Failed to open output file (GDI32 stubs)");
355 out3 = fopen(argv[4],"wb");
358 perror("Failed to open output file (USER32 stubs)");
362 out4 = fopen(argv[5],"wb");
365 perror("Failed to open output file (CSRSS stubs)");
369 ret = process(in,out2,out3,out4);
371 ret = makeSystemServiceTable(in, out1);