feat(s5): 删除 TELL/SIZE 私有 syscall —— 用 lseek 的 SEEK_CUR/SEEK_END 表达
内核:SEEK 补真正的 whence(0=SET 1=CUR 2=END,END 时 offset 为距末尾的距离,offset>size 返回 -1);删除 TELL/SIZE 的枚举项、派发分支与 TELL/fsize 函数(fat32.tell/size 仍留给 SEEK 内部用)。 SDK:vpsdk/fs.vp 的 seek() 增加 whence 参数(默认 0,调用方不变);tell() 改为 lseek(fd,0,SEEK_CUR);fsize() 改为三次 lseek 往返(记住位置 → 跳末尾取大小 → 复位),不改变最终位置。 私有段只剩 5 项:OPENDIR/READDIR/CLOSEDIR(openat+getdents64)与 LOAD_SO/SO_CALL1(动态库加载下沉)。
This commit is contained in:
1 parent
1fc1fab1e1
commit
d6d07b25ee
3 files changed
+31
-43
No files matched your search
@@ -41,10 +41,8 @@ enum Syscall:
|
||||
EXIT = 231 # exit_group():退役当前线程(窗口由 explorer 侧回收)
|
||||
# ---- 临时私有段(0x1000+):Linux 无对应,且**逐条都会被消掉** ----
|
||||
# 目标形态:私有能力不占 syscall 号 → 改 devfs 设备文件。
|
||||
# UI 那 11 个已在 S3e 删除(窗口/输入整体下沉到用户态图形壳 explorer + /dev/desk);
|
||||
# SERIAL_PUTS 已在 S4 删除(改为用户态 write(/dev/serial0),见 vpsdk/devfs.vp)。
|
||||
TELL = 0x1001 # TODO(linux):可由 lseek(fd, 0, SEEK_CUR) 表达
|
||||
SIZE = 0x1002 # TODO(linux):可由 fstat 表达
|
||||
# S3e 删掉 UI 那 11 个;S4 删掉 SERIAL_PUTS(改 /dev/serial0);S5 删掉 TELL/SIZE
|
||||
# (改为 lseek(fd,0,SEEK_CUR) / lseek(fd,0,SEEK_END),见 SEEK 的 whence 支持)。
|
||||
OPENDIR = 0x1003 # TODO(linux):openat(O_DIRECTORY) + getdents64
|
||||
READDIR = 0x1004 # TODO(linux):getdents64
|
||||
CLOSEDIR = 0x1005 # TODO(linux):close
|
||||
@@ -261,7 +259,11 @@ def IOCTL(fd: int, request: uint32, arg: rawptr) -> int:
|
||||
return -1
|
||||
return devfs.devfs_ioctl(int(uint64(p.fd_table[fd])) - 1, request, arg)
|
||||
|
||||
def SEEK(fd: int, offset: uint32) -> int:
|
||||
def SEEK(fd: int, offset: uint32, whence: uint32) -> int:
|
||||
"""lseek(fd, offset, whence):0=SET 1=CUR 2=END(END 时 offset 为"距末尾的距离")。
|
||||
|
||||
私有 syscall TELL/SIZE 已删除:用户态用 lseek(fd,0,SEEK_CUR/SEEK_END) 表达即可。
|
||||
"""
|
||||
p: process.Process* = _current_proc()
|
||||
if fd < 0 or fd >= process.PROC_MAX_FDS:
|
||||
return int(fat32_types.FRESULT.FR_INVALID_OBJECT)
|
||||
@@ -269,34 +271,18 @@ def SEEK(fd: int, offset: uint32) -> int:
|
||||
if not fp:
|
||||
return int(fat32_types.FRESULT.FR_INVALID_OBJECT)
|
||||
fat32.lock()
|
||||
r: int = int(fat32.seek(fp, offset))
|
||||
r: int = -1
|
||||
if whence == uint32(0):
|
||||
r = int(fat32.seek(fp, offset))
|
||||
elif whence == uint32(1):
|
||||
r = int(fat32.seek(fp, fat32.tell(fp) + offset))
|
||||
elif whence == uint32(2):
|
||||
sz: uint32 = fat32.size(fp)
|
||||
if offset <= sz:
|
||||
r = int(fat32.seek(fp, sz - offset))
|
||||
fat32.unlock()
|
||||
return r
|
||||
|
||||
def TELL(fd: int) -> uint32:
|
||||
p: process.Process* = _current_proc()
|
||||
if fd < 0 or fd >= process.PROC_MAX_FDS:
|
||||
return 0
|
||||
fp: rawptr = p.fd_table[fd]
|
||||
if not fp:
|
||||
return 0
|
||||
fat32.lock()
|
||||
pos: uint32 = fat32.tell(fp)
|
||||
fat32.unlock()
|
||||
return pos
|
||||
|
||||
def fsize(fd: int) -> uint32:
|
||||
p: process.Process* = _current_proc()
|
||||
if fd < 0 or fd >= process.PROC_MAX_FDS:
|
||||
return 0
|
||||
fp: rawptr = p.fd_table[fd]
|
||||
if not fp:
|
||||
return 0
|
||||
fat32.lock()
|
||||
sz: uint32 = fat32.size(fp)
|
||||
fat32.unlock()
|
||||
return sz
|
||||
|
||||
def MKDIR(path_ptr: str) -> int:
|
||||
path: const str = path_ptr
|
||||
fat32.lock()
|
||||
@@ -449,11 +435,7 @@ export def syscall_handler(num: uint64, arg1: uint64, arg2: uint64, arg3: uint64
|
||||
elif n == int(Syscall.IOCTL):
|
||||
return uint64(IOCTL(int(arg1), uint32(arg2), rawptr(arg3)))
|
||||
elif n == int(Syscall.SEEK):
|
||||
return uint64(SEEK(int(arg1), uint32(arg2)))
|
||||
elif n == int(Syscall.TELL):
|
||||
return uint64(TELL(int(arg1)))
|
||||
elif n == int(Syscall.SIZE):
|
||||
return uint64(fsize(int(arg1)))
|
||||
return uint64(SEEK(int(arg1), uint32(arg2), uint32(arg3)))
|
||||
elif n == int(Syscall.MKDIR):
|
||||
path_ptr: str = str(arg1)
|
||||
return uint64(MKDIR(path_ptr))
|
||||
|
||||
+12
-4
@@ -28,14 +28,22 @@ def read(fd: int, buf: rawptr, count: uint32) -> int:
|
||||
def write(fd: int, buf: rawptr, count: uint32) -> int:
|
||||
return int(syscall._syscall3(uint64(syscall.Syscall.WRITE), uint64(fd), uint64(buf), uint64(count)))
|
||||
|
||||
def seek(fd: int, offset: uint32) -> int:
|
||||
return int(syscall._syscall3(uint64(syscall.Syscall.SEEK), uint64(fd), uint64(offset), 0))
|
||||
def seek(fd: int, offset: uint32, whence: uint32 = 0) -> int:
|
||||
return int(syscall._syscall3(uint64(syscall.Syscall.SEEK), uint64(fd), uint64(offset), uint64(whence)))
|
||||
|
||||
def tell(fd: int) -> uint32:
|
||||
return uint32(syscall._syscall1(uint64(syscall.Syscall.TELL), uint64(fd)))
|
||||
"""当前位置 = lseek(fd, 0, SEEK_CUR)(TELL 私有 syscall 已删除)。"""
|
||||
return uint32(syscall._syscall3(uint64(syscall.Syscall.SEEK), uint64(fd), 0, uint64(SEEK_CUR)))
|
||||
|
||||
def fsize(fd: int) -> uint32:
|
||||
return uint32(syscall._syscall1(uint64(syscall.Syscall.SIZE), uint64(fd)))
|
||||
"""文件大小:SIZE 私有 syscall 已删除,改用 lseek 往返(不改变最终位置)。
|
||||
|
||||
三次 lseek:记住当前位置 → 跳到末尾拿到大小 → 复位。多两次 syscall,换掉一个私有号。
|
||||
"""
|
||||
cur: uint32 = uint32(syscall._syscall3(uint64(syscall.Syscall.SEEK), uint64(fd), 0, uint64(SEEK_CUR)))
|
||||
end: uint32 = uint32(syscall._syscall3(uint64(syscall.Syscall.SEEK), uint64(fd), 0, uint64(SEEK_END)))
|
||||
syscall._syscall3(uint64(syscall.Syscall.SEEK), uint64(fd), uint64(cur), uint64(SEEK_SET))
|
||||
return end
|
||||
|
||||
def mkdir(path: const str) -> int:
|
||||
return int(syscall._syscall3(uint64(syscall.Syscall.MKDIR), uint64(path), 0, 0))
|
||||
|
||||
+2
-4
@@ -25,10 +25,8 @@ enum Syscall:
|
||||
EXIT = 231 # exit_group():退役当前线程(窗口由 explorer 侧回收)
|
||||
# ---- 临时私有段(0x1000+):Linux 无对应,且**逐条都会被消掉** ----
|
||||
# 目标形态:私有能力不占 syscall 号 → 改 devfs 设备文件。
|
||||
# UI 那 11 个已在 S3e 删除(窗口/输入交给用户态图形壳 explorer + /dev/desk);
|
||||
# SERIAL_PUTS 已在 S4 删除(改为写 /dev/serial0,见 vpsdk/devfs.vp 的 serial_puts)。
|
||||
TELL = 0x1001 # TODO(linux):可由 lseek(fd, 0, SEEK_CUR) 表达
|
||||
SIZE = 0x1002 # TODO(linux):可由 fstat 表达
|
||||
# S3e 删 UI 11 个;S4 删 SERIAL_PUTS(改 /dev/serial0);S5 删 TELL/SIZE
|
||||
# (改 lseek 的 SEEK_CUR / SEEK_END,见 vpsdk/fs.vp 的 tell/fsize)。
|
||||
OPENDIR = 0x1003 # TODO(linux):openat(O_DIRECTORY) + getdents64
|
||||
READDIR = 0x1004 # TODO(linux):getdents64
|
||||
CLOSEDIR = 0x1005 # TODO(linux):close
|
||||
|
||||
Reference in new issue
Block a user