source: trunk/src/win32k/ldr/myldrOpen.cpp@ 1467

Last change on this file since 1467 was 1467, checked in by bird, 26 years ago

Corrections to make win32k work.
(And now it does work, at least at my test machine...)

File size: 5.8 KB
Line 
1/* $Id: myldrOpen.cpp,v 1.3 1999-10-27 02:02:58 bird Exp $
2 *
3 * myldrOpen - _ldrOpen.
4 *
5 * Copyright (c) 1998-1999 knut st. osmundsen
6 *
7 */
8
9
10/*******************************************************************************
11* Defined Constants And Macros *
12*******************************************************************************/
13#define INCL_DOSERRORS
14#define INCL_NOPMAPI
15
16/*******************************************************************************
17* Header Files *
18*******************************************************************************/
19#include <os2.h>
20
21#include "malloc.h"
22#include <memory.h>
23#include <stdlib.h>
24
25
26#include "log.h"
27#include <peexe.h>
28#include <exe386.h>
29#include "OS2Krnl.h"
30#include "pe2lx.h"
31#include "elf.h"
32#include "avl.h"
33#include "ldr.h"
34#include "ldrCalls.h"
35
36
37/**
38 * _ldrOpen override.
39 * @returns Return code.
40 * @param phFile Pointer to file handler. Holds filehandle on output.
41 * @param pszFilename Pointer to filename.
42 * @parma param3 Probably some flags.
43 */
44ULONG LDRCALL myldrOpen(PSFN phFile, char *pszFilename, ULONG param3)
45{
46 ULONG rc;
47 int i;
48
49 rc = _ldrOpen(phFile, pszFilename, param3);
50
51 if (rc == NO_ERROR)
52 kprintf(("_ldrOpen: phFile=%#.4x, flags=%#.8x, pszFn=%s\n", *phFile, param3, pszFilename));
53
54 if (rc == NO_ERROR)
55 {
56 static char achBuffer[sizeof(IMAGE_DOS_HEADER)];
57 PIMAGE_DOS_HEADER pMzHdr = (PIMAGE_DOS_HEADER)&achBuffer[0];
58 char *pach = &achBuffer[0];
59
60 /**
61 * See if this is an recognizable module format.
62 * This costs up to two disk reads!
63 */
64 rc = _ldrRead(*phFile, 0UL, pMzHdr, 0UL, sizeof(*pMzHdr), NULL);
65 if (rc == NO_ERROR)
66 {
67 if (pMzHdr->e_magic == IMAGE_DOS_SIGNATURE &&
68 pMzHdr->e_lfanew > sizeof(IMAGE_DOS_HEADER) && pMzHdr->e_lfanew < 0x04000000UL) /* Larger than 64 bytes and less that 64MB. */
69 { /* MZ header found */
70 /* read */
71 rc = _ldrRead(*phFile, pMzHdr->e_lfanew, pMzHdr, 0UL, 4UL, NULL);
72 if (rc == NO_ERROR && *(PULONG)pach == IMAGE_NT_SIGNATURE)
73 { /* PE signature found */
74 PMODULE pMod;
75
76 kprintf(("_ldrOpen: PE executable...\n"));
77 #pragma info(none)
78 if (/* invoke pe.exe or do conversion now? */ 1)
79 { /* pe2lx - win32k */
80 #pragma info(restore)
81 Pe2Lx * pPe2Lx = new Pe2Lx(*phFile);
82 if (pPe2Lx != NULL)
83 {
84 rc = pPe2Lx->init(pszFilename);
85 if (rc == NO_ERROR)
86 {
87 kprintf(("_ldrOpen: Successfully init of Pe2Lx object.\n"));
88 rc = addModule(*phFile, NULL, MOD_TYPE_PE2LX, pPe2Lx);
89 if (rc == NO_ERROR)
90 SetState(*phFile, HSTATE_OUR);
91 else
92 kprintf(("_ldrOpen: Failed to add the module. rc=%d\n"));
93 }
94 else
95 kprintf(("_ldrOpen: Failed to init Pe2Lx object. rc=%d\n"));
96 if (rc != NO_ERROR)
97 delete pPe2Lx;
98 }
99 else
100 kprintf(("_ldrOpen: Failed to allocate Pe2Lx object.\n"));
101 }
102 else
103 { /* pe.exe */
104 kprintf(("_ldrOpen: pe.exe - opening\n"));
105 _ldrClose(*phFile);
106 rc = _ldrOpen(phFile, "pe.exe", param3); /* path....! problems! */
107 kprintf(("_ldrOpen: pe.exe - open returned with rc = %d\n", rc));
108 }
109 }
110 rc = NO_ERROR;
111 }
112 else
113 {
114 if (*pach == '#')
115 {
116 /* unix styled script...? must be more than 64 bytes long.... */
117 char *pszStart = pach+1;
118 char *pszEnd;
119 kprintf(("_ldrOpen: unix script?\n"));
120 /* skip blanks */
121 while (*pszStart != '\0' && (*pszStart == ' ' || *pszStart == '\t'))
122 pszStart++;
123 if (*pszStart != '\0' && *pszStart != '\r' && *pszStart != '\n')
124 { /* find end-of-word */
125 while (*pszEnd != '\0' && *pszEnd != '\n' && *pszEnd != '\r'
126 && *pszEnd != '\t' && *pszEnd != ' ')
127 pszEnd++;
128 *pszEnd = '\0';
129 kprintf(("_ldrOpen: unix script - opening %s\n", pszStart));
130 _ldrClose(*phFile);
131 rc = _ldrOpen(phFile, pszStart, param3);
132 kprintf(("_ldrOpen: unix script - open returned with rc = %d\n", rc));
133 }
134 else
135 kprintf(("_ldrOpen: unix script - unexpected end of line/file. (line: %.10s\n", pach));
136 }
137 else if (pach[0] == ELFMAG0 && pach[1] == ELFMAG1 && pach[2] == ELFMAG2 && pach[3] == ELFMAG3)
138 {
139 /* ELF signature found */
140 kprintf(("_ldrOpen: ELF executable! - not implemented yet!\n"));
141 }
142 }
143 }
144 else
145 {
146 kprintf(("_ldrOpen: _ldrRead failed with rc=%d when reading DosHdr.\n", rc));
147 rc = NO_ERROR;
148 }
149 }
150 return rc;
151}
Note: See TracBrowser for help on using the repository browser.