Skip to content

Commit

Permalink
mm: declarations for mmap, munmap, and msync
Browse files Browse the repository at this point in the history
  • Loading branch information
jewelcodes committed Nov 28, 2024
1 parent c4b09eb commit c29f5b4
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/include/kernel/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/types.h>
#include <kernel/boot.h>
#include <kernel/sched.h>

Expand Down Expand Up @@ -40,6 +41,20 @@

// TODO: adjust bit masks and shifting here when implementing true swapping

// protection and flags for memory-mapped files
#define PROT_READ 0x01
#define PROT_WRITE 0x02
#define PROT_EXEC 0x04
#define PROT_NONE 0x00

#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_FIXED 0x04

#define MS_ASYNC 0x01
#define MS_SYNC 0x02
#define MS_INVALIDATE 0x04

typedef struct {
uint64_t highestPhysicalAddress;
uint64_t lowestUsableAddress;
Expand All @@ -53,6 +68,25 @@ typedef struct {
uint64_t usedPages, usedBytes;
} KernelHeapStatus;

typedef struct {
int fd, prot, flags;
pid_t pid, tid; // original owner
bool device;
size_t length;
off_t offset;
} MmapHeader;

struct MmapSyscallParams {
// probably the only syscall whose params will be passed in memory because
// there's just too many
void *addr;
size_t len;
int prot;
int flags;
int fd;
off_t off;
};

void pmmInit(KernelBootInfo *);
void pmmStatus(PhysicalMemoryStatus *);
uintptr_t pmmAllocate(void);
Expand All @@ -72,4 +106,8 @@ void *sbrk(Thread *, intptr_t);

uintptr_t mmio(Thread *, uintptr_t, off_t, int);
uintptr_t pcontig(Thread *, uintptr_t, off_t, int);
uintptr_t vtop(Thread *, uintptr_t);
uintptr_t vtop(Thread *, uintptr_t);

void *mmap(Thread *, void *, size_t, int, int, int, off_t);
int munmap(Thread *, void *, size_t);
int msync(Thread *, void *, size_t, int);

0 comments on commit c29f5b4

Please sign in to comment.