mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 18:15:11 +00:00
genntdll enhanced to generate ntoskrnl Zw stubs (to be tested)
svn path=/trunk/; revision=556
This commit is contained in:
parent
6409ce374c
commit
1e589af8e1
2 changed files with 201 additions and 112 deletions
|
@ -1,9 +1,15 @@
|
||||||
/*
|
/* $Id: genntdll.c,v 1.6 1999/06/17 00:10:30 ea Exp $
|
||||||
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS version of ntdll
|
* PROJECT: ReactOS version of ntdll
|
||||||
* FILE: iface/native/genntdll.c
|
* FILE: iface/native/genntdll.c
|
||||||
* PURPOSE: Generates the system call stubs in ntdll
|
* PURPOSE: Generates the system call stubs in ntdll
|
||||||
* CHANGE HISTORY: Added a '@xx' to deal with stdcall [ Ariadne ]
|
* CHANGE HISTORY: Added a '@xx' to deal with stdcall [ Ariadne ]
|
||||||
|
* 19990616 (ea)
|
||||||
|
* Four arguments now required; 4th is the file
|
||||||
|
* for ntoskrnl ZwXXX functions (which are merely calls
|
||||||
|
* to twin NtXXX calls, via int 0x2e (x86).
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* INCLUDE ******************************************************************/
|
/* INCLUDE ******************************************************************/
|
||||||
|
@ -17,129 +23,195 @@
|
||||||
|
|
||||||
#define PARAMETERIZED_LIBS
|
#define PARAMETERIZED_LIBS
|
||||||
|
|
||||||
|
#define VERBOSE
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
int process(FILE* in, FILE* out, FILE *out2)
|
int
|
||||||
|
process(
|
||||||
|
FILE * in,
|
||||||
|
FILE * out,
|
||||||
|
FILE * out2,
|
||||||
|
FILE * out3
|
||||||
|
)
|
||||||
{
|
{
|
||||||
char line[255];
|
char line [255];
|
||||||
char* s;
|
char * s;
|
||||||
char* name;
|
char * name; /* NtXXX name */
|
||||||
char* name2;
|
char * name2; /* ZwXXX name */
|
||||||
int value;
|
int value;
|
||||||
char* nr_args;
|
char * nr_args; /* stack_size / machine_word_size */
|
||||||
char* stmp;
|
char * stmp;
|
||||||
|
|
||||||
unsigned char first1 = TRUE;
|
unsigned char first1 = TRUE;
|
||||||
|
|
||||||
fprintf(out,"// Machine generated, don't edit\n");
|
|
||||||
fprintf(out,"\n\n");
|
|
||||||
|
|
||||||
fprintf(out2,"// Machine generated, don't edit\n");
|
|
||||||
fprintf(out2,"\n\n");
|
|
||||||
//fprintf(out2,"#include <ntddk.h>");
|
|
||||||
fprintf(out2,"\n\n\n");
|
|
||||||
fprintf(out2,"SERVICE_TABLE _SystemServiceTable[256] = {\n");
|
|
||||||
|
|
||||||
|
|
||||||
value = 0;
|
/*
|
||||||
while (!feof(in) && fgets(line,255,in) != NULL)
|
* NTDLL stubs file header
|
||||||
{
|
*/
|
||||||
// fgets(line,255,in);
|
fprintf(out,"// Machine generated, don't edit\n");
|
||||||
if ((s=(char *)strchr(line,13))!=NULL)
|
fprintf(out,"\n\n");
|
||||||
{
|
/*
|
||||||
*s=0;
|
* Service table header
|
||||||
}
|
*/
|
||||||
s=&line[0];
|
fprintf(out2,"// Machine generated, don't edit\n");
|
||||||
if ((*s)!='#' && (*s) != 0)
|
fprintf(out2,"\n\n");
|
||||||
{
|
//fprintf(out2,"#include <ntddk.h>");
|
||||||
name = (char *)strtok(s," \t");
|
fprintf(out2,"\n\n\n");
|
||||||
name2 = (char *)strtok(NULL," \t");
|
fprintf(out2,"SERVICE_TABLE _SystemServiceTable[256] = {\n");
|
||||||
// value = strtok(NULL," \t");
|
/*
|
||||||
nr_args = (char *)strtok(NULL," \t");
|
* NTOSKRNL Zw functions stubs header
|
||||||
|
*/
|
||||||
|
fprintf(out3,"// Machine generated, don't edit\n");
|
||||||
|
fprintf(out3,"\n\n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scan the database. DB is a text file; each line
|
||||||
|
* is a record, which contains data for one system
|
||||||
|
* function. Each record has three columns:
|
||||||
|
*
|
||||||
|
* NT_NAME (e.g. NtCreateProcess)
|
||||||
|
* ZW_NAME (e.g. ZwCreateProcess)
|
||||||
|
* STACK_SIZE (in machine words: for x[3456]86
|
||||||
|
* processors a machine word is 4 bytes)
|
||||||
|
*/
|
||||||
|
value = 0;
|
||||||
|
while (!feof(in) && fgets(line,255,in) != NULL)
|
||||||
|
{
|
||||||
|
//fgets(line,255,in);
|
||||||
|
if ((s=(char *)strchr(line,13))!=NULL)
|
||||||
|
{
|
||||||
|
*s=0;
|
||||||
|
}
|
||||||
|
s = & line[0];
|
||||||
|
if ((*s)!='#' && (*s) != 0)
|
||||||
|
{
|
||||||
|
name = (char *)strtok(s," \t");
|
||||||
|
name2 = (char *)strtok(NULL," \t");
|
||||||
|
//value = strtok(NULL," \t");
|
||||||
|
nr_args = (char *)strtok(NULL," \t");
|
||||||
|
|
||||||
if ((stmp=strchr(nr_args,'\n'))!=NULL)
|
if ((stmp=strchr(nr_args,'\n'))!=NULL)
|
||||||
{
|
{
|
||||||
*stmp=0;
|
*stmp=0;
|
||||||
}
|
}
|
||||||
|
#ifdef VERBOSE
|
||||||
// printf("name %s value %d\n",name,value);
|
printf("name = \"%s\" value = %d\n",name,value);
|
||||||
#ifdef PARAMETERIZED_LIBS
|
|
||||||
fprintf(out,"__asm__(\"\\n\\t.global _%s@%s\\n\\t\"\n",name,nr_args);
|
|
||||||
fprintf(out,"\".global _%s@%s\\n\\t\"\n",name2,nr_args);
|
|
||||||
fprintf(out,"\"_%s@%s:\\n\\t\"\n",name,nr_args);
|
|
||||||
fprintf(out,"\"_%s@%s:\\n\\t\"\n",name2,nr_args);
|
|
||||||
#else
|
|
||||||
fprintf(out,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name);
|
|
||||||
fprintf(out,"\".global _%s\\n\\t\"\n",name2);
|
|
||||||
fprintf(out,"\"_%s:\\n\\t\"\n",name);
|
|
||||||
fprintf(out,"\"_%s:\\n\\t\"\n",name2);
|
|
||||||
#endif
|
#endif
|
||||||
fprintf(out,"\t\"mov\t$%d,%%eax\\n\\t\"\n",value);
|
/*
|
||||||
fprintf(out,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
|
* Write the NTDLL stub for the current
|
||||||
fprintf(out,"\t\"int\t$0x2E\\n\\t\"\n");
|
* system call: NtXXX and ZwXXX symbols
|
||||||
fprintf(out,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args);
|
* are aliases.
|
||||||
|
*/
|
||||||
|
#ifdef PARAMETERIZED_LIBS
|
||||||
|
fprintf(out,"__asm__(\"\\n\\t.global _%s@%s\\n\\t\"\n",name,nr_args);
|
||||||
|
fprintf(out,"\".global _%s@%s\\n\\t\"\n",name2,nr_args);
|
||||||
|
fprintf(out,"\"_%s@%s:\\n\\t\"\n",name,nr_args);
|
||||||
|
fprintf(out,"\"_%s@%s:\\n\\t\"\n",name2,nr_args);
|
||||||
|
#else
|
||||||
|
fprintf(out,"__asm__(\"\\n\\t.global _%s\\n\\t\"\n",name);
|
||||||
|
fprintf(out,"\".global _%s\\n\\t\"\n",name2);
|
||||||
|
fprintf(out,"\"_%s:\\n\\t\"\n",name);
|
||||||
|
fprintf(out,"\"_%s:\\n\\t\"\n",name2);
|
||||||
|
#endif
|
||||||
|
fprintf(out,"\t\"mov\t$%d,%%eax\\n\\t\"\n",value);
|
||||||
|
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);
|
||||||
|
|
||||||
|
/*
|
||||||
value++;
|
* Now write the current system call's name
|
||||||
|
* in the service table.
|
||||||
|
*/
|
||||||
|
value++;
|
||||||
|
|
||||||
if ( first1 == TRUE )
|
if (first1 == TRUE)
|
||||||
first1 = FALSE;
|
{
|
||||||
else
|
first1 = FALSE;
|
||||||
fprintf(out2,",\n");
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf(out2,",\n");
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(out2,"\t\t{ %s, (ULONG)%s }",nr_args,name);
|
fprintf(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.
|
||||||
|
*/
|
||||||
|
fprintf(out3,"__asm__(\n");
|
||||||
|
fprintf(out3,"\".global _%s@%s\\n\\t\"\n",name2,nr_args);
|
||||||
|
fprintf(out3,"\"_%s@%s:\\n\\t\"\n",name2,nr_args);
|
||||||
|
fprintf(out3,"\t\"mov\t$%d,%%eax\\n\\t\"\n",value);
|
||||||
|
fprintf(out3,"\t\"lea\t4(%%esp),%%edx\\n\\t\"\n");
|
||||||
|
fprintf(out3,"\t\"int\t$0x2E\\n\\t\"\n");
|
||||||
|
fprintf(out3,"\t\"ret\t$%s\\n\\t\");\n\n",nr_args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fprintf(out2,"\n};\n");
|
fprintf(out2,"\n};\n");
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage(void)
|
void usage(char * argv0)
|
||||||
{
|
{
|
||||||
printf("Usage: genntdll sysfuncs.lst outfile.asm outfile.h\n");
|
printf("\
|
||||||
|
Usage: %s sysfuncs.lst napi.c napi.h zw.c\n\
|
||||||
|
sysfuncs.lst system functions database\n\
|
||||||
|
napi.c NTDLL stubs\n\
|
||||||
|
napi.h NTOSKRNL service table\n\
|
||||||
|
zw.c NTOSKRNL Zw stubs\n",
|
||||||
|
argv0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
FILE* in;
|
FILE * in; /* System calls database */
|
||||||
FILE* out;
|
FILE * out; /* NTDLL stubs */
|
||||||
FILE *out2;
|
FILE * out2; /* SERVICE_TABLE */
|
||||||
int ret;
|
FILE * out3; /* NTOSKRNL Zw stubs */
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (argc!=4)
|
if (argc != 5)
|
||||||
{
|
{
|
||||||
usage();
|
usage(argv[0]);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
in = fopen(argv[1],"rb");
|
in = fopen(argv[1],"rb");
|
||||||
if (in==NULL)
|
if (in == NULL)
|
||||||
{
|
{
|
||||||
perror("Failed to open input file");
|
perror("Failed to open input file (system calls database)");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
out = fopen(argv[2],"wb");
|
out = fopen(argv[2],"wb");
|
||||||
if (out==NULL)
|
if (out == NULL)
|
||||||
{
|
{
|
||||||
perror("Failed to open output file");
|
perror("Failed to open output file (NTDLL stubs)");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
out2 = fopen(argv[3],"wb");
|
out2 = fopen(argv[3],"wb");
|
||||||
if (out2==NULL)
|
if (out2 == NULL)
|
||||||
{
|
{
|
||||||
perror("Failed to open output file");
|
perror("Failed to open output file (NTOSKRNL service table)");
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
out3 = fopen(argv[4],"wb");
|
||||||
|
if (out3 == NULL)
|
||||||
|
{
|
||||||
|
perror("Failed to open output file (NTOSKRNL Zw stubs)");
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = process(in,out,out2,out3);
|
||||||
|
|
||||||
ret = process(in,out,out2);
|
fclose(in);
|
||||||
|
fclose(out);
|
||||||
|
fclose(out2);
|
||||||
|
fclose(out3);
|
||||||
|
|
||||||
fclose(in);
|
return(ret);
|
||||||
fclose(out);
|
|
||||||
fclose(out2);
|
|
||||||
|
|
||||||
return(ret);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,43 @@
|
||||||
|
# $Id: makefile,v 1.8 1999/06/17 00:10:30 ea Exp $
|
||||||
#
|
#
|
||||||
|
# ReactOS Operating System
|
||||||
#
|
#
|
||||||
|
# Generate:
|
||||||
|
# - genntdll
|
||||||
|
# - ntoskrnl.exe service table;
|
||||||
|
# - ntoskrnl.exe Zw functions stubs to call Nt functions from kernel mode;
|
||||||
|
# - ntdll.dll stubs to call system functions from user mode applications.
|
||||||
#
|
#
|
||||||
|
TARGET = genntdll
|
||||||
|
SYSTEM_CALLS_DB = sysfuncs.lst
|
||||||
|
NTDLL_STUBS = ../../lib/ntdll/napi.c
|
||||||
|
KERNEL_SERVICE_TABLE = ../../include/ntdll/napi.h
|
||||||
|
KERNEL_ZW_CALLS = ../../ntoskrnl/nt/zw.c
|
||||||
|
NAPI_FILES = $(NTDLL_STUBS) $(KERNEL_SERVICE_TABLE) $(KERNEL_ZW_CALLS)
|
||||||
|
|
||||||
NAPI_FILES = ../../lib/ntdll/napi.c ../../include/ntdll/napi.h
|
all: $(TARGET)$(EXE_POSTFIX) $(NAPI_FILES)
|
||||||
|
|
||||||
all: genntdll$(EXE_POSTFIX) $(NAPI_FILES)
|
$(NAPI_FILES): $(SYSTEM_CALLS_DB) $(TARGET)$(EXE_POSTFIX)
|
||||||
|
$(TARGET)$(EXE_POSTFIX) \
|
||||||
$(NAPI_FILES): sysfuncs.lst genntdll$(EXE_POSTFIX)
|
$(SYSTEM_CALLS_DB) \
|
||||||
genntdll$(EXE_POSTFIX) sysfuncs.lst ../../lib/ntdll/napi.c ../../include/ntdll/napi.h
|
$(NTDLL_STUBS) \
|
||||||
|
$(KERNEL_SERVICE_TABLE) \
|
||||||
|
$(KERNEL_ZW_CALLS)
|
||||||
|
|
||||||
# (rjj) i removed the following option from line below: -If:\gnu\mingw32\include
|
# (rjj) i removed the following option from line below: -If:\gnu\mingw32\include
|
||||||
genntdll$(EXE_POSTFIX): genntdll.c
|
$(TARGET)$(EXE_POSTFIX): $(TARGET).c
|
||||||
$(NATIVE_CC) -g genntdll.c -o genntdll$(EXE_POSTFIX)
|
$(NATIVE_CC) -g $(TARGET).c -o $(TARGET)$(EXE_POSTFIX)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
- $(RM) genntdll$(EXE_POSTFIX)
|
- $(RM) $(TARGET)$(EXE_POSTFIX)
|
||||||
ifeq ($(DOSCLI),yes)
|
ifeq ($(DOSCLI),yes)
|
||||||
- $(RM) ..\..\lib\ntdll\napi.c
|
- $(RM) ..\..\lib\ntdll\napi.c
|
||||||
- $(RM) ..\..\include\ntdll\napi.h
|
- $(RM) ..\..\include\ntdll\napi.h
|
||||||
|
- $(RM) ..\..\ntoskrnl\nt\zw.c
|
||||||
else
|
else
|
||||||
- $(RM) ../../lib/ntdll/napi.c
|
- $(RM) $(NTDLL_STUBS)
|
||||||
- $(RM) ../../include/ntdll/napi.h
|
- $(RM) $(KERNEL_SERVICE_TABLE)
|
||||||
|
- $(RM) $(KERNEL_ZW_CALLS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: all clean
|
.PHONY: all clean
|
||||||
|
|
Loading…
Reference in a new issue