mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-29 02:59:24 +02:00
* WebAssembly threads: made FreeStackAndTlsBlock set the StackBlock and
TlsPointers to nil
This commit is contained in:
parent
c8b9eb3c5c
commit
4abbd82135
@ -452,12 +452,20 @@ exports wasi_thread_start;
|
|||||||
|
|
||||||
Function wasi_thread_spawn(start_arg: PWasmThread) : LongInt; external 'wasi' name 'thread-spawn';
|
Function wasi_thread_spawn(start_arg: PWasmThread) : LongInt; external 'wasi' name 'thread-spawn';
|
||||||
|
|
||||||
|
{ Just because we set the original pointer to nil, using InterlockedExchange
|
||||||
|
to avoid race conditions leading to double free, doesn't mean this function is
|
||||||
|
meant to be called more than once, or from multiple threads. This just adds
|
||||||
|
some extra layer of protection. }
|
||||||
procedure FreeStackAndTlsBlock(T : PWasmThread);
|
procedure FreeStackAndTlsBlock(T : PWasmThread);
|
||||||
|
var
|
||||||
|
P: Pointer;
|
||||||
begin
|
begin
|
||||||
if Assigned(T^.StackBlock) then
|
P:=InterlockedExchange(T^.StackBlock,nil);
|
||||||
FreeMem(T^.StackBlock);
|
if Assigned(P) then
|
||||||
if Assigned(T^.TLSBlock) then
|
FreeMem(P);
|
||||||
FreeMem(T^.TLSBlock);
|
P:=InterlockedExchange(T^.TLSBlock,nil);
|
||||||
|
if Assigned(P) then
|
||||||
|
FreeMem(P);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function WasiBeginThread(sa : Pointer;stacksize : PtrUInt; ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword; var ThreadId : TThreadID) : TThreadID;
|
function WasiBeginThread(sa : Pointer;stacksize : PtrUInt; ThreadFunction : tthreadfunc;p : pointer;creationFlags : dword; var ThreadId : TThreadID) : TThreadID;
|
||||||
|
Loading…
Reference in New Issue
Block a user