console separation 1/4

Eric Pouech eric.pouech at wanadoo.fr
Tue Jul 30 14:24:24 CDT 2002


this serie of 4 patches is dedicated to moving all client console code
from ntdll (DLL and directory) and put it into kernel (DLL and
directory)

3 preliminary patches are necessary:
1/ one to fix the process creation code (and mode the console related
bits from ntdll to kernel). This is done by 1/ moving the creation flag
from a static var into the env db, and then let the kernel
initialisation code take care of the console creation
2/ one to dispatch properly from ntdll some signals (by installing some
hooks)
3/ the last one is to let the (Read|Write)File code (which is in ntdll)
callback (Read|Write)Console (in kernel) by using a function pointer and
getting its address dynamically. This may disappear when the file
handling code is properly separated between ntdll and kernel

4/ then the remaining code from win32 directory is moved into
dlls/kernel


A+
-------------- next part --------------
Name:          con_cp
ChangeLog:     moved console creation code while in CreateProcess from ntdll to kernel
	put most of Wine internal Wine structures into wine/process.h
License:       X11
GenDate:       2002/07/30 19:13:29 UTC
ModifiedFiles: dlls/kernel/kernel_main.c memory/environ.c scheduler/process.c
AddedFiles:    include/wine/process.h
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/dlls/kernel/kernel_main.c,v
retrieving revision 1.29
diff -u -u -r1.29 kernel_main.c
--- dlls/kernel/kernel_main.c	16 May 2002 20:32:16 -0000	1.29
+++ dlls/kernel/kernel_main.c	30 Jul 2002 18:56:49 -0000
@@ -24,20 +24,22 @@
 #include <ctype.h>
 #include <string.h>
 #include <sys/stat.h>
 
 #include "winbase.h"
 
 #include "wine/winbase16.h"
 #include "wine/library.h"
+#include "wine/process.h"
 #include "file.h"
 #include "global.h"
 #include "miscemu.h"
 #include "module.h"
 #include "task.h"
+#include "wincon.h"
 
 extern void CODEPAGE_Init(void);
 extern BOOL RELAY_Init(void);
 
 
 /***********************************************************************
  *           KERNEL process initialisation routine
@@ -45,6 +50,7 @@
 static BOOL process_attach(void)
 {
     HMODULE16 hModule;
+    struct _PDB *pdb;
 
     /* Get the umask */
     FILE_umask = umask(0777);
@@ -99,6 +105,11 @@
 
     /* Create the shared heap for broken win95 native dlls */
     HeapCreate( HEAP_SHARED, 0, 0 );
+
+    pdb = (struct _PDB*)GetProcessDword(0, GPD_PDB);
+    if (pdb->flags & PDB32_CONSOLE_PROC && 
+        (pdb->env_db->dwCreationFlags & CREATE_NEW_CONSOLE))
+        AllocConsole();
 
     return TRUE;
 }
Index: memory/environ.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/memory/environ.c,v
retrieving revision 1.34
diff -u -u -r1.34 environ.c
--- memory/environ.c	31 May 2002 23:06:52 -0000	1.34
+++ memory/environ.c	30 Jul 2002 08:43:23 -0000
@@ -33,27 +33,7 @@
 #include "heap.h"
 #include "ntddk.h"
 #include "selectors.h"
-
-/* Win32 process environment database */
-typedef struct _ENVDB
-{
-    LPSTR            env;              /* 00 Process environment strings */
-    DWORD            unknown1;         /* 04 Unknown */
-    LPSTR            cmd_line;         /* 08 Command line */
-    LPSTR            cur_dir;          /* 0c Current directory */
-    STARTUPINFOA    *startup_info;     /* 10 Startup information */
-    HANDLE           hStdin;           /* 14 Handle for standard input */
-    HANDLE           hStdout;          /* 18 Handle for standard output */
-    HANDLE           hStderr;          /* 1c Handle for standard error */
-    DWORD            unknown2;         /* 20 Unknown */
-    DWORD            inherit_console;  /* 24 Inherit console flag */
-    DWORD            break_type;       /* 28 Console events flag */
-    void            *break_sem;        /* 2c SetConsoleCtrlHandler semaphore */
-    void            *break_event;      /* 30 SetConsoleCtrlHandler event */
-    void            *break_thread;     /* 34 SetConsoleCtrlHandler thread */
-    void            *break_handlers;   /* 38 List of console handlers */
-} ENVDB;
-
+#include "wine/process.h"
 
 /* Format of an environment block:
  * ASCIIZ   string 1 (xx=yy format)
@@ -74,7 +54,7 @@
 /* Maximum length of a Win16 environment string (including NULL) */
 #define MAX_WIN16_LEN  128
 
-STARTUPINFOA current_startupinfo =
+static STARTUPINFOA current_startupinfo =
 {
     sizeof(STARTUPINFOA),    /* cb */
     0,                       /* lpReserved */
Index: scheduler/process.c
===================================================================
RCS file: /home/cvs/cvsroot/wine/wine/scheduler/process.c,v
retrieving revision 1.191
diff -u -u -r1.191 process.c
--- scheduler/process.c	23 Jul 2002 21:02:31 -0000	1.191
+++ scheduler/process.c	30 Jul 2002 11:57:29 -0000
@@ -34,13 +34,13 @@
 #include "wine/winuser16.h"
 #include "wine/exception.h"
 #include "wine/library.h"
+#include "wine/process.h"
 #include "drive.h"
 #include "module.h"
 #include "file.h"
 #include "heap.h"
 #include "thread.h"
 #include "winerror.h"
-#include "wincon.h"
 #include "wine/server.h"
 #include "options.h"
 #include "wine/debug.h"
@@ -50,72 +50,11 @@
 WINE_DECLARE_DEBUG_CHANNEL(snoop);
 WINE_DECLARE_DEBUG_CHANNEL(win32);
 
-struct _ENVDB;
-
-/* Win32 process database */
-typedef struct _PDB
-{
-    LONG             header[2];        /* 00 Kernel object header */
-    HMODULE          module;           /* 08 Main exe module (NT) */
-    void            *event;            /* 0c Pointer to an event object (unused) */
-    DWORD            exit_code;        /* 10 Process exit code */
-    DWORD            unknown2;         /* 14 Unknown */
-    HANDLE           heap;             /* 18 Default process heap */
-    HANDLE           mem_context;      /* 1c Process memory context */
-    DWORD            flags;            /* 20 Flags */
-    void            *pdb16;            /* 24 DOS PSP */
-    WORD             PSP_sel;          /* 28 Selector to DOS PSP */
-    WORD             imte;             /* 2a IMTE for the process module */
-    WORD             threads;          /* 2c Number of threads */
-    WORD             running_threads;  /* 2e Number of running threads */
-    WORD             free_lib_count;   /* 30 Recursion depth of FreeLibrary calls */
-    WORD             ring0_threads;    /* 32 Number of ring 0 threads */
-    HANDLE           system_heap;      /* 34 System heap to allocate handles */
-    HTASK            task;             /* 38 Win16 task */
-    void            *mem_map_files;    /* 3c Pointer to mem-mapped files */
-    struct _ENVDB   *env_db;           /* 40 Environment database */
-    void            *handle_table;     /* 44 Handle table */
-    struct _PDB     *parent;           /* 48 Parent process */
-    void            *modref_list;      /* 4c MODREF list */
-    void            *thread_list;      /* 50 List of threads */
-    void            *debuggee_CB;      /* 54 Debuggee context block */
-    void            *local_heap_free;  /* 58 Head of local heap free list */
-    DWORD            unknown4;         /* 5c Unknown */
-    CRITICAL_SECTION crit_section;     /* 60 Critical section */
-    DWORD            unknown5[3];      /* 78 Unknown */
-    void            *console;          /* 84 Console */
-    DWORD            tls_bits[2];      /* 88 TLS in-use bits */
-    DWORD            process_dword;    /* 90 Unknown */
-    struct _PDB     *group;            /* 94 Process group */
-    void            *exe_modref;       /* 98 MODREF for the process EXE */
-    void            *top_filter;       /* 9c Top exception filter */
-    DWORD            priority;         /* a0 Priority level */
-    HANDLE           heap_list;        /* a4 Head of process heap list */
-    void            *heap_handles;     /* a8 Head of heap handles list */
-    DWORD            unknown6;         /* ac Unknown */
-    void            *console_provider; /* b0 Console provider (??) */
-    WORD             env_selector;     /* b4 Selector to process environment */
-    WORD             error_mode;       /* b6 Error mode */
-    HANDLE           load_done_evt;    /* b8 Event for process loading done */
-    void            *UTState;          /* bc Head of Univeral Thunk list */
-    DWORD            unknown8;         /* c0 Unknown (NT) */
-    LCID             locale;           /* c4 Locale to be queried by GetThreadLocale (NT) */
-} PDB;
-
 PDB current_process;
 
-/* Process flags */
-#define PDB32_DEBUGGED      0x0001  /* Process is being debugged */
-#define PDB32_WIN16_PROC    0x0008  /* Win16 process */
-#define PDB32_DOS_PROC      0x0010  /* Dos process */
-#define PDB32_CONSOLE_PROC  0x0020  /* Console process */
-#define PDB32_FILE_APIS_OEM 0x0040  /* File APIs are OEM */
-#define PDB32_WIN32S_PROC   0x8000  /* Win32s process */
-
 static char main_exe_name[MAX_PATH];
 static char *main_exe_name_ptr = main_exe_name;
 static HANDLE main_exe_file;
-static int main_create_flags;
 
 static unsigned int server_startticks;
 
@@ -123,7 +62,6 @@
 extern struct _ENVDB *ENV_InitStartupInfo( size_t info_size, char *main_exe_name,
                                            size_t main_exe_size );
 extern BOOL ENV_BuildCommandLine( char **argv );
-extern STARTUPINFOA current_startupinfo;
 
 /* scheduler/pthread.c */
 extern void PTHREAD_init_done(void);
@@ -222,13 +160,13 @@
     if ( dwFlags & USIG_FLAGS_GUI )
     {
         /* Feedback defaults to ON */
-        if ( !(current_startupinfo.dwFlags & STARTF_FORCEOFFFEEDBACK) )
+        if ( !(current_envdb.startup_info->dwFlags & STARTF_FORCEOFFFEEDBACK) )
             dwFlags |= USIG_FLAGS_FEEDBACK;
     }
     else
     {
         /* Feedback defaults to OFF */
-        if (current_startupinfo.dwFlags & STARTF_FORCEONFEEDBACK)
+        if (current_envdb.startup_info->dwFlags & STARTF_FORCEONFEEDBACK)
             dwFlags |= USIG_FLAGS_FEEDBACK;
     }
 
@@ -383,13 +321,13 @@
         req->ppid      = getppid();
         if ((ret = !wine_server_call_err( req )))
         {
-            main_exe_file     = reply->exe_file;
-            main_create_flags = reply->create_flags;
-            info_size         = reply->info_size;
-            server_startticks = reply->server_start;
-            current_startupinfo.hStdInput   = reply->hstdin;
-            current_startupinfo.hStdOutput  = reply->hstdout;
-            current_startupinfo.hStdError   = reply->hstderr;
+            main_exe_file                           = reply->exe_file;
+            current_envdb.dwCreationFlags           = reply->create_flags;
+            info_size                               = reply->info_size;
+            server_startticks                       = reply->server_start;
+            current_envdb.startup_info->hStdInput   = reply->hstdin;
+            current_envdb.startup_info->hStdOutput  = reply->hstdout;
+            current_envdb.startup_info->hStdError   = reply->hstderr;
         }
     }
     SERVER_END_REQ;
@@ -398,10 +336,10 @@
     /* Create the process heap */
     current_process.heap = HeapCreate( HEAP_GROWABLE, 0, 0 );
 
-    if (main_create_flags == 0 &&
-	current_startupinfo.hStdInput  == 0 &&
-	current_startupinfo.hStdOutput == 0 &&
-	current_startupinfo.hStdError  == 0)
+    if (current_envdb.dwCreationFlags == 0 &&
+	current_envdb.startup_info->hStdInput  == 0 &&
+	current_envdb.startup_info->hStdOutput == 0 &&
+	current_envdb.startup_info->hStdError  == 0)
     {
 	/* no parent, and no new console requested, create a simple console with bare handles to
 	 * unix stdio input & output streams (aka simple console)
@@ -414,11 +352,11 @@
         wine_server_fd_to_handle( 1, GENERIC_WRITE|SYNCHRONIZE, TRUE, &handle );
         SetStdHandle( STD_ERROR_HANDLE, handle );
     }
-    else if (!(main_create_flags & (DETACHED_PROCESS|CREATE_NEW_CONSOLE)))
+    else if (!(current_envdb.dwCreationFlags & (DETACHED_PROCESS|CREATE_NEW_CONSOLE)))
     {
-	SetStdHandle( STD_INPUT_HANDLE,  current_startupinfo.hStdInput  );
-	SetStdHandle( STD_OUTPUT_HANDLE, current_startupinfo.hStdOutput );
-	SetStdHandle( STD_ERROR_HANDLE,  current_startupinfo.hStdError  );
+	SetStdHandle( STD_INPUT_HANDLE,  current_envdb.startup_info->hStdInput  );
+	SetStdHandle( STD_OUTPUT_HANDLE, current_envdb.startup_info->hStdOutput );
+	SetStdHandle( STD_ERROR_HANDLE,  current_envdb.startup_info->hStdError  );
     }
 
     /* Now we can use the pthreads routines */
@@ -472,7 +410,6 @@
     if (console_app)
     {
         current_process.flags |= PDB32_CONSOLE_PROC;
-        if (main_create_flags & CREATE_NEW_CONSOLE) AllocConsole();
     }
 
     /* Signal the parent process to continue */
@@ -1347,30 +1284,30 @@
         return (DWORD)&current_process;
 
     case GPD_STARTF_SHELLDATA: /* return stdoutput handle from startupinfo ??? */
-        return current_startupinfo.hStdOutput;
+        return current_envdb.startup_info->hStdOutput;
 
     case GPD_STARTF_HOTKEY: /* return stdinput handle from startupinfo ??? */
-        return current_startupinfo.hStdInput;
+        return current_envdb.startup_info->hStdInput;
 
     case GPD_STARTF_SHOWWINDOW:
-        return current_startupinfo.wShowWindow;
+        return current_envdb.startup_info->wShowWindow;
 
     case GPD_STARTF_SIZE:
-        x = current_startupinfo.dwXSize;
+        x = current_envdb.startup_info->dwXSize;
         if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
-        y = current_startupinfo.dwYSize;
+        y = current_envdb.startup_info->dwYSize;
         if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
         return MAKELONG( x, y );
 
     case GPD_STARTF_POSITION:
-        x = current_startupinfo.dwX;
+        x = current_envdb.startup_info->dwX;
         if ( (INT)x == CW_USEDEFAULT ) x = CW_USEDEFAULT16;
-        y = current_startupinfo.dwY;
+        y = current_envdb.startup_info->dwY;
         if ( (INT)y == CW_USEDEFAULT ) y = CW_USEDEFAULT16;
         return MAKELONG( x, y );
 
     case GPD_STARTF_FLAGS:
-        return current_startupinfo.dwFlags;
+        return current_envdb.startup_info->dwFlags;
 
     case GPD_PARENT:
         return 0;
--- /dev/null	Thu Jan  1 01:00:00 1970
+++ include/wine/process.h	Tue Jul 30 13:57:42 2002
@@ -0,0 +1,103 @@
+/*
+ * Win32 processes
+ *
+ * Copyright 1996, 1998 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifdef __WINE__
+
+/* Win32 process environment database */
+typedef struct _ENVDB
+{
+    LPSTR            env;              /* 00 Process environment strings */
+    DWORD            dwCreationFlags;  /* 04 Unknown: in Wine, flags from CreateProcess parameters */
+    LPSTR            cmd_line;         /* 08 Command line */
+    LPSTR            cur_dir;          /* 0c Current directory */
+    STARTUPINFOA    *startup_info;     /* 10 Startup information */
+    HANDLE           hStdin;           /* 14 Handle for standard input */
+    HANDLE           hStdout;          /* 18 Handle for standard output */
+    HANDLE           hStderr;          /* 1c Handle for standard error */
+    DWORD            unknown2;         /* 20 Unknown */
+    DWORD            inherit_console;  /* 24 Inherit console flag */
+    DWORD            break_type;       /* 28 Console events flag */
+    void            *break_sem;        /* 2c SetConsoleCtrlHandler semaphore */
+    void            *break_event;      /* 30 SetConsoleCtrlHandler event */
+    void            *break_thread;     /* 34 SetConsoleCtrlHandler thread */
+    void            *break_handlers;   /* 38 List of console handlers */
+} ENVDB;
+
+extern ENVDB current_envdb;
+
+/* Win32 process database */
+typedef struct _PDB
+{
+    LONG             header[2];        /* 00 Kernel object header */
+    HMODULE          module;           /* 08 Main exe module (NT) */
+    void            *event;            /* 0c Pointer to an event object (unused) */
+    DWORD            exit_code;        /* 10 Process exit code */
+    DWORD            unknown2;         /* 14 Unknown */
+    HANDLE           heap;             /* 18 Default process heap */
+    HANDLE           mem_context;      /* 1c Process memory context */
+    DWORD            flags;            /* 20 Flags */
+    void            *pdb16;            /* 24 DOS PSP */
+    WORD             PSP_sel;          /* 28 Selector to DOS PSP */
+    WORD             imte;             /* 2a IMTE for the process module */
+    WORD             threads;          /* 2c Number of threads */
+    WORD             running_threads;  /* 2e Number of running threads */
+    WORD             free_lib_count;   /* 30 Recursion depth of FreeLibrary calls */
+    WORD             ring0_threads;    /* 32 Number of ring 0 threads */
+    HANDLE           system_heap;      /* 34 System heap to allocate handles */
+    HTASK            task;             /* 38 Win16 task */
+    void            *mem_map_files;    /* 3c Pointer to mem-mapped files */
+    struct _ENVDB   *env_db;           /* 40 Environment database */
+    void            *handle_table;     /* 44 Handle table */
+    struct _PDB     *parent;           /* 48 Parent process */
+    void            *modref_list;      /* 4c MODREF list */
+    void            *thread_list;      /* 50 List of threads */
+    void            *debuggee_CB;      /* 54 Debuggee context block */
+    void            *local_heap_free;  /* 58 Head of local heap free list */
+    DWORD            unknown4;         /* 5c Unknown */
+    CRITICAL_SECTION crit_section;     /* 60 Critical section */
+    DWORD            unknown5[3];      /* 78 Unknown */
+    void            *console;          /* 84 Console */
+    DWORD            tls_bits[2];      /* 88 TLS in-use bits */
+    DWORD            process_dword;    /* 90 Unknown */
+    struct _PDB     *group;            /* 94 Process group */
+    void            *exe_modref;       /* 98 MODREF for the process EXE */
+    void            *top_filter;       /* 9c Top exception filter */
+    DWORD            priority;         /* a0 Priority level */
+    HANDLE           heap_list;        /* a4 Head of process heap list */
+    void            *heap_handles;     /* a8 Head of heap handles list */
+    DWORD            unknown6;         /* ac Unknown */
+    void            *console_provider; /* b0 Console provider (??) */
+    WORD             env_selector;     /* b4 Selector to process environment */
+    WORD             error_mode;       /* b6 Error mode */
+    HANDLE           load_done_evt;    /* b8 Event for process loading done */
+    void            *UTState;          /* bc Head of Univeral Thunk list */
+    DWORD            unknown8;         /* c0 Unknown (NT) */
+    LCID             locale;           /* c4 Locale to be queried by GetThreadLocale (NT) */
+} PDB;
+
+/* Process flags */
+#define PDB32_DEBUGGED      0x0001  /* Process is being debugged */
+#define PDB32_WIN16_PROC    0x0008  /* Win16 process */
+#define PDB32_DOS_PROC      0x0010  /* Dos process */
+#define PDB32_CONSOLE_PROC  0x0020  /* Console process */
+#define PDB32_FILE_APIS_OEM 0x0040  /* File APIs are OEM */
+#define PDB32_WIN32S_PROC   0x8000  /* Win32s process */
+
+#endif


More information about the wine-patches mailing list