+Commandline option '--load-module'
authorshort <>
Thu, 30 Jan 2003 10:59:06 +0000 (10:59 +0000)
committershort <>
Thu, 30 Jan 2003 10:59:06 +0000 (10:59 +0000)
 - loads W32-PE/.so module; it does not run DriverEntry() init on it
 - it is now mandatory to load W32 ntoskrnl.exe
-call ExpInitLookasideLists()
 - we now use "pass"ed W32 implementation of LookasideList
+support of <patch>ed W32 modules (currently only ntoskrnl.exe)
Filesystem DriverEntry() has now fully initialized W32 environment

src/libcaptive/client/init.c

index 13a6d8c..343e3c3 100644 (file)
@@ -39,9 +39,9 @@
 #include "captive/signal.h"    /* for captive_signal_init() */
 #include "reactos/ddk/psfuncs.h"       /* for PsGetCurrentThread() */
 #include <stdio.h>
-#include "reactos/internal/ex.h"       /* for ExpInitLookasideLists() */
 #include <popt.h>
 #include <glib/gstrfuncs.h>
+#include <glib/glist.h>
 
 
 /* Are we initialized? */
@@ -62,6 +62,7 @@ enum captive_option_rwmode captive_option_rwmode=CAPTIVE_OPTION_RWMODE_BLIND;
 enum captive_option_media captive_option_media=CAPTIVE_OPTION_MEDIA_DISK;
 GIOChannel *captive_image_iochannel;
 guint64 captive_image_size;
+static GList *captive_load_module;
 
 
 static gchar *captive_popt_optarg;
@@ -73,6 +74,11 @@ static void arg_filesystem(void)
        captive_option_filesystem=g_strdup(captive_popt_optarg);
 }
 
+static void arg_load_module(void)
+{
+       captive_load_module=g_list_append(captive_load_module,g_strdup(captive_popt_optarg));
+}
+
 static void arg_ro(void)
 {
        captive_option_rwmode=CAPTIVE_OPTION_RWMODE_RO;
@@ -118,12 +124,13 @@ const struct poptOption captive_popt[]={
 #define CAPTIVE_POPT_NONE(longname,descripP) \
                CAPTIVE_POPT(longname,POPT_ARG_NONE  ,NULL                ,descripP,NULL       )
 
-               CAPTIVE_POPT_STRING("filesystem",N_("Path to .sys or .so filesystem module file"),N_("pathname")),
-               CAPTIVE_POPT_NONE(  "ro"        ,N_("Read/write mode: Any write access will be forbidden")),
-               CAPTIVE_POPT_NONE(  "blind"     ,N_("Read/write mode: All writes are just simulated in memory (default)")),
-               CAPTIVE_POPT_NONE(  "rw"        ,N_("Read/write mode: Write directly to the image file/device")),
-               CAPTIVE_POPT_NONE(  "cdrom"     ,N_("Media type: CD-ROM")),
-               CAPTIVE_POPT_NONE(  "disk"      ,N_("Media type: Disk (default)")),
+               CAPTIVE_POPT_STRING("filesystem" ,N_("Path to .sys or .so filesystem module file"),N_("pathname")),
+               CAPTIVE_POPT_STRING("load-module",N_("Path to any W32 module to load w/o initialization"),N_("pathname")),
+               CAPTIVE_POPT_NONE(  "ro"         ,N_("Read/write mode: Any write access will be forbidden")),
+               CAPTIVE_POPT_NONE(  "blind"      ,N_("Read/write mode: All writes are just simulated in memory (default)")),
+               CAPTIVE_POPT_NONE(  "rw"         ,N_("Read/write mode: Write directly to the image file/device")),
+               CAPTIVE_POPT_NONE(  "cdrom"      ,N_("Media type: CD-ROM")),
+               CAPTIVE_POPT_NONE(  "disk"       ,N_("Media type: Disk (default)")),
 
 #undef CAPTIVE_POPT_NONE
 #undef CAPTIVE_POPT_STRING
@@ -140,6 +147,7 @@ static const struct poptOption captive_popt_standalone[]={
 
 static void (*const popt_func_table[])(void)={
                arg_filesystem,
+               arg_load_module,
                arg_ro,
                arg_blind,
                arg_rw,
@@ -211,10 +219,6 @@ GIOStatus erriostatus;
                        /* Part of reactos/ntoskrnl/ps/psmgr.c/PiInitProcessManager() ends. */
                /*...*/
                IoInit();
-               /* Exinit(); */
-                       /* Part of reactos/ntoskrnl/ex/init.c/Exinit() begins. */
-                       ExpInitLookasideLists();
-                       /* Part of reactos/ntoskrnl/ex/init.c/Exinit() ends. */
                /*...*/
                /* LdrInitModuleManagement(); */
                        /* Part of reactos/ntoskrnl/ldr/loader.c/LdrInitModuleManagement() begins
@@ -228,7 +232,7 @@ GIOStatus erriostatus;
                /* Part of reactos/ntoskrnl/ke/main.c/ExpInitializeExecutive() ends. */
        /* Part of reactos/ntoskrnl/ke/main.c/KiSystemStartup() ends. */
 
-       /* Simulate our PE headers and export the symbols of {NTOSKRNL,HAL} */
+       /* Simulate our PE headers and export the symbols of our complete libraries */
        captive_kernel_exports();
 
        errbool=captive_cdrom_init();
@@ -236,12 +240,22 @@ GIOStatus erriostatus;
        errbool=captive_disk_init();
        g_return_val_if_fail(errbool==TRUE,FALSE);
 
-       err=captive_LdrpLoadAndCallImage(
-                       &ModuleObject,  /* ModuleObjectp */
-                       captive_utf8_to_UnicodeString_alloca(captive_option_filesystem),        /* ModuleName */
-                       &DriverObject,  /* DriverEntry_DriverObject */
-                       captive_utf8_to_UnicodeString_alloca("\\captive\\filesystem")); /* DriverEntry_RegistryPath */
-       g_return_val_if_fail(NT_SUCCESS(err),FALSE);
+       while (captive_load_module) {
+gchar *modulename=captive_load_module->data;
+PMODULE_OBJECT ModuleObject_tmp;
+NTSTATUS err;
+
+               /* load the module */
+               err=LdrLoadModule(
+                               captive_utf8_to_UnicodeString_alloca(modulename),       /* ModuleName */
+                               &ModuleObject_tmp);     /* ModuleObjectp */
+               g_return_val_if_fail(NT_SUCCESS(err),FALSE);
+
+               captive_load_module=g_list_remove(captive_load_module,modulename);
+               }
+
+       /* Patch 'ntoskrnl.exe' loaded by 'captive_load_module' above. */
+       captive_kernel_patches();
 
        /* set TopLevelIrp() - FIXME: where is it set by native reactos? */
        PsGetCurrentThread()->TopLevelIrp=&TopLevelIrp; /* otherwise Io{Get,Set}TopLevelIrp() would SIGSEGV */
@@ -252,6 +266,16 @@ GIOStatus erriostatus;
         */
        captive_signal_init();
 
+       /* You must have already captive_signal_init() passed here as the module may
+        * call some functions from W32 ntoskrnl.exe.
+        */
+       err=captive_LdrpLoadAndCallImage(
+                       &ModuleObject,  /* ModuleObjectp */
+                       captive_utf8_to_UnicodeString_alloca(captive_option_filesystem),        /* ModuleName */
+                       &DriverObject,  /* DriverEntry_DriverObject */
+                       captive_utf8_to_UnicodeString_alloca("\\captive\\filesystem")); /* DriverEntry_RegistryPath */
+       g_return_val_if_fail(NT_SUCCESS(err),FALSE);
+
        return TRUE;
 }