diff --git a/src/emu/nosv/event.c b/src/emu/nosv/event.c index cca6fe6..fc9ccba 100644 --- a/src/emu/nosv/event.c +++ b/src/emu/nosv/event.c @@ -555,6 +555,11 @@ process_ev(struct emu *emu) return -1; } + if (emu->thread->is_out_of_cpu) { + err("current thread %d out of CPU", emu->thread->tid); + return -1; + } + switch (emu->ev->c) { case 'S': case 'U': diff --git a/src/emu/ovni/event.c b/src/emu/ovni/event.c index 3c74d72..b49e7a5 100644 --- a/src/emu/ovni/event.c +++ b/src/emu/ovni/event.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2021-2023 Barcelona Supercomputing Center (BSC) +/* Copyright (c) 2021-2024 Barcelona Supercomputing Center (BSC) * SPDX-License-Identifier: GPL-3.0-or-later */ #include "ovni_priv.h" @@ -458,6 +458,11 @@ model_ovni_event(struct emu *emu) return -1; } + if (emu->thread->is_out_of_cpu) { + err("current thread %d out of CPU", emu->thread->tid); + return -1; + } + switch (emu->ev->c) { case 'H': return pre_thread(emu); diff --git a/test/emu/kernel/instr_kernel.h b/test/emu/kernel/instr_kernel.h new file mode 100644 index 0000000..73bc80b --- /dev/null +++ b/test/emu/kernel/instr_kernel.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#ifndef INSTR_KERNEL_H +#define INSTR_KERNEL_H + +#include "instr.h" + +static inline void +instr_kernel_init(void) +{ + instr_require("kernel"); +} + +INSTR_0ARG(instr_kernel_cs_out, "KCO") +INSTR_0ARG(instr_kernel_cs_in, "KCI") + +#endif /* INSTR_KERNEL_H */ diff --git a/test/emu/nosv/CMakeLists.txt b/test/emu/nosv/CMakeLists.txt index dccdd50..9bef0db 100644 --- a/test/emu/nosv/CMakeLists.txt +++ b/test/emu/nosv/CMakeLists.txt @@ -31,3 +31,6 @@ test_emu(bad-pause-parallel.c SHOULD_FAIL REGEX "body_pause: body(id=1,taskid=1) is not allowed to pause") test_emu(bad-nest-from-parallel.c SHOULD_FAIL REGEX "body_execute: cannot nest body(id=2,taskid=2) over body(id=1,taskid=1) which is already running") + +test_emu(events-from-outside-cpu.c SHOULD_FAIL + REGEX "current thread .* out of CPU") diff --git a/test/emu/nosv/events-from-outside-cpu.c b/test/emu/nosv/events-from-outside-cpu.c new file mode 100644 index 0000000..04f4192 --- /dev/null +++ b/test/emu/nosv/events-from-outside-cpu.c @@ -0,0 +1,24 @@ +/* Copyright (c) 2024 Barcelona Supercomputing Center (BSC) + * SPDX-License-Identifier: GPL-3.0-or-later */ + +#include +#include "instr_nosv.h" +#include "../kernel/instr_kernel.h" + +int +main(void) +{ + instr_start(0, 1); + instr_nosv_init(); + instr_kernel_init(); + + /* Make the current thread out of CPU */ + instr_kernel_cs_out(); + + /* Try to emit a nOS-V event: should fail */ + instr_nosv_type_create(666); + + instr_end(); + + return 0; +}