]> Zhao Yanbai Git Server - kernel.git/commitdiff
在ring3中触发#PF
authorzhaoyanbai <zhaoyanbai@126.com>
Sat, 3 Oct 2026 04:35:17 +0000 (12:35 +0800)
committerzhaoyanbai <zhaoyanbai@126.com>
Sat, 3 Oct 2026 04:35:17 +0000 (12:35 +0800)
kernel/ring3.S
kernel/task_user.c
scripts/link.ld

index 57746859e2b5f1896272185b895ceb8470d0aa91..9ec9176c7dd32864957b216df59472b571b62023 100644 (file)
@@ -10,6 +10,8 @@
 #define ASM
 #include <syscall.h>
 
+.extern ring3_c_text
+
 # a allocatable 可分配,表示这个节在程序运行时需要加载到内存中
 # x executable  可执行,表示这个节包含可执行的代码
 # w writable    可写,通常用于数据节
@@ -58,6 +60,9 @@ ring3_entry:
     addl    $0x18, %esp
 
 
+    call    ring3_c_text
+
+
     # 纯消耗CPU时间
     movl    $0xFF0F0F0F, %ecx
 1:
index 31ee601eeb2db083634b415af266e1f8563fbebf..73fdf66c98dcc6f69f08bbfb8f5774611b4d456e 100644 (file)
@@ -61,3 +61,10 @@ void user_task_entry() {
 
     asm volatile("sysexit;" ::"d"(ring3_page_vaddr), "c"(ring3_stack_top_vaddr));
 }
+
+// 用于触发#PF以验证COW
+__attribute__((__section__(".ring3.data"))) uint32_t ring3_x = 0;
+__attribute__((__section__(".ring3.text"))) void ring3_c_text() {
+    asm("nop;nop;nop;nop;nop;nop;nop;nop;");
+    ring3_x += 1;
+}
index d80f3750ed15878140b2fccaacf2a8ba85f210b8..d91f95af63ad14e3939fadb68d30f2279c66015a 100644 (file)
@@ -64,6 +64,7 @@ SECTIONS
     {
         ring3_page_begin = .;
         *(.ring3.entry)
+        *(.ring3.text)
         . = ALIGN(0x100);
         ring3_text_size = SIZEOF(.ring3);
         ring3_page_end = .;
@@ -72,6 +73,14 @@ SECTIONS
     /* 带绝对 VMA 的节写完后 . 不会自动接上,而是变成 该节VMA+SIZEOF(该节名) */
     . = ring3_lma + SIZEOF(.ring3);
 
+    . = ALIGN(0x1000);
+    ring3_data_lma = .;
+    .ring3_data 0x10000000 : AT(ring3_data_lma)
+    {
+        *(.ring3.data)
+    }
+    . = ring3_data_lma + SIZEOF(.ring3_data);
+
     . = ALIGN(0x1000);
     /* . = kernel_begin; */
     . += kernel_virtual_addr_start;