03827fded7eb9e13565a33f6c2755ec7f7880c7b
1 /* $Id: genntdll.c,v 1.7 1999/06/17 18:09:27 ea 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 /* FUNCTIONS ****************************************************************/
39 char line
[INPUT_BUFFER_SIZE
];
41 char * name
; /* NtXXX name */
42 char * name2
; /* ZwXXX name */
43 int sys_call_idx
; /* NtXXX index number in the service table */
44 char * nr_args
; /* stack_size / machine_word_size */
48 * NTDLL stubs file header
50 fprintf(out
,"// Machine generated, don't edit\n");
53 * Service table header
55 fprintf(out2
,"// Machine generated, don't edit\n");
57 //fprintf(out2,"#include <ntddk.h>");
58 fprintf(out2
,"\n\n\n");
59 fprintf(out2
,"SERVICE_TABLE _SystemServiceTable[256] = {\n");
61 * NTOSKRNL Zw functions stubs header
63 fprintf(out3
,"// Machine generated, don't edit\n");
66 * Scan the database. DB is a text file; each line
67 * is a record, which contains data for one system
68 * function. Each record has three columns:
70 * NT_NAME (e.g. NtCreateProcess)
71 * ZW_NAME (e.g. ZwCreateProcess)
72 * STACK_SIZE (in machine words: for x[3456]86
73 * processors a machine word is 4 bytes)
75 for ( /* First system call has index zero */
77 /* Go on until EOF or read zero bytes */
79 && (fgets(line
, sizeof line
, in
) != NULL
)
81 /* Next system call index */
87 * Remove, if present, the trailing CR.
90 if ((s
= (char *) strchr(line
,'\r')) != NULL
)
95 * Skip comments (#) and empty lines.
98 if ((*s
) != '#' && (*s
) != '\0')
100 /* Extract the NtXXX name */
101 name
= (char *)strtok(s
," \t");
102 /* Extract the ZwXXX name */
103 name2
= (char *)strtok(NULL
," \t");
104 //value = strtok(NULL," \t");
105 /* Extract the stack size */
106 nr_args
= (char *)strtok(NULL
," \t");
108 * Remove, if present, the trailing LF.
110 if ((stmp
= strchr(nr_args
, '\n')) != NULL
)
115 printf("name = \"%s\" value = %d\n",name
,sys_call_idx
);
118 * Write the NTDLL stub for the current
119 * system call: NtXXX and ZwXXX symbols
122 #ifdef PARAMETERIZED_LIBS
123 fprintf(out
,"__asm__(\"\\n\\t.global _%s@%s\\n\\t\"\n",name
,nr_args
);
124 fprintf(out
,"\".global _%s@%s\\n\\t\"\n",name2
,nr_args
);
125 fprintf(out
,"\"_%s@%s:\\n\\t\"\n",name
,nr_args
);
126 fprintf(out
,"\"_%s@%s:\\n\\t\"\n",name2
,nr_args
);
128 fprintf(out
,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name
);
129 fprintf(out
,"\".global _%s\\n\\t\"\n",name2
);
130 fprintf(out
,"\"_%s:\\n\\t\"\n",name
);
131 fprintf(out
,"\"_%s:\\n\\t\"\n",name2
);
133 fprintf(out
,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx
);
134 fprintf(out
,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
135 fprintf(out
,"\t\"int\t$0x2E\\n\\t\"\n");
136 fprintf(out
,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args
);
138 * Mark the end of the previous service
139 * table's element (C array syntax). When
140 * the current function is the n-th, we
141 * close the (n - 1)-th entry.
143 if (sys_call_idx
> 0)
148 * Now write the current system call's name
149 * in the service table.
151 fprintf(out2
,"\t\t{ %s, (ULONG)%s }",nr_args
,name
);
153 * Now write the NTOSKRNL stub for the
154 * current system call. ZwXXX does NOT
155 * alias the corresponding NtXXX call.
157 fprintf(out3
,"__asm__(\n");
158 fprintf(out3
,"\".global _%s@%s\\n\\t\"\n",name2
,nr_args
);
159 fprintf(out3
,"\"_%s@%s:\\n\\t\"\n",name2
,nr_args
);
160 fprintf(out3
,"\t\"mov\t$%d,%%eax\\n\\t\"\n",sys_call_idx
);
161 fprintf(out3
,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
162 fprintf(out3
,"\t\"int\t$0x2E\\n\\t\"\n");
163 fprintf(out3
,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args
);
166 /* Close the service table (C syntax) */
167 fprintf(out2
,"\n};\n");
172 void usage(char * argv0
)
175 Usage: %s sysfuncs.lst napi.c napi.h zw.c\n\
176 sysfuncs.lst system functions database\n\
177 napi.c NTDLL stubs\n\
178 napi.h NTOSKRNL service table\n\
179 zw.c NTOSKRNL Zw stubs\n",
184 int main(int argc
, char* argv
[])
186 FILE * in
; /* System calls database */
187 FILE * out
; /* NTDLL stubs */
188 FILE * out2
; /* SERVICE_TABLE */
189 FILE * out3
; /* NTOSKRNL Zw stubs */
198 in
= fopen(argv
[1],"rb");
201 perror("Failed to open input file (system calls database)");
205 out
= fopen(argv
[2],"wb");
208 perror("Failed to open output file (NTDLL stubs)");
211 out2
= fopen(argv
[3],"wb");
214 perror("Failed to open output file (NTOSKRNL service table)");
217 out3
= fopen(argv
[4],"wb");
220 perror("Failed to open output file (NTOSKRNL Zw stubs)");
224 ret
= process(in
,out
,out2
,out3
);