Sign in to follow this  
Verg

where is the assembled code mapped (Win32/assembler)

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this