mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
cpu: change _cpu()->thread calls to current_thread() to fix smp race
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
void arch_syscall_entry();
|
||||
static void illisr(isr_t *self, context_t *ctx) {
|
||||
if (ARCH_CONTEXT_ISUSER(ctx)) {
|
||||
signal_signalthread(_cpu()->thread, SIGILL, true);
|
||||
signal_signalthread(current_thread(), SIGILL, true);
|
||||
} else {
|
||||
_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) {
|
||||
if (ARCH_CONTEXT_ISUSER(ctx)) {
|
||||
signal_signalthread(_cpu()->thread, SIGFPE, true);
|
||||
signal_signalthread(current_thread(), SIGFPE, true);
|
||||
} else {
|
||||
_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) {
|
||||
if (ARCH_CONTEXT_ISUSER(ctx)) {
|
||||
signal_signalthread(_cpu()->thread, SIGFPE, true);
|
||||
signal_signalthread(current_thread(), SIGFPE, true);
|
||||
} else {
|
||||
_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) {
|
||||
if (ARCH_CONTEXT_ISUSER(ctx)) {
|
||||
signal_signalthread(_cpu()->thread, SIGFPE, true);
|
||||
signal_signalthread(current_thread(), SIGFPE, true);
|
||||
} else {
|
||||
_panic("x87 Floating-Point Exception", ctx);
|
||||
}
|
||||
|
||||
@@ -220,11 +220,11 @@ void arch_mmu_tlbipi(isr_t *isr, context_t *context) {
|
||||
|
||||
void arch_mmu_tlbshootdown(void *page) {
|
||||
// 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;
|
||||
|
||||
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
|
||||
int oldipl = interrupt_raiseipl(IPL_DPC);
|
||||
spinlock_acquire(&shootdownlock);
|
||||
@@ -275,7 +275,7 @@ static volatile struct limine_kernel_address_request kaddrreq = {
|
||||
#define ERROR_FETCH 16
|
||||
|
||||
static void pfisr(isr_t *self, context_t *ctx) {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
interrupt_set(true);
|
||||
int vmmerror = 0;
|
||||
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) {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
if (thread->usercopyctx) {
|
||||
memcpy(ctx, thread->usercopyctx, sizeof(context_t));
|
||||
thread->usercopyctx = NULL;
|
||||
|
||||
@@ -206,7 +206,7 @@ __attribute__((no_caller_saved_registers)) void arch_syscall_log(int syscall, ui
|
||||
char argbuff[768];
|
||||
char printbuff[1024];
|
||||
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread->proc;
|
||||
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);
|
||||
@@ -219,7 +219,7 @@ __attribute__((no_caller_saved_registers)) void arch_syscall_log_return(uint64_t
|
||||
#ifdef SYSCALL_LOGGING
|
||||
char printbuff[1024];
|
||||
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
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);
|
||||
|
||||
+10
-10
@@ -43,7 +43,7 @@ file_t *fd_allocate() {
|
||||
}
|
||||
|
||||
static int getfree(int start) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
int fd = -1;
|
||||
int 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)
|
||||
return EMFILE;
|
||||
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
__assert(newcount > proc->fdcount);
|
||||
void *newtable = realloc(proc->fd, sizeof(fd_t) * newcount);
|
||||
if (newtable == NULL)
|
||||
@@ -70,7 +70,7 @@ static int growtable(int newcount) {
|
||||
}
|
||||
|
||||
file_t *fd_get(int fd) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
|
||||
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 error = 0;
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
|
||||
if (proc->fd[fd].file)
|
||||
@@ -98,7 +98,7 @@ int fd_setflags(int fd, int flags) {
|
||||
|
||||
int fd_getflags(int fd, int *flags) {
|
||||
int error = 0;
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
|
||||
if (proc->fd[fd].file)
|
||||
@@ -119,7 +119,7 @@ int fd_new(int flags, file_t **rfile, int *rfd) {
|
||||
if (file == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
|
||||
// find first free fd
|
||||
@@ -148,7 +148,7 @@ int fd_new(int flags, file_t **rfile, int *rfd) {
|
||||
}
|
||||
|
||||
int fd_close(int fd) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
|
||||
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) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
int error = 0;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
|
||||
@@ -197,7 +197,7 @@ int fd_clone(proc_t *targproc) {
|
||||
}
|
||||
|
||||
int fd_insert(file_t *file, int *fdp) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
int err = 0;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
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) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
int err = 0;
|
||||
|
||||
if (newfd < 0 || newfd >= FDTABLE_LIMIT)
|
||||
|
||||
@@ -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) {
|
||||
if (pipenode->readers == 0) {
|
||||
if (_cpu()->thread->proc)
|
||||
signal_signalproc(_cpu()->thread->proc, SIGPIPE);
|
||||
if (current_thread()->proc)
|
||||
signal_signalproc(current_thread()->proc, SIGPIPE);
|
||||
|
||||
return EPIPE;
|
||||
}
|
||||
|
||||
+7
-7
@@ -22,10 +22,10 @@ static spinlock_t listlock;
|
||||
static vfs_t *vfslist;
|
||||
|
||||
static cred_t *getcred() {
|
||||
if (_cpu()->thread == NULL || _cpu()->thread->proc == NULL)
|
||||
if (current_thread() == NULL || current_thread()->proc == NULL)
|
||||
return NULL;
|
||||
else
|
||||
return &_cpu()->thread->proc->cred;
|
||||
return ¤t_thread()->proc->cred;
|
||||
}
|
||||
|
||||
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) {
|
||||
// do resize stuff if regular and applicable
|
||||
err = VOP_RESIZE(node, newsize, &_cpu()->thread->proc->cred);
|
||||
err = VOP_RESIZE(node, newsize, ¤t_thread()->proc->cred);
|
||||
if (err)
|
||||
goto leave;
|
||||
} 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
|
||||
vnode_t *derefstart = current;
|
||||
|
||||
if (*linkderef == '/' && _cpu()->thread && _cpu()->thread->proc) {
|
||||
MUTEX_ACQUIRE(&_cpu()->thread->proc->mutex, false);
|
||||
derefstart = _cpu()->thread->proc->root;
|
||||
if (*linkderef == '/' && current_thread() && current_thread()->proc) {
|
||||
MUTEX_ACQUIRE(¤t_thread()->proc->mutex, false);
|
||||
derefstart = current_thread()->proc->root;
|
||||
VOP_HOLD(derefstart);
|
||||
MUTEX_RELEASE(&_cpu()->thread->proc->mutex);
|
||||
MUTEX_RELEASE(¤t_thread()->proc->mutex);
|
||||
} else if (*linkderef == '/') {
|
||||
derefstart = vfsroot;
|
||||
VOP_HOLD(derefstart);
|
||||
|
||||
@@ -132,7 +132,7 @@ typedef struct proc_t {
|
||||
|
||||
#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)
|
||||
// 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
|
||||
|
||||
@@ -16,7 +16,7 @@ extern mutex_t printf_mutex;
|
||||
#endif
|
||||
|
||||
#define printf(...) { \
|
||||
if (_cpu()->thread) {\
|
||||
if (current_thread()) {\
|
||||
MUTEX_ACQUIRE(&printf_mutex, false); \
|
||||
} else { \
|
||||
while (MUTEX_TRY(&printf_mutex) == false) CPU_PAUSE(); \
|
||||
|
||||
@@ -56,12 +56,18 @@ static inline uint16_t be_to_cpu_w(uint16_t w) {
|
||||
|
||||
cpu_t *_bsp(void);
|
||||
|
||||
static inline cpu_t *_cpu() {
|
||||
static inline cpu_t *_cpu(void) {
|
||||
cpu_t *cpu;
|
||||
asm volatile ("mov %%gs:8, %%rax" : "=a"(cpu) : : "memory");
|
||||
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) {
|
||||
ptr->self = ptr;
|
||||
wrmsr(MSR_GSBASE, (uint64_t)ptr);
|
||||
|
||||
@@ -502,7 +502,7 @@ void uacpi_kernel_reset_event(uacpi_handle sem) {
|
||||
}
|
||||
|
||||
uacpi_thread_id uacpi_kernel_get_thread_id(void) {
|
||||
return _cpu()->thread;
|
||||
return current_thread();
|
||||
}
|
||||
|
||||
uacpi_handle uacpi_kernel_create_spinlock(void) {
|
||||
|
||||
@@ -324,7 +324,7 @@ static void enqueueandwait(queuepair_t *queuepair, entrypair_t *entries) {
|
||||
|
||||
*queuepair->submission.doorbell = queuepair->submission.index;
|
||||
sched_preparesleep(false);
|
||||
entries->thread = _cpu()->thread;
|
||||
entries->thread = current_thread();
|
||||
spinlock_release(&queuepair->lock);
|
||||
sched_yield();
|
||||
interrupt_set(intstatus);
|
||||
|
||||
@@ -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;
|
||||
|
||||
sched_preparesleep(false);
|
||||
blkdev->queuewaiting[idx / 3] = _cpu()->thread;
|
||||
blkdev->queuewaiting[idx / 3] = current_thread();
|
||||
|
||||
++VIO_QUEUE_DRV_IDX(&blkdev->queue);
|
||||
*blkdev->queue.notify = 0;
|
||||
|
||||
@@ -357,8 +357,8 @@ static int localsock_send(socket_t *socket, sockdesc_t *sockdesc) {
|
||||
|
||||
localsocket_t *peer = pair->client == localsocket ? pair->server : pair->client;
|
||||
if (peer == NULL) {
|
||||
if (_cpu()->thread->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0)
|
||||
signal_signalproc(_cpu()->thread->proc, SIGPIPE);
|
||||
if (current_thread()->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0)
|
||||
signal_signalproc(current_thread()->proc, SIGPIPE);
|
||||
|
||||
error = EPIPE;
|
||||
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();
|
||||
vattr_t attr = {
|
||||
.mode = _cpu()->thread->proc ? UMASK(0777) : 0644,
|
||||
.gid = _cpu()->thread->proc ? _cpu()->thread->proc->cred.gid : 0,
|
||||
.uid = _cpu()->thread->proc ? _cpu()->thread->proc->cred.uid : 0
|
||||
.mode = current_thread()->proc ? UMASK(0777) : 0644,
|
||||
.gid = current_thread()->proc ? current_thread()->proc->cred.gid : 0,
|
||||
.uid = current_thread()->proc ? current_thread()->proc->cred.uid : 0
|
||||
};
|
||||
|
||||
vnode_t *vnode;
|
||||
|
||||
@@ -838,7 +838,7 @@ typedef struct {
|
||||
} __attribute__((packed)) synoptions_t;
|
||||
|
||||
__attribute__((noreturn)) static void tcp_worker() {
|
||||
tcpworker_t *self = _cpu()->thread->kernelarg;
|
||||
tcpworker_t *self = current_thread()->kernelarg;
|
||||
ipv4pseudoheader_t ipv4;
|
||||
int tasktype;
|
||||
tcb_t *tcb = NULL;
|
||||
@@ -1254,8 +1254,8 @@ static int tcp_send(socket_t *socket, sockdesc_t *sockdesc) {
|
||||
|
||||
MUTEX_ACQUIRE(&tcb->mutex, false);
|
||||
if (tcb->reset) {
|
||||
if (_cpu()->thread->proc)
|
||||
signal_signalproc(_cpu()->thread->proc, SIGPIPE);
|
||||
if (current_thread()->proc)
|
||||
signal_signalproc(current_thread()->proc, SIGPIPE);
|
||||
error = ECONNRESET;
|
||||
goto leave;
|
||||
}
|
||||
@@ -1272,8 +1272,8 @@ static int tcp_send(socket_t *socket, sockdesc_t *sockdesc) {
|
||||
poll_leave(&polldesc);
|
||||
poll_destroydesc(&polldesc);
|
||||
|
||||
if (_cpu()->thread->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0)
|
||||
signal_signalproc(_cpu()->thread->proc, SIGPIPE);
|
||||
if (current_thread()->proc && (sockdesc->flags & SOCKET_SEND_FLAGS_NOSIGNAL) == 0)
|
||||
signal_signalproc(current_thread()->proc, SIGPIPE);
|
||||
|
||||
error = EPIPE;
|
||||
goto leave;
|
||||
|
||||
@@ -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;
|
||||
|
||||
sched_preparesleep(false);
|
||||
netdev->txwait[idx] = _cpu()->thread;
|
||||
netdev->txwait[idx] = current_thread();
|
||||
*netdev->txqueue.notify = 0;
|
||||
|
||||
spinlock_release(&netdev->txlock);
|
||||
|
||||
@@ -36,7 +36,7 @@ int poll_initdesc(polldesc_t *desc, size_t size) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
desc->thread = _cpu()->thread;
|
||||
desc->thread = current_thread();
|
||||
desc->size = size;
|
||||
SPINLOCK_INIT(desc->lock);
|
||||
SPINLOCK_INIT(desc->eventlock);
|
||||
|
||||
+4
-4
@@ -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));
|
||||
case TIOCSCTTY: {
|
||||
// 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;
|
||||
}
|
||||
case TIOCGPGRP: {
|
||||
@@ -377,7 +377,7 @@ static int open(int minor, vnode_t **vnode, int flags) {
|
||||
|
||||
if (minor == CONTROLLING_TTY_MINOR) {
|
||||
// return controlling tty
|
||||
tty_t *ctty = jobctl_getctty(_cpu()->thread->proc);
|
||||
tty_t *ctty = jobctl_getctty(current_thread()->proc);
|
||||
|
||||
if (ctty == NULL) {
|
||||
return ENXIO;
|
||||
@@ -389,7 +389,7 @@ static int open(int minor, vnode_t **vnode, int flags) {
|
||||
return ENODEV;
|
||||
} else if ((flags & V_FFLAGS_NOCTTY) == 0) {
|
||||
// set as controlling tty
|
||||
jobctl_setctty(_cpu()->thread->proc, tty, false);
|
||||
jobctl_setctty(current_thread()->proc, tty, false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -467,7 +467,7 @@ tty_t *tty_create(char *name, ttydevicewritefn_t writefn, ttyinactivefn_t inacti
|
||||
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 ? ¤t_thread()->proc->cred : NULL)) {
|
||||
freeminor(minor);
|
||||
ringbuffer_destroy(&tty->readbuffer);
|
||||
goto error;
|
||||
|
||||
@@ -34,7 +34,7 @@ static thread_t *get(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
|
||||
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) {
|
||||
if (_cpu()->thread == NULL) {
|
||||
if (current_thread() == NULL) {
|
||||
while (semaphore_test(sem) == false) CPU_PAUSE();
|
||||
return 0;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ int semaphore_wait(semaphore_t *sem, bool interruptible) {
|
||||
spinlock_acquire(&sem->lock);
|
||||
|
||||
if (--sem->i < 0) {
|
||||
insert(sem, _cpu()->thread);
|
||||
insert(sem, current_thread());
|
||||
sched_preparesleep(interruptible);
|
||||
spinlock_release(&sem->lock);
|
||||
ret = sched_yield();
|
||||
|
||||
@@ -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 context with CTX_RET set to EFAULT
|
||||
_cpu()->thread->usercopyctx = ctx;
|
||||
current_thread()->usercopyctx = ctx;
|
||||
|
||||
memcpy(desc->dst, desc->src, desc->size);
|
||||
|
||||
// no errors!
|
||||
CTX_RET(ctx) = 0;
|
||||
_cpu()->thread->usercopyctx = NULL;
|
||||
current_thread()->usercopyctx = NULL;
|
||||
}
|
||||
|
||||
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 context with CTX_RET set to EFAULT
|
||||
_cpu()->thread->usercopyctx = ctx;
|
||||
current_thread()->usercopyctx = ctx;
|
||||
|
||||
*desc->size = strlen(desc->str);
|
||||
|
||||
// no errors!
|
||||
CTX_RET(ctx) = 0;
|
||||
_cpu()->thread->usercopyctx = NULL;
|
||||
current_thread()->usercopyctx = NULL;
|
||||
}
|
||||
|
||||
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 context with CTX_RET set to EFAULT
|
||||
_cpu()->thread->usercopyctx = ctx;
|
||||
current_thread()->usercopyctx = ctx;
|
||||
|
||||
__atomic_load(desc->address, desc->value, __ATOMIC_SEQ_CST);
|
||||
|
||||
// no errors!
|
||||
CTX_RET(ctx) = 0;
|
||||
_cpu()->thread->usercopyctx = NULL;
|
||||
current_thread()->usercopyctx = NULL;
|
||||
}
|
||||
|
||||
int usercopy_touser(void *user, void *kernel, size_t size) {
|
||||
|
||||
+10
-10
@@ -223,7 +223,7 @@ static void destroyrange(vmmrange_t *range, uintmax_t _offset, size_t size, int
|
||||
if (physical == NULL)
|
||||
continue;
|
||||
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread ? thread->proc : 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) {
|
||||
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, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(range->vnode);
|
||||
return error == 0;
|
||||
}
|
||||
@@ -560,7 +560,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread ? thread->proc : NULL;
|
||||
cred_t *cred = proc ? &proc->cred : NULL;
|
||||
|
||||
@@ -584,7 +584,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
if (error == ENOMEM)
|
||||
printf("vmm: out of memory to handle getpage (sending SIGBUS)\n");
|
||||
// address is past the last page of the file
|
||||
signal_signalthread(_cpu()->thread, SIGBUS, true);
|
||||
signal_signalthread(current_thread(), SIGBUS, true);
|
||||
status = true;
|
||||
} else if (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) {
|
||||
printf("vmm: out of memory to map file into address space (sending SIGBUS)\n");
|
||||
pmm_release(pmm_getpageaddress(res));
|
||||
signal_signalthread(_cpu()->thread, SIGBUS, true);
|
||||
signal_signalthread(current_thread(), SIGBUS, 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);
|
||||
if (!status) {
|
||||
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;
|
||||
} else {
|
||||
pmm_hold(zeropage);
|
||||
@@ -630,7 +630,7 @@ bool vmm_pagefault(void *addr, bool user, int actions) {
|
||||
void *newphys = pmm_allocpage(PMM_SECTION_DEFAULT);
|
||||
if (newphys == NULL) {
|
||||
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;
|
||||
} else {
|
||||
memcpy(MAKE_HHDM(newphys), MAKE_HHDM(oldphys), PAGE_SIZE);
|
||||
@@ -820,7 +820,7 @@ vmmcontext_t *vmm_newcontext() {
|
||||
}
|
||||
|
||||
void vmm_destroycontext(vmmcontext_t *context) {
|
||||
vmmcontext_t *oldctx = _cpu()->thread->vmmctx;
|
||||
vmmcontext_t *oldctx = current_thread()->vmmctx;
|
||||
vmm_switchcontext(context);
|
||||
vmm_unmap(context->space.start, context->space.end - context->space.start, 0);
|
||||
vmm_switchcontext(oldctx);
|
||||
@@ -875,8 +875,8 @@ vmmcontext_t *vmm_fork(vmmcontext_t *oldcontext) {
|
||||
}
|
||||
|
||||
void vmm_switchcontext(vmmcontext_t *ctx) {
|
||||
if (_cpu()->thread)
|
||||
_cpu()->thread->vmmctx = ctx;
|
||||
if (current_thread())
|
||||
current_thread()->vmmctx = ctx;
|
||||
_cpu()->vmmctx = ctx;
|
||||
arch_mmu_switch(ctx->pagetable);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
// 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 error = 0;
|
||||
bool intstatus = interrupt_set(false);
|
||||
proc_t *leader;
|
||||
proc_t *tmpproc = _cpu()->thread->proc;
|
||||
proc_t *tmpproc = current_thread()->proc;
|
||||
pid_t senderpgid = sender ? jobctl_getpgid(sender) : 0;
|
||||
|
||||
if (proc == NULL) {
|
||||
|
||||
+30
-30
@@ -231,7 +231,7 @@ static thread_t *runqueuenext(int minprio) {
|
||||
|
||||
static __attribute__((noreturn)) void switchthread(thread_t *thread) {
|
||||
interrupt_set(false);
|
||||
thread_t* current = _cpu()->thread;
|
||||
thread_t* current = current_thread();
|
||||
|
||||
_cpu()->thread = thread;
|
||||
|
||||
@@ -295,8 +295,8 @@ __attribute__((noreturn)) void sched_stopcurrentthread() {
|
||||
interrupt_set(false);
|
||||
|
||||
spinlock_acquire(&runqueuelock);
|
||||
if (_cpu()->thread)
|
||||
_cpu()->thread->flags &= ~SCHED_THREAD_FLAGS_RUNNING;
|
||||
if (current_thread())
|
||||
current_thread()->flags &= ~SCHED_THREAD_FLAGS_RUNNING;
|
||||
|
||||
thread_t *next = runqueuenext(0x0fffffff);
|
||||
if (next == NULL)
|
||||
@@ -309,7 +309,7 @@ __attribute__((noreturn)) void sched_stopcurrentthread() {
|
||||
|
||||
// called when all threads in a process have exited
|
||||
void sched_procexit() {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
__assert(proc != sched_initproc);
|
||||
|
||||
// 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 *) {
|
||||
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
|
||||
// as well as not being preempted at all
|
||||
interrupt_set(false);
|
||||
_cpu()->thread = NULL;
|
||||
|
||||
interrupt_set(false);
|
||||
spinlock_acquire(&runqueuelock);
|
||||
thread->flags |= SCHED_THREAD_FLAGS_DEAD;
|
||||
spinlock_release(&runqueuelock);
|
||||
@@ -396,7 +396,7 @@ static void threadexit_internal(context_t *, void *) {
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void sched_threadexit() {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread->proc;
|
||||
|
||||
vmmcontext_t *oldctx = thread->vmmctx;
|
||||
@@ -430,7 +430,7 @@ typedef struct {
|
||||
// SHOULD NOT BE CALLED WITH THE SCHEDULER STACK
|
||||
static void userspacecheck(void *_args) {
|
||||
checkargs_t *args = _args;
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
|
||||
if (thread->shouldexit) {
|
||||
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
|
||||
__attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *context, bool syscall, uint64_t syscallerrno, uint64_t syscallret) {
|
||||
__assert(_cpu());
|
||||
if (_cpu()->thread == NULL || ARCH_CONTEXT_ISUSER(context) == false)
|
||||
if (current_thread() == NULL || ARCH_CONTEXT_ISUSER(context) == false)
|
||||
return;
|
||||
|
||||
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
|
||||
// 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)) {
|
||||
arch_context_saveandcall(checktrampoline, _cpu()->thread->kernelstacktop, &args);
|
||||
arch_context_saveandcall(checktrampoline, current_thread()->kernelstacktop, &args);
|
||||
} else {
|
||||
userspacecheck(&args);
|
||||
}
|
||||
@@ -476,7 +476,7 @@ __attribute__((no_caller_saved_registers)) void sched_userspacecheck(context_t *
|
||||
}
|
||||
|
||||
void sched_stopotherthreads() {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread->proc;
|
||||
|
||||
bool intstatus = interrupt_set(false);
|
||||
@@ -508,7 +508,7 @@ void sched_stopotherthreads() {
|
||||
}
|
||||
|
||||
void sched_terminateprogram(int status) {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread->proc;
|
||||
if (spinlock_try(&proc->exiting) == false)
|
||||
sched_threadexit();
|
||||
@@ -521,7 +521,7 @@ void sched_terminateprogram(int status) {
|
||||
}
|
||||
|
||||
static void yield(context_t *context, void *) {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
|
||||
spinlock_acquire(&runqueuelock);
|
||||
|
||||
@@ -575,18 +575,18 @@ static void yield(context_t *context, void *) {
|
||||
|
||||
int sched_yield() {
|
||||
__assert(_cpu()->ipl == IPL_NORMAL);
|
||||
bool sleeping = _cpu()->thread->flags & SCHED_THREAD_FLAGS_SLEEP;
|
||||
bool old = sleeping ? _cpu()->thread->sleepintstatus : interrupt_set(false);
|
||||
bool sleeping = current_thread()->flags & SCHED_THREAD_FLAGS_SLEEP;
|
||||
bool old = sleeping ? current_thread()->sleepintstatus : interrupt_set(false);
|
||||
arch_context_saveandcall(yield, _cpu()->schedulerstack, NULL);
|
||||
interrupt_set(old);
|
||||
return sleeping ? _cpu()->thread->wakeupreason : 0;
|
||||
return sleeping ? current_thread()->wakeupreason : 0;
|
||||
}
|
||||
|
||||
void sched_preparesleep(bool interruptible) {
|
||||
_cpu()->thread->sleepintstatus = interrupt_set(false);
|
||||
spinlock_acquire(&_cpu()->thread->sleeplock);
|
||||
current_thread()->sleepintstatus = interrupt_set(false);
|
||||
spinlock_acquire(¤t_thread()->sleeplock);
|
||||
// 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) {
|
||||
@@ -610,7 +610,7 @@ bool sched_wakeup(thread_t *thread, int reason) {
|
||||
}
|
||||
|
||||
static vnode_t *getnodeslock(vnode_t **addr) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
bool intstatus = interrupt_set(false);
|
||||
spinlock_acquire(&proc->nodeslock);
|
||||
vnode_t *vnode = *addr;
|
||||
@@ -621,17 +621,17 @@ static vnode_t *getnodeslock(vnode_t **addr) {
|
||||
}
|
||||
|
||||
vnode_t *sched_getcwd() {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
return getnodeslock(&proc->cwd);
|
||||
}
|
||||
|
||||
vnode_t *sched_getroot() {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
return getnodeslock(&proc->root);
|
||||
}
|
||||
|
||||
static void setnodeslock(vnode_t **addr, vnode_t *new) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
vnode_t *oldnode;
|
||||
VOP_HOLD(new);
|
||||
bool intstatus = interrupt_set(false);
|
||||
@@ -644,11 +644,11 @@ static void setnodeslock(vnode_t **addr, 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);
|
||||
}
|
||||
void sched_setroot(vnode_t *new) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
setnodeslock(&proc->root, new);
|
||||
}
|
||||
|
||||
@@ -657,7 +657,7 @@ static void dopreempt() {
|
||||
// interrupts are disabled, the thread context is already saved
|
||||
spinlock_acquire(&runqueuelock);
|
||||
|
||||
thread_t *current = _cpu()->thread;
|
||||
thread_t *current = current_thread();
|
||||
thread_t *next = runqueuenext(current->priority);
|
||||
|
||||
current->flags &= ~SCHED_THREAD_FLAGS_PREEMPTED;
|
||||
@@ -673,7 +673,7 @@ static void dopreempt() {
|
||||
}
|
||||
|
||||
static void timerhook(context_t *context, dpcarg_t arg) {
|
||||
thread_t* current = _cpu()->thread;
|
||||
thread_t* current = current_thread();
|
||||
interrupt_set(false);
|
||||
|
||||
// no need to preempt it again
|
||||
@@ -699,7 +699,7 @@ static void cpuidlethread() {
|
||||
|
||||
void sched_targetcpu(cpu_t *cpu) {
|
||||
bool intstatus = interrupt_set(false);
|
||||
_cpu()->thread->cputarget = cpu;
|
||||
current_thread()->cputarget = cpu;
|
||||
interrupt_set(intstatus);
|
||||
}
|
||||
|
||||
@@ -712,7 +712,7 @@ void sched_sleepus(size_t us) {
|
||||
timerentry_t sleepentry = {0};
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -747,7 +747,7 @@ void sched_init() {
|
||||
_cpu()->idlethread = sched_newthread(cpuidlethread, PAGE_SIZE * 4, 3, NULL, NULL);
|
||||
__assert(_cpu()->idlethread);
|
||||
_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);
|
||||
// XXX move this resume to a more appropriate place
|
||||
|
||||
@@ -145,7 +145,7 @@ void signal_returnmask(struct thread_t *thread, sigset_t *sigset) {
|
||||
}
|
||||
|
||||
void signal_suspend(sigset_t *sigset) {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
THREAD_ENTER(thread);
|
||||
|
||||
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) {
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
PROCESS_ENTER(thread->proc);
|
||||
THREAD_ENTER(thread);
|
||||
// if timeoutus is 0, this wait is just a poll
|
||||
|
||||
@@ -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);
|
||||
|
||||
ret.errno = socket->ops->bind(socket, &sockaddr, &_cpu()->thread->proc->cred);
|
||||
ret.errno = socket->ops->bind(socket, &sockaddr, ¤t_thread()->proc->cred);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
cleanup:
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
// node expected to be locked
|
||||
static int dochmod(vnode_t *node, mode_t mode) {
|
||||
vattr_t attr;
|
||||
cred_t *cred = &_cpu()->thread->proc->cred;
|
||||
cred_t *cred = ¤t_thread()->proc->cred;
|
||||
|
||||
int e = auth_filesystem_check(cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
|
||||
if (e)
|
||||
|
||||
@@ -10,7 +10,7 @@ syscallret_t syscall_chroot(context_t *, char *upath) {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
ret.errno = auth_system_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_SYSTEM_CHROOT);
|
||||
ret.errno = auth_system_check(¤t_thread()->proc->cred, AUTH_ACTIONS_SYSTEM_CHROOT);
|
||||
if (ret.errno)
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
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), ¤t_thread()->proc->cred) : EOPNOTSUPP;
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
cleanup:
|
||||
|
||||
@@ -177,7 +177,7 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
||||
if (ret.errno)
|
||||
goto error;
|
||||
|
||||
ret.errno = VOP_ACCESS(node, V_ACCESS_EXECUTE, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_ACCESS(node, V_ACCESS_EXECUTE, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(node);
|
||||
if (ret.errno) {
|
||||
goto error;
|
||||
@@ -277,13 +277,13 @@ static syscallret_t execve(context_t *context, char *upath, char *uargv[], char
|
||||
|
||||
// close O_CLOEXEC fds
|
||||
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
for (int fd = 0; fd < proc->fdcount; ++fd) {
|
||||
if (proc->fd[fd].flags & O_CLOEXEC)
|
||||
fd_close(fd);
|
||||
}
|
||||
|
||||
memset(&_cpu()->thread->signals.stack, 0, sizeof(stack_t));
|
||||
memset(¤t_thread()->signals.stack, 0, sizeof(stack_t));
|
||||
|
||||
// execve keeps information about ignored signals
|
||||
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)
|
||||
sgid = vattr.gid;
|
||||
|
||||
cred_doexec(&_cpu()->thread->proc->cred, suid, sgid);
|
||||
cred_doexec(¤t_thread()->proc->cred, suid, sgid);
|
||||
|
||||
error:
|
||||
free(path);
|
||||
|
||||
@@ -38,7 +38,7 @@ syscallret_t syscall_faccessat(context_t *, int dirfd, char *upath, int mode, in
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
ret.errno = VOP_ACCESS(node, mode, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_ACCESS(node, mode, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(node);
|
||||
ret.ret = 0;
|
||||
|
||||
|
||||
@@ -50,14 +50,14 @@ syscallret_t syscall_fchownat(context_t *, int fd, char *upath, uid_t owner, gid
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret.errno = auth_filesystem_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
|
||||
ret.errno = auth_filesystem_check(¤t_thread()->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
|
||||
if (ret.errno) {
|
||||
VOP_UNLOCK(node);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
vattr_t attr;
|
||||
ret.errno = VOP_GETATTR(node, &attr, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_GETATTR(node, &attr, ¤t_thread()->proc->cred);
|
||||
if (ret.errno) {
|
||||
VOP_UNLOCK(node);
|
||||
goto cleanup;
|
||||
@@ -67,7 +67,7 @@ syscallret_t syscall_fchownat(context_t *, int fd, char *upath, uid_t owner, gid
|
||||
attr.gid = group;
|
||||
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), ¤t_thread()->proc->cred);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
VOP_UNLOCK(node);
|
||||
|
||||
@@ -11,7 +11,7 @@ syscallret_t syscall_fork(context_t *ctx) {
|
||||
.errno = 0
|
||||
};
|
||||
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
proc_t *proc = current_thread()->proc;
|
||||
proc_t *nproc = sched_newproc();
|
||||
if (nproc == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
@@ -24,7 +24,7 @@ syscallret_t syscall_fork(context_t *ctx) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
nthread->vmmctx = vmm_fork(_cpu()->thread->vmmctx);
|
||||
nthread->vmmctx = vmm_fork(current_thread()->vmmctx);
|
||||
|
||||
if (nthread->vmmctx == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
@@ -43,8 +43,8 @@ syscallret_t syscall_fork(context_t *ctx) {
|
||||
|
||||
MUTEX_RELEASE(&proc->mutex);
|
||||
|
||||
nproc->umask = _cpu()->thread->proc->umask;
|
||||
nproc->cred = _cpu()->thread->proc->cred;
|
||||
nproc->umask = current_thread()->proc->umask;
|
||||
nproc->cred = current_thread()->proc->cred;
|
||||
nproc->root = sched_getroot();
|
||||
nproc->cwd = sched_getcwd();
|
||||
nproc->threadlist = nthread;
|
||||
@@ -56,9 +56,9 @@ syscallret_t syscall_fork(context_t *ctx) {
|
||||
CTX_ERRNO(&nthread->context) = 0;
|
||||
jobctl_addproc(proc, nproc);
|
||||
|
||||
memcpy(&nthread->signals.mask, &_cpu()->thread->signals.mask, sizeof(sigset_t));
|
||||
memcpy(&nthread->signals.pending, &_cpu()->thread->signals.pending, sizeof(sigset_t));
|
||||
memcpy(&nthread->signals.stack, &_cpu()->thread->signals.stack, sizeof(stack_t));
|
||||
memcpy(&nthread->signals.mask, ¤t_thread()->signals.mask, sizeof(sigset_t));
|
||||
memcpy(&nthread->signals.pending, ¤t_thread()->signals.pending, sizeof(sigset_t));
|
||||
memcpy(&nthread->signals.stack, ¤t_thread()->signals.stack, sizeof(stack_t));
|
||||
memcpy(&nproc->signals.pending, &proc->signals.pending, sizeof(sigset_t));
|
||||
memcpy(&nproc->signals.actions, &proc->signals.actions[0], sizeof(sigaction_t) * NSIG);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
syscallret_t syscall_getpid(context_t *ctx) {
|
||||
syscallret_t ret = {
|
||||
.ret = _cpu()->thread->proc->pid,
|
||||
.ret = current_thread()->proc->pid,
|
||||
.errno = 0
|
||||
};
|
||||
return ret;
|
||||
@@ -13,7 +13,7 @@ syscallret_t syscall_getpid(context_t *ctx) {
|
||||
|
||||
syscallret_t syscall_getppid(context_t *ctx) {
|
||||
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
|
||||
};
|
||||
return ret;
|
||||
@@ -25,7 +25,7 @@ syscallret_t syscall_getpgid(context_t *ctx, pid_t pid) {
|
||||
};
|
||||
|
||||
__assert(pid == 0);
|
||||
ret.ret = jobctl_getpgid(_cpu()->thread->proc);
|
||||
ret.ret = jobctl_getpgid(current_thread()->proc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,6 @@ syscallret_t syscall_getsid(context_t *ctx, pid_t pid) {
|
||||
};
|
||||
|
||||
__assert(pid == 0);
|
||||
ret.ret = jobctl_getsid(_cpu()->thread->proc);
|
||||
ret.ret = jobctl_getsid(current_thread()->proc);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ syscallret_t syscall_getresgid(context_t *, gid_t *gidp, gid_t *egidp, gid_t *sg
|
||||
};
|
||||
|
||||
int gid, egid, sgid;
|
||||
cred_getgids(&_cpu()->thread->proc->cred, &gid, &egid, &sgid);
|
||||
cred_getgids(¤t_thread()->proc->cred, &gid, &egid, &sgid);
|
||||
|
||||
ret.errno = usercopy_touser(gidp, &gid, sizeof(gid));
|
||||
if (ret.errno)
|
||||
|
||||
@@ -8,7 +8,7 @@ syscallret_t syscall_getresuid(context_t *, uid_t *uidp, uid_t *euidp, uid_t *su
|
||||
};
|
||||
|
||||
int uid, euid, suid;
|
||||
cred_getuids(&_cpu()->thread->proc->cred, &uid, &euid, &suid);
|
||||
cred_getuids(¤t_thread()->proc->cred, &uid, &euid, &suid);
|
||||
|
||||
ret.errno = usercopy_touser(uidp, &uid, sizeof(uid));
|
||||
if (ret.errno)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
syscallret_t syscall_gettid(context_t *) {
|
||||
syscallret_t ret = {
|
||||
.errno = 0,
|
||||
.ret = _cpu()->thread->tid
|
||||
.ret = current_thread()->tid
|
||||
};
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -33,7 +33,7 @@ syscallret_t syscall_hostname(context_t *, char *unew, size_t newsize, char *uol
|
||||
char old[HOST_NAME_MAX + 1];
|
||||
|
||||
if (unew) {
|
||||
ret.errno = auth_system_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_SYSTEM_SETHOSTNAME);
|
||||
ret.errno = auth_system_check(¤t_thread()->proc->cred, AUTH_ACTIONS_SYSTEM_SETHOSTNAME);
|
||||
if (ret.errno)
|
||||
return ret;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ syscallret_t syscall_ioctl(context_t *, int fd, unsigned long request, void *arg
|
||||
|
||||
int r = 0;
|
||||
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, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(file->vnode);
|
||||
ret.ret = ret.errno ? -1 : r;
|
||||
|
||||
|
||||
@@ -31,17 +31,17 @@ syscallret_t syscall_kill(context_t *context, int pid, int signal) {
|
||||
goto leave;
|
||||
|
||||
if (pid >= 1) {
|
||||
if (signal != SIGCONT || jobctl_getpgid(target) != jobctl_getpgid(_cpu()->thread->proc)) {
|
||||
ret.errno = auth_process_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_PROCESS_SIGNAL, target);
|
||||
if (signal != SIGCONT || jobctl_getpgid(target) != jobctl_getpgid(current_thread()->proc)) {
|
||||
ret.errno = auth_process_check(¤t_thread()->proc->cred, AUTH_ACTIONS_PROCESS_SIGNAL, target);
|
||||
if (ret.errno)
|
||||
goto leave;
|
||||
}
|
||||
|
||||
signal_signalproc(target, signal);
|
||||
} else if (pid == -1) {
|
||||
ret.errno = sched_signalall(signal, _cpu()->thread->proc);
|
||||
ret.errno = sched_signalall(signal, current_thread()->proc);
|
||||
} else {
|
||||
ret.errno = jobctl_signal(target, signal, _cpu()->thread->proc);
|
||||
ret.errno = jobctl_signal(target, signal, current_thread()->proc);
|
||||
}
|
||||
|
||||
leave:
|
||||
|
||||
@@ -14,7 +14,7 @@ syscallret_t syscall_killthread(context_t *context, int pid, int tid, int signal
|
||||
return ret;
|
||||
}
|
||||
|
||||
proc_t *sender = _cpu()->thread->proc;
|
||||
proc_t *sender = current_thread()->proc;
|
||||
proc_t *target = sched_getprocfrompid(pid);
|
||||
if (target == NULL) {
|
||||
ret.errno = ESRCH;
|
||||
|
||||
@@ -50,8 +50,8 @@ syscallret_t syscall_linkat(context_t *, int olddirfd, char *uoldpath, int newdi
|
||||
goto cleanup;
|
||||
|
||||
vattr_t attr = {
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid,
|
||||
.gid = current_thread()->proc->cred.gid,
|
||||
.uid = current_thread()->proc->cred.uid,
|
||||
.mode = UMASK(0777)
|
||||
};
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, char *upath, mode_t mode) {
|
||||
|
||||
vattr_t attr = {
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.egid,
|
||||
.uid = _cpu()->thread->proc->cred.euid
|
||||
.gid = current_thread()->proc->cred.egid,
|
||||
.uid = current_thread()->proc->cred.euid
|
||||
};
|
||||
|
||||
ret.errno = vfs_create(dirnode, path, &attr, V_TYPE_DIR, NULL);
|
||||
|
||||
@@ -38,8 +38,8 @@ syscallret_t syscall_mknodat(context_t *, int dirfd, char *upath, mode_t mode, d
|
||||
|
||||
vattr_t attr = {
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.egid,
|
||||
.uid = _cpu()->thread->proc->cred.euid,
|
||||
.gid = current_thread()->proc->cred.egid,
|
||||
.uid = current_thread()->proc->cred.euid,
|
||||
.rdevmajor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MAJORDEV(dev) : 0,
|
||||
.rdevminor = (type == V_TYPE_CHDEV || type == V_TYPE_BLKDEV) ? MINORDEV(dev) : 0,
|
||||
};
|
||||
|
||||
@@ -15,15 +15,15 @@ syscallret_t syscall_newthread(context_t *, void *entry, void *stack) {
|
||||
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) {
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
thread->vmmctx = _cpu()->thread->vmmctx;
|
||||
thread->vmmctx = current_thread()->vmmctx;
|
||||
|
||||
bool intstatus = interrupt_set(false);
|
||||
spinlock_acquire(&proc->threadlistlock);
|
||||
|
||||
@@ -55,8 +55,8 @@ syscallret_t syscall_openat(context_t *context, int dirfd, char *path, int flags
|
||||
// create file
|
||||
vattr_t attr = {
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.egid,
|
||||
.uid = _cpu()->thread->proc->cred.euid
|
||||
.gid = current_thread()->proc->cred.egid,
|
||||
.uid = current_thread()->proc->cred.euid
|
||||
};
|
||||
|
||||
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;
|
||||
ret.errno = VOP_GETATTR(vnode, &attr, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_GETATTR(vnode, &attr, ¤t_thread()->proc->cred);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
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, ¤t_thread()->proc->cred);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ static void open(file_t *file, vnode_t *node, int flags) {
|
||||
file->offset = 0;
|
||||
file->mode = 0777;
|
||||
VOP_LOCK(node);
|
||||
VOP_OPEN(&node, fileflagstovnodeflags(flags) | V_FFLAGS_NONBLOCKING, &_cpu()->thread->proc->cred);
|
||||
VOP_OPEN(&node, fileflagstovnodeflags(flags) | V_FFLAGS_NONBLOCKING, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(node);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,8 +124,8 @@ syscallret_t syscall_ppoll(context_t *context, pollfd_t *fds, size_t nfds, times
|
||||
if (ret.errno)
|
||||
return ret;
|
||||
|
||||
signal_changemask(_cpu()->thread, SIG_SETMASK, &sigset, &savedset);
|
||||
signal_returnmask(_cpu()->thread, &savedset);
|
||||
signal_changemask(current_thread(), SIG_SETMASK, &sigset, &savedset);
|
||||
signal_returnmask(current_thread(), &savedset);
|
||||
}
|
||||
|
||||
syscallret_t ret = syscall_poll(context, fds, nfds, utimeout ? (timeout.s * 1000 + timeout.ns / 1000000) : -1);
|
||||
|
||||
@@ -38,7 +38,7 @@ syscallret_t syscall_readlinkat(context_t *, int dirfd, char *upath, char *ubuff
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
ret.errno = VOP_READLINK(node, &buffer, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_READLINK(node, &buffer, ¤t_thread()->proc->cred);
|
||||
// locked by vfs_lookup
|
||||
VOP_UNLOCK(node);
|
||||
if (ret.errno)
|
||||
|
||||
@@ -44,7 +44,7 @@ syscallret_t syscall_seek(context_t *context, int fd, off_t offset, int whence)
|
||||
} else {
|
||||
vattr_t attr;
|
||||
VOP_LOCK(file->vnode);
|
||||
ret.errno = VOP_GETATTR(file->vnode, &attr, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_GETATTR(file->vnode, &attr, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(file->vnode);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
@@ -15,11 +15,11 @@ typedef struct {
|
||||
static itimer_t *selectitimer(int which) {
|
||||
itimer_t *itimer = NULL;
|
||||
if (which == ITIMER_REAL)
|
||||
itimer = &_cpu()->thread->proc->timer.realtime;
|
||||
itimer = ¤t_thread()->proc->timer.realtime;
|
||||
else if (which == ITIMER_VIRTUAL)
|
||||
itimer = &_cpu()->thread->proc->timer.virtualtime;
|
||||
itimer = ¤t_thread()->proc->timer.virtualtime;
|
||||
else if (which == ITIMER_PROF)
|
||||
itimer = &_cpu()->thread->proc->timer.profiling;
|
||||
itimer = ¤t_thread()->proc->timer.profiling;
|
||||
|
||||
return itimer;
|
||||
}
|
||||
@@ -36,14 +36,14 @@ syscallret_t syscall_getitimer(context_t *context, int which, itimerval_t *value
|
||||
return ret;
|
||||
}
|
||||
|
||||
MUTEX_ACQUIRE(&_cpu()->thread->proc->timer.mutex, false);
|
||||
MUTEX_ACQUIRE(¤t_thread()->proc->timer.mutex, false);
|
||||
|
||||
uintmax_t oldremaining, oldrepeat;
|
||||
itimer_pause(itimer, &oldremaining, &oldrepeat);
|
||||
if (oldremaining)
|
||||
itimer_resume(itimer);
|
||||
|
||||
MUTEX_RELEASE(&_cpu()->thread->proc->timer.mutex);
|
||||
MUTEX_RELEASE(¤t_thread()->proc->timer.mutex);
|
||||
|
||||
itimerval_t tmp;
|
||||
|
||||
@@ -76,7 +76,7 @@ syscallret_t syscall_setitimer(context_t *context, int which, itimerval_t *unew,
|
||||
return ret;
|
||||
}
|
||||
|
||||
MUTEX_ACQUIRE(&_cpu()->thread->proc->timer.mutex, false);
|
||||
MUTEX_ACQUIRE(¤t_thread()->proc->timer.mutex, false);
|
||||
uintmax_t 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)
|
||||
itimer_resume(itimer);
|
||||
|
||||
MUTEX_RELEASE(&_cpu()->thread->proc->timer.mutex);
|
||||
MUTEX_RELEASE(¤t_thread()->proc->timer.mutex);
|
||||
|
||||
ret.errno = 0;
|
||||
if (uold) {
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
syscallret_t syscall_setsid(context_t *) {
|
||||
syscallret_t ret;
|
||||
|
||||
ret.errno = jobctl_newsession(_cpu()->thread->proc);
|
||||
ret.ret = ret.errno ? -1 : _cpu()->thread->proc->pid;
|
||||
ret.errno = jobctl_newsession(current_thread()->proc);
|
||||
ret.ret = ret.errno ? -1 : current_thread()->proc->pid;
|
||||
return ret;
|
||||
}
|
||||
|
||||
syscallret_t syscall_setpgid(context_t *, pid_t pid, pid_t pgid) {
|
||||
syscallret_t ret;
|
||||
|
||||
proc_t *currentproc = _cpu()->thread->proc;
|
||||
proc_t *currentproc = current_thread()->proc;
|
||||
|
||||
if (pgid < 0) {
|
||||
ret.errno = EINVAL;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
syscallret_t syscall_setresgid(context_t *, gid_t gid, gid_t egid, gid_t sgid) {
|
||||
syscallret_t ret;
|
||||
|
||||
ret.errno = cred_setgids(&_cpu()->thread->proc->cred, gid, egid, sgid);
|
||||
ret.errno = cred_setgids(¤t_thread()->proc->cred, gid, egid, sgid);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
syscallret_t syscall_setresuid(context_t *, uid_t uid, uid_t euid, uid_t suid) {
|
||||
syscallret_t ret;
|
||||
|
||||
ret.errno = cred_setuids(&_cpu()->thread->proc->cred, uid, euid, suid);
|
||||
ret.errno = cred_setuids(¤t_thread()->proc->cred, uid, euid, suid);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
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 ret;
|
||||
|
||||
ret.errno = cred_setuid(&_cpu()->thread->proc->cred, uid);
|
||||
ret.errno = cred_setuid(¤t_thread()->proc->cred, uid);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
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 ret;
|
||||
|
||||
ret.errno = cred_seteuid(&_cpu()->thread->proc->cred, euid);
|
||||
ret.errno = cred_seteuid(¤t_thread()->proc->cred, euid);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
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 ret;
|
||||
|
||||
ret.errno = cred_setgid(&_cpu()->thread->proc->cred, gid);
|
||||
ret.errno = cred_setgid(¤t_thread()->proc->cred, gid);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
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 ret;
|
||||
|
||||
ret.errno = cred_setegid(&_cpu()->thread->proc->cred, egid);
|
||||
ret.errno = cred_setegid(¤t_thread()->proc->cred, egid);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -67,7 +67,7 @@ syscallret_t syscall_setsockopt(context_t *, int fd, int level, int optname, voi
|
||||
if (val == NULL)
|
||||
ret.errno = EFAULT;
|
||||
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, ¤t_thread()->proc->cred) : ENOPROTOOPT;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -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))) {
|
||||
ret.errno = EFAULT;
|
||||
|
||||
@@ -12,7 +12,7 @@ syscallret_t syscall_sigaltstack(context_t *, stack_t *new, stack_t *old) {
|
||||
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))) {
|
||||
ret.errno = EFAULT;
|
||||
|
||||
@@ -6,7 +6,7 @@ syscallret_t syscall_sigpending(context_t *, sigset_t *uset) {
|
||||
syscallret_t ret;
|
||||
|
||||
sigset_t set;
|
||||
signal_pending(_cpu()->thread, &set);
|
||||
signal_pending(current_thread(), &set);
|
||||
|
||||
ret.errno = usercopy_touser(uset, &set, sizeof(sigset_t));
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
@@ -23,7 +23,7 @@ syscallret_t syscall_sigprocmask(context_t *, int how, sigset_t *set, sigset_t *
|
||||
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))) {
|
||||
ret.errno = EFAULT;
|
||||
|
||||
@@ -13,12 +13,12 @@ __attribute__((noreturn)) void syscall_sigreturn(context_t *context) {
|
||||
}
|
||||
|
||||
interrupt_set(false);
|
||||
signal_altstack(_cpu()->thread, &sigframe.oldstack, NULL);
|
||||
signal_changemask(_cpu()->thread, SIG_SETMASK, &sigframe.oldmask, NULL);
|
||||
signal_altstack(current_thread(), &sigframe.oldstack, NULL);
|
||||
signal_changemask(current_thread(), SIG_SETMASK, &sigframe.oldmask, NULL);
|
||||
|
||||
__assert(ARCH_CONTEXT_ISUSER(&sigframe.context));
|
||||
memcpy(&_cpu()->thread->extracontext, &sigframe.extracontext, sizeof(extracontext_t));
|
||||
ARCH_CONTEXT_THREADLOAD(_cpu()->thread, context);
|
||||
memcpy(¤t_thread()->extracontext, &sigframe.extracontext, sizeof(extracontext_t));
|
||||
ARCH_CONTEXT_THREADLOAD(current_thread(), context);
|
||||
|
||||
interrupt_set(true);
|
||||
arch_context_switch(&sigframe.context);
|
||||
|
||||
@@ -28,7 +28,7 @@ syscallret_t syscall_nanosleep(context_t *, timespec_t *utime, timespec_t *remai
|
||||
sched_preparesleep(true);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// vnode should be locked
|
||||
static int dostat(vnode_t *vnode, stat_t *stat) {
|
||||
vattr_t attr;
|
||||
int e = VOP_GETATTR(vnode, &attr, &_cpu()->thread->proc->cred);
|
||||
int e = VOP_GETATTR(vnode, &attr, ¤t_thread()->proc->cred);
|
||||
if (e)
|
||||
return e;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ syscallret_t syscall_ftruncate(int fd, size_t size) {
|
||||
}
|
||||
|
||||
VOP_LOCK(file->vnode);
|
||||
ret.errno = VOP_RESIZE(file->vnode, size, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_RESIZE(file->vnode, size, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(file->vnode);
|
||||
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
@@ -8,7 +8,7 @@ syscallret_t syscall_umask(context_t *, mode_t mode) {
|
||||
|
||||
mode &= 0777;
|
||||
|
||||
ret.ret = __atomic_exchange_n(&_cpu()->thread->proc->umask, mode, __ATOMIC_SEQ_CST);
|
||||
ret.ret = __atomic_exchange_n(¤t_thread()->proc->umask, mode, __ATOMIC_SEQ_CST);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ syscallret_t syscall_utimensat(context_t *, int fd, char *upath, timespec_t uts[
|
||||
}
|
||||
|
||||
vattr_t attr;
|
||||
ret.errno = VOP_GETATTR(node, &attr, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_GETATTR(node, &attr, ¤t_thread()->proc->cred);
|
||||
if (ret.errno) {
|
||||
VOP_UNLOCK(node);
|
||||
goto cleanup;
|
||||
@@ -71,10 +71,10 @@ syscallret_t syscall_utimensat(context_t *, int fd, char *upath, timespec_t uts[
|
||||
attr.atime = ts[0];
|
||||
attr.mtime = ts[1];
|
||||
|
||||
ret.errno = auth_filesystem_check(&_cpu()->thread->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
|
||||
ret.errno = auth_filesystem_check(¤t_thread()->proc->cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
|
||||
if (ret.errno) {
|
||||
if (uts == NULL)
|
||||
ret.errno = VOP_ACCESS(node, V_ACCESS_WRITE, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_ACCESS(node, V_ACCESS_WRITE, ¤t_thread()->proc->cred);
|
||||
|
||||
if (ret.errno) {
|
||||
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, ¤t_thread()->proc->cred);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
VOP_UNLOCK(node);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ syscallret_t syscall_waitpid(context_t *context, pid_t pid, int *status, int opt
|
||||
// TODO implement these
|
||||
__assert(pid == -1 || pid > 0);
|
||||
|
||||
thread_t *thread = _cpu()->thread;
|
||||
thread_t *thread = current_thread();
|
||||
proc_t *proc = thread->proc;
|
||||
MUTEX_ACQUIRE(&proc->mutex, false);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ syscallret_t syscall_write(context_t *context, int fd, void *buffer, size_t size
|
||||
vattr_t attr;
|
||||
// TODO racey
|
||||
VOP_LOCK(file->vnode);
|
||||
ret.errno = VOP_GETATTR(file->vnode, &attr, &_cpu()->thread->proc->cred);
|
||||
ret.errno = VOP_GETATTR(file->vnode, &attr, ¤t_thread()->proc->cred);
|
||||
VOP_UNLOCK(file->vnode);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
Reference in New Issue
Block a user