From 00690fd68540dac4422dbfb1bedad1b8fb4ccc71 Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Mon, 17 Jul 2023 19:15:08 +0300 Subject: [PATCH] [orbis-kernel] Event flag fixes --- orbis-kernel/include/orbis/KernelContext.hpp | 4 +++- orbis-kernel/src/sys/sys_sce.cpp | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/orbis-kernel/include/orbis/KernelContext.hpp b/orbis-kernel/include/orbis/KernelContext.hpp index 10992449..6ce34f96 100644 --- a/orbis-kernel/include/orbis/KernelContext.hpp +++ b/orbis-kernel/include/orbis/KernelContext.hpp @@ -65,6 +65,7 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final { auto [it, inserted] = m_event_flags.try_emplace(std::move(name), nullptr); if (inserted) { it->second = knew(flags, initPattern); + std::strncpy(it->second->name, it->first.c_str(), 32); } return {it->second.get(), inserted}; @@ -106,7 +107,6 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final { } private: - shared_mutex m_evf_mtx; mutable pthread_mutex_t m_heap_mtx; void *m_heap_next = this + 1; bool m_heap_is_freeing = false; @@ -119,6 +119,8 @@ class alignas(__STDCPP_DEFAULT_NEW_ALIGNMENT__) KernelContext final { mutable shared_mutex m_proc_mtx; utils::LinkedNode *m_processes = nullptr; + + shared_mutex m_evf_mtx; utils::kmap> m_event_flags; }; diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index 435fd7d2..ede47ae4 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -94,9 +94,10 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr name, } switch (attrs & (kEvfAttrSingle | kEvfAttrMulti)) { - case 0: case kEvfAttrSingle | kEvfAttrMulti: - attrs = (attrs & ~(kEvfAttrSingle | kEvfAttrMulti)) | kEvfAttrSingle; + return ErrorCode::INVAL; + case 0: + attrs |= kEvfAttrSingle; break; default: @@ -104,9 +105,10 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr name, } switch (attrs & (kEvfAttrThPrio | kEvfAttrThFifo)) { - case 0: case kEvfAttrThPrio | kEvfAttrThFifo: - attrs = (attrs & ~(kEvfAttrThPrio | kEvfAttrThFifo)) | kEvfAttrThFifo; + return ErrorCode::INVAL; + case 0: + attrs |= kEvfAttrThFifo; break; default: @@ -131,6 +133,7 @@ orbis::SysResult orbis::sys_evf_create(Thread *thread, ptr name, eventFlag = insertedEvf; } else { eventFlag = knew(attrs, initPattern); + std::strncpy(eventFlag->name, _name, 32); } thread->retval[0] = thread->tproc->evfMap.insert(eventFlag); @@ -162,7 +165,6 @@ orbis::SysResult orbis::sys_evf_open(Thread *thread, ptr name) { return ErrorCode::SRCH; } - std::strcpy(eventFlag->name, _name); thread->retval[0] = thread->tproc->evfMap.insert(eventFlag); return {}; }