How does executable load dll ?

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator: Moderators

Post Reply
exor
Posts: 13
Joined: Tue Mar 23, 2010 11:01 am

How does executable load dll ?

Post by exor » Wed Mar 31, 2010 11:43 pm

hi :)

tutorial 15 is about hal, wrote in c;

hal functions are compiled as dll, and linked to exe ... i've understood stage2 loads kernel.exe and call entry point ( main() ), but how does kernel.exe refers to dll without include in as lib ?
should it to load dll in memory or not ?

and after load an exe, how does it knows the address where i loaded to ?
is not VAS implemented by kernel ?

User avatar
Mike
Site Admin
Posts: 465
Joined: Sat Oct 20, 2007 7:58 pm
Contact:

Re: How does executable load dll ?

Post by Mike » Thu Apr 01, 2010 8:03 am

Hello,

The main series does not use DLLs for simplicity purposes. Instead, all libraries are built and linked into the kernel as static libraries.

This does not limit you from adding DLL loading support yourself (It isnt hard) if you decide to try it.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

exor
Posts: 13
Joined: Tue Mar 23, 2010 11:01 am

Re: How does executable load dll ?

Post by exor » Thu Apr 01, 2010 9:28 am

how does exe know the address where i loaded to ?

and couldn't i to use binary format ?
if i'll use a binary library, for example, i could to create an header where exe retrieves functions addresses, isnt it?

the main question is, why do we use pe format and dlls ?
can we make a form of dinamic library (in binary form), to load when kernel binary file instead pe needs it ?

it seems much better then make a kernel of 1 mb, with every library included in :)

i'm sorry for these questions, but till tutorial 15, everything was explained fine, here something (like the need for pe format instead bin) was not explained and that makes some trouble :S

tnx for help

User avatar
Mike
Site Admin
Posts: 465
Joined: Sat Oct 20, 2007 7:58 pm
Contact:

Re: How does executable load dll ?

Post by Mike » Thu Apr 01, 2010 6:05 pm

Hello,
how does exe know the address where i loaded to ?
The EXE base address can be retrieved from either MSVC itself. Through programming, this involves reading a sector or two of the file and obtaining its base address (to load it to) from the PE header structures (This is described in the MSVC chapter.)

DLLs are the same way.

You will need to write your own tool if you decide to create your own library format (that of what you described.) The series uses PE format because it currently only uses the toolchain provided by MSVC. I use the PE format and DLLs in Neptune (my real OS) because I prefer them. You do not need to use any format (or even go with ELF if you prefer), it will just require some changes in your setup.

Even so, I personally would not include any of the projects as DLLs if you want to go microkernel. Rather, it would be better to build a driver interface, load them, and treat them as real drivers rather then kernel DLLs. Kernel DLLs should be reserved for kernel-specific functionality.

---

The series uses C (technically C++ but its features were never used.) as it is basically the standard systems programming language. The series provides chapters describing the setups and basic formats for different compilers (although currently only PE and MSVC are described., GCC with PE and loading with GRUB has also been possible.)

Please note that the use of PE format and how to set up MSVC to use it is explained in the Kernel Setup chapters. As of current, the only one is Kernel Setup: MSVC which provides the information you need.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

exor
Posts: 13
Joined: Tue Mar 23, 2010 11:01 am

Re: How does executable load dll ?

Post by exor » Fri Apr 02, 2010 5:56 pm

o.O
The EXE base address can be retrieved from either MSVC itself. Through programming, this involves reading a sector or two of the file and obtaining its base address (to load it to) from the PE header structures (This is described in the MSVC chapter.)
uhm .. how can msvc set the address where exe is loaded to if it doesn't know how many free memory is there ?

:S

User avatar
Mike
Site Admin
Posts: 465
Joined: Sat Oct 20, 2007 7:58 pm
Contact:

Re: How does executable load dll ?

Post by Mike » Fri Apr 02, 2010 8:55 pm

Hello,

MSVC provides an option for setting the preferred base address of the executable image. This value is set in the programs header structure which can be read by your bootloader to load the program binary at that location in memory.

This is the way the series bootloader loads your kernel.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

ehenkes
Posts: 34
Joined: Fri Jul 24, 2009 5:35 pm

Re: How does executable load dll ?

Post by ehenkes » Sun Apr 04, 2010 11:37 pm


exor
Posts: 13
Joined: Tue Mar 23, 2010 11:01 am

Re: How does executable load dll ?

Post by exor » Thu Apr 08, 2010 2:14 pm

tnx i've read MSVC tutorial and i've understood :)

so, the story is that we've to load images manually in a fixed memory address. The same thing is for dlls :) (i found an microsoft doc where they explain dlls header is as pe header, only a check byte changes).

i suppose the only way is that untill we use a VAS method that should we to allow to set base address of our images to 0x0 ...

Post Reply