Skip to content

Commit 8a37372

Browse files
committed
Add g_alloc_mem_p to return physical allocated address
1 parent f40d81a commit 8a37372

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

kernel/src/kernel/calls/syscall_memory.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ void syscallAllocateMemory(g_task* task, g_syscall_alloc_mem* data)
7070
return;
7171
}
7272

73+
g_physical_address page = 0;
7374
bool failedPhysical = false;
7475
for(uint32_t i = 0; i < pages; i++)
7576
{
76-
g_physical_address page = memoryPhysicalAllocate();
77+
page = memoryPhysicalAllocate();
7778
if(!page)
7879
{
7980
failedPhysical = true;
@@ -96,6 +97,7 @@ void syscallAllocateMemory(g_task* task, g_syscall_alloc_mem* data)
9697
}
9798

9899
data->virtualResult = (void*) mapped;
100+
data->physicalResult = (task->securityLevel <= G_SECURITY_LEVEL_DRIVER && pages == 1) ? (void*) page : nullptr;
99101
}
100102

101103
void syscallUnmap(g_task* task, g_syscall_unmap* data)

libapi/inc/ghost/memory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ __BEGIN_C
3838
* @param size
3939
* the size in bytes
4040
*
41+
* @param out_phys
42+
* optionally, the physical output, only for security-level DRIVER and only
43+
* if just one page was allocated
44+
*
4145
* @return a pointer to the allocated memory region, or 0 if failed
4246
*
4347
* @security-level APPLICATION
4448
*/
4549
void* g_alloc_mem(g_size size);
50+
void* g_alloc_mem_p(g_size size, void** out_phys);
4651

4752
/**
4853
* Shares a memory area with another process.

libapi/inc/ghost/memory/callstructs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@
3333
* address space. this address is page-aligned. if allocation
3434
* fails, this field is 0.
3535
*
36+
* @field physicalResult
37+
* the physical address of the allocated area, only exposed when the
38+
* executing process has security-level DRIVER and only if just one
39+
* page was allocated
40+
*
3641
* @security-level APPLICATION
3742
*/
3843
typedef struct
3944
{
4045
g_size size;
4146

4247
void* virtualResult;
48+
void* physicalResult;
4349
}__attribute__((packed)) g_syscall_alloc_mem;
4450

4551
/**

libapi/src/memory/g_alloc_mem.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ void* g_alloc_mem(g_size size)
3434

3535
return data.virtualResult;
3636
}
37+
38+
/**
39+
* @see header
40+
*/
41+
void* g_alloc_mem_p(g_size size, void** out_phys)
42+
{
43+
g_syscall_alloc_mem data;
44+
data.size = size;
45+
46+
g_syscall(G_SYSCALL_ALLOCATE_MEMORY, (g_address) &data);
47+
48+
if(out_phys)
49+
*out_phys = data.physicalResult;
50+
return data.virtualResult;
51+
}

0 commit comments

Comments
 (0)