You can probably get an idea of some of the various fixups a rebaser needs to perform by reading the PE portable executable - the format Windows executables use spec, and scattered in various articles on MSDN.
Learn More. Ask a question. Quick access. Search related threads. Remove From My Forums. Asked by:. Archived Forums. Windows Desktop SDK. Sign in to vote. Any other documents to refer? Friday, February 1, AM. In partial answer to 1 and 2: Processes have a limited amount of address space.
Friday, February 1, PM. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Is rebasing DLLs or providing an appropriate default load address worth the trouble? Ask Question. Asked 11 years ago. Active 1 year, 9 months ago.
Viewed 5k times. The question is now: Is it worth the trouble? Martin Ba. Martin Ba Martin Ba This is back from so not answering your question, but in case anyone wants to read about why rebasing was and maybe still is?
Add a comment. Active Oldest Votes. Hans Passant Hans Passant k gold badges silver badges bronze badges. This situation where this makes a big difference is running the application in a Terminal server environment. If fixups are applied, then the memory used by the modules cannot be effectively shared across sessions.
If no fixups are applied than the memory used by a module can be shared. Not sharing modules can have a significant memory impact when many sessions are running the same applications quite common in terminal server environments. Rebasing does not seem "cheap" anymore when you have DLLs to manage. At most 30 or so of them will be loaded together, but they are all optional plugins that are potentially loaded into the app and each customer uses a different combination. So I have to keep them off each other and that becomes a bit annoying :- — Martin Ba.
After recently fiddling with DLL base addresses in our application, I will here give my conclusion: I think that, unless you can prove otherwise, providing DLLs with a non-default Base Address is an exercise in futility. If the code from the file's image without changing the address is allowed to execute, some 4-byte value in the first DLL module will be overwritten with the value 5. This can't possibly be allowed. The loader must somehow fix this code.
When the linker builds your module, it embeds a relocation section in the resulting file. If the loader can map a module at its preferred base address, the module's relocation section is never accessed by the system. This is certainly what we want—you never want the relocation section to be used because of the below reasons.
If the module cannot be mapped at its preferred base address, the loader opens the module's relocation section and iterates though all the entries. For each entry found, the loader goes to the page of storage that contains the machine code instruction to be modified.
It then grabs the memory address that the machine instruction is currently using and adds to the address the difference between the module's preferred base address and the address where the module actually got mapped.
So, in the example above, the second DLL was mapped at 0x, but its preferred base address is 0x This yields a difference of 0x, which is then added to the address in the machine code instruction, giving us this:.
To avoid this, instead change the settings while compilation so as to give different base addresses during compilation itself. If for some reason, it cannot be loaded at the other address specified, then it has to reallocate the DLL and the above process is carried. The second point above is truly bad. It means that the module's code pages can no longer be discarded and reloaded from the module's file image on disk.
Instead, the pages are swapped to and from the system's paging file as necessary. This hurts performance too. But wait, it gets worse. Since the paging file backs all of the module's code pages, the system has less storage available for all processes running in the system. By the way, you can create an executable or DLL module that doesn't have a relocation section in it.
Using this switch makes the module smaller in bytes but it means that the module cannot be relocated. If the module cannot load at its preferred base address, it cannot load at all. If the loader must relocate a module but no relocation section exists for the module, the loader kills the entire process and displays an "Abnormal Process Termination" message to the user. In this case, I have made base address of both DLLs same, i. In this particular example, I have tried to cover all aspects, i.
Suggestions for improvement are most welcome. I would like to acknowledge author Mr. Jeffery Richter and his book on Windows OS, which is one of the best books to know about the Windows operating system internals. Parts of this article is taken from the book and examples were added to simplify things. Libase differs from the Platform SDK utility Rebase in that it chooses the new base address for the DLL based on a hash of the filename, instead of asking you to provide a base address explicitly.
Every Win32 application loads in a private memory address space. The operating system makes it appear that each process has a linear address range that starts from zero. By signing up, you agree to our Terms of Use and Privacy Policy. Enter the email address associated with your account. We'll send a magic link to your inbox.
Email Address. All Sign in options. Enter a Email Address.
0コメント