Index: trunk/src/kernel32/windll.cpp
===================================================================
--- trunk/src/kernel32/windll.cpp	(revision 543)
+++ trunk/src/kernel32/windll.cpp	(revision 544)
@@ -1,3 +1,3 @@
-/* $Id: windll.cpp,v 1.8 1999-07-07 08:42:48 sandervl Exp $ */
+/* $Id: windll.cpp,v 1.9 1999-08-18 12:24:16 sandervl Exp $ */
 
 /*
@@ -154,5 +154,5 @@
 //******************************************************************************
 //******************************************************************************
-BOOL Win32Dll::init()
+BOOL Win32Dll::init(ULONG reservedMem)
 {
  char  *syspath;
@@ -177,5 +177,5 @@
 	else	fclose(dllfile);
 	if(isPEImage(szFileName) == TRUE) {
-		fRet = Win32Image::init();
+		fRet = Win32Image::init(0);
 		dllEntryPoint = (WIN32DLLENTRY)entryPoint;
 		return fRet;
Index: trunk/src/kernel32/winimage.cpp
===================================================================
--- trunk/src/kernel32/winimage.cpp	(revision 543)
+++ trunk/src/kernel32/winimage.cpp	(revision 544)
@@ -1,8 +1,8 @@
-/* $Id: winimage.cpp,v 1.9 1999-08-17 17:04:52 sandervl Exp $ */
+/* $Id: winimage.cpp,v 1.10 1999-08-18 12:24:16 sandervl Exp $ */
 
 /*
  * Win32 PE Image class
  *
- * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
+ * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
  * Copyright 1998 Knut St. Osmundsen
  *
@@ -25,6 +25,4 @@
 #include <stdlib.h>
 
-//#include <iostream.h>
-//#include <fstream.h>
 #include <assert.h>
 #include "misc.h"
@@ -136,29 +134,29 @@
 
   if(NameTable)
-    DosFreeResource((PVOID)NameTable);
+    	DosFreeResource((PVOID)NameTable);
 
   if(Win32Table)
-    DosFreeResource((PVOID)Win32Table);
+    	DosFreeResource((PVOID)Win32Table);
 
   while(winres)
   {
-    res    = winres->next;
-    delete(winres);
-    winres = res;
+    	res    = winres->next;
+    	delete(winres);
+    	winres = res;
   }
   if(realBaseAddress)
-    DosFreeMem((PVOID)realBaseAddress);
+    	DosFreeMem((PVOID)realBaseAddress);
 
   if(nameexports)
-    free(nameexports);
+    	free(nameexports);
 
   if(ordexports)
-    free(ordexports);
+    	free(ordexports);
   if(fullpath)
-    free(fullpath);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL Win32Image::init()
+    	free(fullpath);
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32Image::init(ULONG reservedMem)
 {
  HFILE  win32handle;
@@ -170,4 +168,5 @@
  ULONG  filesize, ulRead;
  PIMAGE_SECTION_HEADER psh;
+ IMAGE_TLS_DIRECTORY *tlsDir = NULL;
  int    nSections, i;
 
@@ -185,7 +184,7 @@
 
   if (rc != NO_ERROR) {
-    sprintf(szErrorMsg, "Unable to open %32s\n", szFileName);
+    	sprintf(szErrorMsg, "Unable to open %32s\n", szFileName);
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    errorState = ERROR_INTERNAL;
+    	errorState = ERROR_INTERNAL;
         return(FALSE);
   }
@@ -198,52 +197,52 @@
   win32file = malloc(filesize);
   if(win32file == NULL) {
-    fout << "Error allocating memory" << endl;
+    	fout << "Error allocating memory" << endl;
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    DosClose(win32handle);                /* Close the file */
-    errorState = ERROR_INTERNAL;
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	errorState = ERROR_INTERNAL;
+    	return(FALSE);
   }
   rc = DosRead(win32handle, win32file, filesize, &ulRead);
   if(rc != NO_ERROR) {
-    fout << "DosRead returned " << rc << endl;
+    	fout << "DosRead returned " << rc << endl;
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szFileErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    DosClose(win32handle);                /* Close the file */
-    errorState = ERROR_INTERNAL;
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	errorState = ERROR_INTERNAL;
+    	return(FALSE);
   }
 
   if(GetPEFileHeader (win32file, &fh) == FALSE) {
-    fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl;
+    	fout << "Not a valid PE file (probably a 16 bits windows exe/dll)!" << endl;
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    DosClose(win32handle);                /* Close the file */
-    errorState = ERROR_INTERNAL;
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	errorState = ERROR_INTERNAL;
+    	return(FALSE);
   }
 
   if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid
-    fout << "Not a valid PE file!" << endl;
+    	fout << "Not a valid PE file!" << endl;
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szPEErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    DosClose(win32handle);                /* Close the file */
-    errorState = ERROR_INTERNAL;
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	errorState = ERROR_INTERNAL;
+    	return(FALSE);
   }
   if(fh.Machine != IMAGE_FILE_MACHINE_I386) {
-    fout << "You need a REAL CPU to run this code" << endl;
+    	fout << "You need a REAL CPU to run this code" << endl;
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szCPUErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    DosClose(win32handle);                /* Close the file */
-    errorState = ERROR_INTERNAL;
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	errorState = ERROR_INTERNAL;
+    	return(FALSE);
   }
   //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)?
   if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
-    fout << "Can't convert system files" << endl;
+    	fout << "Can't convert system files" << endl;
         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szExeErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
-    DosClose(win32handle);                /* Close the file */
-    errorState = ERROR_INTERNAL;
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	errorState = ERROR_INTERNAL;
+    	return(FALSE);
   }
 
   if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) {
-    fout << "No fixups, might not run!" << endl;
+    	fout << "No fixups, might not run!" << endl;
   }
 
@@ -270,11 +269,9 @@
     fout << endl << "*************************PE SECTIONS START**************************" << endl;
     for (i=0; i<nSections; i++) {
-        fout << "Raw data size:       " << psh[i].SizeOfRawData << endl;
-        fout << "Virtual Address:     " << psh[i].VirtualAddress << endl;
-        fout << "Virtual Size:        " << psh[i].Misc.VirtualSize << endl;
-        fout << "Pointer to raw data: " << psh[i].PointerToRawData << endl;
-        fout.setf(ios::hex, ios::basefield);
-        fout << "Section flags:       " << psh[i].Characteristics << endl << endl;
-        fout.setf(ios::dec, ios::basefield);
+        fout << "Raw data size:       " << hex(psh[i].SizeOfRawData) << endl;
+        fout << "Virtual Address:     " << hex(psh[i].VirtualAddress) << endl;
+        fout << "Virtual Size:        " << hex(psh[i].Misc.VirtualSize) << endl;
+        fout << "Pointer to raw data: " << hex(psh[i].PointerToRawData) << endl;
+        fout << "Section flags:       " << hex(psh[i].Characteristics) << endl << endl;
         if(strcmp(psh[i].Name, ".reloc") == 0) {
             fout << ".reloc" << endl << endl;
@@ -298,4 +295,20 @@
             continue;
         }
+ 	if(strcmp(psh[i].Name, ".tls") == 0)
+	{
+		tlsDir = (IMAGE_TLS_DIRECTORY *)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_TLS);
+		if(tlsDir) {
+			fout << "TLS Directory" << endl;
+			fout << "TLS Address of Index     " << hex((ULONG)tlsDir->AddressOfIndex) << endl;
+			fout << "TLS Address of Callbacks " << hex((ULONG)tlsDir->AddressOfCallBacks) << endl;
+			fout << "TLS SizeOfZeroFill       " << hex(tlsDir->SizeOfZeroFill) << endl;
+			fout << "TLS Characteristics      " << hex(tlsDir->Characteristics) << endl;
+		        addSection(SECTION_TLS, (char *)win32file+psh[i].PointerToRawData,
+                		   psh[i].SizeOfRawData, psh[i].VirtualAddress + oh.ImageBase,
+                   		   psh[i].Misc.VirtualSize);
+		}
+		continue;
+	}
+
         if(strcmp(psh[i].Name, ".debug") == 0) {
             fout << ".rdebug" << endl << endl;
@@ -371,42 +384,71 @@
 
   if(imageSize != imageVirtEnd - oh.ImageBase) {
-    fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
-    imageSize = imageVirtEnd - oh.ImageBase;
-  }
-  if(allocSections() == FALSE) {
-    fout << "Failed to allocate image memory, rc " << errorState << endl;
-    return(FALSE);
+    	fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
+    	imageSize = imageVirtEnd - oh.ImageBase;
+  }
+  if(allocSections(reservedMem) == FALSE) {
+    	fout << "Failed to allocate image memory, rc " << errorState << endl;
+    	return(FALSE);
   }
   fout << "OS/2 base address " << baseAddress << endl;
   if(storeSections() == FALSE) {
-    fout << "Failed to store sections, rc " << errorState << endl;
-    return(FALSE);
+    	fout << "Failed to store sections, rc " << errorState << endl;
+    	return(FALSE);
   }
   entryPoint = baseAddress + oh.AddressOfEntryPoint;
 
-  if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) {
-    fout << "Failed to set fixups" << endl;
-    return(FALSE);
-  }
+  if(tlsDir != NULL) {
+   Section *sect = findSection(SECTION_TLS);
+
+	if(sect == NULL) {
+		fout << "Couldn't find TLS section!!" << endl;
+		return(FALSE);
+	}
+  	setTLSAddress((char *)(sect->realvirtaddr + (tlsDir->StartAddressOfRawData - sect->virtaddr)));
+  	setTLSInitSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData);
+  	setTLSTotalSize(tlsDir->EndAddressOfRawData - tlsDir->StartAddressOfRawData + tlsDir->SizeOfZeroFill);
+
+	sect = findSectionByAddr((ULONG)tlsDir->AddressOfIndex);
+	if(sect == NULL) {
+		fout << "Couldn't find TLS AddressOfIndex section!!" << endl;
+		return(FALSE);
+	}
+  	setTLSIndexAddr((LPDWORD)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfIndex - sect->virtaddr)));
+
+	sect = findSectionByAddr((ULONG)tlsDir->AddressOfCallBacks);
+	if(sect == NULL) {
+		fout << "Couldn't find TLS AddressOfCallBacks section!!" << endl;
+		return(FALSE);
+	}
+  	setTLSCallBackAddr((PIMAGE_TLS_CALLBACK *)(sect->realvirtaddr + ((ULONG)tlsDir->AddressOfCallBacks - sect->virtaddr)));
+  }
+
+  if(realBaseAddress != oh.ImageBase) {
+  	if(setFixups((PIMAGE_BASE_RELOCATION)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_BASERELOC)) == FALSE) {
+    		fout << "Failed to set fixups" << endl;
+    		return(FALSE);
+	}
+  }
+
   if(processImports((char *)win32file) == FALSE) {
-    fout << "Failed to process imports!" << endl;
-    return(FALSE);
+    	fout << "Failed to process imports!" << endl;
+    	return(FALSE);
   }
 
   if(fh.Characteristics & IMAGE_FILE_DLL) {
-    if(processExports((char *)win32file) == FALSE) {
-        fout << "Failed to process exported apis" << endl;
-        return(FALSE);
-    }
+    	if(processExports((char *)win32file) == FALSE) {
+        	fout << "Failed to process exported apis" << endl;
+        	return(FALSE);
+    	}
   }
   IMAGE_SECTION_HEADER sh;
   if(GetSectionHdrByName (win32file, &sh, ".rsrc")) {
-    //get offset in resource object of directory entry
-    pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE);
+    	//get offset in resource object of directory entry
+    	pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE);
   }
   //set final memory protection flags (storeSections sets them to read/write)
   if(setMemFlags() == FALSE) {
-    fout << "Failed to set memory protection" << endl;
-    return(FALSE);
+    	fout << "Failed to set memory protection" << endl;
+    	return(FALSE);
   }
 
@@ -428,5 +470,5 @@
 
   if(type == SECTION_RESOURCE) {
-    pResSection = &section[nrsections];
+    	pResSection = &section[nrsections];
   }
   virtsize   = ((virtsize - 1) & ~0xFFF) + PAGE_SIZE;
@@ -435,7 +477,7 @@
 
   if(virtaddress < imageVirtBase)
-    imageVirtBase = virtaddress;
+    	imageVirtBase = virtaddress;
   if(virtaddress + virtsize > imageVirtEnd)
-    imageVirtEnd = virtaddress + virtsize;
+    	imageVirtEnd = virtaddress + virtsize;
 
   nrsections++;
@@ -443,16 +485,16 @@
 //******************************************************************************
 //******************************************************************************
-BOOL Win32Image::allocSections()
+BOOL Win32Image::allocSections(ULONG reservedMem)
 {
  APIRET rc;
 
   if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) {
-    fout << "No fixups, might not run!" << endl;
-    return allocFixedMem();
+    	fout << "No fixups, might not run!" << endl;
+    	return allocFixedMem(reservedMem);
   }
   rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);
   if(rc) {
-    errorState = rc;
-    return(FALSE);
+    	errorState = rc;
+    	return(FALSE);
   }
   realBaseAddress = baseAddress;
@@ -460,7 +502,29 @@
 }
 //******************************************************************************
+//******************************************************************************
+Section *Win32Image::findSection(ULONG type)
+{
+  for(int i=0;i<nrsections;i++) {
+	if(section[i].type == type) {
+		return &section[i];
+	}
+  }
+  return NULL;
+}
+//******************************************************************************
+//******************************************************************************
+Section *Win32Image::findSectionByAddr(ULONG addr)
+{
+  for(int i=0;i<nrsections;i++) {
+	if(section[i].virtaddr <= addr && section[i].virtaddr + section[i].virtualsize > addr) {
+		return &section[i];
+	}
+  }
+  return NULL;
+}
+//******************************************************************************
 #define FALLOC_SIZE (1024*1024)
 //******************************************************************************
-BOOL Win32Image::allocFixedMem()
+BOOL Win32Image::allocFixedMem(ULONG reservedMem)
 {
  ULONG  address = 0;
@@ -471,49 +535,59 @@
 
   baseAddress = realBaseAddress = 0;
+  
+  if(reservedMem && reservedMem <= oh.ImageBase && 
+     ((oh.ImageBase - reservedMem) + imageSize < PELDR_RESERVEDMEMSIZE)) 
+  {
+	//ok, it fits perfectly
+       	realBaseAddress = oh.ImageBase;
+       	baseAddress = oh.ImageBase;
+	return TRUE;
+  }
 
   while(TRUE) {
-    rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ);
-    if(rc) break;
-
-    if(firstaddress == 0)
-        firstaddress = address;
-
-    fout << "DosAllocMem returned " << address << endl;
-    if(address + FALLOC_SIZE >= oh.ImageBase) {
-        if(address > oh.ImageBase) {//we've passed it!
-            DosFreeMem((PVOID)address);
-            return(FALSE);
-        }
-        //found the right address
-        DosFreeMem((PVOID)address);
-        //align at 64 kb boundary
-        realBaseAddress = oh.ImageBase & 0xFFFF0000;
-        diff = realBaseAddress - address;
-        if(diff) {
-            rc = DosAllocMem((PPVOID)&address, diff, PAG_READ);
-            if(rc) break;
-        }
-        rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);
-        if(rc) break;
-
-        if(baseAddress != realBaseAddress) {
-            fout << "baseAddress != realBaseAddress!!" << endl;
-            break;
-        }
-        if(diff) DosFreeMem((PVOID)address);
-
-        address = realBaseAddress;
-        realBaseAddress = baseAddress;
-        baseAddress = oh.ImageBase;
-        break;
-    }
-    lastaddress = address;
+    	rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ);
+    	if(rc) break;
+
+    	if(firstaddress == 0)
+        	firstaddress = address;
+
+    	fout << "DosAllocMem returned " << address << endl;
+    	if(address + FALLOC_SIZE >= oh.ImageBase) {
+        	if(address > oh.ImageBase) {//we've passed it!
+            		DosFreeMem((PVOID)address);
+            		return(FALSE);
+        	}
+        	//found the right address
+        	DosFreeMem((PVOID)address);
+        	//align at 64 kb boundary
+        	realBaseAddress = oh.ImageBase & 0xFFFF0000;
+        	diff = realBaseAddress - address;
+        	if(diff) {
+            		rc = DosAllocMem((PPVOID)&address, diff, PAG_READ);
+            		if(rc) break;
+        	}
+        	rc = DosAllocMem((PPVOID)&baseAddress, imageSize, PAG_READ);
+        	if(rc) break;
+
+        	if(baseAddress != realBaseAddress) {
+            		fout << "baseAddress != realBaseAddress!!" << endl;
+            		break;
+        	}
+        	if(diff) DosFreeMem((PVOID)address);
+
+        	address = realBaseAddress;
+        	realBaseAddress = baseAddress;
+        	baseAddress = oh.ImageBase;
+        	break;
+    	}
+    	lastaddress = address;
   }
   while(firstaddress <= lastaddress) {
-    DosFreeMem((PVOID)firstaddress);
-    firstaddress += FALLOC_SIZE;
+    	DosFreeMem((PVOID)firstaddress);
+    	firstaddress += FALLOC_SIZE;
   }
   if(baseAddress == 0) //Let me guess.. MS Office app?
-    return(FALSE);
+    	return(FALSE);
+
   return(TRUE);
 }
@@ -527,9 +601,9 @@
 
   for(i=0;i<nrsections;i++) {
-    section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase);
+    	section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase);
   }
   for(i=0;i<nrsections;i++) {
-    pagFlags = PAG_COMMIT;
-    switch(section[i].type) {
+    	pagFlags = PAG_COMMIT;
+    	switch(section[i].type) {
         case SECTION_CODE:
         case (SECTION_CODE | SECTION_IMPORT):
@@ -539,23 +613,24 @@
         case SECTION_READONLYDATA:
         case SECTION_RESOURCE:
-            pagFlags |= PAG_WRITE | PAG_READ;
-            break;
+	case SECTION_TLS:
+          	pagFlags |= PAG_WRITE | PAG_READ;
+            	break;
         case SECTION_EXPORT:
         case SECTION_DEBUG:
         case SECTION_RELOC:
-            pagFlags = 0;   //don't commit
-            break;
-    }
-    if(pagFlags == 0)   continue;   //debug or export section
-
-    rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
-    if(rc) {
-        errorState = rc;
-        return(FALSE);
-    }
-    if(section[i].type != SECTION_UNINITDATA) {
-        assert(section[i].rawdata);
-        memcpy((char *)section[i].realvirtaddr, section[i].rawdata, section[i].rawsize);
-    }
+            	pagFlags = 0;   //don't commit
+            	break;
+    	}
+    	if(pagFlags == 0)   continue;   //debug or export section
+
+    	rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
+    	if(rc) {
+        	errorState = rc;
+      		return(FALSE);
+    	}
+    	if(section[i].type != SECTION_UNINITDATA) {
+        	assert(section[i].rawdata);
+        	memcpy((char *)section[i].realvirtaddr, section[i].rawdata, section[i].rawsize);
+    	}
   }
   return(TRUE);
@@ -570,27 +645,28 @@
 
   for(i=0;i<nrsections;i++) {
-    pagFlags = 0;
-    switch(section[i].type) {
+    	pagFlags = 0;
+    	switch(section[i].type) {
         case SECTION_CODE:
         case (SECTION_CODE | SECTION_IMPORT):
-            pagFlags |= PAG_EXECUTE | PAG_READ;
-            break;
+            	pagFlags |= PAG_EXECUTE | PAG_READ;
+            	break;
         case SECTION_INITDATA:
         case SECTION_UNINITDATA:
         case SECTION_IMPORT: //TODO: read only?
-            pagFlags |= PAG_WRITE | PAG_READ;
-            break;
+            	pagFlags |= PAG_WRITE | PAG_READ;
+            	break;
         case SECTION_READONLYDATA:
         case SECTION_RESOURCE:
-            pagFlags |= PAG_READ;
-            break;
+	case SECTION_TLS:
+            	pagFlags |= PAG_READ;
+            	break;
         default:
-            continue;
-    }
-    rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
-    if(rc) {
-        errorState = rc;
-        return(FALSE);
-    }
+            	continue;
+    	}
+    	rc = DosSetMem((PVOID)section[i].realvirtaddr, section[i].virtualsize, pagFlags);
+    	if(rc) {
+        	errorState = rc;
+        	return(FALSE);
+    	}
   }
   return(TRUE);
@@ -804,16 +880,16 @@
 
   if(nameexports == NULL) {
-    nameExportSize= 4096;
-    nameexports   = (NameExport *)malloc(nameExportSize);
-    curnameexport = nameexports;
+    	nameExportSize= 4096;
+    	nameexports   = (NameExport *)malloc(nameExportSize);
+    	curnameexport = nameexports;
   }
   nsize = (ULONG)curnameexport - (ULONG)nameexports;
   if(nsize + sizeof(NameExport) + strlen(apiname) > nameExportSize) {
-    nameExportSize += 4096;
-    char *tmp = (char *)nameexports;
-    nameexports = (NameExport *)malloc(nameExportSize);
-    memcpy(nameexports, tmp, nsize);
-    curnameexport = (NameExport *)((ULONG)nameexports + nsize);
-    free(tmp);
+    	nameExportSize += 4096;
+    	char *tmp = (char *)nameexports;
+    	nameexports = (NameExport *)malloc(nameExportSize);
+    	memcpy(nameexports, tmp, nsize);
+    	curnameexport = (NameExport *)((ULONG)nameexports + nsize);
+    	free(tmp);
   }
   curnameexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase);
@@ -824,5 +900,6 @@
   curnameexport->nlength = strlen(apiname) + 1;
   if(curnameexport->nlength < sizeof(curnameexport->name))
-    curnameexport->nlength = sizeof(curnameexport->name);
+    	curnameexport->nlength = sizeof(curnameexport->name);
+
   curnameexport = (NameExport *)((ULONG)curnameexport->name + curnameexport->nlength);
 }
@@ -832,6 +909,6 @@
 {
   if(ordexports == NULL) {
-    ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
-    curordexport = ordexports;
+    	ordexports   = (OrdExport *)malloc(nrOrdExports * sizeof(OrdExport));
+    	curordexport = ordexports;
   }
   curordexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase);
@@ -980,5 +1057,5 @@
     WinDll = Win32Dll::findModule(pszCurModule);
     if(WinDll == NULL)
-     {  //not found, so load it
+    {  //not found, so load it
         WinDll = new Win32Dll(pszCurModule);
 
@@ -992,5 +1069,5 @@
         fout << "**********************     Loading Module        *********************" << endl;
         fout << "**********************************************************************" << endl;
-        if(WinDll->init() == FALSE) {
+        if(WinDll->init(0) == FALSE) {
             fout << "Internal WinDll error " << WinDll->getError() << endl;
             return(FALSE);
@@ -1076,8 +1153,7 @@
   if (rc != NO_ERROR)
   {
-    dprintf(("KERNEL32:Win32Image::isPEImage(%s) failed with %u\n",
-             szFileName,
-             rc));
-    return(FALSE);
+    	dprintf(("KERNEL32:Win32Image::isPEImage(%s) failed with %u\n",
+             	  szFileName, rc));
+    	return(FALSE);
   }
 
@@ -1087,11 +1163,11 @@
   IMAGE_DOS_HEADER *pdoshdr = (IMAGE_DOS_HEADER *)malloc(sizeof(IMAGE_DOS_HEADER));
   if(pdoshdr == NULL)   {
-    DosClose(win32handle);                /* Close the file */
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	return(FALSE);
   }
   rc = DosRead(win32handle, pdoshdr, sizeof(IMAGE_DOS_HEADER), &ulRead);
   if(rc != NO_ERROR) {
-    DosClose(win32handle);                /* Close the file */
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	return(FALSE);
   }
   ULONG hdrsize = pdoshdr->e_lfanew + SIZE_OF_NT_SIGNATURE + sizeof(IMAGE_FILE_HEADER);
@@ -1103,25 +1179,25 @@
   win32file = malloc(hdrsize);
   if(win32file == NULL) {
-    DosClose(win32handle);                /* Close the file */
-    return(FALSE);
+    	DosClose(win32handle);                /* Close the file */
+    	return(FALSE);
   }
   rc = DosRead(win32handle, win32file, hdrsize, &ulRead);
   if(rc != NO_ERROR) {
-    goto failure;
+    	goto failure;
   }
 
   if(GetPEFileHeader (win32file, &fh) == FALSE) {
-    goto failure;
+    	goto failure;
   }
 
   if(!(fh.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE)) {//not valid
-    goto failure;
+    	goto failure;
   }
   if(fh.Machine != IMAGE_FILE_MACHINE_I386) {
-    goto failure;
+    	goto failure;
   }
   //IMAGE_FILE_SYSTEM == only drivers (device/file system/video etc)?
   if(fh.Characteristics & IMAGE_FILE_SYSTEM) {
-    goto failure;
+    	goto failure;
   }
   DosClose(win32handle);
Index: trunk/src/kernel32/wprocess.cpp
===================================================================
--- trunk/src/kernel32/wprocess.cpp	(revision 543)
+++ trunk/src/kernel32/wprocess.cpp	(revision 544)
@@ -1,3 +1,3 @@
-/* $Id: wprocess.cpp,v 1.20 1999-08-17 17:04:52 sandervl Exp $ */
+/* $Id: wprocess.cpp,v 1.21 1999-08-18 12:24:17 sandervl Exp $ */
 
 /*
@@ -395,5 +395,5 @@
         return(0);
 
-    module->init();
+    module->init(0);
     if(module->getError() != NO_ERROR) {
         dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
@@ -467,5 +467,5 @@
         return(0);
 
-    module->init();
+    module->init(0);
     if(module->getError() != NO_ERROR) {
         dprintf(("LoadLibary %s failed (::init)\n", lpszLibFile));
Index: trunk/src/peldr/initterm.cpp
===================================================================
--- trunk/src/peldr/initterm.cpp	(revision 543)
+++ trunk/src/peldr/initterm.cpp	(revision 544)
@@ -1,3 +1,3 @@
-/* $Id: initterm.cpp,v 1.1 1999-08-16 13:54:06 sandervl Exp $ */
+/* $Id: initterm.cpp,v 1.2 1999-08-18 12:24:32 sandervl Exp $ */
 
 /*
@@ -32,4 +32,5 @@
 #include <odin.h>
 #include <misc.h>       /*PLF Wed  98-03-18 23:18:15*/
+#include <winimage.h>
 
 /*-------------------------------------------------------------------*/
@@ -75,5 +76,5 @@
          //     This is done before any Odin or PMWIN dll is loaded, so we'll get
          //     a very low virtual address. (which is exactly what we want)
-	 rc = DosAllocMem((PPVOID)&reservedMemory, 16*1024*1024, PAG_WRITE | PAG_READ);
+	 rc = DosAllocMem((PPVOID)&reservedMemory, PELDR_RESERVEDMEMSIZE, PAG_WRITE | PAG_READ);
 
          /*******************************************************************/
Index: trunk/src/peldr/pe.cpp
===================================================================
--- trunk/src/peldr/pe.cpp	(revision 543)
+++ trunk/src/peldr/pe.cpp	(revision 544)
@@ -1,3 +1,3 @@
-/* $Id: pe.cpp,v 1.5 1999-08-16 13:54:07 sandervl Exp $ */
+/* $Id: pe.cpp,v 1.6 1999-08-18 12:24:32 sandervl Exp $ */
 
 /*
@@ -72,6 +72,4 @@
  HMODULE hmodPMWin, hmodKernel32;
 
-  printf("memory allocated at %X\n", ReserveMem());
-
   rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
   rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize);
@@ -130,5 +128,5 @@
   WinExe->setCommandLine(szCmdLine);
 
-  if(WinExe->init() == FALSE) {
+  if(WinExe->init(ReserveMem()) == FALSE) {
         delete WinExe;
         return(1);
