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
+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
// 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
View File
@@ -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(&current_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
+2 -2
View File
@@ -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
+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);
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;
cleanup:
+1 -1
View File
@@ -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 = &current_thread()->proc->cred;
int e = auth_filesystem_check(cred, AUTH_ACTIONS_FILESYSTEM_SETATTR, node, NULL);
if (e)
+1 -1
View File
@@ -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(&current_thread()->proc->cred, AUTH_ACTIONS_SYSTEM_CHROOT);
if (ret.errno)
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);
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;
cleanup:
+4 -4
View File
@@ -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, &current_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(&current_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(&current_thread()->proc->cred, suid, sgid);
error:
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)
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);
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;
}
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) {
VOP_UNLOCK(node);
goto cleanup;
}
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) {
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), &current_thread()->proc->cred);
ret.ret = ret.errno ? -1 : 0;
VOP_UNLOCK(node);
+7 -7
View File
@@ -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, &current_thread()->signals.mask, sizeof(sigset_t));
memcpy(&nthread->signals.pending, &current_thread()->signals.pending, sizeof(sigset_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.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 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;
}
+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;
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));
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;
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));
if (ret.errno)
+1 -1
View File
@@ -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;
+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];
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)
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;
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);
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;
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(&current_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:
+1 -1
View File
@@ -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;
+2 -2
View File
@@ -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)
};
+2 -2
View File
@@ -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);
+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 = {
.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,
};
+3 -3
View File
@@ -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);
+4 -4
View File
@@ -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, &current_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, &current_thread()->proc->cred);
if (ret.errno)
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->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, &current_thread()->proc->cred);
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)
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);
+1 -1
View File
@@ -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, &current_thread()->proc->cred);
// locked by vfs_lookup
VOP_UNLOCK(node);
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 {
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, &current_thread()->proc->cred);
VOP_UNLOCK(file->vnode);
if (ret.errno)
goto cleanup;
+7 -7
View File
@@ -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 = &current_thread()->proc->timer.realtime;
else if (which == ITIMER_VIRTUAL)
itimer = &_cpu()->thread->proc->timer.virtualtime;
itimer = &current_thread()->proc->timer.virtualtime;
else if (which == ITIMER_PROF)
itimer = &_cpu()->thread->proc->timer.profiling;
itimer = &current_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(&current_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(&current_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(&current_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(&current_thread()->proc->timer.mutex);
ret.errno = 0;
if (uold) {
+3 -3
View File
@@ -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;
+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 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;
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 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;
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(&current_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(&current_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(&current_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(&current_thread()->proc->cred, egid);
ret.ret = ret.errno ? -1 : 0;
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)
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, &current_thread()->proc->cred) : ENOPROTOOPT;
break;
}
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))) {
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;
}
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;
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
+4 -4
View File
@@ -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(&current_thread()->extracontext, &sigframe.extracontext, sizeof(extracontext_t));
ARCH_CONTEXT_THREADLOAD(current_thread(), context);
interrupt_set(true);
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_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;
+1 -1
View File
@@ -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, &current_thread()->proc->cred);
if (e)
return e;
+1 -1
View File
@@ -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, &current_thread()->proc->cred);
VOP_UNLOCK(file->vnode);
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;
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;
}
+4 -4
View File
@@ -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, &current_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(&current_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, &current_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, &current_thread()->proc->cred);
ret.ret = ret.errno ? -1 : 0;
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
__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);
+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;
// TODO racey
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);
if (ret.errno)
goto cleanup;