/* $Id$ * Init and cleanup code of libcaptive to be called by client application * Copyright (C) 2002 Jan Kratochvil * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; exactly version 2 of June 1991 is required * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "captive/client.h" /* self */ #include "captive/ldr.h" #include "captive/ldr_exports.h" #include "captive/unicode.h" #include "captive/file.h" #include #include #include "reactos/internal/ldr.h" #include "reactos/napi/types.h" #include "reactos/internal/kd.h" /* for KDB_LOADDRIVER_HOOK */ #include #include /* for PROT_READ, MAP_SHARED */ #include "reactos/ddk/kefuncs.h" /* for KeInitializeSpinLock() */ #include "reactos/internal/ntoskrnl.h" /* for RtlpInitNlsTables() and IoInit() */ #include "reactos/internal/ps.h" /* for PsInitProcessManagment() and PsInitThreadManagment() */ /* Are we initialized? */ static gboolean active; /* Module of fs module itself loaded by captive_init(fs_path) */ static PMODULE_OBJECT ModuleObject; /* Driver in fs module loaded by captive_init(fs_path) */ static DRIVER_OBJECT DriverObject_static; /** * captive_init: * @fs_path: #utf8 pathname to %.sys filesystem module file * * Initializes %libcaptive and loads the specified filesystem. * * Returns: %TRUE if successfuly loaded. */ gboolean captive_init(const gchar *fs_path) { NTSTATUS err; #ifdef MAINTAINER_MODE g_log_set_always_fatal(~(0 |G_LOG_LEVEL_MESSAGE |G_LOG_LEVEL_INFO |G_LOG_LEVEL_DEBUG )); #endif g_return_val_if_fail(fs_path!=NULL,FALSE); g_return_val_if_fail(active==FALSE,FALSE); /* Part of reactos/ntoskrnl/ke/main.c/KiSystemStartup() begins. */ /* ExpInitializeExecutive(); */ /* Part of reactos/ntoskrnl/ke/main.c/ExpInitializeExecutive() begins * here as the rest of the function does a lot of hardware initializations. */ /* LdrInit1(); */ /* Part of reactos/ntoskrnl/ldr/loader.c/LdrInit1() begins. */ InitializeListHead(&ModuleTextListHead); /* Part of reactos/ntoskrnl/ldr/loader.c/LdrInit1() ends. */ /*...*/ /* create default nls tables */ RtlpInitNlsTables(); /*...*/ ObInit(); /*...*/ /* PiInitProcessManager(); */ /* Part of reactos/ntoskrnl/ps/psmgr.c/PiInitProcessManager() begins. */ PsInitProcessManagment(); PsInitThreadManagment(); /* Part of reactos/ntoskrnl/ps/psmgr.c/PiInitProcessManager() ends. */ /*...*/ IoInit(); /*...*/ /* LdrInitModuleManagement(); */ /* Part of reactos/ntoskrnl/ldr/loader.c/LdrInitModuleManagement() begins * here as the rest "Create module object for {NTOSKRNL,HAL}" * is dependent on {NTOSKRNL,HAL} PE image headers not provided by libcaptive. */ /* Initialize the module list and spinlock */ InitializeListHead(&ModuleListHead); KeInitializeSpinLock(&ModuleListLock); /* Part of reactos/ntoskrnl/ldr/loader.c/LdrInitModuleManagement ends. */ /* 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} */ captive_kernel_exports(); err=captive_LdrpLoadAndCallImage( &ModuleObject, /* ModuleObjectp */ captive_utf8_to_UnicodeString_alloca(fs_path), /* ModuleName */ &DriverObject_static, /* DriverEntry_DriverObject */ captive_utf8_to_UnicodeString_alloca("\\FIXME\\FIXME")); /* DriverEntry_RegistryPath */ g_return_val_if_fail(NT_SUCCESS(err),FALSE); active=TRUE; return TRUE; } /** * captive_cleanup: * * Closes #libcaptive. Frees any used system resources. You are forbidden * to touch any #libcaptive data or funtions before a new captive_init() * is done. Forbidden to call it before successful captive_init() is done. * * Currently this function IS NOT IMPLEMENTED. * * Returns: %TRUE if the successful resource cleanup was done during the call. */ gboolean captive_cleanup(void) { NTSTATUS err; g_return_val_if_fail(active==TRUE,FALSE); err=LdrUnloadModule(ModuleObject); g_assert(NT_SUCCESS(err)); /* captive_cleanup() NOT IMPLEMENTED */ g_return_val_if_reached(FALSE); active=FALSE; return TRUE; }