1 /* $Id: genw32k.c,v 1.2 2002/07/04 19:56:33 dwelch Exp $
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
);
178 char line
[INPUT_BUFFER_SIZE
];
180 char * name
; /* NtXXX name */
181 int sys_call_idx
; /* NtXXX index number in the service table */
182 char * nr_args
; /* stack_size / machine_word_size */
187 * GDI32 stubs file header
189 fprintf(out1
,"// Machine generated, don't edit\n");
190 fprintf(out1
,"\n\n");
193 * USER32 stubs file header
195 fprintf(out2
,"// Machine generated, don't edit\n");
196 fprintf(out2
,"\n\n");
198 * Scan the database. DB is a text file; each line
199 * is a record, which contains data for one system
200 * function. Each record has three columns:
202 * NT_NAME (e.g. NtCreateProcess)
203 * ZW_NAME (e.g. ZwCreateProcess)
204 * STACK_SIZE (in machine words: for x[3456]86
205 * processors a machine word is 4 bytes)
208 /* First system call has index zero */
211 /* Go on until EOF or read zero bytes */
213 && (fgets(line
, sizeof line
, in
) != NULL
)
218 * Remove, if present, the trailing CR.
221 if ((s
= (char *) strchr(line
,'\r')) != NULL
)
226 * Skip comments (#) and empty lines.
229 if ((*s
) != '#' && (*s
) != '\0')
231 /* Extract the NtXXX name */
232 name
= (char *)strtok(s
," \t");
233 /* Extract the stack size */
234 nr_args
= (char *)strtok(NULL
," \t");
235 stacksize
= atoi(nr_args
)*sizeof(void*);
237 * Remove, if present, the trailing LF.
239 if ((stmp
= strchr(nr_args
, '\n')) != NULL
)
244 printf("%3d \"%s\"\n",sys_call_idx
| INDEX
,name
);
248 * Write the GDI32 stub for the current system call.
250 #ifdef PARAMETERIZED_LIBS
251 fprintf(out1
,"__asm__(\"\\n\\t.global _%s@%d\\n\\t\"\n",name
,stacksize
);
252 fprintf(out1
,"\"_%s@%d:\\n\\t\"\n",name
,stacksize
);
254 fprintf(out1
,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name
);
255 fprintf(out1
,"\"_%s:\\n\\t\"\n",name
);
257 fprintf(out1
,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx
| INDEX
);
258 fprintf(out1
,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
259 fprintf(out1
,"\t\"int\t$0x2E\\n\\t\"\n");
260 fprintf(out1
,"\t\"ret\t$%d\\n\\t\");\n\n",stacksize
);
263 * Write the USER32 stub for the current system call
265 #ifdef PARAMETERIZED_LIBS
266 fprintf(out2
,"__asm__(\"\\n\\t.global _%s@%d\\n\\t\"\n",name
,stacksize
);
267 fprintf(out2
,"\"_%s@%d:\\n\\t\"\n",name
,stacksize
);
269 fprintf(out2
,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name
);
270 fprintf(out2
,"\"_%s:\\n\\t\"\n",name
);
272 fprintf(out2
,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx
| INDEX
);
273 fprintf(out2
,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
274 fprintf(out2
,"\t\"int\t$0x2E\\n\\t\"\n");
275 fprintf(out2
,"\t\"ret\t$%d\\n\\t\");\n\n",stacksize
);
277 /* Next system call index */
285 void usage(char * argv0
)
287 printf("Usage: %s w32k.lst ssdt.h win32k.c win32k.c\n"
288 " w32k.lst system functions database\n"
289 " ssdt.h WIN32K service table\n"
290 " win32k.c GDI32 stubs\n"
291 " win32k.c USER32 stubs\n",
296 int main(int argc
, char* argv
[])
298 FILE * in
; /* System calls database */
299 FILE * out1
; /* SERVICE_TABLE */
300 FILE * out2
; /* GDI32 stubs */
301 FILE * out3
; /* USER32 stubs */
310 in
= fopen(argv
[1],"rb");
313 perror("Failed to open input file (system calls database)");
317 out1
= fopen(argv
[2],"wb");
320 perror("Failed to open output file (WIN32K service table)");
324 out2
= fopen(argv
[3],"wb");
327 perror("Failed to open output file (GDI32 stubs)");
331 out3
= fopen(argv
[4],"wb");
334 perror("Failed to open output file (USER32 stubs)");
338 ret
= process(in
,out2
,out3
);
340 ret
= makeSystemServiceTable(in
, out1
);