Compare commits

..

20 Commits

Author SHA1 Message Date
Mathieu Maret b352eab798 gdb: print_list can take the next element name in param 2024-02-08 23:15:29 +01:00
Mathieu Maret b8c4c782de Fix findVirtualRegionBeforeAddr 2024-02-08 23:15:29 +01:00
Mathieu Maret 1895781213 Assign a mapped ressource to init prog 2024-02-08 23:15:29 +01:00
Mathieu Maret cca78b269d init: use zero driver for stack alloc 2024-02-08 23:15:29 +01:00
Mathieu Maret bf7008fc98 Fix write rights on pageflt 2024-02-08 23:15:29 +01:00
Mathieu Maret ccfafe4a04 userspace: mmap test read and write 2024-02-08 23:15:29 +01:00
Mathieu Maret 62a1c1cefb zero: finish implementation 2024-02-08 23:15:29 +01:00
Mathieu Maret f751835115 Improve debug message 2024-02-08 23:15:29 +01:00
Mathieu Maret 5a2042e577 Fix MMU context on ressource checking 2024-02-08 23:15:29 +01:00
Mathieu Maret 9fa9bd0411 userspace: add PROT flag for mmap 2024-02-08 23:15:29 +01:00
Mathieu Maret a4873a7d30 Implement freeing ressource on uAS destroy 2024-02-08 23:15:29 +01:00
Mathieu Maret 205d174c8a pagefault_handler print error code before killing thread 2024-02-08 23:15:29 +01:00
Mathieu Maret d9051ea59c Propagate page fault to ressource handler
Fix mmap arguments handling
2024-02-08 23:15:29 +01:00
Mathieu Maret b9d741060f Add the ability to map/unmap a ressource 2024-02-08 23:15:29 +01:00
Mathieu Maret 1bb81fd57e Typo fix 2024-02-08 23:15:29 +01:00
Mathieu Maret 44c5551655 Wip: zero mmap 2024-02-08 23:15:29 +01:00
Mathieu Maret b6fd550e7f Add some documentation 2024-02-08 23:15:26 +01:00
Mathieu Maret 8af3ba0762 mmap syscall declaration 2024-02-08 23:08:14 +01:00
Mathieu Maret 1e3be650f2 Put back kernel sym in debug.gdb
As gnu-debuglink does not seems to be working everwhere
2024-02-08 23:05:54 +01:00
Mathieu Maret bd25bb8478 Add calloc, realloc, memmove. Sync klibc and libc 2024-01-31 12:57:35 +01:00
4 changed files with 75 additions and 12 deletions

View File

@ -102,6 +102,7 @@ screenshot: ## Take a screenshot of the qemu window
clean:
$(RM) kernel $(asmobj) $(gasmobj) $(cobj) $(deps) $(cinc) fd.iso kernel.debug kernel.map $(docobj)
$(RM) -r isodir
$(MAKE) -C userspace clean
.PHONY:
userspace screenshot

View File

@ -37,8 +37,8 @@ int vprintf(const char *format, va_list ap) __attribute__ ((__format__ (printf,
int printf(const char *format, ...) __attribute__ ((__format__ (printf, 1, 2)));
// Could be used after malloc is available
int asprintf(char **strp, const char *fmt, ...);
int vasprintf(char **strp, const char *fmt, va_list ap);
int asprintf(char **strp, const char *fmt, ...) __attribute__ ((__format__ (printf, 2, 3)));
int vasprintf(char **strp, const char *fmt, va_list ap) __attribute__ ((__format__ (printf, 2, 0)));
/*
* Dummy printk for disabled debugging statements to use whilst maintaining

View File

@ -81,6 +81,16 @@ void *memcpy(void *dst0, const void *src0, size_t len0)
#endif
}
void *memmove(void *dst, const void *src, size_t n)
{
char *dstChar = dst;
const char *srcChar = src;
for (size_t i = 0; i < n; i++) {
*(dstChar++) = *(srcChar++);
}
return dst;
}
void *memset(void *src, int c, size_t n)
{
for (char *ptr = (char *)src; n > 0; n--, ptr++) {
@ -603,20 +613,25 @@ struct heapBlock {
static struct heapBlock *heapBlkList = NULL;
struct heapBlock *findFreeBlock(size_t size){
struct heapBlock *cur = NULL;
static struct heapBlock *findFreeBlock(size_t size)
{
struct heapBlock *cur = NULL;
struct heapBlock *found = NULL;
int idx;
list_foreach(heapBlkList, cur, idx){
if(cur->size >= size && cur->free){
list_foreach(heapBlkList, cur, idx)
{
if (cur->size >= size && cur->free) {
found = cur;
break;
}
}
return found;
}
struct heapBlock *allocNewBlock(size_t size) {
static struct heapBlock *allocNewBlock(size_t size)
{
struct heapBlock *blk = sbrk(size + sizeof(struct heapBlock));
struct heapBlock *head = sbrk(0);
size_t blkSize = (intptr_t)head - (intptr_t)blk - sizeof(struct heapBlock);
@ -626,10 +641,11 @@ struct heapBlock *allocNewBlock(size_t size) {
blk->size = blkSize;
blk->free = 1;
list_add_tail(heapBlkList, blk);
return blk;
}
struct heapBlock *splitBlock(struct heapBlock *blk, size_t neededSize)
static struct heapBlock *splitBlock(struct heapBlock *blk, size_t neededSize)
{
if (blk->size < neededSize + sizeof(struct heapBlock) + 1) {
return NULL;
@ -638,6 +654,7 @@ struct heapBlock *splitBlock(struct heapBlock *blk, size_t neededSize)
newBlk->free = 1;
newBlk->size = blk->size - sizeof(struct heapBlock) - neededSize;
blk->size = neededSize;
return newBlk;
}
@ -656,15 +673,18 @@ void *malloc(size_t size)
list_add_head(heapBlkList, remainBlock);
}
blk->free = 0;
return blk + 1; // return the area after the blk description
}
struct heapBlock *getHeapBlock(void *ptr) {
static struct heapBlock *getHeapBlock(void *ptr)
{
return (struct heapBlock *)ptr - 1;
}
void free(void *ptr){
if(!ptr)
void free(void *ptr)
{
if (!ptr)
return;
struct heapBlock *blk = getHeapBlock(ptr);
@ -673,6 +693,39 @@ void free(void *ptr){
blk->free = 1;
}
void *calloc(size_t nmemb, size_t size)
{
size_t allocSize = nmemb * size;
void *ptr = malloc(allocSize);
if (ptr != NULL)
memset(ptr, 0, allocSize);
return ptr;
}
void *realloc(void *ptr, size_t size)
{
if (!ptr) {
return malloc(size);
}
struct heapBlock *blk = getHeapBlock(ptr);
if (blk->size >= size) {
return ptr;
}
void *new_ptr;
new_ptr = malloc(size);
if (!new_ptr) {
return NULL;
}
memmove(new_ptr, ptr, blk->size);
free(ptr);
return new_ptr;
}
void *mmap(void *addr, size_t len, int prot, int flags, char *path) {
int ret = syscall5(SYSCALL_ID_MMAP, (unsigned int)&addr, len, prot, flags, (unsigned int)path);

View File

@ -14,8 +14,15 @@
#define isprint(c) ((' ' <= (c)) && ((c) <= '~'))
#define EOF (-1)
/** compares the first @param n bytes (each interpreted as
* unsigned char) of the memory areas @param s1 and @param s2.
*/
__attribute__ ((access (read_only, 1, 3), access (read_only, 2, 3))) int memcmp(const void *s1, const void *s2, size_t n);
/**
* copies n bytes from memory area src to memory area dest. The memory areas may overlap
*/
__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memmove(void *dest, const void *src, size_t n);
__attribute__ ((access (write_only, 1, 3), access (read_only, 2, 3))) void *memcpy(void *dest, const void *src, size_t n);
__attribute__ ((access (write_only, 1, 3))) void *memset(void *s, int c, size_t n);
char *itoa(long long int value, char *str, int base);
@ -56,4 +63,6 @@ int readline(char *buf, int size);
int brk(void *addr);
void *sbrk(intptr_t increment);
void *malloc(size_t size);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
void free(void *ptr);