Pass implicit PID into syscalls
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
struct Dev;
|
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 {
|
typedef struct Dev {
|
||||||
int _hshtbstate;
|
int _hshtbstate;
|
||||||
|
|||||||
@ -10,8 +10,13 @@
|
|||||||
#include "bootinfo/bootinfo.h"
|
#include "bootinfo/bootinfo.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
|
|
||||||
int32_t fbdev_getinfo(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
|
int32_t fbdev_getinfo(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
|
||||||
(void)dev; (void)buffer; (void)len; (void)extra;
|
(void)dev; (void)pid;
|
||||||
|
|
||||||
|
if (len != sizeof(FbDevGetInfo)) {
|
||||||
|
return E_INVALIDARGUMENT;
|
||||||
|
}
|
||||||
|
|
||||||
FbDevGetInfo info = {
|
FbDevGetInfo info = {
|
||||||
.w = BOOT_INFO.fb->width,
|
.w = BOOT_INFO.fb->width,
|
||||||
.h = BOOT_INFO.fb->height,
|
.h = BOOT_INFO.fb->height,
|
||||||
|
|||||||
@ -163,9 +163,9 @@ struct {
|
|||||||
Ps2kbEvConsumer *list;
|
Ps2kbEvConsumer *list;
|
||||||
} PS2KB_CONSUMERS = {0};
|
} PS2KB_CONSUMERS = {0};
|
||||||
|
|
||||||
int32_t ps2kbdev_readch(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
|
int32_t ps2kbdev_readch(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
|
||||||
(void)dev; (void)len; (void)extra;
|
(void)dev; (void)buffer; (void)len;
|
||||||
uint64_t pid = (uint64_t)buffer;
|
|
||||||
Proc *consproc = NULL;
|
Proc *consproc = NULL;
|
||||||
spinlock_acquire(&PROCS.spinlock);
|
spinlock_acquire(&PROCS.spinlock);
|
||||||
Proc *proc, *proctmp;
|
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
|
#define CONSUMER_RBUF_MAX 0x400
|
||||||
|
|
||||||
int32_t ps2kbdev_attchcons(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
|
int32_t ps2kbdev_attchcons(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
|
||||||
(void)dev; (void)len; (void)extra;
|
(void)dev; (void)buffer; (void)len;
|
||||||
uint64_t pid = (uint64_t)buffer;
|
|
||||||
spinlock_acquire(&PROCS.spinlock);
|
spinlock_acquire(&PROCS.spinlock);
|
||||||
Proc *proc, *proctmp;
|
Proc *proc, *proctmp;
|
||||||
LL_FOREACH_SAFE(PROCS.procs, proc, proctmp) {
|
LL_FOREACH_SAFE(PROCS.procs, proc, proctmp) {
|
||||||
|
|||||||
@ -48,24 +48,24 @@ void serial_sendb(uint8_t b) {
|
|||||||
io_out8(PORT, b);
|
io_out8(PORT, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t serialdev_sendb(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
|
int32_t serialdev_sendb(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
|
||||||
(void)dev; (void)len; (void)extra;
|
(void)dev; (void)len;
|
||||||
serial_sendb(buffer[0]);
|
serial_sendb(buffer[0]);
|
||||||
return E_OK;
|
return E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t serialdev_sendready(struct Dev *dev, uint8_t *buffer, size_t 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; (void) extra;
|
(void)dev; (void)buffer; (void)len;
|
||||||
return serial_sendready();
|
return serial_sendready();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t serialdev_recvb(struct Dev *dev, uint8_t *buffer, size_t 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; (void)extra;
|
(void)dev; (void)buffer; (void)len;
|
||||||
return serial_recvb();
|
return serial_recvb();
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t serialdev_recvready(struct Dev *dev, uint8_t *buffer, size_t 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; (void)extra;
|
(void)dev; (void)buffer; (void)len;
|
||||||
return serial_recvready();
|
return serial_recvready();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
#include "hshtb.h"
|
#include "hshtb.h"
|
||||||
#include "sysdefs/dev.h"
|
#include "sysdefs/dev.h"
|
||||||
|
|
||||||
int32_t termdev_putch(struct Dev *dev, uint8_t *buffer, size_t len, void *extra) {
|
int32_t termdev_putch(struct Dev *dev, uint8_t *buffer, size_t len, uint64_t pid) {
|
||||||
(void)dev; (void)extra;
|
(void)dev;
|
||||||
kprintf("%.*s", (int)len, (char *)buffer);
|
kprintf("%.*s", (int)len, (char *)buffer);
|
||||||
return E_OK;
|
return E_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -193,8 +193,12 @@ void hal_syscalldispatch(IntrStackFrame *frame) {
|
|||||||
frame->regs.rax = E_BADSYSCALL;
|
frame->regs.rax = E_BADSYSCALL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int32_t ret = fn(frame, frame->regs.rdi, frame->regs.rsi, frame->regs.rdx,
|
spinlock_acquire(&PROCS.spinlock);
|
||||||
frame->regs.r10, frame->regs.r8, frame->regs.r9);
|
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) {
|
if (ret == E_DOSCHEDULING) {
|
||||||
proc_sched((void *)frame);
|
proc_sched((void *)frame);
|
||||||
|
|||||||
@ -62,7 +62,7 @@
|
|||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro _vecintr_bodygen
|
.macro _vecintr_bodygen
|
||||||
// cli
|
cli
|
||||||
_push_regs
|
_push_regs
|
||||||
cld
|
cld
|
||||||
movq %rsp, %rdi
|
movq %rsp, %rdi
|
||||||
|
|||||||
@ -102,7 +102,7 @@ done:
|
|||||||
return ret;
|
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 *devh = (uint64_t *)dev1;
|
||||||
uint64_t cmd = cmd1;
|
uint64_t cmd = cmd1;
|
||||||
int32_t ret = E_OK;
|
int32_t ret = E_OK;
|
||||||
@ -127,7 +127,7 @@ int32_t SYSCALL5(sys_dev_cmd, dev1, cmd1, argbuf1, len1, extra1) {
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
spinlock_acquire(&dev->spinlock);
|
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);
|
spinlock_release(&dev->spinlock);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|||||||
@ -8,6 +8,6 @@
|
|||||||
int32_t SYSCALL2(sys_dev_gethandle, dev1, devname1);
|
int32_t SYSCALL2(sys_dev_gethandle, dev1, devname1);
|
||||||
int32_t SYSCALL0(sys_dev_listsize);
|
int32_t SYSCALL0(sys_dev_listsize);
|
||||||
int32_t SYSCALL2(sys_dev_stat, devstat1, idx1);
|
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_
|
#endif // SYSCALL_DEV_H_
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#define SYSCALL0(name) \
|
#define SYSCALL0(name) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
UNUSED uint64_t _1, \
|
UNUSED uint64_t _1, \
|
||||||
UNUSED uint64_t _2, \
|
UNUSED uint64_t _2, \
|
||||||
UNUSED uint64_t _3, \
|
UNUSED uint64_t _3, \
|
||||||
@ -19,6 +20,7 @@
|
|||||||
|
|
||||||
#define SYSCALL1(name, arg1) \
|
#define SYSCALL1(name, arg1) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
UNUSED uint64_t _2, \
|
UNUSED uint64_t _2, \
|
||||||
UNUSED uint64_t _3, \
|
UNUSED uint64_t _3, \
|
||||||
@ -29,6 +31,7 @@
|
|||||||
|
|
||||||
#define SYSCALL2(name, arg1, arg2) \
|
#define SYSCALL2(name, arg1, arg2) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
UNUSED uint64_t _3, \
|
UNUSED uint64_t _3, \
|
||||||
@ -39,6 +42,7 @@
|
|||||||
|
|
||||||
#define SYSCALL3(name, arg1, arg2, arg3) \
|
#define SYSCALL3(name, arg1, arg2, arg3) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -49,6 +53,7 @@
|
|||||||
|
|
||||||
#define SYSCALL4(name, arg1, arg2, arg3, arg4) \
|
#define SYSCALL4(name, arg1, arg2, arg3, arg4) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -59,6 +64,7 @@
|
|||||||
|
|
||||||
#define SYSCALL5(name, arg1, arg2, arg3, arg4, arg5) \
|
#define SYSCALL5(name, arg1, arg2, arg3, arg4, arg5) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -69,6 +75,7 @@
|
|||||||
|
|
||||||
#define SYSCALL6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
|
#define SYSCALL6(name, arg1, arg2, arg3, arg4, arg5, arg6) \
|
||||||
name(UNUSED IntrStackFrame *frame, \
|
name(UNUSED IntrStackFrame *frame, \
|
||||||
|
UNUSED uint64_t _caller_pid, \
|
||||||
uint64_t arg1, \
|
uint64_t arg1, \
|
||||||
uint64_t arg2, \
|
uint64_t arg2, \
|
||||||
uint64_t arg3, \
|
uint64_t arg3, \
|
||||||
@ -77,7 +84,13 @@
|
|||||||
uint64_t arg6 \
|
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];
|
extern SyscallFn SYSCALL_TABLE[SYSCALLS_MAX];
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
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) {
|
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, (uint64_t)extra, 0);
|
return syscall(SYS_DEV_CMD, (uint64_t)dev, (uint64_t)cmd, (uint64_t)buf, (uint64_t)len, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t time(Time *time) {
|
int32_t time(Time *time) {
|
||||||
|
|||||||
@ -41,7 +41,7 @@ int32_t fs_delete(char *path);
|
|||||||
int32_t dev_gethandle(Dev_t *dev, char *name);
|
int32_t dev_gethandle(Dev_t *dev, char *name);
|
||||||
int32_t dev_listsize(void);
|
int32_t dev_listsize(void);
|
||||||
int32_t dev_stat(DevStat *devstatbuf, size_t idx);
|
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);
|
int32_t time(Time *time);
|
||||||
|
|
||||||
#endif // ULIB_SYSTEM_SYSTEM_H_
|
#endif // ULIB_SYSTEM_SYSTEM_H_
|
||||||
|
|||||||
@ -20,7 +20,7 @@ void tb_runinitscript(void) {
|
|||||||
string_memset(buf, 0, sizeof(buf));
|
string_memset(buf, 0, sizeof(buf));
|
||||||
r = ipc_piperead(tb, 0, (uint8_t *const)buf, sizeof(buf)-1);
|
r = ipc_piperead(tb, 0, (uint8_t *const)buf, sizeof(buf)-1);
|
||||||
if (r > 0) {
|
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 {
|
} else {
|
||||||
schedrelease();
|
schedrelease();
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ void tb_runinitscript(void) {
|
|||||||
void main(void) {
|
void main(void) {
|
||||||
PID = proc_getpid();
|
PID = proc_getpid();
|
||||||
dev_gethandle(&ps2kbdev, "ps2kbdev");
|
dev_gethandle(&ps2kbdev, "ps2kbdev");
|
||||||
dev_cmd(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, (void *)PID, 0, NULL);
|
dev_cmd(&ps2kbdev, DEV_PS2KBDEV_ATTCHCONS, NULL, 0);
|
||||||
|
|
||||||
tb_runinitscript();
|
tb_runinitscript();
|
||||||
|
|
||||||
|
|||||||
@ -240,7 +240,7 @@ bool interp_runstring(char *string, InterpResult **res, bool interactive) {
|
|||||||
if (wait) {
|
if (wait) {
|
||||||
while(proc_pollstate(app) != 4) {
|
while(proc_pollstate(app) != 4) {
|
||||||
if (interactive) {
|
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')) {
|
if (key > 0 && (uint8_t)key == C('S')) {
|
||||||
proc_kill(app);
|
proc_kill(app);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|||||||
@ -90,7 +90,7 @@ void do_mode_interactive(void) {
|
|||||||
|
|
||||||
uint8_t b = 0;
|
uint8_t b = 0;
|
||||||
for (;;) {
|
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) {
|
if (key > 0) {
|
||||||
b = (uint8_t)key;
|
b = (uint8_t)key;
|
||||||
switch (b) {
|
switch (b) {
|
||||||
@ -140,7 +140,7 @@ void main(void) {
|
|||||||
|
|
||||||
if (CONFIG.mode == MODE_INTERACTIVE) {
|
if (CONFIG.mode == MODE_INTERACTIVE) {
|
||||||
dev_gethandle(&ps2kbdev, "ps2kbdev");
|
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();
|
do_mode_interactive();
|
||||||
} else if (CONFIG.mode == MODE_RUNFILE) {
|
} else if (CONFIG.mode == MODE_RUNFILE) {
|
||||||
if (CONFIG.filepath == NULL) {
|
if (CONFIG.filepath == NULL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user