MCPcopy Create free account
hub / github.com/RPCSX/rpcsx / sys_mempool_create

Function sys_mempool_create

ps3fw/sys_mempool.cpp:31–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29};
30
31error_code sys_mempool_create(ppu_thread& ppu, vm::ptr<sys_mempool_t> mempool,
32 vm::ptr<void> chunk, const u64 chunk_size,
33 const u64 block_size, const u64 ralignment)
34{
35 sysPrxForUser.warning("sys_mempool_create(mempool=*0x%x, chunk=*0x%x, "
36 "chunk_size=%d, block_size=%d, ralignment=%d)",
37 mempool, chunk, chunk_size, block_size, ralignment);
38
39 if (block_size > chunk_size)
40 {
41 return CELL_EINVAL;
42 }
43
44 u64 alignment = ralignment;
45 if (ralignment == 0 || ralignment == 2)
46 {
47 alignment = 4;
48 }
49
50 // Check if alignment is power of two
51 if ((alignment & (alignment - 1)) != 0)
52 {
53 return CELL_EINVAL;
54 }
55
56 // Test chunk address aligment
57 if (!chunk.aligned(8))
58 {
59 return CELL_EINVAL;
60 }
61
62 auto id = idm::make<memory_pool_t>();
63 *mempool = id;
64
65 auto memory_pool = idm::get_unlocked<memory_pool_t>(id);
66
67 memory_pool->chunk = chunk;
68 memory_pool->chunk_size = chunk_size;
69 memory_pool->block_size = block_size;
70 memory_pool->ralignment = alignment;
71
72 // TODO: check blocks alignment wrt ralignment
73 u64 num_blocks = chunk_size / block_size;
74 memory_pool->free_blocks.resize(num_blocks);
75 for (u32 i = 0; i < num_blocks; ++i)
76 {
77 memory_pool->free_blocks[i] =
78 vm::ptr<void>::make(chunk.addr() + i * static_cast<u32>(block_size));
79 }
80
81 // Create synchronization variables
82 vm::var<u32> mutexid;
83 vm::var<sys_mutex_attribute_t> attr;
84 attr->protocol = SYS_SYNC_PRIORITY;
85 attr->recursive = SYS_SYNC_NOT_RECURSIVE;
86 attr->pshared = SYS_SYNC_NOT_PROCESS_SHARED;
87 attr->adaptive = SYS_SYNC_NOT_ADAPTIVE;
88 attr->ipc_key = 0; // No idea what this is

Callers

nothing calls this directly

Calls 8

strcpy_truncFunction · 0.85
to_stringFunction · 0.85
sys_mutex_createFunction · 0.85
throw_exceptionClass · 0.85
sys_cond_createFunction · 0.85
alignedMethod · 0.80
resizeMethod · 0.45
addrMethod · 0.45

Tested by

no test coverage detected