CS350 COS
COS
Loading...
Searching...
No Matches
mman.c File Reference
#include <stdlib.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <syscall.h>
Include dependency graph for mman.c:

Go to the source code of this file.

Functions

int getpagesizes (size_t *pagesize, int nelem)
 
void * mmap (void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 
int munmap (void *addr, size_t len)
 
int mprotect (void *addr, size_t len, int prot)
 
int madvise (void *addr, size_t len, int behav)
 

Function Documentation

◆ getpagesizes()

int getpagesizes ( size_t pagesize,
int  nelem 
)

Definition at line 16 of file mman.c.

17{
18#if defined(__x86_64__)
19 if (pagesize) {
20 if (nelem >= 1)
21 pagesize[0] = PGSIZE;
22 if (nelem >= 2)
23 pagesize[1] = LARGE_PGSIZE;
24 if (nelem >= 3)
25 pagesize[2] = HUGE_PGSIZE;
26 return (nelem > 3 ? 3 : nelem);
27 }
28 return 3;
29#else
30#error "Unsupported Architecture!"
31#endif
32}
#define HUGE_PGSIZE
Definition: amd64.h:29
#define LARGE_PGSIZE
Definition: amd64.h:25
#define PGSIZE
Definition: malloc.c:21

◆ madvise()

int madvise ( void *  addr,
size_t  len,
int  behav 
)

Definition at line 71 of file mman.c.

72{
73 return 0;
74}

◆ mmap()

void * mmap ( void *  addr,
size_t  len,
int  prot,
int  flags,
int  fd,
off_t  offset 
)

Definition at line 35 of file mman.c.

36{
37 void *realAddr;
38
39 if (!(flags & MAP_FIXED)) {
40 // Find an address
41 }
42
43 if (flags & MAP_ANON) {
44 realAddr = OSMemMap(addr, len, prot | flags);
45 } else {
46 abort();
47 }
48
49 // XXX: Update mapping
50
51 return realAddr;
52}
void * OSMemMap(void *addr, uint64_t len, int flags)
Definition: syscall.c:41
#define MAP_ANON
Definition: mman.h:11
#define MAP_FIXED
Definition: mman.h:12
uint64_t addr
Definition: multiboot.h:1
uint64_t len
Definition: multiboot.h:2
_Noreturn void abort(void)
Definition: abort.c:9
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mprotect()

int mprotect ( void *  addr,
size_t  len,
int  prot 
)

Definition at line 63 of file mman.c.

64{
65 // XXX: Update mappings
66
67 return OSMemProtect(addr, len, prot);
68}
int OSMemProtect(void *addr, uint64_t len, int flags)
Definition: syscall.c:53
Here is the call graph for this function:

◆ munmap()

int munmap ( void *  addr,
size_t  len 
)

Definition at line 55 of file mman.c.

56{
57 // XXX: Update mappings
58
59 return OSMemUnmap(addr, len);
60}
int OSMemUnmap(void *addr, uint64_t len)
Definition: syscall.c:47
Here is the call graph for this function:
Here is the caller graph for this function: