ciberyane wrote:First, thenk you for help me.
With your answer and I have a better idea of how the OS
Now only need to know:
how a Thread is created internally in ReactOS and destroyed?
and
How does ReactOS alloc memory in the Heap?
I think that that would be enough to complete my presentation, I do not need anything too big, just a basic idea to develop it later, anyway I will consult the teacher about it.
Thanks again for your help
I wait for your answer
Creating a Thread
When a Windows app wants to create a new thread, it uses a winapi function named CreateThread().
In MSDN (
http://msdn.microsoft.com/en-us/library ... 85%29.aspx ) you can find "how" the app should call(send parameters to)the API to create a new thread.CreateThread is a function coded in Kernel32.DLL. Microsoft has coded it, so the App developer has just to "call" it and done.
As you can imagine, CreateThread is a function coded by Microsoft and its code is not public available.
So what does happen when the app calls CreateThread?Nobody "knows".We just can "guess" or "study" it in a clean way.
How?We know the objective of the API,the params the API uses, and even some errors that should return as explained in the MSDN doc. There are also books available about the NT system (as the Windows Internal Xth Edition). Add some tests(rostests and winetests)which consists basically to send the API a set of different params and checking the returned values.. and voila: Done!.
So when an app wants to Create a new thread, it calls the CreateThread() function. Really the app "doesnt mind*"if it is being run on top of ReactOS,Wine or Windows.The app just expects CreateThread() to perform its work correctly.
So basically ReactOS is enforced to create a compatible CreateThread() function which accepts the same number and type of parameters and in the same order.It has to be even placed inside the ReactOS Kernel32.dll.Summing up: A total and compatible ReactOS-Opensource CreateThread() function of the Microsoft-closed CreateThread() one.
The biggest difference is that ReactOS CreateThread() function is totally open. You can see the ReactOS CreateThread sourcecode here:
http://doxygen.reactos.org/d0/d85/dll_2 ... 98c1d.html
Doxygen is a really nice tool that can help you to follow how our CreateThread function is coded. In this case we call the CreateRemoteThread function and use its returned value.You can go as deeper as you want. Just click in the function names(they are links) and they will show you the code that implements them. You will end calling some NT functions as NtCreateThread or NtQueryInformationThread. You can follow these links to discover how they are implemented. The deeper you go, the more difficulty to follow they are. You are moving down,down,down...from user mode to kernel mode. Good luck there!
Allocating memory
There are different ways of allocating memory. GlobalAlloc, LocalAlloc, and HeapAlloc functions ultimately allocate memory from the same heap.
An interesting article about the differences among them and others ways of allocating memory can be found here:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
"
GlobalAlloc and LocalAlloc are implemented as wrapper functions that call HeapAlloc using a handle to the process's default heap.", the MSDN doc says.
This gives an important clue to ReactOS devs to know the relationship among them.
In plain English this means that Microsoft GlobalAlloc() function calls HeapAlloc(), and so LocalAlloc() does.
Is,then, ReactOS GlobalAlloc() and ReactOS LocalAlloc() calling HeapAlloc() to perform the task?
Let's check ReactOS code thanks to Doxygen!
ReactOS LocalAlloc() source code can be found here:
http://doxygen.reactos.org/db/dbb/winba ... 2db91d8926
As you can see
LocalAlloc() seems to NOT be calling HeapAlloc() to perform the task through it,
but it is calling RtlAllocateHeap to allocate the memory.
ReactOS GlobalAlloc() source code can be found here:
http://doxygen.reactos.org/db/dbb/winba ... aa6f0db8db
As you can see
GlobalAlloc() seems it is NOT calling HeapAlloc() to perform the task through it,
but it is calling RtlAllocateHeap to allocate the memory.
Thanks to the MSDN reference, we have a Tip of how "internally" Microsoft is handling GlobalAlloc() and LocalAlloc(). But curioslly, ReactOS seems to not be using this tip in our ReactOS GlocalAlloc() and ReactOS LocalAlloc() implementation!!Remember: The tip says that Microsoft GlobalAlloc and LocalAlloc calls HeapAlloc() to perform the task!
Are we trying to reinvent the wheel?
Why don't we follow the same way Windows does thanks to that marvellous extrapieceofinfo?
Well..let's look CLOSER to our ReactOS functions!
What happens if we search HeapAlloc at Doxygen?
The following appears:
http://doxygen.reactos.org/d7/dff/lzexp ... e736e5be91
http://doxygen.reactos.org/d0/db5/dll_2 ... e736e5be91
http://doxygen.reactos.org/d0/db5/dll_2 ... e736e5be91
All those links have the same code:
Which means that
HeapAlloc and RtlAllocateHeap are "sinonimous" most of the time.
In other words:
When ReactOS GlobalAlloc() calls RtlAllocateHeap really it is calling HeapAlloc, as MSDN says!
When ReactOS LocalAlloc() calls RtlAllocateHeap really it is calling HeapAlloc, as MSDN says!
So yes, we aren't reinventing the wheel and we are using this nice info
RtlAllocateHeap is the base of those functions and can be found here:
http://doxygen.reactos.org/d8/d68/lib_2 ... 413ec0416d
Here you can find the internal functions that allocates a piece of memory in the heap. If you are brave enough you can try following how those functions are implemented by following the links. You will end in our lovely Memory Manager for sure
Deeper you go, the more difficult it is.
I don't know which is the supposed level of your presentation, but if you want to understand the deeper concepts about Virtual Memory,Memory manager, Heap and so on...I highly recommend you "Operating System concepts" book and "Windows Internals" one.
Hope this helps!