2022-08-09 16:15:00 +02:00
|
|
|
#pragma once
|
|
|
|
#include "mmuContext.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
struct uAddrSpace;
|
|
|
|
struct uAddrVirtualReg;
|
|
|
|
|
2024-01-31 23:49:07 +01:00
|
|
|
#define UA_MAP_SHARED (1 << 0)
|
2024-02-10 21:26:01 +01:00
|
|
|
#define UA_MAP_PRIVATE (1 << 1)
|
|
|
|
#define UA_MAP_FIXED (1 << 2)
|
|
|
|
|
2023-11-10 09:01:55 +01:00
|
|
|
// TODO : move this struct to .c and add accessors
|
|
|
|
struct uAddrVirtualReg {
|
|
|
|
uaddr_t addr;
|
|
|
|
size_t size;
|
|
|
|
int right; // PAGING_MEM_*
|
|
|
|
uint32_t offset; // in the mappedRessource
|
|
|
|
uint flags;
|
|
|
|
|
|
|
|
struct mappedRessource *res;
|
|
|
|
struct uAddrVirtualReg *nextInAddrSpace, *prevInAddrSpace;
|
|
|
|
struct uAddrVirtualReg *nextInMappedRes, *prevInMappedRes;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mappedRessourceOps {
|
|
|
|
int (*open)(struct uAddrVirtualReg *vreg);
|
|
|
|
int (*close)(struct uAddrVirtualReg *vreg);
|
|
|
|
int (*unmap)(struct uAddrVirtualReg *vreg, uaddr_t addr, size_t size);
|
|
|
|
int (*nopage)(struct uAddrVirtualReg *vreg, uaddr_t addr,
|
|
|
|
int right); // Called by the pageflt handler when the page is missing
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mappedRessource {
|
|
|
|
int allowedRight; // PAGING_MEM_*
|
|
|
|
struct mappedRessourceOps *ops;
|
|
|
|
struct uAddrVirtualReg *listVirtualReg;
|
|
|
|
void *customData;
|
2024-01-31 23:49:07 +01:00
|
|
|
int (*onResMapped)(struct uAddrVirtualReg *reg); // Callabck for when the ressourced get mapped
|
2023-11-10 09:01:55 +01:00
|
|
|
};
|
|
|
|
|
2024-02-10 21:26:01 +01:00
|
|
|
struct uAddrSpace *uAddrSpaceCreate(struct process *proc);
|
2022-08-09 16:15:00 +02:00
|
|
|
int uAddrSpaceDelete(struct uAddrSpace *addr);
|
2024-02-10 21:26:01 +01:00
|
|
|
struct mmu_context *uAddrSpaceGetMMUContext(struct uAddrSpace *addr);
|
2022-08-09 16:15:00 +02:00
|
|
|
int uAddrSpaceSetHeap(struct uAddrSpace *as, uaddr_t addr, size_t size);
|
2024-02-04 21:42:29 +01:00
|
|
|
int uAddrSpaceHeapCheckNAlloc(struct uAddrSpace *as, vaddr_t addr);
|
2022-08-09 16:15:00 +02:00
|
|
|
uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop);
|
2023-11-10 09:01:55 +01:00
|
|
|
|
2024-01-31 23:49:07 +01:00
|
|
|
int uAddrSpaceMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights,
|
|
|
|
uint32_t flags, struct mappedRessource *res, uint32_t offset);
|
|
|
|
int uAddrSpaceUnmap(struct uAddrSpace *as, uaddr_t uaddr, size_t size);
|
2024-02-04 21:42:29 +01:00
|
|
|
int uAddrSpaceSolvePageFault(struct uAddrSpace *as, vaddr_t faultAddr, int isWriteAccess);
|