Pass implicit PID into syscalls
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -62,7 +62,7 @@
|
||||
.endm
|
||||
|
||||
.macro _vecintr_bodygen
|
||||
// cli
|
||||
cli
|
||||
_push_regs
|
||||
cld
|
||||
movq %rsp, %rdi
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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_
|
||||
|
||||
@ -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];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user