Skip to content

Commit

Permalink
vm: add VM_OBJ_PHYSMEM define
Browse files Browse the repository at this point in the history
JIRA: RTOS-665
  • Loading branch information
badochov authored and agkaminski committed Nov 9, 2023
1 parent 7286737 commit dcfb262
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 44 deletions.
4 changes: 2 additions & 2 deletions proc/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void *msg_map(int dir, kmsg_t *kmsg, void *data, size_t size, process_t *
return NULL;
}

vaddr = vm_mmap(msg_common.kmap, NULL, NULL, SIZE_PAGE, PROT_READ | PROT_WRITE, (void *)-1, bpa, flags);
vaddr = vm_mmap(msg_common.kmap, NULL, NULL, SIZE_PAGE, PROT_READ | PROT_WRITE, VM_OBJ_PHYSMEM, bpa, flags);
ml->bvaddr = vaddr;
if (vaddr == NULL) {
return NULL;
Expand Down Expand Up @@ -162,7 +162,7 @@ static void *msg_map(int dir, kmsg_t *kmsg, void *data, size_t size, process_t *
nep = nbp;
}

vaddr = vm_mmap(msg_common.kmap, NULL, NULL, SIZE_PAGE, PROT_READ | PROT_WRITE, (void *)-1, epa, flags);
vaddr = vm_mmap(msg_common.kmap, NULL, NULL, SIZE_PAGE, PROT_READ | PROT_WRITE, VM_OBJ_PHYSMEM, epa, flags);
ml->evaddr = vaddr;
if (vaddr == NULL) {
return NULL;
Expand Down
4 changes: 2 additions & 2 deletions proc/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ int process_load(process_t *process, vm_object_t *o, off_t base, size_t size, vo
hal_tls_t tlsNew;
ptr_t tbssAddr = 0;

if (o != (void *)-1) {
if (o != VM_OBJ_PHYSMEM) {
return -ENOEXEC;
}

Expand Down Expand Up @@ -1327,7 +1327,7 @@ int proc_syspageSpawnName(const char *imap, const char *dmap, const char *name,

int proc_syspageSpawn(syspage_prog_t *program, vm_map_t *imap, vm_map_t *map, const char *path, char **argv)
{
return proc_spawn((void *)-1, imap, map, program->start, program->end - program->start, path, argv, NULL);
return proc_spawn(VM_OBJ_PHYSMEM, imap, map, program->start, program->end - program->start, path, argv, NULL);
}


Expand Down
5 changes: 2 additions & 3 deletions syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void *syscalls_mmap(void *ustack)

if ((flags & MAP_ANONYMOUS) != 0) {
if ((flags & MAP_PHYSMEM) != 0) {
o = (void *)-1;
o = VM_OBJ_PHYSMEM;
}
else if ((flags & MAP_CONTIGUOUS) != 0) {
o = vm_objectContiguous(size);
Expand All @@ -75,10 +75,9 @@ void *syscalls_mmap(void *ustack)
}
}
else {
return MAP_FAILED;
o = NULL;
}
}

else {
if (posix_getOid(fildes, &oid) != EOK) {
return MAP_FAILED;
Expand Down
68 changes: 35 additions & 33 deletions vm/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void map_augment(rbnode_t *node)
break;
}

n->lmaxgap = (size_t) (n->vaddr <= p->vaddr) ? (n->vaddr - n->map->start) : (n->vaddr - p->vaddr) - p->size;
n->lmaxgap = (size_t)(n->vaddr <= p->vaddr) ? (n->vaddr - n->map->start) : (n->vaddr - p->vaddr) - p->size;
}
else {
map_entry_t *l = lib_treeof(map_entry_t, linkage, node->left);
Expand All @@ -91,7 +91,7 @@ static void map_augment(rbnode_t *node)
break;
}

n->rmaxgap = (size_t) (n->vaddr >= p->vaddr) ? (n->map->stop - n->vaddr) - n->size : (p->vaddr - n->vaddr) - n->size;
n->rmaxgap = (size_t)(n->vaddr >= p->vaddr) ? (n->map->stop - n->vaddr) - n->size : (p->vaddr - n->vaddr) - n->size;
}
else {
map_entry_t *r = lib_treeof(map_entry_t, linkage, node->right);
Expand Down Expand Up @@ -228,7 +228,7 @@ static void *_map_map(vm_map_t *map, void *vaddr, process_t *proc, size_t size,
amap_t *amap;

#ifdef NOMMU
if (o == (void *)-1)
if (o == VM_OBJ_PHYSMEM)
return (void *)(ptr_t)offs;
#endif

Expand Down Expand Up @@ -425,12 +425,12 @@ int _vm_munmap(vm_map_t *map, void *vaddr, size_t size)
s->object = vm_objectRef(e->object);
s->offs = (e->offs == -1) ? -1 : e->offs + (vaddr + size - e->vaddr);
s->vaddr = vaddr + size;
s->size = (size_t) (e->vaddr + e->size - s->vaddr);
s->size = (size_t)(e->vaddr + e->size - s->vaddr);
s->aoffs = e->aoffs + (vaddr + size - e->vaddr);

s->amap = amap_ref(e->amap);

e->size = (size_t) (vaddr - e->vaddr);
e->size = (size_t)(vaddr - e->vaddr);
e->rmaxgap = size;

map_augment(&e->linkage);
Expand Down Expand Up @@ -624,7 +624,7 @@ static int _map_force(vm_map_t *map, map_entry_t *e, void *paddr, int prot)

if (e->amap == NULL)
p = vm_objectPage(map, NULL, e->object, paddr, (e->offs < 0) ? e->offs : e->offs + offs);
else /* if (e->object != (void *)-1) FIXME disabled until memory objects are created for syspage progs */
else /* if (e->object != VM_OBJ_PHYSMEM) FIXME disabled until memory objects are created for syspage progs */
p = amap_page(map, e->amap, e->object, paddr, e->aoffs + offs, (e->offs < 0) ? e->offs : e->offs + offs, prot);

if (prot & PROT_WRITE)
Expand All @@ -645,9 +645,10 @@ static int _map_force(vm_map_t *map, map_entry_t *e, void *paddr, int prot)
if (e->flags & MAP_DEVICE)
attr |= PGHD_DEV;

if (p == NULL && e->object == (void *)-1) {
if (page_map(&map->pmap, paddr, e->offs + offs, attr) < 0)
if ((p == NULL) && (e->object == VM_OBJ_PHYSMEM)) {
if (page_map(&map->pmap, paddr, e->offs + offs, attr) < 0) {
return -ENOMEM;
}
}
else if (p == NULL) {
return -ENOMEM;
Expand Down Expand Up @@ -675,7 +676,9 @@ static void map_pageFault(unsigned int n, exc_context_t *ctx)

#ifdef PAGEFAULTSTOP
process_dumpException(n, ctx);
/* clang-format off */
__asm__ volatile ("1: b 1b");
/* clang-format on */
#endif

if (hal_exceptionsPC(ctx) >= VADDR_KERNEL) /* output exception ASAP to avoid being deadlocked on spinlock */
Expand Down Expand Up @@ -928,10 +931,10 @@ void vm_mapinfo(meminfo_t *info)
if (info->entry.map != NULL && info->entry.mapsz > size) {
e = lib_treeof(map_entry_t, linkage, n);

info->entry.map[size].vaddr = e->vaddr;
info->entry.map[size].size = e->size;
info->entry.map[size].flags = e->flags;
info->entry.map[size].prot = e->prot;
info->entry.map[size].vaddr = e->vaddr;
info->entry.map[size].size = e->size;
info->entry.map[size].flags = e->flags;
info->entry.map[size].prot = e->prot;
info->entry.map[size].anonsz = ~0;

if (e->amap != NULL) {
Expand All @@ -942,14 +945,14 @@ void vm_mapinfo(meminfo_t *info)
}
}

info->entry.map[size].offs = e->offs;
info->entry.map[size].offs = e->offs;

if (e->object == NULL)
if (e->object == NULL) {
info->entry.map[size].object = OBJECT_ANONYMOUS;

else if (e->object == (void *)-1)
}
else if (e->object == VM_OBJ_PHYSMEM) {
info->entry.map[size].object = OBJECT_MEMORY;

}
else {
info->entry.map[size].object = OBJECT_OID;
info->entry.map[size].oid = e->object->oid;
Expand All @@ -963,9 +966,9 @@ void vm_mapinfo(meminfo_t *info)
do {
if (info->entry.map != NULL && info->entry.mapsz > size) {
info->entry.map[size].vaddr = e->vaddr;
info->entry.map[size].size = e->size;
info->entry.map[size].size = e->size;
info->entry.map[size].flags = e->flags;
info->entry.map[size].prot = e->prot;
info->entry.map[size].prot = e->prot;
info->entry.map[size].anonsz = ~0;

if (e->amap != NULL) {
Expand All @@ -976,14 +979,14 @@ void vm_mapinfo(meminfo_t *info)
}
}

info->entry.map[size].offs = e->offs;
info->entry.map[size].offs = e->offs;

if (e->object == NULL)
if (e->object == NULL) {
info->entry.map[size].object = OBJECT_ANONYMOUS;

else if (e->object == (void *)-1)
}
else if (e->object == VM_OBJ_PHYSMEM) {
info->entry.map[size].object = OBJECT_MEMORY;

}
else {
info->entry.map[size].object = OBJECT_OID;
info->entry.map[size].oid = e->object->oid;
Expand All @@ -992,8 +995,7 @@ void vm_mapinfo(meminfo_t *info)

++size;
e = e->next;
}
while (e != process->entries);
} while (e != process->entries);
#endif

proc_lockClear(&map->lock);
Expand All @@ -1014,9 +1016,9 @@ void vm_mapinfo(meminfo_t *info)
e = lib_treeof(map_entry_t, linkage, n);

info->entry.kmap[size].vaddr = e->vaddr;
info->entry.kmap[size].size = e->size;
info->entry.kmap[size].size = e->size;
info->entry.kmap[size].flags = e->flags;
info->entry.kmap[size].prot = e->prot;
info->entry.kmap[size].prot = e->prot;
info->entry.kmap[size].anonsz = ~0;

if (e->amap != NULL) {
Expand All @@ -1027,14 +1029,14 @@ void vm_mapinfo(meminfo_t *info)
}
}

info->entry.kmap[size].offs = e->offs;
info->entry.kmap[size].offs = e->offs;

if (e->object == NULL)
if (e->object == NULL) {
info->entry.kmap[size].object = OBJECT_ANONYMOUS;

else if (e->object == (void *)-1)
}
else if (e->object == VM_OBJ_PHYSMEM) {
info->entry.kmap[size].object = OBJECT_MEMORY;

}
else {
info->entry.kmap[size].object = OBJECT_OID;
info->entry.kmap[size].oid = e->object->oid;
Expand Down
7 changes: 3 additions & 4 deletions vm/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ int vm_objectGet(vm_object_t **o, oid_t oid)

vm_object_t *vm_objectRef(vm_object_t *o)
{
if (o != NULL && o != (void *)-1) {
if ((o != NULL) && (o != VM_OBJ_PHYSMEM)) {
proc_lockSet(&object_common.lock);
o->refs++;
proc_lockClear(&object_common.lock);
Expand All @@ -126,8 +126,9 @@ int vm_objectPut(vm_object_t *o)
{
int i;

if (o == NULL || o == (void *)-1)
if ((o == NULL) || (o == VM_OBJ_PHYSMEM)) {
return EOK;
}

proc_lockSet(&object_common.lock);

Expand Down Expand Up @@ -301,8 +302,6 @@ int _object_init(vm_map_t *kmap, vm_object_t *kernel)
}




#if 0
void map_pageFault(unsigned int n, exc_context_t *ctx)
{
Expand Down
4 changes: 4 additions & 0 deletions vm/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "proc/lock.h"
#include "amap.h"


struct _vm_map_t;

typedef struct _vm_object_t {
Expand All @@ -32,6 +33,9 @@ typedef struct _vm_object_t {
} vm_object_t;


#define VM_OBJ_PHYSMEM ((vm_object_t *)-1)


extern vm_object_t *vm_objectRef(vm_object_t *o);


Expand Down

0 comments on commit dcfb262

Please sign in to comment.