Pass implicit PID into syscalls

This commit is contained in:
2025-10-18 12:10:59 +02:00
parent d1d777ec75
commit a5fe64b253
15 changed files with 56 additions and 34 deletions

View File

@ -8,7 +8,7 @@
struct Dev;
typedef int32_t (*DevFn)(struct Dev *dev, uint8_t *buffer, size_t len, void *extra);
typedef int32_t (*DevFn)(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid);
typedef struct Dev {
int _hshtbstate;

View File

@ -10,8 +10,13 @@
#include "bootinfo/bootinfo.h"
#include "errors.h"
int32_t fbdev_getinfo(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void)extra;
int32_t fbdev_getinfo(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)pid;
if (len != sizeof(FbDevGetInfo)) {
return E_INVALIDARGUMENT;
}
FbDevGetInfo info = {
.w = BOOT_INFO.fb->width,
.h = BOOT_INFO.fb->height,

View File

@ -163,9 +163,9 @@ struct {
Ps2kbEvConsumer *list;
} PS2KB_CONSUMERS = {0};
int32_t ps2kbdev_readch(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)len; (void)extra;
uint64_t pid = (uint64_t)buffer;
int32_t ps2kbdev_readch(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)buffer; (void)len;
Proc *consproc = NULL;
spinlock_acquire(&PROCS.spinlock);
Proc *proc, *proctmp;
@ -202,9 +202,9 @@ int32_t ps2kbdev_readch(struct Dev *dev, uint8_t *buffer, size_t len, void *extr
#define CONSUMER_RBUF_MAX 0x400
int32_t ps2kbdev_attchcons(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)len; (void)extra;
uint64_t pid = (uint64_t)buffer;
int32_t ps2kbdev_attchcons(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)buffer; (void)len;
spinlock_acquire(&PROCS.spinlock);
Proc *proc, *proctmp;
LL_FOREACH_SAFE(PROCS.procs, proc, proctmp) {

View File

@ -48,24 +48,24 @@ void serial_sendb(uint8_t b) {
io_out8(PORT, b);
}
int32_t serialdev_sendb(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)len; (void)extra;
int32_t serialdev_sendb(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)len;
serial_sendb(buffer[0]);
return E_OK;
}
int32_t serialdev_sendready(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void) extra;
int32_t serialdev_sendready(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)buffer; (void)len;
return serial_sendready();
}
int32_t serialdev_recvb(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void)extra;
int32_t serialdev_recvb(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)buffer; (void)len;
return serial_recvb();
}
int32_t serialdev_recvready(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)buffer; (void)len; (void)extra;
int32_t serialdev_recvready(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev; (void)buffer; (void)len;
return serial_recvready();
}

View File

@ -9,8 +9,8 @@
#include "hshtb.h"
#include "sysdefs/dev.h"
int32_t termdev_putch(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
(void)dev; (void)extra;
int32_t termdev_putch(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
(void)dev;
kprintf("%.*s", (int)len, (char *)buffer);
return E_OK;
}

View File

@ -193,8 +193,12 @@ void hal_syscalldispatch(IntrStackFrame *frame) {
frame->regs.rax = E_BADSYSCALL;
return;
}
int32_t ret = fn(frame, frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
frame->regs.r10, frame->regs.r8, frame->regs.r9);
spinlock_acquire(&PROCS.spinlock);
uint64_t calling_proc_pid = PROCS.current->pid;
spinlock_release(&PROCS.spinlock);
hal_intr_enable();
int32_t ret = fn(frame, calling_proc_pid, frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
frame->regs.r10, frame->regs.r8, frame->regs.r9);
if (ret == E_DOSCHEDULING) {
proc_sched((void *)frame);

View File

@ -62,7 +62,7 @@
.endm
.macro _vecintr_bodygen
// cli
cli
_push_regs
cld
movq %rsp, %rdi

View File

@ -102,7 +102,7 @@ done:
return ret;
}
int32_t SYSCALL5(sys_dev_cmd, dev1, cmd1, argbuf1, len1, extra1) {
int32_t SYSCALL4(sys_dev_cmd, dev1, cmd1, argbuf1, len1) {
uint64_t *devh = (uint64_t *)dev1;
uint64_t cmd = cmd1;
int32_t ret = E_OK;
@ -127,7 +127,7 @@ int32_t SYSCALL5(sys_dev_cmd, dev1, cmd1, argbuf1, len1, extra1) {
goto done;
}
spinlock_acquire(&dev->spinlock);
ret = dev->fns[cmd](dev, (uint8_t *)argbuf1, (size_t)len1, (void *)extra1);
ret = dev->fns[cmd](dev, (uint8_t *)argbuf1, (size_t)len1, _caller_pid);
spinlock_release(&dev->spinlock);
done:

View File

@ -8,6 +8,6 @@
int32_t SYSCALL2(sys_dev_gethandle, dev1, devname1);
int32_t SYSCALL0(sys_dev_listsize);
int32_t SYSCALL2(sys_dev_stat, devstat1, idx1);
int32_t SYSCALL5(sys_dev_cmd, dev1, cmd1, argbuf1, len1, extra1);
int32_t SYSCALL4(sys_dev_cmd, dev1, cmd1, argbuf1, len1);
#endif // SYSCALL_DEV_H_

View File

@ -9,6 +9,7 @@
#define SYSCALL0(name) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
UNUSED uint64_t _1, \
UNUSED uint64_t _2, \
UNUSED uint64_t _3, \
@ -19,6 +20,7 @@
#define SYSCALL1(name, arg1) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
uint64_t arg1, \
UNUSED uint64_t _2, \
UNUSED uint64_t _3, \
@ -29,6 +31,7 @@
#define SYSCALL2(name, arg1, arg2) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
uint64_t arg1, \
uint64_t arg2, \
UNUSED uint64_t _3, \
@ -39,6 +42,7 @@
#define SYSCALL3(name, arg1, arg2, arg3) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
uint64_t arg1, \
uint64_t arg2, \
uint64_t arg3, \
@ -49,6 +53,7 @@
#define SYSCALL4(name, arg1, arg2, arg3, arg4) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
uint64_t arg1, \
uint64_t arg2, \
uint64_t arg3, \
@ -59,6 +64,7 @@
#define SYSCALL5(name, arg1, arg2, arg3, arg4, arg5) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
uint64_t arg1, \
uint64_t arg2, \
uint64_t arg3, \
@ -69,6 +75,7 @@
#define SYSCALL6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
name(UNUSED IntrStackFrame *frame, \
UNUSED uint64_t _caller_pid, \
uint64_t arg1, \
uint64_t arg2, \
uint64_t arg3, \
@ -77,7 +84,13 @@
uint64_t arg6 \
)
typedef int32_t (*SyscallFn)(IntrStackFrame *, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
typedef int32_t (*SyscallFn)(IntrStackFrame *, uint64_t,
uint64_t,
uint64_t,
uint64_t,
uint64_t,
uint64_t,
uint64_t);
extern SyscallFn SYSCALL_TABLE[SYSCALLS_MAX];

View File

@ -135,8 +135,8 @@ int32_t dev_stat(DevStat *devstatbuf, size_t idx) {
return syscall(SYS_DEV_STAT, (uint64_t)devstatbuf, (uint64_t)idx, 0, 0, 0, 0);
}
int32_t dev_cmd(Dev_t *dev, uint64_t cmd, void *buf, size_t len, void *extra) {
return syscall(SYS_DEV_CMD, (uint64_t)dev, (uint64_t)cmd, (uint64_t)buf, (uint64_t)len, (uint64_t)extra, 0);
int32_t dev_cmd(Dev_t *dev, uint64_t cmd, void *buf, size_t len) {
return syscall(SYS_DEV_CMD, (uint64_t)dev, (uint64_t)cmd, (uint64_t)buf, (uint64_t)len, 0, 0);
}
int32_t time(Time *time) {

View File

@ -41,7 +41,7 @@ int32_t fs_delete(char *path);
int32_t dev_gethandle(Dev_t *dev, char *name);
int32_t dev_listsize(void);
int32_t dev_stat(DevStat *devstatbuf, size_t idx);
int32_t dev_cmd(Dev_t *dev, uint64_t cmd, void *buf, size_t len, void *extra);
int32_t dev_cmd(Dev_t *dev, uint64_t cmd, void *buf, size_t len);
int32_t time(Time *time);
#endif // ULIB_SYSTEM_SYSTEM_H_

View File

@ -20,7 +20,7 @@ void tb_runinitscript(void) {
string_memset(buf, 0, sizeof(buf));
r = ipc_piperead(tb, 0, (uint8_t *const)buf, sizeof(buf)-1);
if (r > 0) {
dev_cmd(&termdev, DEV_TERMDEV_PUTCH, buf, string_len(buf), NULL);
dev_cmd(&termdev, DEV_TERMDEV_PUTCH, buf, string_len(buf));
} else {
schedrelease();
}
@ -30,7 +30,7 @@ void tb_runinitscript(void) {
void main(void) {
PID = proc_getpid();
dev_gethandle(&ps2kbdev, "ps2kbdev");
dev_cmd(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, (void *)PID, 0, NULL);
dev_cmd(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, NULL, 0);
tb_runinitscript();

View File

@ -240,7 +240,7 @@ bool interp_runstring(char *string, InterpResult **res, bool interactive) {
if (wait) {
while(proc_pollstate(app) != 4) {
if (interactive) {
int32_t key = dev_cmd(&ps2kbdev, DEV_PS2KBDEV_READCH, (void *)PID, 0, NULL);
int32_t key = dev_cmd(&ps2kbdev, DEV_PS2KBDEV_READCH, NULL, 0);
if (key > 0 && (uint8_t)key == C('S')) {
proc_kill(app);
goto cleanup;

View File

@ -90,7 +90,7 @@ void do_mode_interactive(void) {
uint8_t b = 0;
for (;;) {
int32_t key = dev_cmd(&ps2kbdev, DEV_PS2KBDEV_READCH, (void *)PID, 0, NULL);
int32_t key = dev_cmd(&ps2kbdev, DEV_PS2KBDEV_READCH, NULL, 0);
if (key > 0) {
b = (uint8_t)key;
switch (b) {
@ -140,7 +140,7 @@ void main(void) {
if (CONFIG.mode == MODE_INTERACTIVE) {
dev_gethandle(&ps2kbdev, "ps2kbdev");
dev_cmd(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, (void *)PID, 0, NULL);
dev_cmd(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, NULL, 0);
do_mode_interactive();
} else if (CONFIG.mode == MODE_RUNFILE) {
if (CONFIG.filepath == NULL) {