Compare commits

..

3 Commits

Author SHA1 Message Date
Mathieu Maret
fe6dfbc1c6 Add missing errno.h 2024-02-11 18:50:04 +01:00
Mathieu Maret
7b953e625e Show allocated/mapped stats 2024-02-11 15:34:33 +01:00
Mathieu Maret
026618a730 Merge close VR with same ressource mapped 2024-02-11 15:31:35 +01:00
3 changed files with 84 additions and 16 deletions

View File

@ -36,7 +36,7 @@ void idleThread(void *arg)
{ {
(void)arg; (void)arg;
while (1) { while (1) {
VGAPrintf(GREEN, BLACK, 0, VGA_HEIGHT - 1, "%d", (jiffies / HZ)); VGAPrintf(GREEN, BLACK, 0, VGA_HEIGHT - 1, "%d allocated %d, mapped %d", (jiffies / HZ), getNbAllocatedPage(), getNbMappedPage());
threadYield(); threadYield();
} }
} }

View File

@ -269,7 +269,6 @@ uaddr_t sysBrk(struct uAddrSpace *as, uaddr_t newHeapTop)
incSize = ALIGN(newHeapTop - (as->heapStart + as->heapSize), PAGE_SIZE); incSize = ALIGN(newHeapTop - (as->heapStart + as->heapSize), PAGE_SIZE);
if (incSize < 0){ if (incSize < 0){
//TODO how to free allocated page by uAddrSpaceHeapCheckNAlloc
return as->heapStart + as->heapSize; return as->heapStart + as->heapSize;
} }
@ -317,6 +316,17 @@ free_ppage:
return -1; return -1;
} }
static struct uAddrVirtualReg *uAddrSpaceMergeVr(struct uAddrVirtualReg *prev,
struct uAddrVirtualReg *next)
{
if (prev && next && prev->addr + prev->size == next->addr && prev->right == next->right &&
prev->res == next->res && prev->flags == next->flags && prev->offset == next->offset) {
prev->size += next->size;
return next;
} else
return NULL;
}
int uAddrSpaceMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights, int uAddrSpaceMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t rights,
uint32_t flags, struct mappedRessource *res, uint32_t offset ) uint32_t flags, struct mappedRessource *res, uint32_t offset )
{ {
@ -363,27 +373,48 @@ int uAddrSpaceMmap(struct uAddrSpace *as, uaddr_t *uaddr, size_t size, uint32_t
reg->right = rights; reg->right = rights;
reg->res = res; reg->res = res;
reg->offset = offset; reg->offset = offset;
// TODO merge it with prev/next one
// keep the AddrSpace list sorted // keep the AddrSpace list sorted
struct uAddrVirtualReg *prev = findVirtualRegionBeforeAddr(as, hint_uaddr); struct uAddrVirtualReg *prev = findVirtualRegionBeforeAddr(as, hint_uaddr);
if (prev) bool_t regIsNew = TRUE;
list_insert_after_named(as->listVirtualReg, prev, reg, prevInAddrSpace, if (prev) {
nextInAddrSpace); struct uAddrVirtualReg *toFree = uAddrSpaceMergeVr(prev, reg);
else if (toFree) {
pr_devel("Merge VR with prev\n");
reg = prev;
regIsNew = FALSE;
free(toFree);
}
toFree = uAddrSpaceMergeVr(reg, prev->nextInAddrSpace);
if (toFree) {
pr_devel("Merge VR with next\n");
regIsNew = FALSE;
if (toFree->res && toFree->res->ops && toFree->res->ops->close)
toFree->res->ops->close(toFree);
list_delete_named(as->listVirtualReg, toFree, prevInAddrSpace, nextInAddrSpace);
list_delete_named(toFree->res->listVirtualReg, toFree, prevInMappedRes,
nextInMappedRes);
free(toFree);
}
if (regIsNew)
list_insert_after_named(as->listVirtualReg, prev, reg, prevInAddrSpace,
nextInAddrSpace);
} else
list_add_tail_named(as->listVirtualReg, reg, prevInAddrSpace, nextInAddrSpace); list_add_tail_named(as->listVirtualReg, reg, prevInAddrSpace, nextInAddrSpace);
list_add_tail_named(reg->res->listVirtualReg, reg, prevInMappedRes, nextInMappedRes); if (regIsNew) {
if (res->onResMapped) { list_add_tail_named(reg->res->listVirtualReg, reg, prevInMappedRes, nextInMappedRes);
int cbret = res->onResMapped(reg); if (res->onResMapped) {
if (cbret) { int cbret = res->onResMapped(reg);
pr_devel("Call back failed on ressource mmaped\n"); if (cbret) {
ret = uAddrSpaceUnmap(as, reg->addr, reg->size); pr_devel("Call back failed on ressource mmaped\n");
ret = uAddrSpaceUnmap(as, reg->addr, reg->size);
}
} }
}
if (res->ops->open) if (res->ops->open)
res->ops->open(reg); res->ops->open(reg);
}
*uaddr = hint_uaddr; *uaddr = hint_uaddr;

37
userspace/errno.h Normal file
View File

@ -0,0 +1,37 @@
#pragma once
extern int errno;
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */