Kernel: Fix signal generation

We need to have interrupts enabled when signal kills the process as
process does mutex locking. Also signals are now only checked when
returning to userspace in the same place where userspace segments are
loaded.
This commit is contained in:
2026-04-04 22:36:54 +03:00
parent 47d85eb281
commit a29681a524
7 changed files with 166 additions and 143 deletions

View File

@@ -1,20 +1,20 @@
.macro maybe_load_kernel_segments, n
testb $3, \n(%esp)
jz 1f; jnp 1f
.macro intr_header, n
pushal
testb $3, \n+8*4(%esp)
jz 1f
movw $0x10, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw $0x28, %ax
movw %ax, %gs
1:
1: cld
.endm
.macro maybe_load_userspace_segments, n
testb $3, \n(%esp)
jz 1f; jnp 1f
.macro intr_footer, n
testb $3, \n+8*4(%esp)
jz 1f
call cpp_check_signal
movw $(0x20 | 3), %bx
movw %bx, %ds
movw %bx, %es
@@ -22,14 +22,11 @@
movw %bx, %fs
movw $(0x38 | 3), %bx
movw %bx, %gs
1:
1: popal
.endm
isr_stub:
pushal
maybe_load_kernel_segments 44
cld
intr_header 12
movl %cr0, %eax; pushl %eax
movl %cr2, %eax; pushl %eax
movl %cr3, %eax; pushl %eax
@@ -57,15 +54,12 @@ isr_stub:
movl %ebp, %esp
addl $24, %esp
maybe_load_userspace_segments 44
popal
intr_footer 12
addl $8, %esp
iret
irq_stub:
pushal
maybe_load_kernel_segments 44
cld
intr_header 12
movl 32(%esp), %edi # interrupt number
@@ -78,16 +72,13 @@ irq_stub:
movl %ebp, %esp
maybe_load_userspace_segments 44
popal
intr_footer 12
addl $8, %esp
iret
.global asm_ipi_handler
asm_ipi_handler:
pushal
maybe_load_kernel_segments 36
cld
intr_header 4
movl %esp, %ebp
andl $-16, %esp
@@ -96,15 +87,12 @@ asm_ipi_handler:
movl %ebp, %esp
maybe_load_userspace_segments 36
popal
intr_footer 4
iret
.global asm_timer_handler
asm_timer_handler:
pushal
maybe_load_kernel_segments 36
cld
intr_header 4
movl %esp, %ebp
andl $-16, %esp
@@ -113,8 +101,7 @@ asm_timer_handler:
movl %ebp, %esp
maybe_load_userspace_segments 36
popal
intr_footer 4
iret
.macro isr n

View File

@@ -1,12 +1,4 @@
.macro swapgs_if_necessary, n
testb $3, \n(%rsp)
jz 1f; jnp 1f
swapgs
1:
.endm
.macro pushaq, n
swapgs_if_necessary \n
.macro intr_header, n
pushq %rax
pushq %rcx
pushq %rdx
@@ -22,10 +14,18 @@
pushq %r13
pushq %r14
pushq %r15
testb $3, \n+15*8(%rsp)
jz 1f
swapgs
1: cld
.endm
.macro popaq, n
popq %r15
.macro intr_footer, n
testb $3, \n+15*8(%rsp)
jz 1f
call cpp_check_signal
swapgs
1: popq %r15
popq %r14
popq %r13
popq %r12
@@ -40,12 +40,10 @@
popq %rdx
popq %rcx
popq %rax
swapgs_if_necessary \n
.endm
isr_stub:
pushaq 24
cld
intr_header 24
movq %cr0, %rax; pushq %rax
movq %cr2, %rax; pushq %rax
movq %cr3, %rax; pushq %rax
@@ -58,33 +56,33 @@ isr_stub:
call cpp_isr_handler
addq $32, %rsp
popaq 24
intr_footer 24
addq $16, %rsp
iretq
irq_stub:
pushaq 24
cld
intr_header 24
xorq %rbp, %rbp
movq 120(%rsp), %rdi # irq number
call cpp_irq_handler
popaq 24
intr_footer 24
addq $16, %rsp
iretq
.global asm_ipi_handler
asm_ipi_handler:
pushaq 8
cld
intr_header 8
xorq %rbp, %rbp
call cpp_ipi_handler
popaq 8
intr_footer 8
iretq
.global asm_timer_handler
asm_timer_handler:
pushaq 8
cld
intr_header 8
xorq %rbp, %rbp
call cpp_timer_handler
popaq 8
intr_footer 8
iretq
.macro isr n