forked from Bananymous/banan-os
Kernel: Fix shm object freeing and track lpid
I was deleting based on the key instead of the id which of course does not work :D
This commit is contained in:
@@ -27,8 +27,9 @@ namespace Kernel
|
|||||||
private:
|
private:
|
||||||
struct Object : public BAN::RefCounted<Object>
|
struct Object : public BAN::RefCounted<Object>
|
||||||
{
|
{
|
||||||
Object(key_t key, shmid_ds info)
|
Object(key_t key, int id, shmid_ds info)
|
||||||
: key(key)
|
: key(key)
|
||||||
|
, id(id)
|
||||||
, info(info)
|
, info(info)
|
||||||
{ }
|
{ }
|
||||||
~Object();
|
~Object();
|
||||||
@@ -36,6 +37,7 @@ namespace Kernel
|
|||||||
bool can_current_process_access(int flags) const;
|
bool can_current_process_access(int flags) const;
|
||||||
|
|
||||||
const key_t key;
|
const key_t key;
|
||||||
|
const int id;
|
||||||
shmid_ds info;
|
shmid_ds info;
|
||||||
|
|
||||||
Mutex mutex;
|
Mutex mutex;
|
||||||
|
|||||||
@@ -93,7 +93,15 @@ namespace Kernel
|
|||||||
const pid_t pid = process.pid();
|
const pid_t pid = process.pid();
|
||||||
const mode_t mode = shmflg & 0777;
|
const mode_t mode = shmflg & 0777;
|
||||||
|
|
||||||
auto object = TRY(BAN::RefPtr<Object>::create(key, shmid_ds {
|
const int shmid = ({
|
||||||
|
int id;
|
||||||
|
do {
|
||||||
|
id = Random::get<unsigned>() & BAN::numeric_limits<int>::max();
|
||||||
|
} while (m_ids.contains(shmid));
|
||||||
|
id;
|
||||||
|
});
|
||||||
|
|
||||||
|
auto object = TRY(BAN::RefPtr<Object>::create(key, shmid, shmid_ds {
|
||||||
.shm_perm = {
|
.shm_perm = {
|
||||||
.uid = uid,
|
.uid = uid,
|
||||||
.gid = gid,
|
.gid = gid,
|
||||||
@@ -111,12 +119,6 @@ namespace Kernel
|
|||||||
}));
|
}));
|
||||||
TRY(object->paddrs.resize(BAN::Math::div_round_up(size, PAGE_SIZE), 0));
|
TRY(object->paddrs.resize(BAN::Math::div_round_up(size, PAGE_SIZE), 0));
|
||||||
|
|
||||||
auto generate_id = []() { return Random::get<unsigned>() & BAN::numeric_limits<int>::max(); };
|
|
||||||
|
|
||||||
int shmid = generate_id();
|
|
||||||
while (m_ids.contains(shmid))
|
|
||||||
shmid = generate_id();
|
|
||||||
|
|
||||||
if (key != IPC_PRIVATE)
|
if (key != IPC_PRIVATE)
|
||||||
TRY(m_ids.insert(key, shmid));
|
TRY(m_ids.insert(key, shmid));
|
||||||
|
|
||||||
@@ -222,14 +224,16 @@ namespace Kernel
|
|||||||
LockGuard _(m_object->mutex);
|
LockGuard _(m_object->mutex);
|
||||||
m_object->info.shm_nattch++;
|
m_object->info.shm_nattch++;
|
||||||
m_object->info.shm_atime = SystemTimer::get().real_time().tv_sec;
|
m_object->info.shm_atime = SystemTimer::get().real_time().tv_sec;
|
||||||
|
m_object->info.shm_lpid = Process::current().pid();
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedMemoryObject::~SharedMemoryObject()
|
SharedMemoryObject::~SharedMemoryObject()
|
||||||
{
|
{
|
||||||
LockGuard _(m_object->mutex);
|
LockGuard _(m_object->mutex);
|
||||||
if (--m_object->info.shm_nattch == 0 && m_object->marked_for_deletion)
|
if (--m_object->info.shm_nattch == 0 && m_object->marked_for_deletion)
|
||||||
SharedMemoryObjectManager::get().m_objects.remove(m_object->key);
|
SharedMemoryObjectManager::get().m_objects.remove(m_object->id);
|
||||||
m_object->info.shm_dtime = SystemTimer::get().real_time().tv_sec;
|
m_object->info.shm_dtime = SystemTimer::get().real_time().tv_sec;
|
||||||
|
m_object->info.shm_lpid = Process::current().pid();
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> SharedMemoryObject::clone(PageTable& new_page_table)
|
BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> SharedMemoryObject::clone(PageTable& new_page_table)
|
||||||
|
|||||||
Reference in New Issue
Block a user