This commit is contained in:
Pavel 2023-02-27 12:12:36 +03:00
parent 142137b203
commit 545f823d4e
10 changed files with 66 additions and 46 deletions

View File

@ -21,8 +21,8 @@ function sys_cpuset_setaffinity(level,which:Integer;id,cpusetsize:QWORD;mask:p_c
implementation
uses
errno,
systm,
sys_kernel,
kern_thread,
vm_machdep;

View File

@ -7,7 +7,6 @@ interface
uses
gtailq,
sys_kernel,
time,
signal,
signalvar,
@ -100,6 +99,7 @@ implementation
uses
ntapi,
errno,
systm,
kern_mtx,
kern_time,

View File

@ -8,7 +8,6 @@ interface
uses
ntapi,
windows,
sys_kernel,
ucontext,
signal,
signalvar,
@ -239,6 +238,7 @@ implementation
uses
gtailq,
errno,
systm,
vm_machdep,
kern_rwlock,

View File

@ -6,7 +6,6 @@ unit kern_time;
interface
uses
sys_kernel,
windows,
ntapi,
time;
@ -21,6 +20,9 @@ function kern_clock_getres(clock_id:Integer;tp:Ptimespec):Integer;
implementation
uses
errno;
Const
UNIT_PER_SEC =10000000;
DELTA_EPOCH_IN_UNIT =116444736000000000;

View File

@ -10,10 +10,8 @@ uses
kern_rwlock,
time,
kern_time,
kern_thread,
_umtx,
sys_kernel;
_umtx;
procedure _umutex_init(mtx:p_umutex); inline;
@ -35,6 +33,7 @@ implementation
uses
HAMT,
errno,
systm,
trap,
vm_machdep;

View File

@ -9,8 +9,7 @@ uses
signal,
signalvar,
ucontext,
kern_thread,
sys_kernel;
kern_thread;
const
_ucodesel=(8 shl 3) or 3;
@ -24,6 +23,7 @@ function sys_sigreturn(sigcntxp:p_ucontext_t):Integer;
implementation
uses
errno,
systm,
md_psl,
kern_sig,

View File

@ -258,6 +258,7 @@ procedure fast_syscall; assembler; nostackframe;
label
_after_call,
_doreti,
_fail,
_ast,
_doreti_exit;
asm
@ -265,11 +266,18 @@ asm
pushq %rbp
movq %rsp,%rbp
lock orl SIG_STI_LOCK,%gs:teb.iflag //lock interrupt
movqq %rax,-16(%rsp) //save rax
movqq %rax,-16(%rsp) //save rax
lahf //load to AH
shr $8,%rax
andl $0xFF,%rax //filter
movqq %rax,-8(%rsp) //save flags
movqq %gs:teb.thread,%rax //curkthread
test %rax,%rax
jz _fail
lock orl SIG_STI_LOCK,%gs:teb.iflag //lock interrupt
andl NOT_PCB_FULL_IRET,kthread.pcb_flags(%rax) //clear PCB_FULL_IRET
@ -307,12 +315,13 @@ asm
movqq -16(%rsp),%r11 //get rax
movqq %r11,trapframe.tf_rax(%rax)
pushfq //push FLAGS
popq %r11 //get FLAGS
movqq -8(%rsp),%r11 //get flags
movqq %r11,trapframe.tf_rflags(%rax)
movqq %gs:teb.thread,%rsp //curkthread
movqq kthread.td_kstack(%rsp),%rsp //td_kstack
movqq kthread.td_kstack(%rsp),%rsp //td_kstack (Implicit lock interrupt)
lock andl NOT_SIG_STI_LOCK,%gs:teb.iflag //unlock interrupt
andq $-32,%rsp //align stack
@ -329,29 +338,44 @@ asm
testl TDF_AST,kthread.td_flags(%rax)
jne _ast
movqq %gs:teb.thread,%rax //curkthread
movqq kthread.td_frame(%rax),%rax //td_frame
movqq %gs:teb.thread,%rcx //curkthread
movqq kthread.td_frame(%rcx),%rcx //td_frame
//Restore preserved registers.
movqq trapframe.tf_rflags(%rax),%r11
pushq %r11 //set FLAGS
popfq //pop FLAGS
movqq trapframe.tf_rflags(%rcx),%rax
shl $8,%rax
sahf //restore flags
movqq trapframe.tf_rdi(%rax),%rdi
movqq trapframe.tf_rsi(%rax),%rsi
movqq trapframe.tf_rdx(%rax),%rdx
movqq trapframe.tf_rdi(%rcx),%rdi
movqq trapframe.tf_rsi(%rcx),%rsi
movqq trapframe.tf_rdx(%rcx),%rdx
movqq trapframe.tf_rax(%rcx),%rax
movqq trapframe.tf_rsp(%rax),%rsp
lea -16(%rsp),%rsp //restore rsp
movqq trapframe.tf_rsp(%rcx),%r11
lea -16(%r11),%r11
movqq trapframe.tf_rax(%rax),%rax //restore rax
movqq %r11,%rsp //restore rsp (Implicit unlock interrupt)
lock andl NOT_SIG_STI_LOCK,%gs:teb.iflag //unlock interrupt
movqq $0,%rcx
movqq $0,%r11
//epilog (debugger)
popq %rbp
ret
//fail:
_fail:
movqq -8(%rsp),%rax //get flags
shl $8,%rax
or $1,%ah //CF
sahf //restore flags
movqq $14,%rax //EFAULT
popq %rbp
ret
//ast
_ast:
@ -371,9 +395,7 @@ asm
_doreti_exit:
//Restore full.
xor %rdi,%rdi
inc %rdi
call ipi_sigreturn //1
call ipi_sigreturn
hlt
end;
@ -406,8 +428,7 @@ asm
jmp _ast
_ast_exit:
xor %rdi,%rdi
call ipi_sigreturn //0
call ipi_sigreturn
hlt
end;

View File

@ -11,7 +11,6 @@ uses
md_psl,
ucontext,
trap,
sys_kernel,
kern_thread;
var
@ -27,7 +26,7 @@ procedure cpu_set_user_tls(td:p_kthread;base:Pointer);
function cpu_set_priority(td:p_kthread;prio:Integer):Integer;
function cpu_getstack(td:p_kthread):QWORD;
procedure ipi_sigreturn(unlock:Integer);
procedure ipi_sigreturn;
function ipi_send_cpu(td:p_kthread):Integer;
function _umtxq_alloc:THandle; inline;
@ -41,6 +40,7 @@ function wakeup_td(td:p_kthread):Integer; inline;
implementation
uses
errno,
systm,
machdep,
signal,
@ -248,7 +248,7 @@ begin
end;
end;
procedure ipi_sigreturn(unlock:Integer);
procedure ipi_sigreturn;
var
_Context:array[0..SizeOf(TCONTEXT)+14] of Byte;
Context :PCONTEXT;
@ -287,11 +287,6 @@ begin
Context^.SegSs:=KGDT64_R3_DATA or RPL_MASK;
Context^.SegFs:=KGDT64_R3_CMTEB or RPL_MASK;
if (unlock<>0) then
begin
sig_cli;
end;
NtContinue(Context,False);
end;
@ -364,7 +359,7 @@ begin
begin
NtResumeThread(td_handle,nil);
w.QuadPart:=-10000;
SwDelayExecution(False,@w); //100ms
NtDelayExecution(False,@w); //100ms
goto tryagain;
end;

View File

@ -6,7 +6,7 @@ unit sys_umtx;
interface
uses
sys_kernel,
errno,
time,
_umtx;

View File

@ -175,18 +175,19 @@ begin
sigaction(SIGUSR1,@act,nil,0);
//thr_kill(tid,SIGUSR1);
thr_wake(tid);
thr_kill(tid,SIGUSR1);
//thr_wake(tid);
end else
begin
Writeln('thr_suspend:',thr_suspend(nil));
//Writeln('thr_suspend:',thr_suspend(nil));
{
oset.qwords[0]:=QWORD(-1);
oset.qwords[1]:=QWORD(-1);
Writeln('sigwait:',sigwait(@oset,@_sig));
Writeln('intr:',_sig);
}
{
Writeln('before: sptr:',HexStr(sptr));
repeat
asm
@ -195,7 +196,6 @@ begin
until (intr<>0);
Writeln('intr');
Writeln('after: sptr:',HexStr(sptr));
}
end;
sig_lock;
@ -612,6 +612,9 @@ var
begin
//test_map;
e:=_umtx_op(nil,UMTX_OP_RW_WRLOCK,0,nil,nil);
Writeln('me=',e);
kern_clock_gettime_unit(CLOCK_PROCTIME,@_time);
writeln(_time/10000000:0:3);