diff --git a/reactos/iface/native/genntdll.c b/reactos/iface/native/genntdll.c index e390c06d0d8..d9f752db0c9 100644 --- a/reactos/iface/native/genntdll.c +++ b/reactos/iface/native/genntdll.c @@ -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 * PROJECT: ReactOS version of ntdll * FILE: iface/native/genntdll.c * PURPOSE: Generates the system call stubs in ntdll * 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 ******************************************************************/ @@ -17,129 +23,195 @@ #define PARAMETERIZED_LIBS +#define VERBOSE + /* FUNCTIONS ****************************************************************/ -int process(FILE* in, FILE* out, FILE *out2) +int +process( + FILE * in, + FILE * out, + FILE * out2, + FILE * out3 + ) { - char line[255]; - char* s; - char* name; - char* name2; - int value; - char* nr_args; - char* stmp; + char line [255]; + char * s; + char * name; /* NtXXX name */ + char * name2; /* ZwXXX name */ + int value; + char * nr_args; /* stack_size / machine_word_size */ + char * stmp; - 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 "); - fprintf(out2,"\n\n\n"); - fprintf(out2,"SERVICE_TABLE _SystemServiceTable[256] = {\n"); - + unsigned char first1 = TRUE; - 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"); + /* + * NTDLL stubs file header + */ + fprintf(out,"// Machine generated, don't edit\n"); + fprintf(out,"\n\n"); + /* + * Service table header + */ + fprintf(out2,"// Machine generated, don't edit\n"); + fprintf(out2,"\n\n"); + //fprintf(out2,"#include "); + fprintf(out2,"\n\n\n"); + fprintf(out2,"SERVICE_TABLE _SystemServiceTable[256] = {\n"); + /* + * 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) - { - *stmp=0; - } - -// 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); + if ((stmp=strchr(nr_args,'\n'))!=NULL) + { + *stmp=0; + } +#ifdef VERBOSE + printf("name = \"%s\" value = %d\n",name,value); #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); + /* + * Write the NTDLL stub for the current + * system call: NtXXX and ZwXXX symbols + * 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 ) - first1 = FALSE; - else - fprintf(out2,",\n"); + if (first1 == TRUE) + { + first1 = FALSE; + } + 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[]) { - FILE* in; - FILE* out; - FILE *out2; - int ret; + FILE * in; /* System calls database */ + FILE * out; /* NTDLL stubs */ + FILE * out2; /* SERVICE_TABLE */ + FILE * out3; /* NTOSKRNL Zw stubs */ + int ret; - if (argc!=4) - { - usage(); - return(1); - } + if (argc != 5) + { + usage(argv[0]); + return(1); + } - in = fopen(argv[1],"rb"); - if (in==NULL) - { - perror("Failed to open input file"); - 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"); - return(1); - } - out2 = fopen(argv[3],"wb"); - if (out2==NULL) - { - perror("Failed to open output file"); - 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) + { + 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); - fclose(out); - fclose(out2); - - return(ret); + return(ret); } diff --git a/reactos/iface/native/makefile b/reactos/iface/native/makefile index d31d463c96a..78e356b2736 100644 --- a/reactos/iface/native/makefile +++ b/reactos/iface/native/makefile @@ -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): sysfuncs.lst genntdll$(EXE_POSTFIX) - genntdll$(EXE_POSTFIX) sysfuncs.lst ../../lib/ntdll/napi.c ../../include/ntdll/napi.h +$(NAPI_FILES): $(SYSTEM_CALLS_DB) $(TARGET)$(EXE_POSTFIX) + $(TARGET)$(EXE_POSTFIX) \ + $(SYSTEM_CALLS_DB) \ + $(NTDLL_STUBS) \ + $(KERNEL_SERVICE_TABLE) \ + $(KERNEL_ZW_CALLS) # (rjj) i removed the following option from line below: -If:\gnu\mingw32\include -genntdll$(EXE_POSTFIX): genntdll.c - $(NATIVE_CC) -g genntdll.c -o genntdll$(EXE_POSTFIX) +$(TARGET)$(EXE_POSTFIX): $(TARGET).c + $(NATIVE_CC) -g $(TARGET).c -o $(TARGET)$(EXE_POSTFIX) clean: - - $(RM) genntdll$(EXE_POSTFIX) + - $(RM) $(TARGET)$(EXE_POSTFIX) ifeq ($(DOSCLI),yes) - $(RM) ..\..\lib\ntdll\napi.c - $(RM) ..\..\include\ntdll\napi.h + - $(RM) ..\..\ntoskrnl\nt\zw.c else - - $(RM) ../../lib/ntdll/napi.c - - $(RM) ../../include/ntdll/napi.h + - $(RM) $(NTDLL_STUBS) + - $(RM) $(KERNEL_SERVICE_TABLE) + - $(RM) $(KERNEL_ZW_CALLS) endif .PHONY: all clean