I read the source code of FastMM4, and notice this interesting function
function GetThreadID: Cardinal;
{$ifdef 32Bit}
asm
mov eax, FS:[$24]
end;
{$else}
begin
Result := GetCurrentThreadID;
end;
{$endif}
I've tested it, and it works, so my question is any explanation why it works?
The x86 register FS points to the Thread Information Block in Windows. The value in TIB at address FS+0x24 contains ID of the current thread. By moving the value to eax, which is used to pass the function return value, GetThreadID returns the current thread ID.
This method uses the information stored in the Thread Environment Block
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With