mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 05:58:22 +00:00
cpu: change _cpu()->thread calls to current_thread() to fix smp race
This commit is contained in:
+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);
|
||||
|
||||
Reference in New Issue
Block a user