Merge branch 'master' into prog-loader
authorMinep <zelong56@gmail.com>
Tue, 17 Jan 2023 10:30:13 +0000 (10:30 +0000)
committerMinep <zelong56@gmail.com>
Tue, 17 Jan 2023 10:30:13 +0000 (10:30 +0000)
1  2 
README.md
docs/README_en.md
lunaix-os/kernel/process/sched.c

diff --combined README.md
index 7740e1b6d1b3bb3c94258b647ae9fe9550c185f7,c593d19accfe57ec8d5cdb74bfaa86074394a635..a9d1b66eb5b38eba7063d779bd83d9a4eea9b175
+++ b/README.md
@@@ -3,7 -3,7 +3,7 @@@
  </p>
  
  <p align="center">
-   <span>简体中文</span> | <a href="docs/README_en.md">English</a>
+   <a href="#lunaixos-project">简体中文</a> | <a href="docs/README_en.md">English</a>
  </p>
  
  # LunaixOS Project
@@@ -23,7 -23,7 +23,7 @@@ LunaixOS - ä¸\80个ç®\80å\8d\95ç\9a\84ï¼\8c详ç»\86ç\9a\84ï
  + 内存管理与按需分页(Demand Paging)
  + 键盘输入
  + 多进程
 -+ 47个常见的Linux/POSIX系统调用([附录1](#appendix1))
 ++ 50个常见的Linux/POSIX系统调用([附录1](#appendix1))
  + 用户模式
  + 信号机制
  + PCI 3.0
@@@ -144,7 -144,6 +144,7 @@@ qemu-img create -f vdi machine/disk0.vd
  + [ECMA-119 (ISO9660)](https://www.ecma-international.org/publications-and-standards/standards/ecma-119/)
  + Rock Ridge Interchange Protocol (RRIP: IEEE P1282)
  + System Use Sharing Protocol (SUSP: IEEE P1281)
 ++ Tool Interface Standard (TIS) Portable Formats Specification (Version 1.1)
  
  **免责声明:PCI相关的标准最终解释权归PCI-SIG所有。此处提供的副本仅供个人学习使用。任何商用目的须向PCI-SIG购买。**
  
  2. `write(2)`
  2. `open(2)`
  2. `close(2)`
 -2. `mkdir(2)`
 +2. `mkdir(2)`
  2. `lseek(2)`
  2. `readdir(2)`
  2. `readlink(2)`※
  2. `ioctl(2)`
  2. `getpgid(2)`
  2. `setpgid(2)`
 +2. `mmap(2)`
 +2. `munmap(2)`
 +2. `execve(2)`
  
  **LunaixOS自有**
  
diff --combined docs/README_en.md
index 1de21a68ebdb5f14340b68da6d7d5fd824cfaf8b,a0ce1252806854c79e51a0890ab9bc6841f06a2e..a7dd4156c3cbfcdbc5b10308059da6bf9fbe11f2
@@@ -3,7 -3,7 +3,7 @@@
  </p>
  
  <p align="center">
-   <a href="../README.md"><b>简体中文</b></a> | <span><b>English</b></span>
+   <a href="../README.md"><b>简体中文</b></a> | <a href="#the-lunaixos-project"><b>English</b></a>
  </p>
  
  # The LunaixOS Project
@@@ -25,7 -25,7 +25,7 @@@ The following list presents all feature
  + Memory management & demand paging
  + PS/2 Keyboard support
  + Muti-tasking and task management
 -+ 47 commonly used POSIX syscall([See Appendix 1](#appendix1))
 ++ 50 commonly used POSIX syscall([See Appendix 1](#appendix1))
  + User Space
  + Signal
  + PCI 3.0
@@@ -142,7 -142,6 +142,7 @@@ The following list also enumerated suc
  + [ECMA-119 (ISO9660)](https://www.ecma-international.org/publications-and-standards/standards/ecma-119/)
  + Rock Ridge Interchange Protocol (RRIP: IEEE P1282)
  + System Use Sharing Protocol (SUSP: IEEE P1281)
 ++ Tool Interface Standard (TIS) Portable Formats Specification (Version 1.1)
  
  **DISCLAIMER: All rights of PCI-related specification is reserved by PCI-SIG. It is provided ONLY for learning purpose. Any commercial use should purchase a copy from PCI-SIG**
  
  2. `write(2)`
  2. `open(2)`
  2. `close(2)`
 -2. `mkdir(2)`
 +2. `mkdir(2)`
  2. `lseek(2)`
  2. `readdir(2)`
  2. `readlink(2)`※
  2. `setxattr(2)`※
  2. `fgetxattr(2)`※
  2. `fsetxattr(2)`※
 -2. `ioctl(2)`
 +2. `ioctl(2)`
  2. `getpgid(2)`
  2. `setpgid(2)`
 +2. `mmap(2)`
 +2. `munmap(2)`
 +2. `execve(2)`
  
  **LunaixOS**
  
index ade13b31c6414f4e1e1588b26645f255475f2c6c,5e882b7df8f4c32fa3ff7757f84be78d215efae4..edde8bc79f54f9c677207fce9813f5e79a88a6fa
@@@ -6,7 -6,7 +6,7 @@@
  
  #include <lunaix/fs/taskfs.h>
  #include <lunaix/mm/cake.h>
 -#include <lunaix/mm/kalloc.h>
 +#include <lunaix/mm/mmap.h>
  #include <lunaix/mm/pmm.h>
  #include <lunaix/mm/valloc.h>
  #include <lunaix/mm/vmm.h>
@@@ -18,8 -18,6 +18,8 @@@
  #include <lunaix/syscall.h>
  #include <lunaix/syslog.h>
  
 +#include <klibc/string.h>
 +
  volatile struct proc_info* __current;
  
  static struct proc_info dummy_proc;
@@@ -60,23 -58,23 +60,23 @@@ sched_init_dummy(
      extern void my_dummy();
      static char dummy_stack[DUMMY_STACK_SIZE] __attribute__((aligned(16)));
  
 -    // memset to 0
 -    dummy_proc = (struct proc_info){};
 -    dummy_proc.intr_ctx = (isr_param){
 -        .registers = { .ds = KDATA_SEG,
 -                       .es = KDATA_SEG,
 -                       .fs = KDATA_SEG,
 -                       .gs = KDATA_SEG,
 -                       .esp = (void*)dummy_stack + DUMMY_STACK_SIZE - 20 },
 +    struct exec_param* execp =
 +      (void*)dummy_stack + DUMMY_STACK_SIZE - sizeof(struct exec_param);
 +
 +    *execp = (struct exec_param){
          .cs = KCODE_SEG,
 +        .eflags = cpu_reflags() | 0x0200,
          .eip = (void*)my_dummy,
          .ss = KDATA_SEG,
 -        .eflags = cpu_reflags() | 0x0200
      };
  
 -    *(u32_t*)(&dummy_stack[DUMMY_STACK_SIZE - 4]) = dummy_proc.intr_ctx.eflags;
 -    *(u32_t*)(&dummy_stack[DUMMY_STACK_SIZE - 8]) = KCODE_SEG;
 -    *(u32_t*)(&dummy_stack[DUMMY_STACK_SIZE - 12]) = dummy_proc.intr_ctx.eip;
 +    // memset to 0
 +    dummy_proc = (struct proc_info){};
 +    dummy_proc.intr_ctx = (isr_param){ .registers = { .ds = KDATA_SEG,
 +                                                      .es = KDATA_SEG,
 +                                                      .fs = KDATA_SEG,
 +                                                      .gs = KDATA_SEG },
 +                                       .execp = execp };
  
      dummy_proc.page_table = cpu_rcr3();
      dummy_proc.state = PS_READY;
@@@ -99,7 -97,7 +99,7 @@@ run(struct proc_info* proc
          由于这中间没有进行地址空间的交换,所以第二次跳转使用的是同一个内核栈,而之前默认tss.esp0的值是永远指向最顶部
          这样一来就有可能会覆盖更早的上下文信息(比如嵌套的信号捕获函数)
      */
 -    tss_update_esp(proc->intr_ctx.registers.esp);
 +    tss_update_esp(proc->intr_ctx.esp);
  
      apic_done_servicing();
  
@@@ -215,7 -213,10 +215,10 @@@ __DEFINE_LXSYSCALL1(unsigned int, sleep
  
      struct proc_info* root_proc = sched_ctx._procs[0];
      __current->sleep.wakeup_time = clock_systime() + seconds * 1000;
-     llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
+     if (llist_empty(&__current->sleep.sleepers)) {
+         llist_append(&root_proc->sleep.sleepers, &__current->sleep.sleepers);
+     }
  
      __current->intr_ctx.registers.eax = seconds;
  
@@@ -326,14 -327,13 +329,14 @@@ alloc_process(
  
      proc->state = PS_CREATED;
      proc->pid = i;
 +    proc->mm.pid = i;
      proc->created = clock_systime();
      proc->pgid = proc->pid;
      proc->fdtable = vzalloc(sizeof(struct v_fdtable));
      proc->fxstate =
        vzalloc_dma(512); // FXSAVE需要十六位对齐地址,使用DMA块(128位对齐)
  
 -    llist_init_head(&proc->mm.regions.head);
 +    llist_init_head(&proc->mm.regions);
      llist_init_head(&proc->tasks);
      llist_init_head(&proc->children);
      llist_init_head(&proc->grp_member);
@@@ -403,18 -403,17 +406,18 @@@ destroy_process(pid_t pid
      vfree(proc->fdtable);
      vfree_dma(proc->fxstate);
  
 +    vmm_mount_pd(VMS_MOUNT_1, proc->page_table);
 +
      struct mm_region *pos, *n;
 -    llist_for_each(pos, n, &proc->mm.regions.head, head)
 +    llist_for_each(pos, n, &proc->mm.regions, head)
      {
 -        vfree(pos);
 +        mem_sync_pages(VMS_MOUNT_1, pos, pos->start, pos->end - pos->start, 0);
 +        region_release(pos);
      }
  
 -    vmm_mount_pd(PD_MOUNT_1, proc->page_table);
 -
 -    __del_pagetable(pid, PD_MOUNT_1);
 +    __del_pagetable(pid, VMS_MOUNT_1);
  
 -    vmm_unmount_pd(PD_MOUNT_1);
 +    vmm_unmount_pd(VMS_MOUNT_1);
  
      cake_release(proc_pile, proc);