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
+1 -1
View File
@@ -502,7 +502,7 @@ void uacpi_kernel_reset_event(uacpi_handle sem) {
}
uacpi_thread_id uacpi_kernel_get_thread_id(void) {
return _cpu()->thread;
return current_thread();
}
uacpi_handle uacpi_kernel_create_spinlock(void) {
+1 -1
View File
@@ -324,7 +324,7 @@ static void enqueueandwait(queuepair_t *queuepair, entrypair_t *entries) {
*queuepair->submission.doorbell = queuepair->submission.index;
sched_preparesleep(false);
entries->thread = _cpu()->thread;
entries->thread = current_thread();
spinlock_release(&queuepair->lock);
sched_yield();
interrupt_set(intstatus);
+1 -1
View File
@@ -88,7 +88,7 @@ static void vioblk_enqueue(vioblkdev_t *blkdev, requestheader_t *headerphys, voi
VIO_QUEUE_DRV_RING(&blkdev->queue)[driveridx % blkdev->queue.size] = idx;
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;
+5 -5
View File
@@ -357,8 +357,8 @@ static int localsock_send(socket_t *socket, sockdesc_t *sockdesc) {
localsocket_t *peer = pair->client == localsocket ? pair->server : pair->client;
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;
+5 -5
View File
@@ -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;
+1 -1
View File
@@ -139,7 +139,7 @@ static int vionet_sendpacket(netdev_t *internal, netdesc_t desc, mac_t targetmac
VIO_QUEUE_DRV_RING(&netdev->txqueue)[driveridx % netdev->txqueue.size] = idx;
sched_preparesleep(false);
netdev->txwait[idx] = _cpu()->thread;
netdev->txwait[idx] = current_thread();
*netdev->txqueue.notify = 0;
spinlock_release(&netdev->txlock);
+1 -1
View File
@@ -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
View File
@@ -322,7 +322,7 @@ int tty_ioctl(tty_t *tty, unsigned long req, void *arg, int *result, cred_t *cre
return USERCOPY_POSSIBLY_FROM_USER(&tty->termios, arg, sizeof(termios_t));
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 ? &current_thread()->proc->cred : NULL)) {
freeminor(minor);
ringbuffer_destroy(&tty->readbuffer);
goto error;