cpu: change _cpu()->thread calls to current_thread() to fix smp race

This commit is contained in:
Matheus
2024-09-15 17:47:26 -03:00
parent d1c0f2a5fd
commit e058d62261
65 changed files with 196 additions and 190 deletions
+4 -4
View File
@@ -9,7 +9,7 @@
void arch_syscall_entry(); void arch_syscall_entry();
static void illisr(isr_t *self, context_t *ctx) { static void illisr(isr_t *self, context_t *ctx) {
if (ARCH_CONTEXT_ISUSER(ctx)) { if (ARCH_CONTEXT_ISUSER(ctx)) {
signal_signalthread(_cpu()->thread, SIGILL, true); signal_signalthread(current_thread(), SIGILL, true);
} else { } else {
_panic("Invalid Opcode", ctx); _panic("Invalid Opcode", ctx);
} }
@@ -17,7 +17,7 @@ static void illisr(isr_t *self, context_t *ctx) {
static void div0isr(isr_t *self, context_t *ctx) { static void div0isr(isr_t *self, context_t *ctx) {
if (ARCH_CONTEXT_ISUSER(ctx)) { if (ARCH_CONTEXT_ISUSER(ctx)) {
signal_signalthread(_cpu()->thread, SIGFPE, true); signal_signalthread(current_thread(), SIGFPE, true);
} else { } else {
_panic("Division by 0", ctx); _panic("Division by 0", ctx);
} }
@@ -25,7 +25,7 @@ static void div0isr(isr_t *self, context_t *ctx) {
static void simdisr(isr_t *self, context_t *ctx) { static void simdisr(isr_t *self, context_t *ctx) {
if (ARCH_CONTEXT_ISUSER(ctx)) { if (ARCH_CONTEXT_ISUSER(ctx)) {
signal_signalthread(_cpu()->thread, SIGFPE, true); signal_signalthread(current_thread(), SIGFPE, true);
} else { } else {
_panic("SIMD Exception", ctx); _panic("SIMD Exception", ctx);
} }
@@ -33,7 +33,7 @@ static void simdisr(isr_t *self, context_t *ctx) {
static void x87isr(isr_t *self, context_t *ctx) { static void x87isr(isr_t *self, context_t *ctx) {
if (ARCH_CONTEXT_ISUSER(ctx)) { if (ARCH_CONTEXT_ISUSER(ctx)) {
signal_signalthread(_cpu()->thread, SIGFPE, true); signal_signalthread(current_thread(), SIGFPE, true);
} else { } else {
_panic("x87 Floating-Point Exception", ctx); _panic("x87 Floating-Point Exception", ctx);
} }
+4 -4
View File
@@ -220,11 +220,11 @@ void arch_mmu_tlbipi(isr_t *isr, context_t *context) {
void arch_mmu_tlbshootdown(void *page) { void arch_mmu_tlbshootdown(void *page) {
// scheduler not up yet, or there are no other cpus, nothing to do // scheduler not up yet, or there are no other cpus, nothing to do
if (_cpu()->thread == NULL || arch_smp_cpusawake == 1) if (current_thread() == NULL || arch_smp_cpusawake == 1)
return; return;
if (page >= KERNELSPACE_START || if (page >= KERNELSPACE_START ||
(_cpu()->thread->proc->runningthreadcount > 1 && page >= USERSPACE_START && page < USERSPACE_END)) { (current_thread()->proc->runningthreadcount > 1 && page >= USERSPACE_START && page < USERSPACE_END)) {
// shoot down if page is in the kernel space or in a multithreaded userland application // shoot down if page is in the kernel space or in a multithreaded userland application
int oldipl = interrupt_raiseipl(IPL_DPC); int oldipl = interrupt_raiseipl(IPL_DPC);
spinlock_acquire(&shootdownlock); spinlock_acquire(&shootdownlock);
@@ -275,7 +275,7 @@ static volatile struct limine_kernel_address_request kaddrreq = {
#define ERROR_FETCH 16 #define ERROR_FETCH 16
static void pfisr(isr_t *self, context_t *ctx) { static void pfisr(isr_t *self, context_t *ctx) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
interrupt_set(true); interrupt_set(true);
int vmmerror = 0; int vmmerror = 0;
if (ctx->error & ERROR_PRESENT) if (ctx->error & ERROR_PRESENT)
@@ -301,7 +301,7 @@ static void pfisr(isr_t *self, context_t *ctx) {
} }
static void gpfisr(isr_t *self, context_t *ctx) { static void gpfisr(isr_t *self, context_t *ctx) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
if (thread->usercopyctx) { if (thread->usercopyctx) {
memcpy(ctx, thread->usercopyctx, sizeof(context_t)); memcpy(ctx, thread->usercopyctx, sizeof(context_t));
thread->usercopyctx = NULL; thread->usercopyctx = NULL;
+2 -2
View File
@@ -206,7 +206,7 @@ __attribute__((no_caller_saved_registers)) void arch_syscall_log(int syscall, ui
char argbuff[768]; char argbuff[768];
char printbuff[1024]; char printbuff[1024];
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread->proc; proc_t *proc = thread->proc;
snprintf(argbuff, 768, syscall < SYSCALL_COUNT ? args[syscall] : "N/A", a1, a2, a3, a4, a5, a6); snprintf(argbuff, 768, syscall < SYSCALL_COUNT ? args[syscall] : "N/A", a1, a2, a3, a4, a5, a6);
snprintf(printbuff, 1024, "\e[92msyscall: pid %d tid %d: %s: %s (%lu cached pages, %lu free pages)\n\e[0m", proc->pid, thread->tid, syscall < SYSCALL_COUNT ? name[syscall] : "invalid syscall", argbuff, vmmcache_cachedpages, freepagecount); snprintf(printbuff, 1024, "\e[92msyscall: pid %d tid %d: %s: %s (%lu cached pages, %lu free pages)\n\e[0m", proc->pid, thread->tid, syscall < SYSCALL_COUNT ? name[syscall] : "invalid syscall", argbuff, vmmcache_cachedpages, freepagecount);
@@ -219,7 +219,7 @@ __attribute__((no_caller_saved_registers)) void arch_syscall_log_return(uint64_t
#ifdef SYSCALL_LOGGING #ifdef SYSCALL_LOGGING
char printbuff[1024]; char printbuff[1024];
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread->proc; proc_t *proc = thread->proc;
snprintf(printbuff, 1024, "\e[94msyscall return: pid %d tid %d: %lu %s (%lu cached pages, %lu free pages)\n\e[0m", proc->pid, thread->tid, ret, strerror(errno), vmmcache_cachedpages, freepagecount); snprintf(printbuff, 1024, "\e[94msyscall return: pid %d tid %d: %lu %s (%lu cached pages, %lu free pages)\n\e[0m", proc->pid, thread->tid, ret, strerror(errno), vmmcache_cachedpages, freepagecount);
+10 -10
View File
@@ -43,7 +43,7 @@ file_t *fd_allocate() {
} }
static int getfree(int start) { static int getfree(int start) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
int fd = -1; int fd = -1;
int sfd; int sfd;
for (sfd = start; sfd < proc->fdcount && proc->fd[sfd].file; ++sfd); for (sfd = start; sfd < proc->fdcount && proc->fd[sfd].file; ++sfd);
@@ -58,7 +58,7 @@ static int growtable(int newcount) {
if (newcount > FDTABLE_LIMIT) if (newcount > FDTABLE_LIMIT)
return EMFILE; return EMFILE;
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
__assert(newcount > proc->fdcount); __assert(newcount > proc->fdcount);
void *newtable = realloc(proc->fd, sizeof(fd_t) * newcount); void *newtable = realloc(proc->fd, sizeof(fd_t) * newcount);
if (newtable == NULL) if (newtable == NULL)
@@ -70,7 +70,7 @@ static int growtable(int newcount) {
} }
file_t *fd_get(int fd) { file_t *fd_get(int fd) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
file_t *file = fd < proc->fdcount ? proc->fd[fd].file : NULL; file_t *file = fd < proc->fdcount ? proc->fd[fd].file : NULL;
@@ -84,7 +84,7 @@ file_t *fd_get(int fd) {
int fd_setflags(int fd, int flags) { int fd_setflags(int fd, int flags) {
int error = 0; int error = 0;
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
if (proc->fd[fd].file) if (proc->fd[fd].file)
@@ -98,7 +98,7 @@ int fd_setflags(int fd, int flags) {
int fd_getflags(int fd, int *flags) { int fd_getflags(int fd, int *flags) {
int error = 0; int error = 0;
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
if (proc->fd[fd].file) if (proc->fd[fd].file)
@@ -119,7 +119,7 @@ int fd_new(int flags, file_t **rfile, int *rfd) {
if (file == NULL) if (file == NULL)
return ENOMEM; return ENOMEM;
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
// find first free fd // find first free fd
@@ -148,7 +148,7 @@ int fd_new(int flags, file_t **rfile, int *rfd) {
} }
int fd_close(int fd) { int fd_close(int fd) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
file_t *file = fd < proc->fdcount ? proc->fd[fd].file : NULL; file_t *file = fd < proc->fdcount ? proc->fd[fd].file : NULL;
@@ -171,7 +171,7 @@ int fd_close(int fd) {
} }
int fd_clone(proc_t *targproc) { int fd_clone(proc_t *targproc) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
int error = 0; int error = 0;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
@@ -197,7 +197,7 @@ int fd_clone(proc_t *targproc) {
} }
int fd_insert(file_t *file, int *fdp) { int fd_insert(file_t *file, int *fdp) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
int err = 0; int err = 0;
MUTEX_ACQUIRE(&proc->fdmutex, false); MUTEX_ACQUIRE(&proc->fdmutex, false);
int fd = getfree(0); int fd = getfree(0);
@@ -220,7 +220,7 @@ int fd_insert(file_t *file, int *fdp) {
} }
int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) { int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
int err = 0; int err = 0;
if (newfd < 0 || newfd >= FDTABLE_LIMIT) if (newfd < 0 || newfd >= FDTABLE_LIMIT)
+2 -2
View File
@@ -183,8 +183,8 @@ int pipefs_read(vnode_t *node, void *buffer, size_t size, uintmax_t offset, int
static int writetopipe(pipenode_t *pipenode, void *buffer, size_t size, size_t *writec) { static int writetopipe(pipenode_t *pipenode, void *buffer, size_t size, size_t *writec) {
if (pipenode->readers == 0) { if (pipenode->readers == 0) {
if (_cpu()->thread->proc) if (current_thread()->proc)
signal_signalproc(_cpu()->thread->proc, SIGPIPE); signal_signalproc(current_thread()->proc, SIGPIPE);
return EPIPE; return EPIPE;
} }
+7 -7
View File
@@ -22,10 +22,10 @@ static spinlock_t listlock;
static vfs_t *vfslist; static vfs_t *vfslist;
static cred_t *getcred() { static cred_t *getcred() {
if (_cpu()->thread == NULL || _cpu()->thread->proc == NULL) if (current_thread() == NULL || current_thread()->proc == NULL)
return NULL; return NULL;
else else
return &_cpu()->thread->proc->cred; return &current_thread()->proc->cred;
} }
int vfs_pollstub(vnode_t *node, struct polldata *, int events) { int vfs_pollstub(vnode_t *node, struct polldata *, int events) {
@@ -251,7 +251,7 @@ int vfs_write(vnode_t *node, void *buffer, size_t size, uintmax_t offset, size_t
if (node->type == V_TYPE_REGULAR && newsize) { if (node->type == V_TYPE_REGULAR && newsize) {
// do resize stuff if regular and applicable // do resize stuff if regular and applicable
err = VOP_RESIZE(node, newsize, &_cpu()->thread->proc->cred); err = VOP_RESIZE(node, newsize, &current_thread()->proc->cred);
if (err) if (err)
goto leave; goto leave;
} else if (node->type == V_TYPE_BLKDEV) { } else if (node->type == V_TYPE_BLKDEV) {
@@ -780,11 +780,11 @@ int vfs_lookup(vnode_t **result, vnode_t *start, char *path, char *lastcomp, int
// get the start node of the dereference // get the start node of the dereference
vnode_t *derefstart = current; vnode_t *derefstart = current;
if (*linkderef == '/' && _cpu()->thread && _cpu()->thread->proc) { if (*linkderef == '/' && current_thread() && current_thread()->proc) {
MUTEX_ACQUIRE(&_cpu()->thread->proc->mutex, false); MUTEX_ACQUIRE(&current_thread()->proc->mutex, false);
derefstart = _cpu()->thread->proc->root; derefstart = current_thread()->proc->root;
VOP_HOLD(derefstart); VOP_HOLD(derefstart);
MUTEX_RELEASE(&_cpu()->thread->proc->mutex); MUTEX_RELEASE(&current_thread()->proc->mutex);
} else if (*linkderef == '/') { } else if (*linkderef == '/') {
derefstart = vfsroot; derefstart = vfsroot;
VOP_HOLD(derefstart); VOP_HOLD(derefstart);
+1 -1
View File
@@ -132,7 +132,7 @@ typedef struct proc_t {
#include <arch/cpu.h> #include <arch/cpu.h>
#define UMASK(mode) ((mode) & ~_cpu()->thread->proc->umask) #define UMASK(mode) ((mode) & ~current_thread()->proc->umask)
#define PROC_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST) #define PROC_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST)
// the acquire of the pid table mutex is done here to prevent a nasty race condition where sched_inactiveproc could be called multiple times // the acquire of the pid table mutex is done here to prevent a nasty race condition where sched_inactiveproc could be called multiple times
// due to the pid table itself not holding any references to the process // due to the pid table itself not holding any references to the process
+1 -1
View File
@@ -16,7 +16,7 @@ extern mutex_t printf_mutex;
#endif #endif
#define printf(...) { \ #define printf(...) { \
if (_cpu()->thread) {\ if (current_thread()) {\
MUTEX_ACQUIRE(&printf_mutex, false); \ MUTEX_ACQUIRE(&printf_mutex, false); \
} else { \ } else { \
while (MUTEX_TRY(&printf_mutex) == false) CPU_PAUSE(); \ while (MUTEX_TRY(&printf_mutex) == false) CPU_PAUSE(); \
+7 -1
View File
@@ -56,12 +56,18 @@ static inline uint16_t be_to_cpu_w(uint16_t w) {
cpu_t *_bsp(void); cpu_t *_bsp(void);
static inline cpu_t *_cpu() { static inline cpu_t *_cpu(void) {
cpu_t *cpu; cpu_t *cpu;
asm volatile ("mov %%gs:8, %%rax" : "=a"(cpu) : : "memory"); asm volatile ("mov %%gs:8, %%rax" : "=a"(cpu) : : "memory");
return cpu; return cpu;
} }
static inline thread_t *current_thread(void) {
thread_t *thread;
asm volatile ("mov %%gs:0, %%rax" : "=a"(thread) : : "memory");
return thread;
}
static inline void cpu_set(cpu_t *ptr) { static inline void cpu_set(cpu_t *ptr) {
ptr->self = ptr; ptr->self = ptr;
wrmsr(MSR_GSBASE, (uint64_t)ptr); wrmsr(MSR_GSBASE, (uint64_t)ptr);
+1 -1
View File
@@ -502,7 +502,7 @@ void uacpi_kernel_reset_event(uacpi_handle sem) {
} }
uacpi_thread_id uacpi_kernel_get_thread_id(void) { uacpi_thread_id uacpi_kernel_get_thread_id(void) {
return _cpu()->thread; return current_thread();
} }
uacpi_handle uacpi_kernel_create_spinlock(void) { uacpi_handle uacpi_kernel_create_spinlock(void) {
+1 -1
View File
@@ -324,7 +324,7 @@ static void enqueueandwait(queuepair_t *queuepair, entrypair_t *entries) {
*queuepair->submission.doorbell = queuepair->submission.index; *queuepair->submission.doorbell = queuepair->submission.index;
sched_preparesleep(false); sched_preparesleep(false);
entries->thread = _cpu()->thread; entries->thread = current_thread();
spinlock_release(&queuepair->lock); spinlock_release(&queuepair->lock);
sched_yield(); sched_yield();
interrupt_set(intstatus); interrupt_set(intstatus);
+1 -1
View File
@@ -88,7 +88,7 @@ static void vioblk_enqueue(vioblkdev_t *blkdev, requestheader_t *headerphys, voi
VIO_QUEUE_DRV_RING(&blkdev->queue)[driveridx % blkdev->queue.size] = idx; VIO_QUEUE_DRV_RING(&blkdev->queue)[driveridx % blkdev->queue.size] = idx;
sched_preparesleep(false); sched_preparesleep(false);
blkdev->queuewaiting[idx / 3] = _cpu()->thread; blkdev->queuewaiting[idx / 3] = current_thread();
++VIO_QUEUE_DRV_IDX(&blkdev->queue); ++VIO_QUEUE_DRV_IDX(&blkdev->queue);
*blkdev->queue.notify = 0; *blkdev->queue.notify = 0;
+5 -5
View File
@@ -357,8 +357,8 @@ static int localsock_send(socket_t *socket, sockdesc_t *sockdesc) {
localsocket_t *peer = pair->client == localsocket ? pair->server : pair->client; localsocket_t *peer = pair->client == localsocket ? pair->server : pair->client;
if (peer == NULL) { if (peer == NULL) {
if (_cpu()->thread->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0) if (current_thread()->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0)
signal_signalproc(_cpu()->thread->proc, SIGPIPE); signal_signalproc(current_thread()->proc, SIGPIPE);
error = EPIPE; error = EPIPE;
goto leave; goto leave;
@@ -873,9 +873,9 @@ static int localsock_bind(socket_t *socket, sockaddr_t *addr, cred_t *cred) {
refnode = *path == '/' ? sched_getroot() : sched_getcwd(); refnode = *path == '/' ? sched_getroot() : sched_getcwd();
vattr_t attr = { vattr_t attr = {
.mode = _cpu()->thread->proc ? UMASK(0777) : 0644, .mode = current_thread()->proc ? UMASK(0777) : 0644,
.gid = _cpu()->thread->proc ? _cpu()->thread->proc->cred.gid : 0, .gid = current_thread()->proc ? current_thread()->proc->cred.gid : 0,
.uid = _cpu()->thread->proc ? _cpu()->thread->proc->cred.uid : 0 .uid = current_thread()->proc ? current_thread()->proc->cred.uid : 0
}; };
vnode_t *vnode; vnode_t *vnode;
+5 -5
View File
@@ -838,7 +838,7 @@ typedef struct {
} __attribute__((packed)) synoptions_t; } __attribute__((packed)) synoptions_t;
__attribute__((noreturn)) static void tcp_worker() { __attribute__((noreturn)) static void tcp_worker() {
tcpworker_t *self = _cpu()->thread->kernelarg; tcpworker_t *self = current_thread()->kernelarg;
ipv4pseudoheader_t ipv4; ipv4pseudoheader_t ipv4;
int tasktype; int tasktype;
tcb_t *tcb = NULL; tcb_t *tcb = NULL;
@@ -1254,8 +1254,8 @@ static int tcp_send(socket_t *socket, sockdesc_t *sockdesc) {
MUTEX_ACQUIRE(&tcb->mutex, false); MUTEX_ACQUIRE(&tcb->mutex, false);
if (tcb->reset) { if (tcb->reset) {
if (_cpu()->thread->proc) if (current_thread()->proc)
signal_signalproc(_cpu()->thread->proc, SIGPIPE); signal_signalproc(current_thread()->proc, SIGPIPE);
error = ECONNRESET; error = ECONNRESET;
goto leave; goto leave;
} }
@@ -1272,8 +1272,8 @@ static int tcp_send(socket_t *socket, sockdesc_t *sockdesc) {
poll_leave(&polldesc); poll_leave(&polldesc);
poll_destroydesc(&polldesc); poll_destroydesc(&polldesc);
if (_cpu()->thread->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0) if (current_thread()->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0)
signal_signalproc(_cpu()->thread->proc, SIGPIPE); signal_signalproc(current_thread()->proc, SIGPIPE);
error = EPIPE; error = EPIPE;
goto leave; goto leave;
+1 -1
View File
@@ -139,7 +139,7 @@ static int vionet_sendpacket(netdev_t *internal, netdesc_t desc, mac_t targetmac
VIO_QUEUE_DRV_RING(&netdev->txqueue)[driveridx % netdev->txqueue.size] = idx; VIO_QUEUE_DRV_RING(&netdev->txqueue)[driveridx % netdev->txqueue.size] = idx;
sched_preparesleep(false); sched_preparesleep(false);
netdev->txwait[idx] = _cpu()->thread; netdev->txwait[idx] = current_thread();
*netdev->txqueue.notify = 0; *netdev->txqueue.notify = 0;
spinlock_release(&netdev->txlock); spinlock_release(&netdev->txlock);
+1 -1
View File
@@ -36,7 +36,7 @@ int poll_initdesc(polldesc_t *desc, size_t size) {
return ENOMEM; return ENOMEM;
} }
desc->thread = _cpu()->thread; desc->thread = current_thread();
desc->size = size; desc->size = size;
SPINLOCK_INIT(desc->lock); SPINLOCK_INIT(desc->lock);
SPINLOCK_INIT(desc->eventlock); SPINLOCK_INIT(desc->eventlock);
+4 -4
View File
@@ -322,7 +322,7 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result, cred_t *cre
return USERCOPY_POSSIBLY_FROM_USER(&tty->termios, arg, sizeof(termios_t)); return USERCOPY_POSSIBLY_FROM_USER(&tty->termios, arg, sizeof(termios_t));
case TIOCSCTTY: { case TIOCSCTTY: {
// set as controlling tty // set as controlling tty
return jobctl_setctty(_cpu()->thread->proc, tty, (uintptr_t)arg == 1); return jobctl_setctty(current_thread()->proc, tty, (uintptr_t)arg == 1);
break; break;
} }
case TIOCGPGRP: { case TIOCGPGRP: {
@@ -377,7 +377,7 @@ static int open(int minor, vnode_t **vnode, int flags) {
if (minor == CONTROLLING_TTY_MINOR) { if (minor == CONTROLLING_TTY_MINOR) {
// return controlling tty // return controlling tty
tty_t *ctty = jobctl_getctty(_cpu()->thread->proc); tty_t *ctty = jobctl_getctty(current_thread()->proc);
if (ctty == NULL) { if (ctty == NULL) {
return ENXIO; return ENXIO;
@@ -389,7 +389,7 @@ static int open(int minor, vnode_t **vnode, int flags) {
return ENODEV; return ENODEV;
} else if ((flags & V_FFLAGS_NOCTTY) == 0) { } else if ((flags & V_FFLAGS_NOCTTY) == 0) {
// set as controlling tty // set as controlling tty
jobctl_setctty(_cpu()->thread->proc, tty, false); jobctl_setctty(current_thread()->proc, tty, false);
} }
return 0; return 0;
@@ -467,7 +467,7 @@ tty_t *tty_create(char *name, ttydevicewritefn_t writefn, ttyinactivefn_t inacti
goto error; goto error;
} }
if (devfs_register(&devops, name, V_TYPE_CHDEV, DEV_MAJOR_TTY, minor, 0600, _cpu()->thread->proc ? &_cpu()->thread->proc->cred : NULL)) { if (devfs_register(&devops, name, V_TYPE_CHDEV, DEV_MAJOR_TTY, minor, 0600, current_thread()->proc ? &current_thread()->proc->cred : NULL)) {
freeminor(minor); freeminor(minor);
ringbuffer_destroy(&tty->readbuffer); ringbuffer_destroy(&tty->readbuffer);
goto error; goto error;
+3 -3
View File
@@ -34,7 +34,7 @@ static thread_t *get(semaphore_t *sem) {
} }
static void removeself(semaphore_t *sem) { static void removeself(semaphore_t *sem) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
// first see if we have been removed already // first see if we have been removed already
if ((sem->head == NULL && sem->tail == NULL) || // no threads in sleep list if ((sem->head == NULL && sem->tail == NULL) || // no threads in sleep list
@@ -59,7 +59,7 @@ static void removeself(semaphore_t *sem) {
} }
int semaphore_wait(semaphore_t *sem, bool interruptible) { int semaphore_wait(semaphore_t *sem, bool interruptible) {
if (_cpu()->thread == NULL) { if (current_thread() == NULL) {
while (semaphore_test(sem) == false) CPU_PAUSE(); while (semaphore_test(sem) == false) CPU_PAUSE();
return 0; return 0;
} }
@@ -69,7 +69,7 @@ int semaphore_wait(semaphore_t *sem, bool interruptible) {
spinlock_acquire(&sem->lock); spinlock_acquire(&sem->lock);
if (--sem->i < 0) { if (--sem->i < 0) {
insert(sem, _cpu()->thread); insert(sem, current_thread());
sched_preparesleep(interruptible); sched_preparesleep(interruptible);
spinlock_release(&sem->lock); spinlock_release(&sem->lock);
ret = sched_yield(); ret = sched_yield();
+6 -6
View File
@@ -23,13 +23,13 @@ static void memcpyinternal(context_t *ctx, void *arg) {
// this sets up the thread so that in the next invalid page fault, it will jump to // this sets up the thread so that in the next invalid page fault, it will jump to
// this context with CTX_RET set to EFAULT // this context with CTX_RET set to EFAULT
_cpu()->thread->usercopyctx = ctx; current_thread()->usercopyctx = ctx;
memcpy(desc->dst, desc->src, desc->size); memcpy(desc->dst, desc->src, desc->size);
// no errors! // no errors!
CTX_RET(ctx) = 0; CTX_RET(ctx) = 0;
_cpu()->thread->usercopyctx = NULL; current_thread()->usercopyctx = NULL;
} }
static void strleninternal(context_t *ctx, void *arg) { static void strleninternal(context_t *ctx, void *arg) {
@@ -37,13 +37,13 @@ static void strleninternal(context_t *ctx, void *arg) {
// this sets up the thread so that in the next invalid page fault, it will jump to // this sets up the thread so that in the next invalid page fault, it will jump to
// this context with CTX_RET set to EFAULT // this context with CTX_RET set to EFAULT
_cpu()->thread->usercopyctx = ctx; current_thread()->usercopyctx = ctx;
*desc->size = strlen(desc->str); *desc->size = strlen(desc->str);
// no errors! // no errors!
CTX_RET(ctx) = 0; CTX_RET(ctx) = 0;
_cpu()->thread->usercopyctx = NULL; current_thread()->usercopyctx = NULL;
} }
static void atomic32internal(context_t *ctx, void *arg) { static void atomic32internal(context_t *ctx, void *arg) {
@@ -51,13 +51,13 @@ static void atomic32internal(context_t *ctx, void *arg) {
// this sets up the thread so that in the next invalid page fault, it will jump to // this sets up the thread so that in the next invalid page fault, it will jump to
// this context with CTX_RET set to EFAULT // this context with CTX_RET set to EFAULT
_cpu()->thread->usercopyctx = ctx; current_thread()->usercopyctx = ctx;
__atomic_load(desc->address, desc->value, __ATOMIC_SEQ_CST); __atomic_load(desc->address, desc->value, __ATOMIC_SEQ_CST);
// no errors! // no errors!
CTX_RET(ctx) = 0; CTX_RET(ctx) = 0;
_cpu()->thread->usercopyctx = NULL; current_thread()->usercopyctx = NULL;
} }
int usercopy_touser(void *user, void *kernel, size_t size) { int usercopy_touser(void *user, void *kernel, size_t size) {
+10 -10
View File
@@ -223,7 +223,7 @@ static void destroyrange(vmmrange_t *range, uintmax_t _offset, size_t size, int
if (physical == NULL) if (physical == NULL)
continue; continue;
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread ? thread->proc : NULL; proc_t *proc = thread ? thread->proc : NULL;
cred_t *cred = proc ? &proc->cred : NULL; cred_t *cred = proc ? &proc->cred : NULL;
@@ -299,7 +299,7 @@ static void changemmurange(vmmrange_t *range, void *base, size_t size, mmuflags_
static inline bool canwritevnode(vmmrange_t *range) { static inline bool canwritevnode(vmmrange_t *range) {
VOP_LOCK(range->vnode); VOP_LOCK(range->vnode);
int error = VOP_ACCESS(range->vnode, V_ACCESS_WRITE, &_cpu()->thread->proc->cred); int error = VOP_ACCESS(range->vnode, V_ACCESS_WRITE, &current_thread()->proc->cred);
VOP_UNLOCK(range->vnode); VOP_UNLOCK(range->vnode);
return error == 0; return error == 0;
} }
@@ -560,7 +560,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
goto cleanup; goto cleanup;
} }
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread ? thread->proc : NULL; proc_t *proc = thread ? thread->proc : NULL;
cred_t *cred = proc ? &proc->cred : NULL; cred_t *cred = proc ? &proc->cred : NULL;
@@ -584,7 +584,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
if (error == ENOMEM) if (error == ENOMEM)
printf("vmm: out of memory to handle getpage (sending SIGBUS)\n"); printf("vmm: out of memory to handle getpage (sending SIGBUS)\n");
// address is past the last page of the file // address is past the last page of the file
signal_signalthread(_cpu()->thread, SIGBUS, true); signal_signalthread(current_thread(), SIGBUS, true);
status = true; status = true;
} else if (error) { } else if (error) {
printf("vmm: error on vmmcache_getpage(): %d\n", error); printf("vmm: error on vmmcache_getpage(): %d\n", error);
@@ -594,7 +594,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
if (!status) { if (!status) {
printf("vmm: out of memory to map file into address space (sending SIGBUS)\n"); printf("vmm: out of memory to map file into address space (sending SIGBUS)\n");
pmm_release(pmm_getpageaddress(res)); pmm_release(pmm_getpageaddress(res));
signal_signalthread(_cpu()->thread, SIGBUS, true); signal_signalthread(current_thread(), SIGBUS, true);
status = true; status = true;
} }
} }
@@ -604,7 +604,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
status = arch_mmu_map(_cpu()->vmmctx->pagetable, zeropage, addr, range->mmuflags & ~ARCH_MMU_FLAGS_WRITE); status = arch_mmu_map(_cpu()->vmmctx->pagetable, zeropage, addr, range->mmuflags & ~ARCH_MMU_FLAGS_WRITE);
if (!status) { if (!status) {
printf("vmm: out of memory to map zero page into address space (sending SIGBUS)\n"); printf("vmm: out of memory to map zero page into address space (sending SIGBUS)\n");
signal_signalthread(_cpu()->thread, SIGBUS, true); signal_signalthread(current_thread(), SIGBUS, true);
status = true; status = true;
} else { } else {
pmm_hold(zeropage); pmm_hold(zeropage);
@@ -630,7 +630,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
void *newphys = pmm_allocpage(PMM_SECTION_DEFAULT); void *newphys = pmm_allocpage(PMM_SECTION_DEFAULT);
if (newphys == NULL) { if (newphys == NULL) {
printf("vmm: out of memory to do copy on write on address space (sending SIGBUS)\n"); printf("vmm: out of memory to do copy on write on address space (sending SIGBUS)\n");
signal_signalthread(_cpu()->thread, SIGBUS, true); signal_signalthread(current_thread(), SIGBUS, true);
status = true; status = true;
} else { } else {
memcpy(MAKE_HHDM(newphys), MAKE_HHDM(oldphys), PAGE_SIZE); memcpy(MAKE_HHDM(newphys), MAKE_HHDM(oldphys), PAGE_SIZE);
@@ -820,7 +820,7 @@ vmmcontext_t *vmm_newcontext() {
} }
void vmm_destroycontext(vmmcontext_t *context) { void vmm_destroycontext(vmmcontext_t *context) {
vmmcontext_t *oldctx = _cpu()->thread->vmmctx; vmmcontext_t *oldctx = current_thread()->vmmctx;
vmm_switchcontext(context); vmm_switchcontext(context);
vmm_unmap(context->space.start, context->space.end - context->space.start, 0); vmm_unmap(context->space.start, context->space.end - context->space.start, 0);
vmm_switchcontext(oldctx); vmm_switchcontext(oldctx);
@@ -875,8 +875,8 @@ vmmcontext_t *vmm_fork(vmmcontext_t *oldcontext) {
} }
void vmm_switchcontext(vmmcontext_t *ctx) { void vmm_switchcontext(vmmcontext_t *ctx) {
if (_cpu()->thread) if (current_thread())
_cpu()->thread->vmmctx = ctx; current_thread()->vmmctx = ctx;
_cpu()->vmmctx = ctx; _cpu()->vmmctx = ctx;
arch_mmu_switch(ctx->pagetable); arch_mmu_switch(ctx->pagetable);
} }
+2 -2
View File
@@ -378,12 +378,12 @@ void jobctl_procremove(proc_t *proc) {
} }
// proc can be null if the signal is being sent to the calling processes own process group // proc can be null if the signal is being sent to the calling processes own process group
// since that is only passed from a userland thread, we can assume _cpu()->thread->proc is not null // since that is only passed from a userland thread, we can assume current_thread()->proc is not null
int jobctl_signal(proc_t *proc, int signal, proc_t *sender) { int jobctl_signal(proc_t *proc, int signal, proc_t *sender) {
int error = 0; int error = 0;
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
proc_t *leader; proc_t *leader;
proc_t *tmpproc = _cpu()->thread->proc; proc_t *tmpproc = current_thread()->proc;
pid_t senderpgid = sender ? jobctl_getpgid(sender) : 0; pid_t senderpgid = sender ? jobctl_getpgid(sender) : 0;
if (proc == NULL) { if (proc == NULL) {
+30 -30
View File
@@ -231,7 +231,7 @@ static thread_t *runqueuenext(int minprio) {
static __attribute__((noreturn)) void switchthread(thread_t *thread) { static __attribute__((noreturn)) void switchthread(thread_t *thread) {
interrupt_set(false); interrupt_set(false);
thread_t* current = _cpu()->thread; thread_t* current = current_thread();
_cpu()->thread = thread; _cpu()->thread = thread;
@@ -295,8 +295,8 @@ __attribute__((noreturn)) void sched_stopcurrentthread() {
interrupt_set(false); interrupt_set(false);
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
if (_cpu()->thread) if (current_thread())
_cpu()->thread->flags &= ~SCHED_THREAD_FLAGS_RUNNING; current_thread()->flags &= ~SCHED_THREAD_FLAGS_RUNNING;
thread_t *next = runqueuenext(0x0fffffff); thread_t *next = runqueuenext(0x0fffffff);
if (next == NULL) if (next == NULL)
@@ -309,7 +309,7 @@ __attribute__((noreturn)) void sched_stopcurrentthread() {
// called when all threads in a process have exited // called when all threads in a process have exited
void sched_procexit() { void sched_procexit() {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
__assert(proc != sched_initproc); __assert(proc != sched_initproc);
// the process is going to be referenced by the child list, hold it // the process is going to be referenced by the child list, hold it
@@ -378,12 +378,12 @@ void sched_inactiveproc(proc_t *proc) {
} }
static void threadexit_internal(context_t *, void *) { static void threadexit_internal(context_t *, void *) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
// we don't need to access the current thread anymore, as any state will be ignored and we are running on the scheduler stack // we don't need to access the current thread anymore, as any state will be ignored and we are running on the scheduler stack
// as well as not being preempted at all // as well as not being preempted at all
interrupt_set(false);
_cpu()->thread = NULL; _cpu()->thread = NULL;
interrupt_set(false);
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
thread->flags |= SCHED_THREAD_FLAGS_DEAD; thread->flags |= SCHED_THREAD_FLAGS_DEAD;
spinlock_release(&runqueuelock); spinlock_release(&runqueuelock);
@@ -396,7 +396,7 @@ static void threadexit_internal(context_t *, void *) {
} }
__attribute__((noreturn)) void sched_threadexit() { __attribute__((noreturn)) void sched_threadexit() {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread->proc; proc_t *proc = thread->proc;
vmmcontext_t *oldctx = thread->vmmctx; vmmcontext_t *oldctx = thread->vmmctx;
@@ -430,7 +430,7 @@ typedef struct {
// SHOULD NOT BE CALLED WITH THE SCHEDULER STACK // SHOULD NOT BE CALLED WITH THE SCHEDULER STACK
static void userspacecheck(void *_args) { static void userspacecheck(void *_args) {
checkargs_t *args = _args; checkargs_t *args = _args;
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
if (thread->shouldexit) { if (thread->shouldexit) {
interrupt_set(true); interrupt_set(true);
@@ -451,7 +451,7 @@ static void checktrampoline(context_t *context, void *_args) {
// called right before going back to userspace in the syscall handler, interrupt handler and arch_context_switch // called right before going back to userspace in the syscall handler, interrupt handler and arch_context_switch
__attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *context, bool syscall, uint64_t syscallerrno, uint64_t syscallret) { __attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *context, bool syscall, uint64_t syscallerrno, uint64_t syscallret) {
__assert(_cpu()); __assert(_cpu());
if (_cpu()->thread == NULL || ARCH_CONTEXT_ISUSER(context) == false) if (current_thread() == NULL || ARCH_CONTEXT_ISUSER(context) == false)
return; return;
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
@@ -467,7 +467,7 @@ __attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *
// if we are running on the scheduler stack, run on the kernel stack // if we are running on the scheduler stack, run on the kernel stack
// so we don't risk stack corruption (as we have to turn on interrupts should the thread need to exit) // so we don't risk stack corruption (as we have to turn on interrupts should the thread need to exit)
if (&args < (checkargs_t *)_cpu()->schedulerstack && &args >= (checkargs_t *)((uintptr_t)_cpu()->schedulerstack - SCHEDULER_STACK_SIZE)) { if (&args < (checkargs_t *)_cpu()->schedulerstack && &args >= (checkargs_t *)((uintptr_t)_cpu()->schedulerstack - SCHEDULER_STACK_SIZE)) {
arch_context_saveandcall(checktrampoline, _cpu()->thread->kernelstacktop, &args); arch_context_saveandcall(checktrampoline, current_thread()->kernelstacktop, &args);
} else { } else {
userspacecheck(&args); userspacecheck(&args);
} }
@@ -476,7 +476,7 @@ __attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *
} }
void sched_stopotherthreads() { void sched_stopotherthreads() {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread->proc; proc_t *proc = thread->proc;
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
@@ -508,7 +508,7 @@ void sched_stopotherthreads() {
} }
void sched_terminateprogram(int status) { void sched_terminateprogram(int status) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread->proc; proc_t *proc = thread->proc;
if (spinlock_try(&proc->exiting) == false) if (spinlock_try(&proc->exiting) == false)
sched_threadexit(); sched_threadexit();
@@ -521,7 +521,7 @@ void sched_terminateprogram(int status) {
} }
static void yield(context_t *context, void *) { static void yield(context_t *context, void *) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
@@ -575,18 +575,18 @@ static void yield(context_t *context, void *) {
int sched_yield() { int sched_yield() {
__assert(_cpu()->ipl == IPL_NORMAL); __assert(_cpu()->ipl == IPL_NORMAL);
bool sleeping = _cpu()->thread->flags & SCHED_THREAD_FLAGS_SLEEP; bool sleeping = current_thread()->flags & SCHED_THREAD_FLAGS_SLEEP;
bool old = sleeping ? _cpu()->thread->sleepintstatus : interrupt_set(false); bool old = sleeping ? current_thread()->sleepintstatus : interrupt_set(false);
arch_context_saveandcall(yield, _cpu()->schedulerstack, NULL); arch_context_saveandcall(yield, _cpu()->schedulerstack, NULL);
interrupt_set(old); interrupt_set(old);
return sleeping ? _cpu()->thread->wakeupreason : 0; return sleeping ? current_thread()->wakeupreason : 0;
} }
void sched_preparesleep(bool interruptible) { void sched_preparesleep(bool interruptible) {
_cpu()->thread->sleepintstatus = interrupt_set(false); current_thread()->sleepintstatus = interrupt_set(false);
spinlock_acquire(&_cpu()->thread->sleeplock); spinlock_acquire(&current_thread()->sleeplock);
// no locking needed as only we will be accessing it // no locking needed as only we will be accessing it
_cpu()->thread->flags |= SCHED_THREAD_FLAGS_SLEEP | (interruptible ? SCHED_THREAD_FLAGS_INTERRUPTIBLE : 0); current_thread()->flags |= SCHED_THREAD_FLAGS_SLEEP | (interruptible ? SCHED_THREAD_FLAGS_INTERRUPTIBLE : 0);
} }
bool sched_wakeup(thread_t *thread, int reason) { bool sched_wakeup(thread_t *thread, int reason) {
@@ -610,7 +610,7 @@ bool sched_wakeup(thread_t *thread, int reason) {
} }
static vnode_t *getnodeslock(vnode_t **addr) { static vnode_t *getnodeslock(vnode_t **addr) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
spinlock_acquire(&proc->nodeslock); spinlock_acquire(&proc->nodeslock);
vnode_t *vnode = *addr; vnode_t *vnode = *addr;
@@ -621,17 +621,17 @@ static vnode_t *getnodeslock(vnode_t **addr) {
} }
vnode_t *sched_getcwd() { vnode_t *sched_getcwd() {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
return getnodeslock(&proc->cwd); return getnodeslock(&proc->cwd);
} }
vnode_t *sched_getroot() { vnode_t *sched_getroot() {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
return getnodeslock(&proc->root); return getnodeslock(&proc->root);
} }
static void setnodeslock(vnode_t **addr, vnode_t *new) { static void setnodeslock(vnode_t **addr, vnode_t *new) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
vnode_t *oldnode; vnode_t *oldnode;
VOP_HOLD(new); VOP_HOLD(new);
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
@@ -644,11 +644,11 @@ static void setnodeslock(vnode_t **addr, vnode_t *new) {
} }
void sched_setcwd(vnode_t *new) { void sched_setcwd(vnode_t *new) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
setnodeslock(&proc->cwd, new); setnodeslock(&proc->cwd, new);
} }
void sched_setroot(vnode_t *new) { void sched_setroot(vnode_t *new) {
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
setnodeslock(&proc->root, new); setnodeslock(&proc->root, new);
} }
@@ -657,7 +657,7 @@ static void dopreempt() {
// interrupts are disabled, the thread context is already saved // interrupts are disabled, the thread context is already saved
spinlock_acquire(&runqueuelock); spinlock_acquire(&runqueuelock);
thread_t *current = _cpu()->thread; thread_t *current = current_thread();
thread_t *next = runqueuenext(current->priority); thread_t *next = runqueuenext(current->priority);
current->flags &= ~SCHED_THREAD_FLAGS_PREEMPTED; current->flags &= ~SCHED_THREAD_FLAGS_PREEMPTED;
@@ -673,7 +673,7 @@ static void dopreempt() {
} }
static void timerhook(context_t *context, dpcarg_t arg) { static void timerhook(context_t *context, dpcarg_t arg) {
thread_t* current = _cpu()->thread; thread_t* current = current_thread();
interrupt_set(false); interrupt_set(false);
// no need to preempt it again // no need to preempt it again
@@ -699,7 +699,7 @@ static void cpuidlethread() {
void sched_targetcpu(cpu_t *cpu) { void sched_targetcpu(cpu_t *cpu) {
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
_cpu()->thread->cputarget = cpu; current_thread()->cputarget = cpu;
interrupt_set(intstatus); interrupt_set(intstatus);
} }
@@ -712,7 +712,7 @@ void sched_sleepus(size_t us) {
timerentry_t sleepentry = {0}; timerentry_t sleepentry = {0};
sched_preparesleep(false); sched_preparesleep(false);
timer_insert(_cpu()->timer, &sleepentry, timeout, _cpu()->thread, us, false); timer_insert(_cpu()->timer, &sleepentry, timeout, current_thread(), us, false);
sched_yield(); sched_yield();
} }
@@ -747,7 +747,7 @@ void sched_init() {
_cpu()->idlethread = sched_newthread(cpuidlethread, PAGE_SIZE * 4, 3, NULL, NULL); _cpu()->idlethread = sched_newthread(cpuidlethread, PAGE_SIZE * 4, 3, NULL, NULL);
__assert(_cpu()->idlethread); __assert(_cpu()->idlethread);
_cpu()->thread = sched_newthread(NULL, PAGE_SIZE * 32, 0, NULL, NULL); _cpu()->thread = sched_newthread(NULL, PAGE_SIZE * 32, 0, NULL, NULL);
__assert(_cpu()->thread); __assert(current_thread());
timer_insert(_cpu()->timer, &_cpu()->schedtimerentry, timerhook, NULL, QUANTUM_US, true); timer_insert(_cpu()->timer, &_cpu()->schedtimerentry, timerhook, NULL, QUANTUM_US, true);
// XXX move this resume to a more appropriate place // XXX move this resume to a more appropriate place
+2 -2
View File
@@ -145,7 +145,7 @@ void signal_returnmask(struct thread_t *thread, sigset_t *sigset) {
} }
void signal_suspend(sigset_t *sigset) { void signal_suspend(sigset_t *sigset) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
THREAD_ENTER(thread); THREAD_ENTER(thread);
memcpy(&thread->signals.mask, sigset, sizeof(sigset_t)); memcpy(&thread->signals.mask, sigset, sizeof(sigset_t));
@@ -158,7 +158,7 @@ void signal_suspend(sigset_t *sigset) {
} }
int signal_wait(sigset_t *sigset, timespec_t *timeout, siginfo_t *siginfo, int *signum) { int signal_wait(sigset_t *sigset, timespec_t *timeout, siginfo_t *siginfo, int *signum) {
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
PROCESS_ENTER(thread->proc); PROCESS_ENTER(thread->proc);
THREAD_ENTER(thread); THREAD_ENTER(thread);
// if timeoutus is 0, this wait is just a poll // if timeoutus is 0, this wait is just a poll
+1 -1
View File
@@ -46,7 +46,7 @@ syscallret_t syscall_bind(context_t *, int fd, void *uaddr, size_t addrlen) {
socket_t *socket = SOCKFS_SOCKET_FROM_NODE(file->vnode); socket_t *socket = SOCKFS_SOCKET_FROM_NODE(file->vnode);
ret.errno = socket->ops->bind(socket, &sockaddr, &_cpu()->thread->proc->cred); ret.errno = socket->ops->bind(socket, &sockaddr, &current_thread()->proc->cred);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
cleanup: cleanup:
+1 -1
View File
@@ -8,7 +8,7 @@
// node expected to be locked // node expected to be locked
static int dochmod(vnode_t *node, mode_t mode) { static int dochmod(vnode_t *node, mode_t mode) {
vattr_t attr; vattr_t attr;
cred_t *cred = &_cpu()->thread->proc->cred; cred_t *cred = &current_thread()->proc->cred;
int e = auth_filesystem_check(cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL); int e = auth_filesystem_check(cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
if (e) if (e)
+1 -1
View File
@@ -10,7 +10,7 @@ syscallret_t syscall_chroot(context_t *, char *upath) {
.ret = -1 .ret = -1
}; };
ret.errno = auth_system_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_SYSTEM_CHROOT); ret.errno = auth_system_check(&current_thread()->proc->cred, AUTH_ACTIONS_SYSTEM_CHROOT);
if (ret.errno) if (ret.errno)
return ret; return ret;
+1 -1
View File
@@ -47,7 +47,7 @@ syscallret_t syscall_connect(context_t *, int fd, abisockaddr_t *uaddr, size_t a
socket_t *socket = SOCKFS_SOCKET_FROM_NODE(file->vnode); socket_t *socket = SOCKFS_SOCKET_FROM_NODE(file->vnode);
ret.errno = socket->ops->connect ? socket->ops->connect(socket, &sockaddr, fileflagstovnodeflags(file->flags), &_cpu()->thread->proc->cred) : EOPNOTSUPP; ret.errno = socket->ops->connect ? socket->ops->connect(socket, &sockaddr, fileflagstovnodeflags(file->flags), &current_thread()->proc->cred) : EOPNOTSUPP;
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
cleanup: cleanup:
+4 -4
View File
@@ -177,7 +177,7 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
if (ret.errno) if (ret.errno)
goto error; goto error;
ret.errno = VOP_ACCESS(node, V_ACCESS_EXECUTE, &_cpu()->thread->proc->cred); ret.errno = VOP_ACCESS(node, V_ACCESS_EXECUTE, &current_thread()->proc->cred);
VOP_UNLOCK(node); VOP_UNLOCK(node);
if (ret.errno) { if (ret.errno) {
goto error; goto error;
@@ -277,13 +277,13 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
// close O_CLOEXEC fds // close O_CLOEXEC fds
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
for (int fd = 0; fd < proc->fdcount; ++fd) { for (int fd = 0; fd < proc->fdcount; ++fd) {
if (proc->fd[fd].flags & O_CLOEXEC) if (proc->fd[fd].flags & O_CLOEXEC)
fd_close(fd); fd_close(fd);
} }
memset(&_cpu()->thread->signals.stack, 0, sizeof(stack_t)); memset(&current_thread()->signals.stack, 0, sizeof(stack_t));
// execve keeps information about ignored signals // execve keeps information about ignored signals
for (int i = 1; i < NSIG; ++i) { for (int i = 1; i < NSIG; ++i) {
@@ -306,7 +306,7 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
if (vattr.mode & V_ATTR_MODE_SGID) if (vattr.mode & V_ATTR_MODE_SGID)
sgid = vattr.gid; sgid = vattr.gid;
cred_doexec(&_cpu()->thread->proc->cred, suid, sgid); cred_doexec(&current_thread()->proc->cred, suid, sgid);
error: error:
free(path); free(path);
+1 -1
View File
@@ -38,7 +38,7 @@ syscallret_t syscall_faccessat(context_t *, int dirfd, char *upath, int mode, in
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
ret.errno = VOP_ACCESS(node, mode, &_cpu()->thread->proc->cred); ret.errno = VOP_ACCESS(node, mode, &current_thread()->proc->cred);
VOP_UNLOCK(node); VOP_UNLOCK(node);
ret.ret = 0; ret.ret = 0;
+3 -3
View File
@@ -50,14 +50,14 @@ syscallret_t syscall_fchownat(context_t *, int fd, char *upath, uid_t owner, gid
goto cleanup; goto cleanup;
} }
ret.errno = auth_filesystem_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL); ret.errno = auth_filesystem_check(&current_thread()->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
if (ret.errno) { if (ret.errno) {
VOP_UNLOCK(node); VOP_UNLOCK(node);
goto cleanup; goto cleanup;
} }
vattr_t attr; vattr_t attr;
ret.errno = VOP_GETATTR(node, &attr, &_cpu()->thread->proc->cred); ret.errno = VOP_GETATTR(node, &attr, &current_thread()->proc->cred);
if (ret.errno) { if (ret.errno) {
VOP_UNLOCK(node); VOP_UNLOCK(node);
goto cleanup; goto cleanup;
@@ -67,7 +67,7 @@ syscallret_t syscall_fchownat(context_t *, int fd, char *upath, uid_t owner, gid
attr.gid = group; attr.gid = group;
attr.mode = (attr.mode) & ~(V_ATTR_MODE_SGID | V_ATTR_MODE_SUID); attr.mode = (attr.mode) & ~(V_ATTR_MODE_SGID | V_ATTR_MODE_SUID);
ret.errno = VOP_SETATTR(node, &attr, ((owner == -1) ? 0 : V_ATTR_UID) | ((group == -1) ? 0 : V_ATTR_GID) | ((group + owner == -2) ? 0 : V_ATTR_MODE), &_cpu()->thread->proc->cred); ret.errno = VOP_SETATTR(node, &attr, ((owner == -1) ? 0 : V_ATTR_UID) | ((group == -1) ? 0 : V_ATTR_GID) | ((group + owner == -2) ? 0 : V_ATTR_MODE), &current_thread()->proc->cred);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
VOP_UNLOCK(node); VOP_UNLOCK(node);
+7 -7
View File
@@ -11,7 +11,7 @@ syscallret_t syscall_fork(context_t *ctx) {
.errno = 0 .errno = 0
}; };
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
proc_t *nproc = sched_newproc(); proc_t *nproc = sched_newproc();
if (nproc == NULL) { if (nproc == NULL) {
ret.errno = ENOMEM; ret.errno = ENOMEM;
@@ -24,7 +24,7 @@ syscallret_t syscall_fork(context_t *ctx) {
goto cleanup; goto cleanup;
} }
nthread->vmmctx = vmm_fork(_cpu()->thread->vmmctx); nthread->vmmctx = vmm_fork(current_thread()->vmmctx);
if (nthread->vmmctx == NULL) { if (nthread->vmmctx == NULL) {
ret.errno = ENOMEM; ret.errno = ENOMEM;
@@ -43,8 +43,8 @@ syscallret_t syscall_fork(context_t *ctx) {
MUTEX_RELEASE(&proc->mutex); MUTEX_RELEASE(&proc->mutex);
nproc->umask = _cpu()->thread->proc->umask; nproc->umask = current_thread()->proc->umask;
nproc->cred = _cpu()->thread->proc->cred; nproc->cred = current_thread()->proc->cred;
nproc->root = sched_getroot(); nproc->root = sched_getroot();
nproc->cwd = sched_getcwd(); nproc->cwd = sched_getcwd();
nproc->threadlist = nthread; nproc->threadlist = nthread;
@@ -56,9 +56,9 @@ syscallret_t syscall_fork(context_t *ctx) {
CTX_ERRNO(&nthread->context) = 0; CTX_ERRNO(&nthread->context) = 0;
jobctl_addproc(proc, nproc); jobctl_addproc(proc, nproc);
memcpy(&nthread->signals.mask, &_cpu()->thread->signals.mask, sizeof(sigset_t)); memcpy(&nthread->signals.mask, &current_thread()->signals.mask, sizeof(sigset_t));
memcpy(&nthread->signals.pending, &_cpu()->thread->signals.pending, sizeof(sigset_t)); memcpy(&nthread->signals.pending, &current_thread()->signals.pending, sizeof(sigset_t));
memcpy(&nthread->signals.stack, &_cpu()->thread->signals.stack, sizeof(stack_t)); memcpy(&nthread->signals.stack, &current_thread()->signals.stack, sizeof(stack_t));
memcpy(&nproc->signals.pending, &proc->signals.pending, sizeof(sigset_t)); memcpy(&nproc->signals.pending, &proc->signals.pending, sizeof(sigset_t));
memcpy(&nproc->signals.actions, &proc->signals.actions[0], sizeof(sigaction_t) * NSIG); memcpy(&nproc->signals.actions, &proc->signals.actions[0], sizeof(sigaction_t) * NSIG);
+4 -4
View File
@@ -5,7 +5,7 @@
syscallret_t syscall_getpid(context_t *ctx) { syscallret_t syscall_getpid(context_t *ctx) {
syscallret_t ret = { syscallret_t ret = {
.ret = _cpu()->thread->proc->pid, .ret = current_thread()->proc->pid,
.errno = 0 .errno = 0
}; };
return ret; return ret;
@@ -13,7 +13,7 @@ syscallret_t syscall_getpid(context_t *ctx) {
syscallret_t syscall_getppid(context_t *ctx) { syscallret_t syscall_getppid(context_t *ctx) {
syscallret_t ret = { syscallret_t ret = {
.ret = _cpu()->thread->proc->parent ? _cpu()->thread->proc->parent->pid : 1, .ret = current_thread()->proc->parent ? current_thread()->proc->parent->pid : 1,
.errno = 0 .errno = 0
}; };
return ret; return ret;
@@ -25,7 +25,7 @@ syscallret_t syscall_getpgid(context_t *ctx, pid_t pid) {
}; };
__assert(pid == 0); __assert(pid == 0);
ret.ret = jobctl_getpgid(_cpu()->thread->proc); ret.ret = jobctl_getpgid(current_thread()->proc);
return ret; return ret;
} }
@@ -35,6 +35,6 @@ syscallret_t syscall_getsid(context_t *ctx, pid_t pid) {
}; };
__assert(pid == 0); __assert(pid == 0);
ret.ret = jobctl_getsid(_cpu()->thread->proc); ret.ret = jobctl_getsid(current_thread()->proc);
return ret; return ret;
} }
+1 -1
View File
@@ -8,7 +8,7 @@ syscallret_t syscall_getresgid(context_t *, gid_t *gidp, gid_t *egidp, gid_t *sg
}; };
int gid, egid, sgid; int gid, egid, sgid;
cred_getgids(&_cpu()->thread->proc->cred, &gid, &egid, &sgid); cred_getgids(&current_thread()->proc->cred, &gid, &egid, &sgid);
ret.errno = usercopy_touser(gidp, &gid, sizeof(gid)); ret.errno = usercopy_touser(gidp, &gid, sizeof(gid));
if (ret.errno) if (ret.errno)
+1 -1
View File
@@ -8,7 +8,7 @@ syscallret_t syscall_getresuid(context_t *, uid_t *uidp, uid_t *euidp, uid_t *su
}; };
int uid, euid, suid; int uid, euid, suid;
cred_getuids(&_cpu()->thread->proc->cred, &uid, &euid, &suid); cred_getuids(&current_thread()->proc->cred, &uid, &euid, &suid);
ret.errno = usercopy_touser(uidp, &uid, sizeof(uid)); ret.errno = usercopy_touser(uidp, &uid, sizeof(uid));
if (ret.errno) if (ret.errno)
+1 -1
View File
@@ -4,7 +4,7 @@
syscallret_t syscall_gettid(context_t *) { syscallret_t syscall_gettid(context_t *) {
syscallret_t ret = { syscallret_t ret = {
.errno = 0, .errno = 0,
.ret = _cpu()->thread->tid .ret = current_thread()->tid
}; };
return ret; return ret;
+1 -1
View File
@@ -33,7 +33,7 @@ syscallret_t syscall_hostname(context_t *, char *unew, size_t newsize, char *uol
char old[HOST_NAME_MAX + 1]; char old[HOST_NAME_MAX + 1];
if (unew) { if (unew) {
ret.errno = auth_system_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_SYSTEM_SETHOSTNAME); ret.errno = auth_system_check(&current_thread()->proc->cred, AUTH_ACTIONS_SYSTEM_SETHOSTNAME);
if (ret.errno) if (ret.errno)
return ret; return ret;
+1 -1
View File
@@ -20,7 +20,7 @@ syscallret_t syscall_ioctl(context_t *, int fd, unsigned long request, void *arg
int r = 0; int r = 0;
VOP_LOCK(file->vnode); VOP_LOCK(file->vnode);
ret.errno = VOP_IOCTL(file->vnode, request, arg, &r, &_cpu()->thread->proc->cred); ret.errno = VOP_IOCTL(file->vnode, request, arg, &r, &current_thread()->proc->cred);
VOP_UNLOCK(file->vnode); VOP_UNLOCK(file->vnode);
ret.ret = ret.errno ? -1 : r; ret.ret = ret.errno ? -1 : r;
+4 -4
View File
@@ -31,17 +31,17 @@ syscallret_t syscall_kill(context_t *context, int pid, int signal) {
goto leave; goto leave;
if (pid >= 1) { if (pid >= 1) {
if (signal != SIGCONT || jobctl_getpgid(target) != jobctl_getpgid(_cpu()->thread->proc)) { if (signal != SIGCONT || jobctl_getpgid(target) != jobctl_getpgid(current_thread()->proc)) {
ret.errno = auth_process_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_PROCESS_SIGNAL, target); ret.errno = auth_process_check(&current_thread()->proc->cred, AUTH_ACTIONS_PROCESS_SIGNAL, target);
if (ret.errno) if (ret.errno)
goto leave; goto leave;
} }
signal_signalproc(target, signal); signal_signalproc(target, signal);
} else if (pid == -1) { } else if (pid == -1) {
ret.errno = sched_signalall(signal, _cpu()->thread->proc); ret.errno = sched_signalall(signal, current_thread()->proc);
} else { } else {
ret.errno = jobctl_signal(target, signal, _cpu()->thread->proc); ret.errno = jobctl_signal(target, signal, current_thread()->proc);
} }
leave: leave:
+1 -1
View File
@@ -14,7 +14,7 @@ syscallret_t syscall_killthread(context_t *context, int pid, int tid, int signal
return ret; return ret;
} }
proc_t *sender = _cpu()->thread->proc; proc_t *sender = current_thread()->proc;
proc_t *target = sched_getprocfrompid(pid); proc_t *target = sched_getprocfrompid(pid);
if (target == NULL) { if (target == NULL) {
ret.errno = ESRCH; ret.errno = ESRCH;
+2 -2
View File
@@ -50,8 +50,8 @@ syscallret_t syscall_linkat(context_t *, int olddirfd, char *uoldpath, int newdi
goto cleanup; goto cleanup;
vattr_t attr = { vattr_t attr = {
.gid = _cpu()->thread->proc->cred.gid, .gid = current_thread()->proc->cred.gid,
.uid = _cpu()->thread->proc->cred.uid, .uid = current_thread()->proc->cred.uid,
.mode = UMASK(0777) .mode = UMASK(0777)
}; };
+2 -2
View File
@@ -35,8 +35,8 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, char *upath, mode_t mode) {
vattr_t attr = { vattr_t attr = {
.mode = UMASK(mode), .mode = UMASK(mode),
.gid = _cpu()->thread->proc->cred.egid, .gid = current_thread()->proc->cred.egid,
.uid = _cpu()->thread->proc->cred.euid .uid = current_thread()->proc->cred.euid
}; };
ret.errno = vfs_create(dirnode, path, &attr, V_TYPE_DIR, NULL); ret.errno = vfs_create(dirnode, path, &attr, V_TYPE_DIR, NULL);
+2 -2
View File
@@ -38,8 +38,8 @@ syscallret_t syscall_mknodat(context_t *, int dirfd, char *upath, mode_t mode, d
vattr_t attr = { vattr_t attr = {
.mode = UMASK(mode), .mode = UMASK(mode),
.gid = _cpu()->thread->proc->cred.egid, .gid = current_thread()->proc->cred.egid,
.uid = _cpu()->thread->proc->cred.euid, .uid = current_thread()->proc->cred.euid,
.rdevmajor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MAJORDEV(dev) : 0, .rdevmajor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MAJORDEV(dev) : 0,
.rdevminor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MINORDEV(dev) : 0, .rdevminor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MINORDEV(dev) : 0,
}; };
+3 -3
View File
@@ -15,15 +15,15 @@ syscallret_t syscall_newthread(context_t *, void *entry, void *stack) {
return ret; return ret;
} }
proc_t *proc = _cpu()->thread->proc; proc_t *proc = current_thread()->proc;
thread_t *thread = sched_newthread(entry, 16 * PAGE_SIZE, 1, _cpu()->thread->proc, stack); thread_t *thread = sched_newthread(entry, 16 * PAGE_SIZE, 1, current_thread()->proc, stack);
if (thread == NULL) { if (thread == NULL) {
ret.errno = ENOMEM; ret.errno = ENOMEM;
return ret; return ret;
} }
thread->vmmctx = _cpu()->thread->vmmctx; thread->vmmctx = current_thread()->vmmctx;
bool intstatus = interrupt_set(false); bool intstatus = interrupt_set(false);
spinlock_acquire(&proc->threadlistlock); spinlock_acquire(&proc->threadlistlock);
+4 -4
View File
@@ -55,8 +55,8 @@ syscallret_t syscall_openat(context_t *context, int dirfd, char *path, int flags
// create file // create file
vattr_t attr = { vattr_t attr = {
.mode = UMASK(mode), .mode = UMASK(mode),
.gid = _cpu()->thread->proc->cred.egid, .gid = current_thread()->proc->cred.egid,
.uid = _cpu()->thread->proc->cred.euid .uid = current_thread()->proc->cred.euid
}; };
ret.errno = vfs_create(dirnode, pathbuf, &attr, V_TYPE_REGULAR, &vnode); ret.errno = vfs_create(dirnode, pathbuf, &attr, V_TYPE_REGULAR, &vnode);
@@ -79,12 +79,12 @@ syscallret_t syscall_openat(context_t *context, int dirfd, char *path, int flags
} }
vattr_t attr; vattr_t attr;
ret.errno = VOP_GETATTR(vnode, &attr, &_cpu()->thread->proc->cred); ret.errno = VOP_GETATTR(vnode, &attr, &current_thread()->proc->cred);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
if (vnode->type == V_TYPE_REGULAR && (flags & O_TRUNC) && (flags & FILE_WRITE)) { if (vnode->type == V_TYPE_REGULAR && (flags & O_TRUNC) && (flags & FILE_WRITE)) {
ret.errno = VOP_RESIZE(vnode, 0, &_cpu()->thread->proc->cred); ret.errno = VOP_RESIZE(vnode, 0, &current_thread()->proc->cred);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
} }
+1 -1
View File
@@ -12,7 +12,7 @@ static void open(file_t *file, vnode_t *node, int flags) {
file->offset = 0; file->offset = 0;
file->mode = 0777; file->mode = 0777;
VOP_LOCK(node); VOP_LOCK(node);
VOP_OPEN(&node, fileflagstovnodeflags(flags) | V_FFLAGS_NONBLOCKING, &_cpu()->thread->proc->cred); VOP_OPEN(&node, fileflagstovnodeflags(flags) | V_FFLAGS_NONBLOCKING, &current_thread()->proc->cred);
VOP_UNLOCK(node); VOP_UNLOCK(node);
} }
+2 -2
View File
@@ -124,8 +124,8 @@ syscallret_t syscall_ppoll(context_t *context, pollfd_t *fds, size_t nfds, times
if (ret.errno) if (ret.errno)
return ret; return ret;
signal_changemask(_cpu()->thread, SIG_SETMASK, &sigset, &savedset); signal_changemask(current_thread(), SIG_SETMASK, &sigset, &savedset);
signal_returnmask(_cpu()->thread, &savedset); signal_returnmask(current_thread(), &savedset);
} }
syscallret_t ret = syscall_poll(context, fds, nfds, utimeout ? (timeout.s * 1000 + timeout.ns / 1000000) : -1); syscallret_t ret = syscall_poll(context, fds, nfds, utimeout ? (timeout.s * 1000 + timeout.ns / 1000000) : -1);
+1 -1
View File
@@ -38,7 +38,7 @@ syscallret_t syscall_readlinkat(context_t *, int dirfd, char *upath, char *ubuff
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
ret.errno = VOP_READLINK(node, &buffer, &_cpu()->thread->proc->cred); ret.errno = VOP_READLINK(node, &buffer, &current_thread()->proc->cred);
// locked by vfs_lookup // locked by vfs_lookup
VOP_UNLOCK(node); VOP_UNLOCK(node);
if (ret.errno) if (ret.errno)
+1 -1
View File
@@ -44,7 +44,7 @@ syscallret_t syscall_seek(context_t *context, int fd, off_t offset, int whence)
} else { } else {
vattr_t attr; vattr_t attr;
VOP_LOCK(file->vnode); VOP_LOCK(file->vnode);
ret.errno = VOP_GETATTR(file->vnode, &attr, &_cpu()->thread->proc->cred); ret.errno = VOP_GETATTR(file->vnode, &attr, &current_thread()->proc->cred);
VOP_UNLOCK(file->vnode); VOP_UNLOCK(file->vnode);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;
+7 -7
View File
@@ -15,11 +15,11 @@ typedef struct {
static itimer_t *selectitimer(int which) { static itimer_t *selectitimer(int which) {
itimer_t *itimer = NULL; itimer_t *itimer = NULL;
if (which == ITIMER_REAL) if (which == ITIMER_REAL)
itimer = &_cpu()->thread->proc->timer.realtime; itimer = &current_thread()->proc->timer.realtime;
else if (which == ITIMER_VIRTUAL) else if (which == ITIMER_VIRTUAL)
itimer = &_cpu()->thread->proc->timer.virtualtime; itimer = &current_thread()->proc->timer.virtualtime;
else if (which == ITIMER_PROF) else if (which == ITIMER_PROF)
itimer = &_cpu()->thread->proc->timer.profiling; itimer = &current_thread()->proc->timer.profiling;
return itimer; return itimer;
} }
@@ -36,14 +36,14 @@ syscallret_t syscall_getitimer(context_t *context, int which, itimerval_t *value
return ret; return ret;
} }
MUTEX_ACQUIRE(&_cpu()->thread->proc->timer.mutex, false); MUTEX_ACQUIRE(&current_thread()->proc->timer.mutex, false);
uintmax_t oldremaining, oldrepeat; uintmax_t oldremaining, oldrepeat;
itimer_pause(itimer, &oldremaining, &oldrepeat); itimer_pause(itimer, &oldremaining, &oldrepeat);
if (oldremaining) if (oldremaining)
itimer_resume(itimer); itimer_resume(itimer);
MUTEX_RELEASE(&_cpu()->thread->proc->timer.mutex); MUTEX_RELEASE(&current_thread()->proc->timer.mutex);
itimerval_t tmp; itimerval_t tmp;
@@ -76,7 +76,7 @@ syscallret_t syscall_setitimer(context_t *context, int which, itimerval_t *unew,
return ret; return ret;
} }
MUTEX_ACQUIRE(&_cpu()->thread->proc->timer.mutex, false); MUTEX_ACQUIRE(&current_thread()->proc->timer.mutex, false);
uintmax_t oldremaining, oldrepeat; uintmax_t oldremaining, oldrepeat;
itimer_pause(itimer, &oldremaining, &oldrepeat); itimer_pause(itimer, &oldremaining, &oldrepeat);
@@ -87,7 +87,7 @@ syscallret_t syscall_setitimer(context_t *context, int which, itimerval_t *unew,
if (newus) if (newus)
itimer_resume(itimer); itimer_resume(itimer);
MUTEX_RELEASE(&_cpu()->thread->proc->timer.mutex); MUTEX_RELEASE(&current_thread()->proc->timer.mutex);
ret.errno = 0; ret.errno = 0;
if (uold) { if (uold) {
+3 -3
View File
@@ -5,15 +5,15 @@
syscallret_t syscall_setsid(context_t *) { syscallret_t syscall_setsid(context_t *) {
syscallret_t ret; syscallret_t ret;
ret.errno = jobctl_newsession(_cpu()->thread->proc); ret.errno = jobctl_newsession(current_thread()->proc);
ret.ret = ret.errno ? -1 : _cpu()->thread->proc->pid; ret.ret = ret.errno ? -1 : current_thread()->proc->pid;
return ret; return ret;
} }
syscallret_t syscall_setpgid(context_t *, pid_t pid, pid_t pgid) { syscallret_t syscall_setpgid(context_t *, pid_t pid, pid_t pgid) {
syscallret_t ret; syscallret_t ret;
proc_t *currentproc = _cpu()->thread->proc; proc_t *currentproc = current_thread()->proc;
if (pgid < 0) { if (pgid < 0) {
ret.errno = EINVAL; ret.errno = EINVAL;
+1 -1
View File
@@ -5,7 +5,7 @@
syscallret_t syscall_setresgid(context_t *, gid_t gid, gid_t egid, gid_t sgid) { syscallret_t syscall_setresgid(context_t *, gid_t gid, gid_t egid, gid_t sgid) {
syscallret_t ret; syscallret_t ret;
ret.errno = cred_setgids(&_cpu()->thread->proc->cred, gid, egid, sgid); ret.errno = cred_setgids(&current_thread()->proc->cred, gid, egid, sgid);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
return ret; return ret;
+5 -5
View File
@@ -5,7 +5,7 @@
syscallret_t syscall_setresuid(context_t *, uid_t uid, uid_t euid, uid_t suid) { syscallret_t syscall_setresuid(context_t *, uid_t uid, uid_t euid, uid_t suid) {
syscallret_t ret; syscallret_t ret;
ret.errno = cred_setuids(&_cpu()->thread->proc->cred, uid, euid, suid); ret.errno = cred_setuids(&current_thread()->proc->cred, uid, euid, suid);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
return ret; return ret;
@@ -14,7 +14,7 @@ syscallret_t syscall_setresuid(context_t *, uid_t uid, uid_t euid, uid_t suid) {
syscallret_t syscall_setuid(context_t *, uid_t uid) { syscallret_t syscall_setuid(context_t *, uid_t uid) {
syscallret_t ret; syscallret_t ret;
ret.errno = cred_setuid(&_cpu()->thread->proc->cred, uid); ret.errno = cred_setuid(&current_thread()->proc->cred, uid);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
return ret; return ret;
@@ -23,7 +23,7 @@ syscallret_t syscall_setuid(context_t *, uid_t uid) {
syscallret_t syscall_seteuid(context_t *, uid_t euid) { syscallret_t syscall_seteuid(context_t *, uid_t euid) {
syscallret_t ret; syscallret_t ret;
ret.errno = cred_seteuid(&_cpu()->thread->proc->cred, euid); ret.errno = cred_seteuid(&current_thread()->proc->cred, euid);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
return ret; return ret;
@@ -32,7 +32,7 @@ syscallret_t syscall_seteuid(context_t *, uid_t euid) {
syscallret_t syscall_setgid(context_t *, gid_t gid) { syscallret_t syscall_setgid(context_t *, gid_t gid) {
syscallret_t ret; syscallret_t ret;
ret.errno = cred_setgid(&_cpu()->thread->proc->cred, gid); ret.errno = cred_setgid(&current_thread()->proc->cred, gid);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
return ret; return ret;
@@ -41,7 +41,7 @@ syscallret_t syscall_setgid(context_t *, gid_t gid) {
syscallret_t syscall_setegid(context_t *, uid_t egid) { syscallret_t syscall_setegid(context_t *, uid_t egid) {
syscallret_t ret; syscallret_t ret;
ret.errno = cred_setegid(&_cpu()->thread->proc->cred, egid); ret.errno = cred_setegid(&current_thread()->proc->cred, egid);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
return ret; return ret;
+1 -1
View File
@@ -67,7 +67,7 @@ syscallret_t syscall_setsockopt(context_t *, int fd, int level, int optname, voi
if (val == NULL) if (val == NULL)
ret.errno = EFAULT; ret.errno = EFAULT;
else else
ret.errno = socket->ops->setopt ? socket->ops->setopt(socket, optname, buffer, len, &_cpu()->thread->proc->cred) : ENOPROTOOPT; ret.errno = socket->ops->setopt ? socket->ops->setopt(socket, optname, buffer, len, &current_thread()->proc->cred) : ENOPROTOOPT;
break; break;
} }
default: default:
+1 -1
View File
@@ -24,7 +24,7 @@ syscallret_t syscall_sigaction(context_t *, int sig, sigaction_t *new, sigaction
} }
} }
signal_action(_cpu()->thread->proc, sig, new ? &newtmp : NULL, old ? &oldtmp : NULL); signal_action(current_thread()->proc, sig, new ? &newtmp : NULL, old ? &oldtmp : NULL);
if (old && usercopy_touser(old, &oldtmp, sizeof(sigaction_t))) { if (old && usercopy_touser(old, &oldtmp, sizeof(sigaction_t))) {
ret.errno = EFAULT; ret.errno = EFAULT;
+1 -1
View File
@@ -12,7 +12,7 @@ syscallret_t syscall_sigaltstack(context_t *, stack_t *new, stack_t *old) {
return ret; return ret;
} }
signal_altstack(_cpu()->thread, new ? &newtmp : NULL, old ? &oldtmp : NULL); signal_altstack(current_thread(), new ? &newtmp : NULL, old ? &oldtmp : NULL);
if (old && usercopy_touser(old, &oldtmp, sizeof(stack_t))) { if (old && usercopy_touser(old, &oldtmp, sizeof(stack_t))) {
ret.errno = EFAULT; ret.errno = EFAULT;
+1 -1
View File
@@ -6,7 +6,7 @@ syscallret_t syscall_sigpending(context_t *, sigset_t *uset) {
syscallret_t ret; syscallret_t ret;
sigset_t set; sigset_t set;
signal_pending(_cpu()->thread, &set); signal_pending(current_thread(), &set);
ret.errno = usercopy_touser(uset, &set, sizeof(sigset_t)); ret.errno = usercopy_touser(uset, &set, sizeof(sigset_t));
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
+1 -1
View File
@@ -23,7 +23,7 @@ syscallret_t syscall_sigprocmask(context_t *, int how, sigset_t *set, sigset_t *
return ret; return ret;
} }
signal_changemask(_cpu()->thread, how, set ? &new : NULL, oldset ? &old : NULL); signal_changemask(current_thread(), how, set ? &new : NULL, oldset ? &old : NULL);
if (oldset && usercopy_touser(oldset, &old, sizeof(sigset_t))) { if (oldset && usercopy_touser(oldset, &old, sizeof(sigset_t))) {
ret.errno = EFAULT; ret.errno = EFAULT;
+4 -4
View File
@@ -13,12 +13,12 @@ __attribute__((noreturn)) void syscall_sigreturn(context_t *context) {
} }
interrupt_set(false); interrupt_set(false);
signal_altstack(_cpu()->thread, &sigframe.oldstack, NULL); signal_altstack(current_thread(), &sigframe.oldstack, NULL);
signal_changemask(_cpu()->thread, SIG_SETMASK, &sigframe.oldmask, NULL); signal_changemask(current_thread(), SIG_SETMASK, &sigframe.oldmask, NULL);
__assert(ARCH_CONTEXT_ISUSER(&sigframe.context)); __assert(ARCH_CONTEXT_ISUSER(&sigframe.context));
memcpy(&_cpu()->thread->extracontext, &sigframe.extracontext, sizeof(extracontext_t)); memcpy(&current_thread()->extracontext, &sigframe.extracontext, sizeof(extracontext_t));
ARCH_CONTEXT_THREADLOAD(_cpu()->thread, context); ARCH_CONTEXT_THREADLOAD(current_thread(), context);
interrupt_set(true); interrupt_set(true);
arch_context_switch(&sigframe.context); arch_context_switch(&sigframe.context);
+1 -1
View File
@@ -28,7 +28,7 @@ syscallret_t syscall_nanosleep(context_t *, timespec_t *utime, timespec_t *remai
sched_preparesleep(true); sched_preparesleep(true);
sched_targetcpu(_cpu()); sched_targetcpu(_cpu());
timer_insert(_cpu()->timer, &sleepentry, timeout, _cpu()->thread, time.s * 1000000 + time.ns / 1000, false); timer_insert(_cpu()->timer, &sleepentry, timeout, current_thread(), time.s * 1000000 + time.ns / 1000, false);
ret.errno = sched_yield() == SCHED_WAKEUP_REASON_INTERRUPTED ? EINTR : 0; ret.errno = sched_yield() == SCHED_WAKEUP_REASON_INTERRUPTED ? EINTR : 0;
+1 -1
View File
@@ -9,7 +9,7 @@
// vnode should be locked // vnode should be locked
static int dostat(vnode_t *vnode, stat_t *stat) { static int dostat(vnode_t *vnode, stat_t *stat) {
vattr_t attr; vattr_t attr;
int e = VOP_GETATTR(vnode, &attr, &_cpu()->thread->proc->cred); int e = VOP_GETATTR(vnode, &attr, &current_thread()->proc->cred);
if (e) if (e)
return e; return e;
+1 -1
View File
@@ -18,7 +18,7 @@ syscallret_t syscall_ftruncate(int fd, size_t size) {
} }
VOP_LOCK(file->vnode); VOP_LOCK(file->vnode);
ret.errno = VOP_RESIZE(file->vnode, size, &_cpu()->thread->proc->cred); ret.errno = VOP_RESIZE(file->vnode, size, &current_thread()->proc->cred);
VOP_UNLOCK(file->vnode); VOP_UNLOCK(file->vnode);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
+1 -1
View File
@@ -8,7 +8,7 @@ syscallret_t syscall_umask(context_t *, mode_t mode) {
mode &= 0777; mode &= 0777;
ret.ret = __atomic_exchange_n(&_cpu()->thread->proc->umask, mode, __ATOMIC_SEQ_CST); ret.ret = __atomic_exchange_n(&current_thread()->proc->umask, mode, __ATOMIC_SEQ_CST);
return ret; return ret;
} }
+4 -4
View File
@@ -62,7 +62,7 @@ syscallret_t syscall_utimensat(context_t *, int fd, char *upath, timespec_t uts[
} }
vattr_t attr; vattr_t attr;
ret.errno = VOP_GETATTR(node, &attr, &_cpu()->thread->proc->cred); ret.errno = VOP_GETATTR(node, &attr, &current_thread()->proc->cred);
if (ret.errno) { if (ret.errno) {
VOP_UNLOCK(node); VOP_UNLOCK(node);
goto cleanup; goto cleanup;
@@ -71,10 +71,10 @@ syscallret_t syscall_utimensat(context_t *, int fd, char *upath, timespec_t uts[
attr.atime = ts[0]; attr.atime = ts[0];
attr.mtime = ts[1]; attr.mtime = ts[1];
ret.errno = auth_filesystem_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL); ret.errno = auth_filesystem_check(&current_thread()->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
if (ret.errno) { if (ret.errno) {
if (uts == NULL) if (uts == NULL)
ret.errno = VOP_ACCESS(node, V_ACCESS_WRITE, &_cpu()->thread->proc->cred); ret.errno = VOP_ACCESS(node, V_ACCESS_WRITE, &current_thread()->proc->cred);
if (ret.errno) { if (ret.errno) {
VOP_UNLOCK(node); VOP_UNLOCK(node);
@@ -82,7 +82,7 @@ syscallret_t syscall_utimensat(context_t *, int fd, char *upath, timespec_t uts[
} }
} }
ret.errno = VOP_SETATTR(node, &attr, V_ATTR_ATIME | V_ATTR_MTIME, &_cpu()->thread->proc->cred); ret.errno = VOP_SETATTR(node, &attr, V_ATTR_ATIME | V_ATTR_MTIME, &current_thread()->proc->cred);
ret.ret = ret.errno ? -1 : 0; ret.ret = ret.errno ? -1 : 0;
VOP_UNLOCK(node); VOP_UNLOCK(node);
+1 -1
View File
@@ -19,7 +19,7 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
// TODO implement these // TODO implement these
__assert(pid == -1 || pid > 0); __assert(pid == -1 || pid > 0);
thread_t *thread = _cpu()->thread; thread_t *thread = current_thread();
proc_t *proc = thread->proc; proc_t *proc = thread->proc;
MUTEX_ACQUIRE(&proc->mutex, false); MUTEX_ACQUIRE(&proc->mutex, false);
+1 -1
View File
@@ -38,7 +38,7 @@ syscallret_t syscall_write(context_t *context, int fd, void *buffer, size_t size
vattr_t attr; vattr_t attr;
// TODO racey // TODO racey
VOP_LOCK(file->vnode); VOP_LOCK(file->vnode);
ret.errno = VOP_GETATTR(file->vnode, &attr, &_cpu()->thread->proc->cred); ret.errno = VOP_GETATTR(file->vnode, &attr, &current_thread()->proc->cred);
VOP_UNLOCK(file->vnode); VOP_UNLOCK(file->vnode);
if (ret.errno) if (ret.errno)
goto cleanup; goto cleanup;