2
2
228Popka2282021-07-05 01:06:29
DLL
228Popka228, 2021-07-05 01:06:29

How functions from dll receive control?

It seemed to me that dynamic libraries work on the principle of "mapping a file to memory", that is, the process would request additional RAM, into which the contents of the dll file are copied. And the functions themselves in the dll would be stored as normal. As some addresses to which control is transferred and the execution of the machine code of the function begins.

Now I learned that you can transfer control only to an immutable memory area under the code section that is formed when the process is created. But as I understand it, dynamically linked libraries are stored far away from the code section. How then functions from dll-libraries receive control?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Dubrovin, 2021-07-05
@228Popka228

With dynamic linking, the code does not "fall" into one segment, as is usually the case with static linking, the dynamic library has a code segment, each library has its own. Each dynamic library maps to a specific area of ​​the process's address space, not necessarily sequential. Those pages of the address space where the code segment of the library is mapped are marked as executable. The function receives control at the time of the call, the address at which the function is located is determined by the calling function either through the import table, which is filled in during dynamic linking, or through a direct call to GetProcAddr.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question