| 77 | } |
| 78 | |
| 79 | void* MapSharedMemory(int64_t key, process_t* proc, uint64_t hint){ |
| 80 | acquireLock(&lock); |
| 81 | |
| 82 | shared_mem_t* sMem = GetSharedMemory(key); |
| 83 | |
| 84 | if(!sMem) { |
| 85 | releaseLock(&lock); |
| 86 | return nullptr; // Check for invalid key |
| 87 | } |
| 88 | |
| 89 | if(sMem->flags & SMEM_FLAGS_PRIVATE){ // Private Mapping |
| 90 | if(proc->pid != sMem->owner && proc->pid != sMem->recipient){ |
| 91 | releaseLock(&lock); |
| 92 | return nullptr; // Does not have access rights |
| 93 | } |
| 94 | } |
| 95 | sMem->mapCount++; |
| 96 | |
| 97 | void* mapping; |
| 98 | |
| 99 | /*if(hint && Memory::CheckRegion(hint, sMem->pgCount * PAGE_SIZE_4K, proc->addressSpace)){ |
| 100 | mapping = (void*)hint; |
| 101 | } else*/ mapping = Memory::Allocate4KPages(sMem->pgCount, proc->addressSpace); |
| 102 | |
| 103 | for(unsigned i = 0; i < sMem->pgCount; i++){ |
| 104 | Memory::MapVirtualMemory4K(sMem->pages[i], (uintptr_t)mapping + i * PAGE_SIZE_4K, 1, proc->addressSpace); |
| 105 | } |
| 106 | |
| 107 | mem_region_t mReg; |
| 108 | mReg.base = (uintptr_t)mapping; |
| 109 | mReg.pageCount = sMem->pgCount; |
| 110 | proc->sharedMemory.add_back(mReg); |
| 111 | |
| 112 | releaseLock(&lock); |
| 113 | |
| 114 | return mapping; |
| 115 | } |
| 116 | |
| 117 | void DestroySharedMemory(int64_t key){ |
| 118 | //acquireLock(&lock); |
no test coverage detected