Fix tls align alloc

This commit is contained in:
red-prig 2024-03-10 15:53:21 +03:00
parent 19504b1676
commit 7fbfd64da7
2 changed files with 18 additions and 9 deletions

View File

@ -2650,7 +2650,7 @@ Var
adr:Pointer;
begin
tcb_size:=pTls.full_size;
tcb:=_init_tls_tcb(tcb_size,is_static,Handle);
tcb:=_init_tls_tcb(tcb_size,pTls.align,is_static,Handle);
base:=tcb^._dtv.value;
Assert(IsAlign(base,pTls.align));
if (pTls.tmpl_size<>0) then

View File

@ -21,9 +21,10 @@ type
seg_adr:Pointer;
dtv:Pdtv;
_dtv:Tdtv;
base:Pointer;
end;
function _init_tls_tcb(Size,is_static,gen:QWORD):Ptls_tcb;
function _init_tls_tcb(Size,_align,is_static,gen:QWORD):Ptls_tcb;
function _get_tls_tcb(gen:QWORD):Ptls_tcb;
procedure _free_tls_tcb_all;
@ -32,21 +33,29 @@ implementation
threadvar
tls_local:THAMT;
function _init_tls_tcb(Size,is_static,gen:QWORD):Ptls_tcb;
function _init_tls_tcb(Size,_align,is_static,gen:QWORD):Ptls_tcb;
var
full_size:QWORD;
base:Pointer;
tcb:Ptls_tcb;
PP:PPointer;
dtv :Pointer;
tcb :Ptls_tcb;
PP :PPointer;
begin
full_size:=Size+SizeOf(Ttls_tcb);
if (_align=0) then _align:=1;
full_size:=Size+(_align-1)+SizeOf(Ttls_tcb);
base:=AllocMem(full_size);
tcb:=Pointer(base+Size);
dtv :=Align(base,_align);
tcb:=Pointer(dtv+Size);
tcb^.base:=base;
tcb^.seg_adr:=tcb;
tcb^.dtv:=@tcb^._dtv;
tcb^._dtv.value:=base;
tcb^._dtv.value:=dtv;
tcb^._dtv.is_static:=is_static;
tcb^._dtv.gen:=gen;
if (tls_local=nil) then tls_local:=HAMT_create64;
PP:=HAMT_insert64(tls_local,gen,tcb);
Assert(PP<>nil);
@ -70,7 +79,7 @@ Var
begin
tcb:=data;
if (tcb=nil) then Exit;
base:=tcb^._dtv.value;
base:=tcb^.base;
FreeMem(base);
end;