where is the assembled code mapped (Win32/assembler)

Started by
5 comments, last by Catafriggm 18 years, 9 months ago
This is related to the other thread... HINSTANCE/HMODULE... doesn't that just indicate where the assembly code begins in memory? When an invalid page fault happens (if it does)... the address of the fault point is (of course) relative to the HMODULE value... correct? IOW: HMODULE = 0x00400000 page fault point = 0x00401100 where things broke, then == 0x1100 bytes from the beginning of the module correct? ---- The reason I'm asking is that on a different user's computer, the HMODULE/HINSTANCE value will vary, and we still want to be able to find where the code broke. ---- Sorry if this seems a little dull; I'm slow on the uptake sometimes. Just looking for a confirmation, or a "no, no, no you stupid ass" or something [smile] Thanks Chad
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
Advertisement
Yes. The location of code in an executable is fixed relative to the base address of the executable (note that this does not always translate into the offset in the EXE file - there can be holes in memory). I should also note that unless you screw with the compiler settings to make it default to a weird load address, the address it gets loaded at will be the same on all computers (this is only true for EXEs; it is not necessarily true for DLLs).
Cool. Muchas gracias.
my_life:          nop          jmp my_life
[ Keep track of your TDD cycle using "The Death Star" ] [ Verge Video Editor Support Forums ] [ Principles of Verg-o-nomics ] [ "t00t-orials" ]
You know though, I think an executable always begins at 0x00400000.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
When you create a DLL, the general practice is to change the default base address (otherwise the DLL loader will need to rebase the DLL at run time, which is a relatively slow process). If the DLL doesn't overlap any other DLLs loaded, then the base address will also be the same on all computers as well. Remember, the base address is virtual memory, and every process gets it's own virtual address space.
Quote:Original post by Promit
You know though, I think an executable always begins at 0x00400000.


Nope. The base address is a linker setting that defaults to 0x400000, but can be changed. Also, an executable can be loaded into memory like a DLL.
Quote:Original post by Dean Harding
When you create a DLL, the general practice is to change the default base address (otherwise the DLL loader will need to rebase the DLL at run time, which is a relatively slow process). If the DLL doesn't overlap any other DLLs loaded, then the base address will also be the same on all computers as well. Remember, the base address is virtual memory, and every process gets it's own virtual address space.

Yes, assuming nothing grabs memory in the preferred region before then (not as much a problem with compile-time linked DLLs as run-time linked ones). EXEs don't have to worry about that because they're almost the first thing to get allocated in the new process (there are some things that get allocated before the EXE, but they're generally predictable, so a well-chosen preferred load address eliminates the possibility of needing to relocate the executable).

This topic is closed to new replies.

Advertisement