Minor optimization of plt cache

This commit is contained in:
Pavel 2025-06-28 22:52:43 +03:00
parent f34ce347ce
commit de9bb49c15
8 changed files with 220 additions and 132 deletions

View File

@ -134,6 +134,7 @@ type
p_jit_plt=^t_jit_plt;
t_jit_plt=packed record
cache:Pointer;
//block:Pointer;
end;
p_jit_code_chunk=^t_jit_code_chunk;
@ -496,18 +497,22 @@ type
operator :=(const A:TRegValue):t_jit_lea;
operator + (const A,B:t_jit_lea):t_jit_lea;
operator + (const A:t_jit_lea;const B:TRegValue):t_jit_lea;
operator + (const A:t_jit_lea;B:Integer):t_jit_lea;
operator - (const A:t_jit_lea;B:Integer):t_jit_lea;
operator + (const A:t_jit_lea;B:Int64):t_jit_lea;
operator - (const A:t_jit_lea;B:Int64):t_jit_lea;
operator + (const A:t_jit_lea;B:QWORD):t_jit_lea;
operator - (const A:t_jit_lea;B:QWORD):t_jit_lea;
operator + (const A:t_jit_lea;B:TOperandSize):t_jit_lea;
operator :=(const A:TOperandSize):t_jit_lea;
operator + (const A:t_jit_lea;B:Integer):t_jit_lea; inline;
operator - (const A:t_jit_lea;B:Integer):t_jit_lea; inline;
operator + (const A:t_jit_lea;B:Int64):t_jit_lea; inline;
operator - (const A:t_jit_lea;B:Int64):t_jit_lea; inline;
operator + (const A:t_jit_lea;B:QWORD):t_jit_lea; inline;
operator - (const A:t_jit_lea;B:QWORD):t_jit_lea; inline;
operator + (const A:t_jit_lea;B:Pointer):t_jit_lea; inline;
operator - (const A:t_jit_lea;B:Pointer):t_jit_lea; inline;
operator - (const B:Pointer):Pointer; inline;
operator + (const A,B:Pointer):Pointer; inline;
operator + (const A:t_jit_lea;B:TOperandSize):t_jit_lea; inline;
operator :=(const A:TOperandSize):t_jit_lea; inline;
operator * (const A:t_jit_lea;B:Integer):t_jit_lea;
function Sums(mem:t_jit_leas):t_jit_lea;
function mem_size(mem:t_jit_leas):TOperandSize;
function mem_size(mem:t_jit_leas):TOperandSize; inline;
function classif_offset_32(AOffset:Integer):Byte;
function classif_offset_64(AOffset:Int64):TOperandSize;
@ -723,56 +728,80 @@ begin
end;
end;
operator + (const A:t_jit_lea;B:Integer):t_jit_lea;
operator + (const A:t_jit_lea;B:Integer):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset+B;
end;
operator - (const A:t_jit_lea;B:Integer):t_jit_lea;
operator - (const A:t_jit_lea;B:Integer):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset-B;
end;
operator + (const A:t_jit_lea;B:Int64):t_jit_lea;
operator + (const A:t_jit_lea;B:Int64):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset+B;
end;
operator - (const A:t_jit_lea;B:Int64):t_jit_lea;
operator - (const A:t_jit_lea;B:Int64):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset-B;
end;
operator + (const A:t_jit_lea;B:QWORD):t_jit_lea;
operator + (const A:t_jit_lea;B:QWORD):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset+B;
end;
operator - (const A:t_jit_lea;B:QWORD):t_jit_lea;
operator - (const A:t_jit_lea;B:QWORD):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset-B;
end;
operator + (const A:t_jit_lea;B:TOperandSize):t_jit_lea;
operator + (const A:t_jit_lea;B:Pointer):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset+QWORD(B);
end;
operator - (const A:t_jit_lea;B:Pointer):t_jit_lea; inline;
begin
Result:=A;
Result.AOffset:=Result.AOffset-QWORD(B);
end;
operator - (const B:Pointer):Pointer; inline;
begin
Result:=Pointer(-PTRINT(B));
end;
operator + (const A,B:Pointer):Pointer; inline;
begin
Result:=Pointer(PTRINT(A)+PTRINT(B));
end;
operator + (const A:t_jit_lea;B:TOperandSize):t_jit_lea; inline;
begin
Result:=A;
Result.AMemSize:=B;
end;
operator :=(const A:TOperandSize):t_jit_lea;
operator := (const A:TOperandSize):t_jit_lea; inline;
begin
Result:=Default(t_jit_lea);
Result.AMemSize:=A;
@ -814,7 +843,7 @@ begin
end;
end;
function mem_size(mem:t_jit_leas):TOperandSize;
function mem_size(mem:t_jit_leas):TOperandSize; inline;
begin
Result:=Sums(mem).AMemSize;
end;

View File

@ -104,36 +104,82 @@ end;
procedure op_jmp_plt(var ctx:t_jit_context2);
var
plt :t_jit_i_link;
link_jne :t_jit_i_link;
link_jcxz:t_jit_i_link;
link_jmp :t_jit_i_link;
link_exit:t_jit_i_link;
//link_jne :t_jit_i_link;
begin
with ctx.builder do
begin
movq(r13,rcx); //save rcx (break jit_frame)
plt:=leap(r15);
movq(r15,[r15]); //plt^
movq(rcx,[r15+(@p_jplt_cache_asm(nil)^.neg)]); //plt^.neg
leaq(rcx,[rcx+r14]);
link_jcxz:=jcxz(nil_link,as64,os8);
//plt cache fail
movq(rcx,r13); //restore rcx
//restore jit_frame in jit_jmp_dispatch
//reload plt link
leap(r15,plt);
call_far(@jit_jmp_dispatch); //input:r14,r15 out:r14
//exit:
link_jmp:=jmp(nil_link,os8); //jmp _exit
//plt cache succes
link_jcxz.target:=ctx.builder.get_curr_label.after;
movq(rcx,r13); //restore rcx
//restore jit_frame
movq(r13,[GS +teb_thread]);
leaq(r13,[r13+jit_frame_offset]);
movq(r14,[r15+(@p_jplt_cache_asm(nil)^.dst)]); //plt^.dst
//exit
link_jmp.target:=ctx.builder.get_curr_label.after;
/////////////////////////////////////////
{
plt:=leap(r15);
movq(r15,[r15]); //plt^
pushfq(os64);
cmpq(r14,[r15+Integer(@p_jplt_cache_asm(nil)^.src)]);
cmpq(r14,[r15+(@p_jplt_cache_asm(nil)^.src)]);
//next
instr.target:=get_curr_label.after;
link_jne:=jcc(OPSc_nz,nil_link,os8); //jne _non_cache
popfq(os64);
//get blk
movq(r14,[r15+Integer(@p_jplt_cache_asm(nil)^.blk)]);
movq(r14,[r15+(@p_jplt_cache_asm(nil)^.blk)]);
//save current block
movq([r13+
(
-Integer(@p_kthread(nil)^.td_frame.tf_r13)
+Integer(@p_kthread(nil)^.td_jctx.block)
-(@p_kthread(nil)^.td_frame.tf_r13)
+(@p_kthread(nil)^.td_jctx.block)
)
],r14);
//get dst
movq(r14,[r15+Integer(@p_jplt_cache_asm(nil)^.dst)]);
movq(r14,[r15+(@p_jplt_cache_asm(nil)^.dst)]);
//interrupt
//jmp %gs:teb.jit_trp
@ -141,8 +187,7 @@ begin
link_jmp:=jmp(nil_link,os8); //jmp _exit
//_non_cache:
link_exit:=ctx.builder.get_curr_label.after; //_non_cache
link_jne.target:=link_exit;
link_jne.target:=ctx.builder.get_curr_label.after;
popfq(os64);
@ -150,8 +195,11 @@ begin
call_far(@jit_jmp_dispatch); //input:r14,r15 out:r14
//_exit:
link_exit:=ctx.builder.get_curr_label.after; //_exit
link_jmp.target:=link_exit;
link_jmp.target:=ctx.builder.get_curr_label.after;
}
end;
end;
@ -1105,7 +1153,7 @@ begin
mImport:
begin
//set PCB_IS_HLE
ori([r13-jit_frame_offset+Integer(@p_kthread(nil)^.pcb_flags),os8],Byte(PCB_IS_HLE));
ori([r13-jit_frame_offset+(@p_kthread(nil)^.pcb_flags),os8],Byte(PCB_IS_HLE));
end;
else;
end;
@ -1114,20 +1162,20 @@ begin
mInstruction:
begin
//save internal stack
movq([r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_jctx.rsp)],rsp);
movq([r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_jctx.rbp)],rbp);
movq([r13-jit_frame_offset+(@p_kthread(nil)^.td_jctx.rsp)],rsp);
movq([r13-jit_frame_offset+(@p_kthread(nil)^.td_jctx.rbp)],rbp);
//load guest stack
movq(r14,[r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_ustack.stack)]);
movq(r15,[r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_ustack.sttop)]);
movq(r14,[r13-jit_frame_offset+(@p_kthread(nil)^.td_ustack.stack)]);
movq(r15,[r13-jit_frame_offset+(@p_kthread(nil)^.td_ustack.sttop)]);
//set teb
movq([GS+teb_stack],r14);
movq([GS+teb_sttop],r15);
//load rsp,rbp
movq(rsp,[r13+Integer(@p_jit_frame(nil)^.tf_rsp)]);
movq(rbp,[r13+Integer(@p_jit_frame(nil)^.tf_rbp)]);
movq(rsp,[r13+(@p_jit_frame(nil)^.tf_rsp)]);
movq(rbp,[r13+(@p_jit_frame(nil)^.tf_rbp)]);
//
end;
mExport:
@ -1135,11 +1183,11 @@ begin
//load guest stack
//pushq %rbp
//////////push([r13+Integer(@p_jit_frame(nil)^.tf_rbp),os64]);
//////////push([r13+(@p_jit_frame(nil)^.tf_rbp),os64]);
//movq %rsp,%rbp
movq(r14,[r13+Integer(@p_jit_frame(nil)^.tf_rsp)]); //<-rsp
//////////movq([r13+Integer(@p_jit_frame(nil)^.tf_rbp)],r14); //->rbp
movq(r14,[r13+(@p_jit_frame(nil)^.tf_rsp)]); //<-rsp
//////////movq([r13+(@p_jit_frame(nil)^.tf_rbp)],r14); //->rbp
//prolog (debugger)
push(rbp);
@ -1165,20 +1213,20 @@ begin
//restore guest/host stack
//movq %rbp,%rsp
movq(r14,[r13+Integer(@p_jit_frame(nil)^.tf_rbp)]); //<-rbp
movq([r13+Integer(@p_jit_frame(nil)^.tf_rsp)],r14); //->rsp
movq(r14,[r13+(@p_jit_frame(nil)^.tf_rbp)]); //<-rbp
movq([r13+(@p_jit_frame(nil)^.tf_rsp)],r14); //->rsp
//popq %rbp
pop([r13+Integer(@p_jit_frame(nil)^.tf_rbp),os64]);
pop([r13+(@p_jit_frame(nil)^.tf_rbp),os64]);
//
end;
else;
end;
//load r14,r15,r13
movq(r14,[r13+Integer(@p_jit_frame(nil)^.tf_r14)]);
movq(r15,[r13+Integer(@p_jit_frame(nil)^.tf_r15)]);
movq(r13,[r13+Integer(@p_jit_frame(nil)^.tf_r13)]);
movq(r14,[r13+(@p_jit_frame(nil)^.tf_r14)]);
movq(r15,[r13+(@p_jit_frame(nil)^.tf_r15)]);
movq(r13,[r13+(@p_jit_frame(nil)^.tf_r13)]);
end;
end;
@ -1190,38 +1238,38 @@ begin
begin
//save r13
movq([GS+Integer(teb_jitcall)],r13);
movq([GS+teb_jitcall],r13);
//load curkthread,jit_ctx
movq(r13,[GS +Integer(teb_thread)]);
movq(r13,[GS +teb_thread]);
leaq(r13,[r13+jit_frame_offset ]);
//load r14,r15
movq([r13+Integer(@p_jit_frame(nil)^.tf_r14)],r14);
movq([r13+Integer(@p_jit_frame(nil)^.tf_r15)],r15);
movq([r13+(@p_jit_frame(nil)^.tf_r14)],r14);
movq([r13+(@p_jit_frame(nil)^.tf_r15)],r15);
//load r13
movq(r14,[GS+Integer(teb_jitcall)]);
movq([r13+Integer(@p_jit_frame(nil)^.tf_r13)],r14);
movq(r14,[GS+teb_jitcall]);
movq([r13+(@p_jit_frame(nil)^.tf_r13)],r14);
case mode of
mInstruction:
begin
//load rsp,rbp
movq([r13+Integer(@p_jit_frame(nil)^.tf_rsp)],rsp);
movq([r13+Integer(@p_jit_frame(nil)^.tf_rbp)],rbp);
movq([r13+(@p_jit_frame(nil)^.tf_rsp)],rsp);
movq([r13+(@p_jit_frame(nil)^.tf_rbp)],rbp);
//load host stack
movq(r14,[r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_kstack.stack)]);
movq(r15,[r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_kstack.sttop)]);
movq(r14,[r13-jit_frame_offset+(@p_kthread(nil)^.td_kstack.stack)]);
movq(r15,[r13-jit_frame_offset+(@p_kthread(nil)^.td_kstack.sttop)]);
//set teb
movq([GS+teb_stack],r14);
movq([GS+teb_sttop],r15);
//load internal stack
movq(rsp,[r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_jctx.rsp)]);
movq(rbp,[r13-jit_frame_offset+Integer(@p_kthread(nil)^.td_jctx.rbp)]);
movq(rsp,[r13-jit_frame_offset+(@p_kthread(nil)^.td_jctx.rsp)]);
movq(rbp,[r13-jit_frame_offset+(@p_kthread(nil)^.td_jctx.rbp)]);
//
end;
mExport:
@ -1235,11 +1283,11 @@ begin
//restore guest/host stack
//movq %rbp,%rsp
//////////movq(r14,[r13+Integer(@p_jit_frame(nil)^.tf_rbp)]); //<-rbp
//////////movq([r13+Integer(@p_jit_frame(nil)^.tf_rsp)],r14); //->rsp
//////////movq(r14,[r13+(@p_jit_frame(nil)^.tf_rbp)]); //<-rbp
//////////movq([r13+(@p_jit_frame(nil)^.tf_rsp)],r14); //->rsp
//popq %rbp
//////////pop([r13+Integer(@p_jit_frame(nil)^.tf_rbp),os64]);
//////////pop([r13+(@p_jit_frame(nil)^.tf_rbp),os64]);
//
end;
mImport:
@ -1247,17 +1295,17 @@ begin
//load guest stack
//pushq %rbp
push([r13+Integer(@p_jit_frame(nil)^.tf_rbp),os64]);
push([r13+(@p_jit_frame(nil)^.tf_rbp),os64]);
//movq %rsp,%rbp
movq(r14,[r13+Integer(@p_jit_frame(nil)^.tf_rsp)]); //<-rsp
movq([r13+Integer(@p_jit_frame(nil)^.tf_rbp)],r14); //->rbp
movq(r14,[r13+(@p_jit_frame(nil)^.tf_rsp)]); //<-rsp
movq([r13+(@p_jit_frame(nil)^.tf_rbp)],r14); //->rbp
leaq(r14,[r14-$8]); //shift guard
//alloc guest rsp
leaq(r14,[r14-$50]);
movq([r13+Integer(@p_jit_frame(nil)^.tf_rsp)],r14); //rsp
movq([r13+(@p_jit_frame(nil)^.tf_rsp)],r14); //rsp
//preload stack argc
@ -1277,7 +1325,7 @@ begin
mImport:
begin
//reset PCB_IS_HLE
andi([r13-jit_frame_offset+Integer(@p_kthread(nil)^.pcb_flags),os8],not Byte(PCB_IS_HLE));
andi([r13-jit_frame_offset+(@p_kthread(nil)^.pcb_flags),os8],not Byte(PCB_IS_HLE));
//
end;
else;
@ -2246,7 +2294,7 @@ begin
{
op_set_r14_imm(ctx,Int64(ctx.ptr_curr));
with ctx.builder do
movq([GS+Integer(teb_jitcall)],r14);
movq([GS+teb_jitcall],r14);
}
{

View File

@ -48,8 +48,8 @@ type
t_jplt_cache_asm=object
plt:Pointer;
src:Pointer;
neg:Pointer; //(-src)
dst:Pointer;
blk:Pointer;
end;
procedure jit_syscall; assembler;
@ -448,10 +448,10 @@ asm
jne _exit
//get blk
movq t_jplt_cache_asm.blk(%rbp),%r14
//movq t_jplt_cache_asm.blk(%rbp),%r14
//save current block
movqq %r14, - kthread.td_frame.tf_r13 + kthread.td_jctx.block(%r13)
//movqq %r14, - kthread.td_frame.tf_r13 + kthread.td_jctx.block(%r13)
//get dst
movq t_jplt_cache_asm.dst(%rbp),%r14
@ -489,6 +489,9 @@ asm
push %rbp
movq %rsp,%rbp
movq %gs:teb.thread,%r13 //curkthread
leaq kthread.td_frame.tf_r13(%r13),%r13 //jit_frame
call jit_save_ctx // -> pushf
andq $-16,%rsp //align stack

View File

@ -1767,7 +1767,7 @@ begin
with ctx.builder do
begin
//[65 FF 14 25] [00 07 00 00] call gs:[$00000700]
//call([GS+Integer(teb_jit_trp)]);
//call([GS+teb_jit_trp]);
//ctx.label_flags:=ctx.label_flags or LF_JMP_INTERRUPT;
end;
@ -1810,15 +1810,12 @@ begin
end;
procedure op_set_rip_imm(var ctx:t_jit_context2;imm:Int64);
var
i:Integer;
begin
op_set_r14_imm(ctx,imm);
//
with ctx.builder do
begin
i:=Integer(@p_jit_frame(nil)^.tf_rip);
movq([r_thrd+i],r_tmp0);
movq([r_thrd+(@p_jit_frame(nil)^.tf_rip)],r_tmp0);
end;
end;
@ -1978,8 +1975,8 @@ begin
if (rbits.AIndex=r13.AIndex) then
begin
//restore jit_frame
movq(r13,[GS +Integer(teb_thread)]);
leaq(r13,[r13+jit_frame_offset ]);
movq(r13,[GS +teb_thread]);
leaq(r13,[r13+jit_frame_offset]);
end;
end;
end;
@ -4258,8 +4255,8 @@ begin
if (tmp_count=3) then
begin
//restore jit_frame
movq(r13,[GS +Integer(teb_thread)]);
leaq(r13,[r13+jit_frame_offset ]);
movq(r13,[GS +teb_thread]);
leaq(r13,[r13+jit_frame_offset]);
end;
//store result

View File

@ -29,14 +29,6 @@ uses
+----------+ +---------+
}
var
plt_stub:t_jplt_cache_asm=(
plt:nil;
src:nil;
dst:nil;
blk:nil;
);
type
p_jit_dynamic_blob=^t_jit_dynamic_blob;
@ -89,10 +81,15 @@ type
p_jplt_cache=^t_jplt_cache;
t_jplt_cache=object(t_jplt_cache_asm)
//
pLeft :p_jplt_cache; //jpltc_curr
pRight:p_jplt_cache; //jpltc_curr
//
entry:TAILQ_ENTRY; //jpltc_attc
//
self_block:Pointer;
dest_block:Pointer;
//
function c(n1,n2:p_jplt_cache):Integer; static;
end;
@ -114,6 +111,8 @@ type
plta:p_jit_plt;
pltc:ptruint;
plt_stub:t_jplt_cache;
lock:Pointer;
refs:Integer;
@ -133,7 +132,7 @@ type
procedure detach_plt_cache(uplock:p_jit_dynamic_blob;node:p_jplt_cache);
procedure detach_all_attc;
procedure detach_all_curr;
function add_plt_cache(plt:p_jit_plt;src,dst:Pointer;dst_blk:p_jit_dynamic_blob):p_jplt_cache;
function add_plt_cache(plt:p_jit_plt;src,dst:Pointer;dest_block:p_jit_dynamic_blob):p_jplt_cache;
function new_chunk(count:QWORD):p_jcode_chunk;
procedure alloc_base(_size:ptruint);
procedure free_base;
@ -273,7 +272,7 @@ end;
procedure jit_ctx_free(td:p_kthread); public;
begin
td^.td_jctx.block:=nil;
//td^.td_jctx.block:=nil;
end;
procedure switch_to_jit(td:p_kthread); public;
@ -354,7 +353,7 @@ begin
frame:=@td^.td_frame.tf_r13;
jctx^.block:=node^.blob;
//jctx^.block:=node^.blob;
if (jctx^.rsp=nil) then
begin
@ -717,11 +716,11 @@ begin
begin
if (cache^.src=addr) then
begin
jctx^.block:=cache^.blk;
//jctx^.block:=cache^.blk;
Result:=cache^.dst;
if (jctx^.block=nil) or (InterlockedExchangeAdd64(QWORD(cache^.blk),0)=0) then
if (InterlockedExchangeAdd64(QWORD(cache^.dest_block),0)=0) then
begin
//reset all
cache:=nil;
@ -748,20 +747,30 @@ begin
//jctx:=@td^.td_jctx;
curr:=jctx^.block;
//curr:=jctx^.block;
//curr:=fetch_blob_by_host(plt);
//curr:=node^.blob;
//curr:=plt^.block;
if (plt<>nil) then
begin
cache:=plt^.cache;
curr:=cache^.self_block;
end else
begin
curr:=nil;
end;
if (curr=nil) or (plt=nil) then
begin
jctx^.block:=node^.blob;
//jctx^.block:=node^.blob;
end else
begin
cache:=curr^.add_plt_cache(plt,node^.src,node^.dst,node^.blob);
jctx^.local_cache[hash_addr(addr)]:=cache;
jctx^.block:=node^.blob;
//jctx^.block:=node^.blob;
Assert(cache<>nil);
Assert(cache^.src<>nil);
@ -1236,9 +1245,16 @@ var
i:Integer;
begin
if (pltc<>0) then
For i:=0 to pltc-1 do
begin
plta[i].cache:=@plt_stub;
plt_stub.self_block:=@Self;
plt_stub.dest_block:=@Self;
For i:=0 to pltc-1 do
begin
plta[i].cache:=@plt_stub;
//plta[i].block:=@Self;
end;
end;
end;
@ -1253,11 +1269,6 @@ begin
TAILQ_INSERT_TAIL(@jpltc_attc,node,@node^.entry);
if (node^.entry.tqe_prev=nil) then
begin
Assert(false);
end;
if (uplock<>@Self) then
begin
rw_wunlock(lock);
@ -1286,15 +1297,17 @@ begin
end;
end;
procedure _reset_plt(node:p_jplt_cache);
procedure reset_plt(node:p_jplt_cache);
var
blk:p_jit_dynamic_blob;
plt:p_jit_plt;
begin
blk:=node^.self_block;
plt:=node^.plt;
if (plt<>nil) then
if (plt<>nil) and (blk<>nil) then
begin
//one element plt reset
System.InterlockedCompareExchange(plt^.cache,@plt_stub,node);
System.InterlockedCompareExchange(plt^.cache,@blk^.plt_stub,node);
end;
end;
@ -1308,19 +1321,14 @@ begin
begin
next:=TAILQ_NEXT(node,@node^.entry);
if (node^.entry.tqe_prev=nil) then
begin
Assert(false);
end;
TAILQ_REMOVE(@jpltc_attc,node,@node^.entry);
node^.entry:=Default(TAILQ_ENTRY);
_reset_plt(node);
reset_plt(node);
//force deref
if (System.InterlockedCompareExchange(node^.blk,nil,@Self)=@Self) then
if (System.InterlockedCompareExchange(node^.dest_block,nil,@Self)=@Self) then
begin
Self.dec_ref('add_plt_cache');
end;
@ -1346,9 +1354,9 @@ begin
begin
jpltc_curr.Delete(node);
_reset_plt(node);
reset_plt(node);
blk:=System.InterlockedExchange(node^.blk,nil);
blk:=System.InterlockedExchange(node^.dest_block,nil);
if (blk<>nil) then
begin
@ -1362,17 +1370,18 @@ begin
end;
end;
function t_jit_dynamic_blob.add_plt_cache(plt:p_jit_plt;src,dst:Pointer;dst_blk:p_jit_dynamic_blob):p_jplt_cache;
function t_jit_dynamic_blob.add_plt_cache(plt:p_jit_plt;src,dst:Pointer;dest_block:p_jit_dynamic_blob):p_jplt_cache;
var
node:t_jplt_cache;
old_blk:p_jit_dynamic_blob;
_insert:Boolean;
begin
Assert(plt<>nil);
Assert(dst_blk<>nil);
Assert(dest_block<>nil);
node.plt:=plt; //key
node.src:=src; //key
node.neg:=Pointer(-QWORD(src));
repeat
@ -1386,18 +1395,18 @@ begin
//update
Result^.dst:=dst;
//
old_blk:=System.InterlockedExchange(Result^.blk,dst_blk);
if (old_blk<>dst_blk) then
old_blk:=System.InterlockedExchange(Result^.dest_block,dest_block);
if (old_blk<>dest_block) then
begin
if (old_blk<>nil) and (old_blk=@Self) then
begin
//detach immediately
old_blk^.detach_plt_cache(@Self,Result);
end;
if (dst_blk=@Self) then
if (dest_block=@Self) then
begin
//attach immediately
dst_blk^.attach_plt_cache(@Self,Result);
dest_block^.attach_plt_cache(@Self,Result);
end;
end;
end;
@ -1405,7 +1414,7 @@ begin
if (Result<>nil) then
begin
if (old_blk<>dst_blk) then
if (old_blk<>dest_block) then
begin
if (old_blk<>nil) and (old_blk<>@Self) then
begin
@ -1413,10 +1422,10 @@ begin
old_blk^.detach_plt_cache(@Self,Result);
end;
//
if (dst_blk<>@Self) then
if (dest_block<>@Self) then
begin
//attach deferred
dst_blk^.attach_plt_cache(@Self,Result);
dest_block^.attach_plt_cache(@Self,Result);
end;
end;
//
@ -1426,24 +1435,26 @@ begin
Result:=AllocMem(Sizeof(t_jplt_cache));
Result^.plt:=plt; //key
Result^.src:=src; //key
Result^.neg:=Pointer(-QWORD(src));
Result^.dst:=dst;
Result^.blk:=dst_blk;
Result^.self_block:=@Self;
Result^.dest_block:=dest_block;
//
rw_wlock(lock);
_insert:=jpltc_curr.Insert(Result);
if _insert and (dst_blk=@Self) then
if _insert and (dest_block=@Self) then
begin
//attach immediately
dst_blk^.attach_plt_cache(@Self,Result);
dest_block^.attach_plt_cache(@Self,Result);
end;
rw_wunlock(lock);
//
if _insert then
begin
//attach deferred
if (dst_blk<>@Self) then
if (dest_block<>@Self) then
begin
dst_blk^.attach_plt_cache(@Self,Result);
dest_block^.attach_plt_cache(@Self,Result);
end;
//
Break;

View File

@ -545,8 +545,8 @@ begin
}
//restore jit_frame
movq(r13,[GS +Integer(teb_thread)]);
leaq(r13,[r13+jit_frame_offset ]);
movq(r13,[GS +teb_thread]);
leaq(r13,[r13+jit_frame_offset]);
end;
end;

View File

@ -189,7 +189,7 @@ type
p_td_jctx=^t_td_jctx;
t_td_jctx=packed record
block:Pointer;
//block:Pointer;
rsp:Pointer;
rbp:Pointer;
local_cache:array[0..255] of Pointer;

View File

@ -59,7 +59,7 @@ const
SCE_KERNEL_GNMDRIVER =QWORD($00FE0000000);
_VM_MINUSER_ADDRESS =QWORD($00010000000); //(original:$000000000000)
VM_MAXUSER_ADDRESS =QWORD($80000000000); //(original:$800000000000) MAP_AREA_END=0xfc00000000
VM_MAXUSER_ADDRESS =QWORD($80000000000); //(original:$800000000000) [0..47] MAP_AREA_END=0xfc00000000
VM_MIN_GPU_ADDRESS =QWORD($90000000000);
VM_MAX_GPU_ADDRESS =QWORD($A0000000000); //Virtual mirror