Ignore:
Timestamp:
Oct 14, 1999, 3:39:13 AM (26 years ago)
Author:
bird
Message:

New Pe2Lx implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winexepe2lx.cpp

    r956 r1274  
    1 /* $Id: winexepe2lx.cpp,v 1.1 1999-09-15 23:39:07 sandervl Exp $ */
     1/* $Id: winexepe2lx.cpp,v 1.2 1999-10-14 01:37:56 bird Exp $ */
    22
    33/*
     
    55 *
    66 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
    7  *
     7 * Copyright 1999 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
    88 *
    99 * Project Odin Software License can be found in LICENSE.TXT
    1010 *
    1111 */
    12 #define INCL_DOSFILEMGR          /* File Manager values      */
    13 #define INCL_DOSERRORS           /* DOS Error values         */
    14 #define INCL_DOSPROCESS          /* DOS Process values       */
    15 #define INCL_DOSMISC             /* DOS Miscellanous values  */
    16 #define INCL_WIN
    17 #include <os2wrap.h>    //Odin32 OS/2 api wrappers
    18 #include <stdio.h>
    19 #include <string.h>
    20 #include <stdlib.h>
    21 #include <iostream.h>
    22 #include <fstream.h>
     12
     13/*******************************************************************************
     14*   Defined Constants And Macros                                               *
     15*******************************************************************************/
     16#define INCL_DOSERRORS      /* DOS Error values         */
     17
     18
     19/*******************************************************************************
     20*   Header Files                                                               *
     21*******************************************************************************/
     22#include <os2wrap.h>        //Odin32 OS/2 api wrappers
     23
     24#include <stdlib.h>         //getenv
     25
    2326#include <misc.h>
    2427#include <win32type.h>
    2528#include <winexepe2lx.h>
    26 #include <wprocess.h>
    27 #include <pefile.h>
    28 #include "cio.h"
    2929
    30 #include "oslibmisc.h"
    31 #include "oslibdos.h"
    32 
    33 #include "conwin.h"          // Windows Header for console only
     30#include "cio.h"            // I/O
     31#include "oslibmisc.h"      // OSLibGetDllName
     32#include "conwin.h"         // Windows Header for console only
    3433#include "console.h"
    3534
    36 /******************************************************************************/
    37 //******************************************************************************
    38 void WIN32API RegisterPe2LxExe(WIN32EXEENTRY EntryPoint, PIMAGE_TLS_CALLBACK *TlsCallbackAddr,
    39                                LPDWORD TlsIndexAddr, ULONG TlsInitSize,
    40                                ULONG TlsTotalSize, LPVOID TlsAddress,
    41                                LONG Win32TableId, LONG NameTableId, LONG VersionResId,
    42                                LONG Pe2lxVersion, HINSTANCE hinstance, ULONG dwReserved)
     35
     36/**
     37 * Register a Pe2Lx Executable module.
     38 * This is called from the TIBFix code in the Pe2Lx exe. It creates the WinExe object from
     39 * the instance handle passed in.
     40 * @param     ulPe2LxVersion   Pe2Lx version number.
     41 * @param     hinstance        Module handle.
     42 * @param     ulReserved       Reserved.
     43 * @sketch    I/O init.
     44 *            Check that pe2lx version matches the version of kernel32.dll.
     45 *            Frees WinExe if is not NULL - should never happen!
     46 *            Write info to the log.
     47 *            Create Pe2Lx Exe object.
     48 *            Call start (which calls the entry point).
     49 * @status    completely implemented.
     50 * @author    Sander van Leeuwen, knut st. osmundsen
     51 */
     52void WIN32API RegisterPe2LxExe(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulReserved)
    4353{
    44   if(WinExe != NULL) //should never happen
    45         delete(WinExe);
     54    /* I/O init. */
     55    if (getenv("WIN32_IOPL2"))
     56        io_init1();
    4657
    47   CheckVersion(Pe2lxVersion, OSLibGetDllName(hinstance));
     58    /* Check that pe2lx version matches the version of kernel32.dll. */
     59    CheckVersion(ulPe2LxVersion & ~0x80000000UL, OSLibGetDllName(hinstance));
    4860
    49   if(getenv("WIN32_IOPL2")) {
    50     io_init1();
    51   }
     61    /* Frees WinExe if is not NULL - should never happen! */
     62    if (WinExe != NULL)
     63    {
     64        dprintf(("RegisterPe2LxExe: WinExe != NULL\n"));
     65        delete(WinExe);
     66    }
    5267
    53   Win32Pe2LxExe *winexe;
     68    /* Write info to the log. */
     69    dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
     70    dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
     71    dprintf(("RegisterPe2LxExe: ulReserved = %#x\n", ulReserved));
     72    dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
    5473
    55   winexe = new Win32Pe2LxExe(hinstance, NameTableId, Win32TableId);
     74    /* Create Pe2Lx Exe object. */
     75    try
     76    {
     77        Win32Pe2LxExe *pWinPe2LxExe;
     78        pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
     79        if (pWinPe2LxExe == NULL)
     80            throw ((ULONG)ERROR_NOT_ENOUGH_MEMORY);
    5681
    57   if(winexe) {
    58         dprintf(("RegisterExe Win32TableId = %x", Win32TableId));
    59         dprintf(("RegisterExe NameTableId  = %x", NameTableId));
    60         dprintf(("RegisterExe VersionResId = %x", VersionResId));
    61         dprintf(("RegisterExe Pe2lxVersion = %x", Pe2lxVersion));
     82        /* Call start (which calls the entry point). */
     83        /*DebugInt3();*/
     84        pWinPe2LxExe->start();
     85    }
     86    catch (ULONG ul)
     87    {
     88        eprintf(("Win32Pe2LxExe creation failed! ul=%d\n", ul));
     89        DebugInt3();
     90        return;
     91    }
     92}
    6293
    63         winexe->setVersionId(VersionResId);
    64         winexe->setEntryPoint((ULONG)EntryPoint);
    65         winexe->setTLSAddress(TlsAddress);
    66         winexe->setTLSInitSize(TlsInitSize);
    67         winexe->setTLSTotalSize(TlsTotalSize);
    68         winexe->setTLSIndexAddr(TlsIndexAddr);
    69         winexe->setTLSCallBackAddr(TlsCallbackAddr);
    7094
    71         winexe->start();
    72   }
    73   else {
    74         eprintf(("Win32Pe2LxExe creation failed!\n"));
    75         DebugInt3();
    76         return;
    77   }
     95/**
     96 * Constructor - creates an pe2lx exe object from a module handle to a pe2lx exe module.
     97 * @param     hinstance   Module handle.
     98 * @param     fWin32k     TRUE:  Win32k module.
     99 *                        FALSE: Pe2Lx module.
     100 * @status    completely implmented.
     101 * @author    Sander van Leeuwen, knut st. osmundsen
     102 * @remark    Win32Pe2LxImage may throw an exception!
     103 */
     104Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k) throw(ULONG):
     105    Win32ImageBase(hinstance),
     106    Win32ExeBase(hinstance),
     107    Win32Pe2LxImage(hinstance, fWin32k)
     108{
     109    fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
     110
     111    /* console app? */
     112    if (fConsoleApp)
     113    {
     114        APIRET rc;
     115
     116        dprintf(("Console application!\n"));
     117
     118        rc = iConsoleInit();    /* initialize console subsystem */
     119        if (rc != NO_ERROR)     /* check for errors */
     120            dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
     121    }
    78122}
    79 //******************************************************************************
    80 //******************************************************************************
    81 Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, int NameTableId, int Win32TableId) :
    82          Win32ImageBase(hinstance),
    83          Win32ExeBase(hinstance),
    84          Win32Pe2LxImage(hinstance, NameTableId, Win32TableId)
    85 {
    86   if(GET_CONSOLE(Win32TableId) == 1) {//console app
    87    dprintf(("Console application!\n"));
    88123
    89    fConsoleApp = TRUE;
    90    APIRET rc = iConsoleInit();                     /* initialize console subsystem */
    91    if (rc != NO_ERROR)                                  /* check for errors */
    92             dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
    93   }
    94   WinExe = this;
    95 }
    96 //******************************************************************************
    97 //******************************************************************************
     124
     125/**
     126 * Destructor - does nothing.
     127 * @status    completely implemented.
     128 * @author    Sander van Leeuwen
     129 */
    98130Win32Pe2LxExe::~Win32Pe2LxExe()
    99131{
    100132}
    101 //******************************************************************************
    102 //******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.