mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 17:44:45 +00:00
changed syscall tables. now it mimics NT style.
it has a SSDT a SSPT, a KeServiceDescriptorTable and a KeServiceDescriptorTableShadow. genntdll now also generates some useful defines about min syscall number, max syscall number, and number of syscalls. svn path=/trunk/; revision=958
This commit is contained in:
parent
1220167730
commit
65a742ceaa
1 changed files with 201 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $Id: genntdll.c,v 1.8 1999/06/18 22:10:58 ea Exp $
|
||||
/* $Id: genntdll.c,v 1.9 2000/01/23 15:14:42 hochoa Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS version of ntdll
|
||||
|
@ -11,7 +11,7 @@
|
|||
* to twin NtXXX calls, via int 0x2e (x86).
|
||||
* 19990617 (ea)
|
||||
* Fixed a bug in function numbers in kernel ZwXXX stubs.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* INCLUDE ******************************************************************/
|
||||
|
@ -28,6 +28,174 @@
|
|||
|
||||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
int makeSystemServiceTable(FILE *in, FILE *out)
|
||||
{
|
||||
char line [INPUT_BUFFER_SIZE];
|
||||
char *s;
|
||||
char *name;
|
||||
char *name2;
|
||||
int sys_call_idx;
|
||||
char *nr_args;
|
||||
char *stmp;
|
||||
|
||||
/*
|
||||
* Main SSDT Header
|
||||
*/
|
||||
fprintf(out,"// Machine generated, don't edit\n");
|
||||
fprintf(out,"\n\n");
|
||||
|
||||
/*
|
||||
* First we build the Main SSDT
|
||||
*
|
||||
*/
|
||||
fprintf(out,"\n\n\n");
|
||||
fprintf(out,"SSDT MainSSDT[] = {\n");
|
||||
|
||||
for ( /* First system call has index zero */
|
||||
sys_call_idx = 0;
|
||||
/* Go on until EOF or read zero bytes */
|
||||
( (!feof(in))
|
||||
&& (fgets(line, sizeof line, in) != NULL)
|
||||
);
|
||||
/* Next system call index */
|
||||
sys_call_idx++
|
||||
)
|
||||
{
|
||||
if ((s = (char *) strchr(line,'\r')) != NULL)
|
||||
{
|
||||
*s = '\0';
|
||||
}
|
||||
/*
|
||||
* Skip comments (#) and empty lines.
|
||||
*/
|
||||
s = & line[0];
|
||||
if ((*s) != '#' && (*s) != '\0')
|
||||
{
|
||||
/* Extract the NtXXX name */
|
||||
name = (char *)strtok(s," \t");
|
||||
/* Extract the ZwXXX name */
|
||||
name2 = (char *)strtok(NULL," \t");
|
||||
//value = strtok(NULL," \t");
|
||||
/* Extract the stack size */
|
||||
nr_args = (char *)strtok(NULL," \t");
|
||||
/*
|
||||
* Remove, if present, the trailing LF.
|
||||
*/
|
||||
if ((stmp = strchr(nr_args, '\n')) != NULL)
|
||||
{
|
||||
*stmp = '\0';
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("%3d \"%s\"\n",sys_call_idx,name);
|
||||
#endif
|
||||
|
||||
if (sys_call_idx > 0)
|
||||
{
|
||||
fprintf(out,",\n");
|
||||
}
|
||||
/*
|
||||
* Now write the current system call's name
|
||||
* in the service table.
|
||||
*/
|
||||
fprintf(out,"\t\t{ (ULONG)%s }",name);
|
||||
|
||||
}
|
||||
}
|
||||
/* Close the service table (C syntax) */
|
||||
fprintf(out,"\n};\n");
|
||||
|
||||
/*
|
||||
* Now we build the Main SSPT
|
||||
*
|
||||
*/
|
||||
rewind(in);
|
||||
fprintf(out,"\n\n\n");
|
||||
fprintf(out,"SSPT MainSSPT[] = {\n");
|
||||
|
||||
for ( /* First system call has index zero */
|
||||
sys_call_idx = 0;
|
||||
/* Go on until EOF or read zero bytes */
|
||||
( (!feof(in))
|
||||
&& (fgets(line, sizeof line, in) != NULL)
|
||||
);
|
||||
/* Next system call index */
|
||||
sys_call_idx++
|
||||
)
|
||||
{
|
||||
if ((s = (char *) strchr(line,'\r')) != NULL)
|
||||
{
|
||||
*s = '\0';
|
||||
}
|
||||
/*
|
||||
* Skip comments (#) and empty lines.
|
||||
*/
|
||||
s = & line[0];
|
||||
if ((*s) != '#' && (*s) != '\0')
|
||||
{
|
||||
/* Extract the NtXXX name */
|
||||
name = (char *)strtok(s," \t");
|
||||
/* Extract the ZwXXX name */
|
||||
name2 = (char *)strtok(NULL," \t");
|
||||
//value = strtok(NULL," \t");
|
||||
/* Extract the stack size */
|
||||
nr_args = (char *)strtok(NULL," \t");
|
||||
/*
|
||||
* Remove, if present, the trailing LF.
|
||||
*/
|
||||
if ((stmp = strchr(nr_args, '\n')) != NULL)
|
||||
{
|
||||
*stmp = '\0';
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
printf("%3d \"%s\"\n",sys_call_idx,name);
|
||||
#endif
|
||||
|
||||
if (sys_call_idx > 0)
|
||||
{
|
||||
fprintf(out,",\n");
|
||||
}
|
||||
/*
|
||||
* Now write the current system call's ID
|
||||
* in the service table along with its Parameters Size.
|
||||
*/
|
||||
fprintf(out,"\t\t{ %s }",nr_args);
|
||||
|
||||
}
|
||||
}
|
||||
/* Close the service table (C syntax) */
|
||||
fprintf(out,"\n};\n");
|
||||
|
||||
// We write some useful defines
|
||||
fprintf(out, "\n\n#define MIN_SYSCALL_NUMBER 0\n");
|
||||
fprintf(out, "#define MAX_SYSCALL_NUMBER %d\n", sys_call_idx-1);
|
||||
fprintf(out, "#define NUMBER_OF_SYSCALLS %d\n", sys_call_idx);
|
||||
fprintf(out, "#define SSDTSHADOW_MAX_ENTRIES 2\n");
|
||||
|
||||
// Now write the KeServiceDescriptorTable
|
||||
fprintf(out, "\n\n// These Service Descriptor Table its exported by NTOSKRNL and can be used\n");
|
||||
fprintf(out, "// by Device Drivers to hook system services\n");
|
||||
fprintf(out, "\n\nKE_SERVICE_DESCRIPTOR_TABLE_ENTRY KeServiceDescriptorTable = {\n"
|
||||
"\t\tMainSSDT,\n"
|
||||
"\t\tNULL,\n"
|
||||
"\t\tNUMBER_OF_SYSCALLS,\n"
|
||||
"\t\tMainSSPT\n\t\t};\n");
|
||||
|
||||
// Now write the KeServiceDescriptorTableShadow
|
||||
// This would be used when win32k.sys gets implemented
|
||||
fprintf(out, "\n\n// These Service Descriptor Table will be used by the win32k.sys driver\n");
|
||||
fprintf(out, "\n\nKE_SERVICE_DESCRIPTOR_TABLE_ENTRY KeServiceDescriptorTableShadow[SSDTSHADOW_MAX_ENTRIES] = {\n"
|
||||
"\t\t{ MainSSDT, NULL, NUMBER_OF_SYSCALLS, MainSSPT },\n"
|
||||
"\t\t{ NULL, NULL, 0, NULL }\n"
|
||||
"};\n");
|
||||
|
||||
|
||||
|
||||
return(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
process(
|
||||
FILE * in,
|
||||
|
@ -43,7 +211,7 @@ process(
|
|||
int sys_call_idx; /* NtXXX index number in the service table */
|
||||
char * nr_args; /* stack_size / machine_word_size */
|
||||
char * stmp;
|
||||
|
||||
|
||||
/*
|
||||
* NTDLL stubs file header
|
||||
*/
|
||||
|
@ -52,11 +220,14 @@ process(
|
|||
/*
|
||||
* Service table header
|
||||
*/
|
||||
fprintf(out2,"// Machine generated, don't edit\n");
|
||||
fprintf(out2,"\n\n");
|
||||
//Hfprintf(out2,"// Machine generated, don't edit\n");
|
||||
//Hfprintf(out2,"\n\n");
|
||||
|
||||
//fprintf(out2,"#include <ntddk.h>");
|
||||
fprintf(out2,"\n\n\n");
|
||||
fprintf(out2,"SERVICE_TABLE _SystemServiceTable[256] = {\n");
|
||||
|
||||
//H fprintf(out2,"\n\n\n");
|
||||
//H fprintf(out2,"SERVICE_TABLE _SystemServiceTable[256] = {\n");
|
||||
|
||||
/*
|
||||
* NTOSKRNL Zw functions stubs header
|
||||
*/
|
||||
|
@ -72,7 +243,7 @@ process(
|
|||
* STACK_SIZE (in machine words: for x[3456]86
|
||||
* processors a machine word is 4 bytes)
|
||||
*/
|
||||
for ( /* First system call has index zero */
|
||||
for ( /* First system call has index zero */
|
||||
sys_call_idx = 0;
|
||||
/* Go on until EOF or read zero bytes */
|
||||
( (!feof(in))
|
||||
|
@ -134,22 +305,25 @@ process(
|
|||
fprintf(out,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
|
||||
fprintf(out,"\t\"int\t$0x2E\\n\\t\"\n");
|
||||
fprintf(out,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args);
|
||||
/*
|
||||
|
||||
/*
|
||||
* Mark the end of the previous service
|
||||
* table's element (C array syntax). When
|
||||
* the current function is the n-th, we
|
||||
* close the (n - 1)-th entry.
|
||||
*/
|
||||
if (sys_call_idx > 0)
|
||||
{
|
||||
fprintf(out2,",\n");
|
||||
}
|
||||
//Hif (sys_call_idx > 0)
|
||||
//H{
|
||||
//H fprintf(out2,",\n");
|
||||
//H}
|
||||
|
||||
/*
|
||||
* Now write the current system call's name
|
||||
* in the service table.
|
||||
*/
|
||||
fprintf(out2,"\t\t{ %s, (ULONG)%s }",nr_args,name);
|
||||
/*
|
||||
//Hfprintf(out2,"\t\t{ %s, (ULONG)%s }",nr_args,name);
|
||||
|
||||
/*
|
||||
* Now write the NTOSKRNL stub for the
|
||||
* current system call. ZwXXX does NOT
|
||||
* alias the corresponding NtXXX call.
|
||||
|
@ -164,8 +338,8 @@ process(
|
|||
}
|
||||
}
|
||||
/* Close the service table (C syntax) */
|
||||
fprintf(out2,"\n};\n");
|
||||
|
||||
//Hfprintf(out2,"\n};\n");
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
@ -188,32 +362,35 @@ int main(int argc, char* argv[])
|
|||
FILE * out2; /* SERVICE_TABLE */
|
||||
FILE * out3; /* NTOSKRNL Zw stubs */
|
||||
int ret;
|
||||
|
||||
|
||||
if (argc != 5)
|
||||
{
|
||||
usage(argv[0]);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
in = fopen(argv[1],"rb");
|
||||
if (in == NULL)
|
||||
{
|
||||
perror("Failed to open input file (system calls database)");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
out = fopen(argv[2],"wb");
|
||||
if (out == NULL)
|
||||
{
|
||||
perror("Failed to open output file (NTDLL stubs)");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
out2 = fopen(argv[3],"wb");
|
||||
if (out2 == NULL)
|
||||
{
|
||||
perror("Failed to open output file (NTOSKRNL service table)");
|
||||
return(1);
|
||||
}
|
||||
|
||||
out3 = fopen(argv[4],"wb");
|
||||
if (out3 == NULL)
|
||||
{
|
||||
|
@ -222,11 +399,13 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
ret = process(in,out,out2,out3);
|
||||
|
||||
rewind(in);
|
||||
ret = makeSystemServiceTable(in, out2);
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
fclose(out2);
|
||||
fclose(out3);
|
||||
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue