matos/core/uaddrspace.h

55 lines
1.9 KiB
C
Raw Permalink Normal View History

2022-08-09 16:15:00 +02:00
#pragma once
#include "mmuContext.h"
#include "process.h"
2024-02-15 18:40:45 +01:00
#include "stddef.h"
#include "stdint.h"
2022-08-09 16:15:00 +02:00
#include "types.h"
struct uAddrSpace;
struct uAddrVirtualReg;
#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;
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);
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
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);
int uAddrSpaceSolvePageFault(struct uAddrSpace *as, vaddr_t faultAddr, int isWriteAccess);