Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it withoutsegfaulting
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Tue, 21 Mar 2006 10:43:12 +0100
Frank Kotler wrote:
If anyone's into analysing Nasm's "-f win32" behavior... There's an
issue with "vsize" (I think that's the name of the field) in the
*object* header. Does it or does it not include .bss size? My
understanding is that MS documents "no" but *used* to do it "yes". When
MinGW "ld" first came out, they did it "as documented", and considered
Nasm "buggy"... but they "came around" (I understand).
I suppose you are speaking about SizOfImage. But this value is calculated
by the linker and not the assembler (or can NASM directly generate exe files).
All information I have found, says that it has to include all sections
(and therefore also the .bss). Otherwise there wouldn't be memory allocated
for the .bss. Which MS document says "no"?
-------------------------------------------------------------------------------------------------
Peering Inside the PE: A Tour of the Win32 Portable Executable File Format
Matt Pietrek March 1994
Matt Pietrek is the author of Windows Internals (Addison-Wesley, 1993). He works at Nu-Mega
Technologies Inc., and can be reached via CompuServe: 71774,362
This article is reproduced from the March 1994 issue of Microsoft Systems Journal.
DWORD SizeOfImage
This appears to be the total size of the portions of the image that the loader has to worry
about. It is the size of the region starting at the image base up to the end of the last section.
The end of the last section is rounded up to the nearest multiple of the section alignment.
-------------------------------------------------------------------------------------------------
From: THe Portable Executable File Format from Top to Bottom
Randy Kath, Microsoft Network Technology Group, June 12, 1993
SizeOfImage. Indicates the amount of address space to reserve in the address space
for the loaded executable image. This number is influenced by
SectionAlignment. For example, consider a system having a fixed page size of 4096
bytes. If you have an executable with 11 sections, each less than 4096 bytes, aligned
on a 65,536-byte boundary, the SizeOfImage field would be set to 11 * 65,536 =
720,896 (176 pages). The same file linked with 4096-byte alignment would result in
11 * 4096 = 45,056 (11 pages) for the SizeOfImage field. This is a simple example in
which each section requires less than a page of memory. In reality, the linker
determines the exact SizeOfImage by figuring each section individually. It first
determines how many bytes the section requires, then rounds up to the nearest
page boundary, and finally it rounds page count to the nearest SectionAlignment
boundary. The total is then the sum of each section's individual requirement.
-------------------------------------------------------------------------------------------------
http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx
An In-Depth Look into the Win32 Portable Executable File Format
SizeOfImage contains the RVA that would be assigned to the section following the last
section if it existed. This is effectively the amount of memory that the system needs
to reserve when loading this file into memory. This field must be a multiple of the
section alignment.
-------------------------------------------------------------------------------------------------
http://msdn.microsoft.com/msdnmag/issues/02/03/Loader/
What Goes On Inside Windows 2000: Solving the Mysteries of the Loader
The job of LdrpAllocateDataTableEntry is to allocate this object and initialize the
ImageBase field using three values: the HMODULE handle returned by NtMapViewOfSection,
the ImageSize field using the SizeOfImage value found in the portable executable (PE)
file's optional header, and the TimeDateStamp from the equivalent field in the PE file
header. If the memory allocation fails, the routine returns a NULL pointer. LdrpMapDll
then removes the file mapping, closes the section handle, and fails, returning STATUS_NO_MEMORY.
-------------------------------------------------------------------------------------------------
.
- Follow-Ups:
- References:
- NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- From: o//annabee
- Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- From: Betov
- Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- From: o//annabee
- Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- From: Betov
- Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- From: Frank Kotler
- NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- Prev by Date: Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- Next by Date: Re: I need speed! Byte-for-byte comparing ...
- Previous by thread: Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it without segfaulting
- Next by thread: Re: NASM pe segfaults, RosAsm dissassembles the PE and runs it withoutsegfaulting
- Index(es):
Relevant Pages
|