1 /* $Id: mktab.cc,v 1.1 2000/02/20 22:52:47 ea Exp $
3 * COPYRIGHT: See COPYING in the top level directory
5 * FILE : iface/addsys/mktab.c
6 * PURPOSE : Generating any files required for a kernel module
7 * to register an additional system calls table in
11 * Derived from genntdll.c mainly to build
12 * win32k.sys functions table.
15 /* INCLUDE ******************************************************************/
23 #define INPUT_BUFFER_SIZE 255
25 #define DB_RECORD_NAME_SIZE 64
27 #define STACK_ENTRY_SIZE (sizeof(void*))
32 typedef unsigned int DWORD
;
34 typedef char * LPSTR
, CHAR
, * PCHAR
;
36 typedef void VOID
, * PVOID
;
41 CHAR Name
[DB_RECORD_NAME_SIZE
];
45 } DB_RECORD
, * PDB_RECORD
;
57 /* FUNCTIONS ****************************************************************/
60 void usage (char * argv0
)
63 "\nUsage: %s api.db mask table.c apistubs.c\n\n"
64 " api.db additional system functions database (NAME, ARG_COUNT)\n"
65 " mask service table mask (in hex; e.g. 0x1000000)\n"
66 " table.c service table file to be linked in the kernel module\n"
67 " apistubs.c stubs for user mode clients to call the API\n\n"
68 "NOTE: NAME must be an ASCII string and ARG_COUNT a decimal number;\n"
69 "between NAME and ARG_COUNT there must be at least one space or tab.\n",
76 CloseAllFiles (FILE * f0
, FILE * f1
, FILE * f2
)
90 CHAR InputBuffer
[INPUT_BUFFER_SIZE
];
92 static INT LineNumber
= 0;
95 if ( (NULL
== InputFile
)
99 fprintf (stderr
, "GetNextRecord: bad argument!\n");
102 while (TRUE
== BadData
)
104 if ( feof (InputFile
)
116 "GetNextRecord: EOF at line %d\n",
124 * Remove, if present, the trailing CR.
127 if (NULL
!= (s
= (char *) strchr (InputBuffer
,'\r')))
132 * Skip comments (#) and empty lines.
134 s
= & InputBuffer
[0];
152 "GetNextRecord: line %d: syntax error!\n",
157 Dbr
->StackSize
= (Dbr
->ArgumentCount
* sizeof (void*));
162 /* User mode service stubs file generation */
166 OutputStubPrologue (FILE * of
)
170 "/* Machine generated. Don't edit! */\n\n"
177 OutputStub (FILE * of
, PDB_RECORD Dbr
, INT Id
, DWORD Mask
)
179 DWORD CallId
= (Mask
| (DWORD
) Id
);
180 CHAR DecoratedName
[DB_RECORD_NAME_SIZE
];
190 "\t\".global %s\\n\\t\"\n"
192 "\t\"mov\t$0x%08x,%%eax\\n\\t\"\n"
193 "\t\"lea\t4(%%esp),%%edx\\n\\t\"\n"
194 "\t\"int\t$0x2E\\n\\t\"\n"
195 "\t\"ret\t$%d\\n\\t\"\n",
206 OutputStubEpilog (FILE * of
)
215 /* Service table file generation (used by the kernel module) */
219 OutputTablePrologue (FILE * of
)
223 "/* Machine generated. Don't edit! */\n\n"
224 "SERVICE_TABLE W32kServiceTable [] =\n{\n"
230 OutputTable (FILE * of
, PDB_RECORD Dbr
)
232 static BOOL First
= TRUE
;
258 OutputTableEpilog (FILE * of
)
270 main (int argc
, char * argv
[])
280 SELECT_TYPE ReturnValue
;
282 /* --- Check arguments --- */
290 /* --- Create files --- */
292 ApiDb
= fopen (argv
[1], "rb");
297 "%s: fatal: could not open the file \"%s\".\n",
303 printf ("< %s\n", argv
[1]);
305 Stubs
= fopen (argv
[3], "wb");
310 "%s: fatal: could not open the file \"%s\".\n",
314 CloseAllFiles (ApiDb
, Table
, Stubs
);
317 printf ("> %s\n", argv
[3]);
319 Table
= fopen (argv
[4], "wb");
324 "%s: fatal: could not open the file \"%s\".\n",
328 CloseAllFiles (ApiDb
, Table
, Stubs
);
331 printf ("> %s\n", argv
[4]);
333 /* --- Convert the mask value --- */
335 if (1 != sscanf (argv
[2], "%x", & Mask
))
339 "%s: fatal: could not convert the mask \"%s\".\n",
343 CloseAllFiles (ApiDb
, Table
, Stubs
);
346 printf ("& 0x%08x\n", Mask
);
348 /* --- Process data --- */
350 printf ("Processing data...\n");
351 OutputStubPrologue (Stubs
);
352 OutputTablePrologue (Table
);
353 while (SELECT_OK
== (ReturnValue
= GetNextRecord (ApiDb
, & Dbr
)))
355 if (TRUE
== OutputTable (Table
, & Dbr
))
357 if (FALSE
== OutputStub (Stubs
, & Dbr
, Id
, Mask
))
361 "%s: WARNING: %s has no user mode stub\n",
371 "%s: WARNING: %s skipped on I/O error\n",
386 if (SELECT_EOF
== ReturnValue
)
388 OutputStubEpilog (Stubs
);
389 OutputTableEpilog (Table
);
395 "%s: generated files may be incomplete!\n",
400 /* --- Close files --- */
402 CloseAllFiles (ApiDb
, Table
, Stubs
);