内核 intr/syscall.vp 与 vpsdk/syscall.vp 各一份 1..34 的 define 表改为同名 enum Syscall。编号口径:与 Linux 同名同号;Linux 有而我们未实现的留空不占号(12 brk / 39 getpid / 84 rmdir / 217 getdents64 / 257 openat … 需要时按号补)。 15 个语义重合的调用直接用 Linux 号:READ 0 / WRITE 1 / OPEN 2 / CLOSE 3 / STAT 4 / SEEK 8 / MMAP 9 / MUNMAP 11 / YIELD 24 / THREAD_CREATE 56(≈clone) / SPAWN 59(≈execve) / THREAD_EXIT 60(exit) / MKDIR 83 / REMOVE 87 / EXIT 231(exit_group)。 其余 19 个(UI 11 个 + SERIAL_PUTS/TELL/SIZE/OPENDIR/READDIR/CLOSEDIR/LOAD_SO/SO_CALL1)暂放 0x1000 起的**临时私有段**,每条带迁移标注:私有能力最终不占 syscall 号、改走 devfs 设备文件;UI 11 个待用户态 explorer(图形壳)接管 framebuffer 与输入后删除。 内核派发链改 n == int(Syscall.X)(n 是 int/i64、成员是 i32,显式 int() 规避未证实的混合宽度比较);SDK 全部调用点统一为 syscall.Syscall.X;stdlib 的 SYSCALL_MMAP 别名并入 Syscall.MMAP;Terminal 里硬编码的 uint64(18) 改为常量。
70 lines
1.8 KiB
Plaintext
70 lines
1.8 KiB
Plaintext
from . import syscall as syscall
|
|
|
|
|
|
def exit(code: int):
|
|
syscall._syscall1(uint64(syscall.Syscall.EXIT), uint64(code))
|
|
|
|
def thread_exit():
|
|
"""当前用户线程显式退出:内核回收其用户栈并标记线程结束(不返回)。"""
|
|
syscall._syscall0(uint64(syscall.Syscall.THREAD_EXIT))
|
|
|
|
def yield_cpu():
|
|
syscall._syscall2(uint64(syscall.Syscall.WAIT_WINDOW), uint64(0), uint64(2))
|
|
|
|
def spawn(path: const str, blocking: int = 0) -> int:
|
|
return int(syscall._syscall2(uint64(syscall.Syscall.SPAWN), uint64(path), uint64(blocking)))
|
|
|
|
def thread_create(func: rawptr, arg: rawptr = None) -> int:
|
|
return int(syscall._syscall2(uint64(syscall.Syscall.THREAD_CREATE), uint64(func), uint64(arg)))
|
|
|
|
|
|
class Thread:
|
|
_tid: int
|
|
_func: rawptr
|
|
_arg: rawptr
|
|
_running: int
|
|
|
|
def __init__(self, func: rawptr, arg: rawptr = None):
|
|
self._func = func
|
|
self._arg = arg
|
|
self._tid = -1
|
|
self._running = 0
|
|
|
|
def start(self) -> int:
|
|
if self._running: return -1
|
|
self._tid = thread_create(self._func, self._arg)
|
|
if self._tid < 0: return -1
|
|
self._running = 1
|
|
return 0
|
|
|
|
def is_alive(self) -> int:
|
|
return self._running
|
|
|
|
def get_tid(self) -> int:
|
|
return self._tid
|
|
|
|
|
|
class Process:
|
|
_pid: int
|
|
_path: [128]char
|
|
|
|
def __init__(self, path: const str):
|
|
self._pid = -1
|
|
i: int = 0
|
|
for ch in path:
|
|
if i >= 127: break
|
|
self._path[i] = ch
|
|
i += 1
|
|
self._path[i] = 0
|
|
|
|
def start(self) -> int:
|
|
self._pid = spawn(&self._path[0], 0)
|
|
return self._pid
|
|
|
|
def start_blocking(self) -> int:
|
|
self._pid = spawn(&self._path[0], 1)
|
|
return self._pid
|
|
|
|
def get_pid(self) -> int:
|
|
return self._pid
|