PSX: The tool to build internal system calls tables and auxiliary C files.
authorEmanuele Aliberti <ea@iol.it>
Sat, 6 Apr 2002 16:07:34 +0000 (16:07 +0000)
committerEmanuele Aliberti <ea@iol.it>
Sat, 6 Apr 2002 16:07:34 +0000 (16:07 +0000)
svn path=/trunk/; revision=2825

posix/tools/Makefile [new file with mode: 0644]
posix/tools/mksystab.c [new file with mode: 0644]
posix/tools/syscall.db [new file with mode: 0644]

diff --git a/posix/tools/Makefile b/posix/tools/Makefile
new file mode 100644 (file)
index 0000000..2932ac4
--- /dev/null
@@ -0,0 +1,39 @@
+# $Id: Makefile,v 1.1 2002/04/06 16:07:34 ea Exp $
+#
+# Tool to generate the POSIX+ server system calls table
+# and other auxiliary C files.
+#
+PATH_TO_TOP=../../..
+PATH_TO_PSX_TOP=..
+
+TARGET_NAME=mksystab
+SYSCALL_DB=syscall.db
+SYSTAB_C=$(PATH_TO_PSX_TOP)/server/call/syscall.c
+SYSTAB_H=$(PATH_TO_PSX_TOP)/server/include/syscall.h
+SYSCALL_H=$(PATH_TO_PSX_TOP)/include/psx/syscall.h
+STUBS_C=$(PATH_TO_PSX_TOP)/server/call/stubs.c
+
+all: systab
+
+$(TARGET_NAME)$(EXE_POSTFIX): $(TARGET_NAME).c
+       $(CC) $(CFLAGS) -o $(TARGET_NAME)$(EXE_POSTFIX) $(TARGET_NAME).c
+
+systab: $(TARGET_NAME)$(EXE_POSTFIX)
+       $(TARGET_NAME)$(EXE_POSTFIX) \
+               $(SYSCALL_DB) \
+               $(SYSTAB_C) \
+               $(SYSTAB_H) \
+               $(SYSCALL_H) \
+               $(STUBS_C)
+
+clean:
+       - $(RM) $(TARGET_NAME)$(EXE_POSTFIX)
+       - $(RM) *.o
+       - $(RM) $(SYSTAB_C)
+       - $(RM) $(SYSTAB_H)
+       - $(RM) $(SYSCALL_H)
+       - $(RM) $(STUBS_C)
+
+include $(PATH_TO_TOP)/rules.mak
+
+# EOF
diff --git a/posix/tools/mksystab.c b/posix/tools/mksystab.c
new file mode 100644 (file)
index 0000000..ad820b3
--- /dev/null
@@ -0,0 +1,378 @@
+/* $Id: mksystab.c,v 1.1 2002/04/06 16:07:34 ea Exp $
+ *
+ * PROJECT    : ReactOS / POSIX+ Subsystem
+ * DESCRIPTION: Build the system calls table for
+ * DESCRIPTION: the POSIX+ LPC server process.
+ * NOTE       : this code is supposed to be portable.
+ * AUTHOR     : Emanuele Aliberti
+ * DATE       : 2001-05-26
+ * REVISIONS
+ *    2002-03-19 EA added stub file generation
+ *    2002-04-02 EA added to the CVS repository
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#define PARSER_CONTEXT_LINE_SIZE      1024
+#define PARSER_CONTEXT_INTERFACE_SIZE 64
+
+const char * myname = "mksystab";
+
+const char * syscall_name_prefix = "syscall_";
+const char * proxy_name_prefix = "psxss_";
+
+typedef enum {
+    METHOD_SUCCESS,
+    METHOD_EOF,
+    METHOD_FAILURE
+} METHOD_TYPE;
+
+typedef struct _PARSER_CONTEXT
+{
+    int line_number;
+    int id;
+    char line [PARSER_CONTEXT_LINE_SIZE];
+    char status;
+    char interface [PARSER_CONTEXT_INTERFACE_SIZE];
+    int argc;
+
+} PARSER_CONTEXT, * PPARSER_CONTEXT;
+
+typedef struct _MFILE
+{
+    char * name;
+    FILE * fp;
+    char * fopen_mode;
+    METHOD_TYPE (*prologue)(int,PPARSER_CONTEXT);
+    METHOD_TYPE (*iter)(int,PPARSER_CONTEXT);    
+    METHOD_TYPE (*epilog)(int,PPARSER_CONTEXT);    
+
+} MFILE, * PMFILE;
+
+/* MFILE file table */
+
+METHOD_TYPE db_prologue (int self, PPARSER_CONTEXT context);
+METHOD_TYPE db_iter (int self, PPARSER_CONTEXT context);
+METHOD_TYPE db_epilog (int self, PPARSER_CONTEXT context);
+
+METHOD_TYPE systab_prologue (int self, PPARSER_CONTEXT context);
+METHOD_TYPE systab_iter (int self, PPARSER_CONTEXT context);
+METHOD_TYPE systab_epilog (int self, PPARSER_CONTEXT context);
+
+METHOD_TYPE psx_include_prologue (int self, PPARSER_CONTEXT context);
+METHOD_TYPE psx_include_iter (int self, PPARSER_CONTEXT context);
+METHOD_TYPE psx_include_epilog (int self, PPARSER_CONTEXT context);
+
+METHOD_TYPE server_include_prologue (int self, PPARSER_CONTEXT context);
+METHOD_TYPE server_include_iter (int self, PPARSER_CONTEXT context);
+METHOD_TYPE server_include_epilog (int self, PPARSER_CONTEXT context);
+
+METHOD_TYPE stubs_prologue (int self, PPARSER_CONTEXT context);
+METHOD_TYPE stubs_iter (int self, PPARSER_CONTEXT context);
+METHOD_TYPE stubs_epilog (int self, PPARSER_CONTEXT context);
+
+
+MFILE mf [] =
+{ 
+  { NULL, NULL, "r", db_prologue,             db_iter,             db_epilog }, /* it must be 1st */
+  { NULL, NULL, "w", systab_prologue,         systab_iter,         systab_epilog },
+  { NULL, NULL, "w", server_include_prologue, server_include_iter, server_include_epilog },
+  { NULL, NULL, "w", psx_include_prologue,    psx_include_iter,    psx_include_epilog },
+  { NULL, NULL, "w", stubs_prologue,          stubs_iter,          stubs_epilog }
+};
+
+
+/* mf objects methods */
+
+int mf_open (int index)
+{
+    mf [index].fp = fopen (mf [index].name, mf [index].fopen_mode);
+    if (NULL == mf [index].fp)
+    {
+        fprintf (stderr, "%s: error %d while opening \"%s\".", myname, errno, mf [index].name);
+        return METHOD_FAILURE;
+    }
+    return METHOD_SUCCESS;
+}
+
+void mf_close (int index)
+{
+    fclose (mf[index].fp);
+}
+
+/* db file methods */
+
+METHOD_TYPE db_prologue (int self, PPARSER_CONTEXT context)
+{
+    if (METHOD_FAILURE == mf_open (self))
+    {
+        return METHOD_FAILURE;
+    }
+    fprintf (stderr, "Processing \"%s\"...\n", mf [self].name);
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE db_iter (int self, PPARSER_CONTEXT context)
+{
+    char * eol;
+
+    do 
+    {
+        if (feof(mf [self].fp))
+        {
+            return METHOD_EOF;
+        }
+        if (NULL == fgets (context->line, PARSER_CONTEXT_LINE_SIZE, mf [self].fp))
+        {
+            return METHOD_EOF;
+        }
+        ++ context->line_number;
+        eol = strchr(context->line, '\n');
+        if (eol)
+        {
+            *eol = '\0';
+        }
+        /* Is line empty or a comment? */
+    } while (0 == strlen (context->line) || context->line[0] == '#');
+    /* Line is not a comment nor an empty line */
+    if (3 != sscanf (context->line, "%c%s%d", & context->status, context->interface, & context->argc))
+    {
+        fprintf (stderr, "Syntax error at line %d.\n", context->line_number);
+        return METHOD_FAILURE;
+    }
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE db_epilog (int self, PPARSER_CONTEXT context)
+{
+    mf_close (self);
+    return METHOD_SUCCESS;
+}
+
+/* systab file methods */
+
+METHOD_TYPE systab_prologue (int self, PPARSER_CONTEXT context)
+{
+    if (METHOD_FAILURE == mf_open (self))
+    {
+        return METHOD_FAILURE;
+    }
+    fprintf (mf[self].fp, "/* POSIX+ system calls (machine generated: do not edit!) */\n");
+    fprintf (mf[self].fp, "#include <psxss.h>\n");
+    fprintf (mf[self].fp, "#include <syscall.h>\n");
+    fprintf (mf[self].fp, "PSX_SYSTEM_CALL SystemCall [] =\n");
+    fprintf (mf[self].fp, "{\n");
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE systab_iter (int self, PPARSER_CONTEXT context)
+{
+    switch (context->status)
+    {
+    case '+':
+    case '-': /* unimplemented interface */
+        fprintf (mf[self].fp, "(void*)%s%s,\n", syscall_name_prefix, context->interface);
+        break;
+    default:
+        fprintf (stderr, "%s: unknown interface status \"%c\" at line %d.\n",
+            myname, context->status, context->line_number);
+        return METHOD_FAILURE;
+    }
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE systab_epilog (int self, PPARSER_CONTEXT context)
+{
+    fprintf (mf[self].fp,  "0\n};\n");
+    fputs ("/* EOF */", mf[self].fp);
+    return METHOD_SUCCESS;
+}
+
+
+/* server/include file methods */
+
+METHOD_TYPE server_include_prologue (int self, PPARSER_CONTEXT context)
+{
+    if (METHOD_FAILURE == mf_open (self))
+    {
+        return METHOD_FAILURE;
+    }
+    fprintf (mf[self].fp, "/* POSIX+ system calls (machine generated: do not edit!) */\n");
+    fprintf (mf[self].fp, "#ifndef _SERVER_SYSCALL_H\n");
+    fprintf (mf[self].fp, "#define _SERVER_SYSCALL_H\n");
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE server_include_iter (int self, PPARSER_CONTEXT context)
+{
+    char interface [PARSER_CONTEXT_INTERFACE_SIZE*2];
+
+    sprintf (interface, "%s%s", syscall_name_prefix, context->interface);
+    fprintf (mf[self].fp, "NTSTATUS STDCALL %s (PPSX_MAX_MESSAGE);\n", interface);
+
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE server_include_epilog (int self, PPARSER_CONTEXT context)
+{
+    fprintf (mf[self].fp, "#endif /* ndef _SERVER_SYSCALL_H */\n");
+    fputs ("/* EOF */", mf[self].fp);
+    return METHOD_SUCCESS;
+}
+
+
+/* psx/include file methods */
+
+METHOD_TYPE psx_include_prologue (int self, PPARSER_CONTEXT context)
+{
+    if (METHOD_FAILURE == mf_open (self))
+    {
+        return METHOD_FAILURE;
+    }
+    fprintf (mf[self].fp, "/* POSIX+ system calls (machine generated: do not edit!) */\n");
+    fprintf (mf[self].fp, "#ifndef _PSX_SYSCALL_H\n");
+    fprintf (mf[self].fp, "#define _PSX_SYSCALL_H\n");
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE psx_include_iter (int self, PPARSER_CONTEXT context)
+{
+    char interface [PARSER_CONTEXT_INTERFACE_SIZE*2];
+
+    sprintf (interface, "%s%s", proxy_name_prefix, context->interface);
+    fprintf (mf[self].fp, "#define %s %d\n", strupr(interface), context->id ++);
+
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE psx_include_epilog (int self, PPARSER_CONTEXT context)
+{
+    fprintf (mf[self].fp, "#endif /* ndef _PSX_SYSCALL_H */\n");
+    fputs ("/* EOF */", mf[self].fp);
+    return METHOD_SUCCESS;
+}
+
+
+/* stubs file methods */
+
+METHOD_TYPE stubs_prologue (int self, PPARSER_CONTEXT context)
+{
+    if (METHOD_FAILURE == mf_open (self))
+    {
+        return METHOD_FAILURE;
+    }
+    fprintf( mf[self].fp,
+        "/* POSIX+ system calls not yet implemented */\n"
+        "/* (machine generated: do not edit!) */\n"
+        "#include <psxss.h>\n");
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE stubs_iter (int self, PPARSER_CONTEXT context)
+{
+    if ('-' == context->status)
+    {
+        fprintf (
+            mf[self].fp,
+            "NTSTATUS STDCALL %s%s(PPSX_MAX_MESSAGE Msg){Msg->PsxHeader.Status=STATUS_NOT_IMPLEMENTED;return(STATUS_SUCCESS);}\n",
+            syscall_name_prefix,
+            context->interface
+            );
+    }
+    return METHOD_SUCCESS;
+}
+
+METHOD_TYPE stubs_epilog (int self, PPARSER_CONTEXT context)
+{
+    fputs ("/* EOF */", mf[self].fp);
+    return METHOD_SUCCESS;
+}
+
+
+/* main loop */
+
+METHOD_TYPE mksystab ()
+{
+    int index;
+    int index_top = (sizeof mf / sizeof mf[0]);
+    int iterate = 1;
+    PARSER_CONTEXT context;
+    METHOD_TYPE mt;
+
+    /* initialize the parser's context */
+    context.line_number = 0;
+    context.id = 0;
+
+    /* prologue */
+    for (index = 0; index < index_top; index ++)
+    {
+        if (METHOD_FAILURE == mf[index].prologue (index, & context))
+        {
+            return METHOD_FAILURE;
+        }
+    }
+    /* iter */
+    while (iterate)
+    {
+        for (index = 0; index < index_top; index ++)
+        {
+            mt = mf[index].iter (index, & context);
+            if (METHOD_EOF == mt)
+            {
+                if (0 == index) /* input MUST be 1st MFILE */
+                {
+                    iterate = 0;
+                    break; /* input reached EOF */
+                }
+                return METHOD_FAILURE;
+            }
+            else if (METHOD_FAILURE == mt)
+            {
+                return METHOD_FAILURE;
+            }
+        }
+    }
+    /* epilog */
+    for (index = 0; index < index_top; index ++)
+    {
+        if (METHOD_FAILURE == mf[index].epilog (index, & context))
+        {
+            return METHOD_FAILURE;
+        }
+    }
+
+    /* done */
+    return METHOD_SUCCESS;
+}
+
+/* entry point */
+
+int main (int argc, char **argv)
+{
+    int status = 0;
+    int index;
+   
+    /* Check user parameters */ 
+    if ((1 + (sizeof mf / sizeof (MFILE))) != argc)
+    {
+        printf ("ReactOS Operating System - POSIX+ Environment Subsystem\n");
+        printf ("Build the system calls table of the POSIX+ server.\n\n");
+        printf ("usage: %s syscall.db syscall.c syscall.h syscall.h stubs.c\n", argv[0]);
+        exit (METHOD_FAILURE);
+    }
+    /* initialize descriptors */
+    for (index = 0; index < (sizeof mf / sizeof mf[0]); index ++)
+    {      
+        mf [index].name = argv [index + 1];
+    }
+
+    /* do process them */
+    status = mksystab ();
+
+    return (status);
+}
+
+
+/* EOF */
diff --git a/posix/tools/syscall.db b/posix/tools/syscall.db
new file mode 100644 (file)
index 0000000..7b1292b
--- /dev/null
@@ -0,0 +1,130 @@
+# $Id: syscall.db,v 1.1 2002/04/06 16:07:34 ea Exp $
+#
+# ReactOS - Operating System
+# Symbolic system calls table for the POSIX+ server.
+#
+# NOTE: the PSXSS server implements only the system calls
+# that can NOT be implemented in full/correctly in the
+# PSXDLL library.
+#
+# ENTRY SYNTAX
+#      status interface_name argc
+#
+# status = + | -
+#
+# LEGENDA
+# + means the system call is implemented in the server;
+# - means "{errno=ENOSYS;return -1;}".
+#
++ null             0
+- fork             0
+- authenticateuser 0
+- waitpid          3
++ _exit            1
+- kill             2
+- sigaction        3
+- sigprocmask      3
+- sigpending       1
+- sigsuspend       1
+- alarm            1
+- getpsids         0
+- syscall12        0
+- syscall13        0
+- getgroups        2
+- syscall15        0
+- syscall16        0
+- setsid           0
+- setpgid          2
+- syscall19        0
+- syscall20        0
+- times            1
+- ttyname          3
+- isatty           1
+- sysconf          1
+- open             2
+- umask            1
+- link             2
+- mkdir            2
+- mkfifo           2
+- rmdir            1
+- rename           2
+- stat             2
+- fstat            2
+- access           2
+- chmod            2
+- chown            3
+- utime            2
+- pathconf         2
+- fpathconf        2
+- pipe             1
+- syscall41        0
+- dup2             2
+- close            1
+- read             3
+- write            3
+- fcntl            3
+- lseek            3
+- tcgetattr        2
+- tcsetattr        3
+- tcsendbreak      2
+- tcdrain          1
+- tcflush          2
+- tcflow           2
+- tcgetpgrp        1
+- tcsetpgrp        2
+- getpwuid         1
+- getpwnam         1
+- getgrgid         1
+- getgrnam         1
+- unlink           1
+- readdir          1
+- ftruncate        2
+- syscall63        0
+- semctl           4
+- semget           3
+- semop            3
+- shmat            3
+- shmctl           3
+- shmdt            1
+- shmget           3
+- msgctl           3
+- msgget           2
+- msgrcv           5
+- msgsnd           4
+- socket           3
+- accept           3
+- bind             3
+- connect          3
+- getpeername      3
+- getsockname      3
+- getsockopt       5
+- listen           2
+- recv             4
+- recvfrom         6
+- send             4
+- sendto           6
+- setsockopt       5
+- shutdown         2
+- gethostbyname    1
+- gethostbyaddr    3
+- getprotobyname   1
+- getprotobynumber 1
+- getservbyname    2
+- getservbyport    2
+- select           5
+- statvfs          2
+- fstatvfs         2
+- ptsname          1
+- _fdptcheck       0
+- ioctl            2
+- mmap             6
+- syscall102       0
+- uidtontsid       1
+- gettzenv         0
+- pututxline       1
+- renamewtmpx      0
+- fsync            1
+- setgetitimer     0
+- setuser          0
+- ipcs             0
+# EOF