From ff4a9324f9303da06d144e2d66a2b657a85e4230 Mon Sep 17 00:00:00 2001 From: Apolo151 Date: Mon, 25 Nov 2024 21:52:40 +0200 Subject: [PATCH 1/6] init and kernel functions inital implementation --- kern/mem/shared_memory_manager.c | 124 ++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 4 deletions(-) diff --git a/kern/mem/shared_memory_manager.c b/kern/mem/shared_memory_manager.c index 4ddc45a..1125b25 100644 --- a/kern/mem/shared_memory_manager.c +++ b/kern/mem/shared_memory_manager.c @@ -66,9 +66,21 @@ inline struct FrameInfo** create_frames_storage(int numOfFrames) { //TODO: [PROJECT'24.MS2 - #16] [4] SHARED MEMORY - create_frames_storage() //COMMENT THE FOLLOWING LINE BEFORE START CODING - panic("create_frames_storage is not implemented yet"); + //panic("create_frames_storage is not implemented yet"); //Your Code is Here... + if(numOfFrames <= 0){ + return NULL; + } + + struct FrameInfo** FramesArr = (struct FrameInfo**)kmalloc(sizeof(struct FrameInfo*)*numOfFrames); + // if allocation failed -> return NULL + if(FramesArr == NULL) + return NULL; + // initialize to zeros + memset(FramesArr, 0, sizeof(struct FrameInfo*)*numOfFrames); + return FramesArr; + } //===================================== @@ -81,9 +93,39 @@ struct Share* create_share(int32 ownerID, char* shareName, uint32 size, uint8 is { //TODO: [PROJECT'24.MS2 - #16] [4] SHARED MEMORY - create_share() //COMMENT THE FOLLOWING LINE BEFORE START CODING - panic("create_share is not implemented yet"); + //panic("create_share is not implemented yet"); //Your Code is Here... + struct Share* newShare = (struct Share *)kmalloc(sizeof(struct Share)); + if(newShare == NULL){ + return NULL; + } + uint32 nameSize = sizeof(newShare->name); + if (sizeof(shareName) < nameSize) + nameSize = sizeof(shareName); + // setup data + newShare->ID = (int32)newShare & 0x7FFFFFFF; //address of object + masking the MSB (make it +ve) + newShare->ownerID = ownerID; + uint32 i; + for(i = 0; i < nameSize; i++){ + (newShare->name)[i] = shareName[i]; + } + // pad with null terminator + for(; i < sizeof(newShare->name); i++) + (newShare->name)[i] = '\0'; + // + //strcpy((new_object->name),shareName); // not safe + newShare->size = size; + newShare->isWritable = isWritable; + newShare->references = 1; + newShare->framesStorage = create_frames_storage(ROUNDUP(size/PAGE_SIZE, PAGE_SIZE)); + // if allocating frames failed -> return null + if(newShare->framesStorage == NULL){ + kfree(newShare); + return NULL; + } + + return newShare; } //============================= @@ -97,9 +139,37 @@ struct Share* get_share(int32 ownerID, char* name) { //TODO: [PROJECT'24.MS2 - #17] [4] SHARED MEMORY - get_share() //COMMENT THE FOLLOWING LINE BEFORE START CODING - panic("get_share is not implemented yet"); + //panic("get_share is not implemented yet"); //Your Code is Here... + acquire_spinlock(&AllShares.shareslock); + + struct Share *desiredObject; + struct Share *currentOb = LIST_FIRST(&AllShares.shares_list); + int SListSize = LIST_SIZE(&AllShares.shares_list); + bool found = 0; + // traverse list and find shared object + for(int i = 0; i < SListSize;i++) + { + if((currentOb->name) == name && (currentOb->ownerID) == ownerID) + { + found = 1; + desiredObject = currentOb; + break; + } + currentOb = LIST_NEXT(currentOb); + } + + release_spinlock(&AllShares.shareslock); + + if(found) + { + return desiredObject; + } + else + { + return NULL; + } } //========================= @@ -109,10 +179,56 @@ int createSharedObject(int32 ownerID, char* shareName, uint32 size, uint8 isWrit { //TODO: [PROJECT'24.MS2 - #19] [4] SHARED MEMORY [KERNEL SIDE] - createSharedObject() //COMMENT THE FOLLOWING LINE BEFORE START CODING - panic("createSharedObject is not implemented yet"); + //panic("createSharedObject is not implemented yet"); //Your Code is Here... struct Env* myenv = get_cpu_proc(); //The calling environment + + struct Share *isObjectExist = get_share(ownerID,shareName); + if(isObjectExist == NULL) + { + uint32 totalSpace = (uint32)virtual_address + size; + uint32 endOfObject = ROUNDUP(totalSpace,PAGE_SIZE); + struct Share *new_object = create_share(ownerID,shareName,size,isWritable); + + //check if the object created and allocated successfully + if(new_object != NULL) + { + int frameIndex = 0; + for(uint32 currentV = (uint32)virtual_address; currentV < endOfObject; currentV += PAGE_SIZE) + { + struct FrameInfo *objectFrame = NULL; + int check = allocate_frame(&(objectFrame)); + if(check == E_NO_MEM) + { + panic("There is no enough memory!"); + } + + //map each VA to frame and add the frame to framesStorage array + map_frame((myenv->env_page_directory),objectFrame,currentV,PERM_USER | PERM_WRITEABLE); + new_object->framesStorage[frameIndex] = objectFrame; + frameIndex++; + } + + //add the new object to the shared list + acquire_spinlock(&AllShares.shareslock); + LIST_INSERT_TAIL(&(AllShares.shares_list), new_object); + release_spinlock(&AllShares.shareslock); + + return new_object->ID; + } + + else + { + return E_NO_SHARE; + } + } + + else + { + return E_SHARED_MEM_EXISTS; + } + } From e09c081df9166782ceb0df99995bfc6a79cb451e Mon Sep 17 00:00:00 2001 From: moustafa magdy Date: Tue, 26 Nov 2024 01:58:53 +0200 Subject: [PATCH 2/6] smalloc working --- kern/mem/shared_memory_manager.c | 8 +++++-- lib/uheap.c | 38 ++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/kern/mem/shared_memory_manager.c b/kern/mem/shared_memory_manager.c index 1125b25..cd35021 100644 --- a/kern/mem/shared_memory_manager.c +++ b/kern/mem/shared_memory_manager.c @@ -73,12 +73,14 @@ inline struct FrameInfo** create_frames_storage(int numOfFrames) return NULL; } - struct FrameInfo** FramesArr = (struct FrameInfo**)kmalloc(sizeof(struct FrameInfo*)*numOfFrames); + cprintf("numbers of frames:%d\n", numOfFrames); + struct FrameInfo** FramesArr = (struct FrameInfo**)kmalloc(sizeof(char)*numOfFrames); + // if allocation failed -> return NULL if(FramesArr == NULL) return NULL; // initialize to zeros - memset(FramesArr, 0, sizeof(struct FrameInfo*)*numOfFrames); + memset(FramesArr, 0, sizeof(char)*numOfFrames); return FramesArr; } @@ -189,6 +191,7 @@ int createSharedObject(int32 ownerID, char* shareName, uint32 size, uint8 isWrit { uint32 totalSpace = (uint32)virtual_address + size; uint32 endOfObject = ROUNDUP(totalSpace,PAGE_SIZE); + // uint32 endOfObject = (uint32)virtual_address + size; struct Share *new_object = create_share(ownerID,shareName,size,isWritable); //check if the object created and allocated successfully @@ -209,6 +212,7 @@ int createSharedObject(int32 ownerID, char* shareName, uint32 size, uint8 isWrit new_object->framesStorage[frameIndex] = objectFrame; frameIndex++; } + cprintf("virtual_address%p , endOfObject:%p frameIndex:%d\n",virtual_address,endOfObject,frameIndex); //add the new object to the shared list acquire_spinlock(&AllShares.shareslock); diff --git a/lib/uheap.c b/lib/uheap.c index 841a53f..061244d 100644 --- a/lib/uheap.c +++ b/lib/uheap.c @@ -154,7 +154,41 @@ void* smalloc(char *sharedVarName, uint32 size, uint8 isWritable) //============================================================== //TODO: [PROJECT'24.MS2 - #18] [4] SHARED MEMORY [USER SIDE] - smalloc() // Write your code here, remove the panic and write your code - panic("smalloc() is not implemented yet...!!"); + // panic("smalloc() is not implemented yet...!!"); + uint32 num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; // Round up to nearest page + // Page Allocator for larger allocations + + uint32 required_size = num_pages * PAGE_SIZE; // Total required size in bytes + // First-Fit Strategy + for (uint32 addr = myEnv->rlimit+PAGE_SIZE; addr + required_size <= USER_HEAP_MAX - PAGE_SIZE; addr += PAGE_SIZE) + { + uint32 index = (addr - USER_HEAP_START) / PAGE_SIZE; + uint8 is_free = 1; + + + // // Check if all pages in the range are free + for (uint32 i = 0; i < num_pages; i++) + { + if (page_allocation_status[index + i] != 0) + { + is_free = 0; + break; + } + } + // cprintf("addr: %p , pagestatus[idx] %d\n", addr, page_allocation_status[index]); + // if(page_allocation_status[index ] == 0 ) return (void*)addr; + if (is_free) + { + // Mark the pages as allocated + for (uint32 i = 0; i < num_pages; i++) + { + page_allocation_status[index + i] = index; + } + + sys_createSharedObject(sharedVarName,required_size,isWritable,(void*)addr); + return (void*)addr; + } + } return NULL; } @@ -165,7 +199,7 @@ void* sget(int32 ownerEnvID, char *sharedVarName) { //TODO: [PROJECT'24.MS2 - #20] [4] SHARED MEMORY [USER SIDE] - sget() // Write your code here, remove the panic and write your code - panic("sget() is not implemented yet...!!"); + // panic("sget() is not implemented yet...!!"); return NULL; } From 5d5c017f2a13003ddd9b5ab5aee39d71b8124710 Mon Sep 17 00:00:00 2001 From: Apolo151 Date: Tue, 26 Nov 2024 01:17:09 +0200 Subject: [PATCH 3/6] smalloc 100% eval --- kern/mem/shared_memory_manager.c | 68 ++++++++++++++++++++------------ lib/uheap.c | 21 +++++++--- 2 files changed, 58 insertions(+), 31 deletions(-) diff --git a/kern/mem/shared_memory_manager.c b/kern/mem/shared_memory_manager.c index cd35021..63fede4 100644 --- a/kern/mem/shared_memory_manager.c +++ b/kern/mem/shared_memory_manager.c @@ -73,9 +73,10 @@ inline struct FrameInfo** create_frames_storage(int numOfFrames) return NULL; } - cprintf("numbers of frames:%d\n", numOfFrames); + //cprintf("numbers of frames:%d\n", numOfFrames); + //cprintf("size of frames info%d\n", (uint32)sizeof(struct FrameInfo*)); struct FrameInfo** FramesArr = (struct FrameInfo**)kmalloc(sizeof(char)*numOfFrames); - + // if allocation failed -> return NULL if(FramesArr == NULL) return NULL; @@ -145,33 +146,20 @@ struct Share* get_share(int32 ownerID, char* name) //Your Code is Here... acquire_spinlock(&AllShares.shareslock); - struct Share *desiredObject; - struct Share *currentOb = LIST_FIRST(&AllShares.shares_list); - int SListSize = LIST_SIZE(&AllShares.shares_list); - bool found = 0; + struct Share *desiredObject = NULL; + struct Share *currentOb = NULL; - // traverse list and find shared object - for(int i = 0; i < SListSize;i++) - { - if((currentOb->name) == name && (currentOb->ownerID) == ownerID) - { - found = 1; + LIST_FOREACH(currentOb, &(AllShares.shares_list)){ + if(strcmp((currentOb->name), name)==0 && (currentOb->ownerID) == ownerID){ + //cprintf("found obj"); desiredObject = currentOb; break; } - currentOb = LIST_NEXT(currentOb); } release_spinlock(&AllShares.shareslock); - if(found) - { - return desiredObject; - } - else - { - return NULL; - } + return desiredObject; } //========================= @@ -187,6 +175,8 @@ int createSharedObject(int32 ownerID, char* shareName, uint32 size, uint8 isWrit struct Env* myenv = get_cpu_proc(); //The calling environment struct Share *isObjectExist = get_share(ownerID,shareName); + //cprintf("Owner with ID %d want to create obj with name: %s\n", ownerID, shareName); + //cprintf("\n Object value: %x\n", isObjectExist); if(isObjectExist == NULL) { uint32 totalSpace = (uint32)virtual_address + size; @@ -212,12 +202,12 @@ int createSharedObject(int32 ownerID, char* shareName, uint32 size, uint8 isWrit new_object->framesStorage[frameIndex] = objectFrame; frameIndex++; } - cprintf("virtual_address%p , endOfObject:%p frameIndex:%d\n",virtual_address,endOfObject,frameIndex); + //cprintf("virtual_address%p , endOfObject:%p frameIndex:%d\n",virtual_address,endOfObject,frameIndex); //add the new object to the shared list - acquire_spinlock(&AllShares.shareslock); + acquire_spinlock(&(AllShares.shareslock)); LIST_INSERT_TAIL(&(AllShares.shares_list), new_object); - release_spinlock(&AllShares.shareslock); + release_spinlock(&(AllShares.shareslock)); return new_object->ID; } @@ -243,10 +233,38 @@ int getSharedObject(int32 ownerID, char* shareName, void* virtual_address) { //TODO: [PROJECT'24.MS2 - #21] [4] SHARED MEMORY [KERNEL SIDE] - getSharedObject() //COMMENT THE FOLLOWING LINE BEFORE START CODING - panic("getSharedObject is not implemented yet"); + //panic("getSharedObject is not implemented yet"); //Your Code is Here... struct Env* myenv = get_cpu_proc(); //The calling environment + + struct Share *requestedObject = get_share(ownerID,shareName); + if(requestedObject != NULL) + { + uint8 isWrit = requestedObject->isWritable; + int count = 0; + struct FrameInfo *sharedFrame; + uint32 VA = (uint32)virtual_address; + int numOfFrames = sizeof(requestedObject->framesStorage)/sizeof(requestedObject->framesStorage[0]); + while(count < numOfFrames) + { + sharedFrame = requestedObject->framesStorage[count]; + VA += (count * PAGE_SIZE); + //map each page to each shared frame with the permission isWritable + map_frame((myenv->env_page_directory),sharedFrame,VA,PERM_USER | isWrit); + count++; + } + + //update the references + requestedObject->references++; + return requestedObject->ID; + } + else + { + //return if the object is not exist + return E_SHARED_MEM_NOT_EXISTS; + } + } //==================================================================================// diff --git a/lib/uheap.c b/lib/uheap.c index 061244d..9ebac67 100644 --- a/lib/uheap.c +++ b/lib/uheap.c @@ -120,7 +120,7 @@ void free(void* virtual_address) // uint32 page_index = (va - myEnv->rlimit) / PAGE_SIZE; uint32 page_index = (va - USER_HEAP_START) / PAGE_SIZE; - + // Find how many pages were allocated for the given virtual address uint32 num_pages = 0; while (page_allocation_status[page_index + num_pages] == page_index) { @@ -133,15 +133,15 @@ void free(void* virtual_address) for (uint32 i = 0; i < num_pages; i++) { page_allocation_status[page_index + i] = 0; } - + // Call the system function to free the user memory and page file sys_free_user_mem(va, num_pages * PAGE_SIZE); - } + } } else { panic("Invalid address: Address is not allocated."); } - + } //================================= // [4] ALLOCATE SHARED VARIABLE: @@ -159,6 +159,7 @@ void* smalloc(char *sharedVarName, uint32 size, uint8 isWritable) // Page Allocator for larger allocations uint32 required_size = num_pages * PAGE_SIZE; // Total required size in bytes + // First-Fit Strategy for (uint32 addr = myEnv->rlimit+PAGE_SIZE; addr + required_size <= USER_HEAP_MAX - PAGE_SIZE; addr += PAGE_SIZE) { @@ -185,7 +186,12 @@ void* smalloc(char *sharedVarName, uint32 size, uint8 isWritable) page_allocation_status[index + i] = index; } - sys_createSharedObject(sharedVarName,required_size,isWritable,(void*)addr); + uint32 sharedObjId = sys_createSharedObject(sharedVarName,required_size,isWritable,(void*)addr); + if(sharedObjId == E_SHARED_MEM_EXISTS){ + cprintf("exists\n"); + return NULL; + } + return (void*)addr; } } @@ -200,7 +206,10 @@ void* sget(int32 ownerEnvID, char *sharedVarName) //TODO: [PROJECT'24.MS2 - #20] [4] SHARED MEMORY [USER SIDE] - sget() // Write your code here, remove the panic and write your code // panic("sget() is not implemented yet...!!"); - return NULL; + //return NULL; + + + } From 0864ee4acdc070abc60815ed2a27dd0f2d45018b Mon Sep 17 00:00:00 2001 From: Apolo151 Date: Tue, 26 Nov 2024 01:55:09 +0200 Subject: [PATCH 4/6] inital sget impl. --- kern/mem/shared_memory_manager.c | 12 ++-- lib/uheap.c | 120 +++++++++++++++++++++---------- 2 files changed, 86 insertions(+), 46 deletions(-) diff --git a/kern/mem/shared_memory_manager.c b/kern/mem/shared_memory_manager.c index 63fede4..74003dd 100644 --- a/kern/mem/shared_memory_manager.c +++ b/kern/mem/shared_memory_manager.c @@ -249,9 +249,9 @@ int getSharedObject(int32 ownerID, char* shareName, void* virtual_address) while(count < numOfFrames) { sharedFrame = requestedObject->framesStorage[count]; - VA += (count * PAGE_SIZE); + //VA += (count * PAGE_SIZE); //map each page to each shared frame with the permission isWritable - map_frame((myenv->env_page_directory),sharedFrame,VA,PERM_USER | isWrit); + map_frame((myenv->env_page_directory), sharedFrame, VA+(count*PAGE_SIZE), PERM_USER | isWrit); count++; } @@ -259,11 +259,9 @@ int getSharedObject(int32 ownerID, char* shareName, void* virtual_address) requestedObject->references++; return requestedObject->ID; } - else - { - //return if the object is not exist - return E_SHARED_MEM_NOT_EXISTS; - } + + //return if the object is does not exist + return E_SHARED_MEM_NOT_EXISTS; } diff --git a/lib/uheap.c b/lib/uheap.c index 9ebac67..a952d3f 100644 --- a/lib/uheap.c +++ b/lib/uheap.c @@ -155,46 +155,43 @@ void* smalloc(char *sharedVarName, uint32 size, uint8 isWritable) //TODO: [PROJECT'24.MS2 - #18] [4] SHARED MEMORY [USER SIDE] - smalloc() // Write your code here, remove the panic and write your code // panic("smalloc() is not implemented yet...!!"); - uint32 num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; // Round up to nearest page - // Page Allocator for larger allocations - - uint32 required_size = num_pages * PAGE_SIZE; // Total required size in bytes - - // First-Fit Strategy - for (uint32 addr = myEnv->rlimit+PAGE_SIZE; addr + required_size <= USER_HEAP_MAX - PAGE_SIZE; addr += PAGE_SIZE) - { - uint32 index = (addr - USER_HEAP_START) / PAGE_SIZE; - uint8 is_free = 1; + uint32 num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; // Round up to nearest page - - // // Check if all pages in the range are free - for (uint32 i = 0; i < num_pages; i++) - { - if (page_allocation_status[index + i] != 0) - { - is_free = 0; - break; - } - } - // cprintf("addr: %p , pagestatus[idx] %d\n", addr, page_allocation_status[index]); - // if(page_allocation_status[index ] == 0 ) return (void*)addr; - if (is_free) - { - // Mark the pages as allocated - for (uint32 i = 0; i < num_pages; i++) - { - page_allocation_status[index + i] = index; - } - - uint32 sharedObjId = sys_createSharedObject(sharedVarName,required_size,isWritable,(void*)addr); - if(sharedObjId == E_SHARED_MEM_EXISTS){ - cprintf("exists\n"); - return NULL; - } - - return (void*)addr; - } - } + // Page Allocator for larger allocations + uint32 required_size = num_pages * PAGE_SIZE; // Total required size in bytes + // First-Fit Strategy + for (uint32 addr = myEnv->rlimit+PAGE_SIZE; addr + required_size <= USER_HEAP_MAX - PAGE_SIZE; addr += PAGE_SIZE) + { + uint32 index = (addr - USER_HEAP_START) / PAGE_SIZE; + uint8 is_free = 1; + // // Check if all pages in the range are free + for (uint32 i = 0; i < num_pages; i++) + { + if (page_allocation_status[index + i] != 0) + { + is_free = 0; + break; + } + } + // cprintf("addr: %p , pagestatus[idx] %d\n", addr, page_allocation_status[index]); + // if(page_allocation_status[index ] == 0 ) return (void*)addr; + if (is_free) + { + // Mark the pages as allocated + for (uint32 i = 0; i < num_pages; i++) + { + page_allocation_status[index + i] = index; + } + + uint32 sharedObjId = sys_createSharedObject(sharedVarName,required_size,isWritable,(void*)addr); + if(sharedObjId == E_SHARED_MEM_EXISTS){ + cprintf("exists\n"); + return NULL; + } + + return (void*)addr; + } + } return NULL; } @@ -208,7 +205,52 @@ void* sget(int32 ownerEnvID, char *sharedVarName) // panic("sget() is not implemented yet...!!"); //return NULL; + // get obj size + uint32 size = sys_getSizeOfSharedObject(ownerEnvID, sharedVarName); + if(size == (uint32)NULL){ + return NULL; + } + // find space in current process virtual memory + uint32 num_pages = (size + PAGE_SIZE - 1) / PAGE_SIZE; // Round up to nearest page + // Page Allocator for larger allocations + uint32 required_size = num_pages * PAGE_SIZE; // Total required size in bytes + // First-Fit Strategy + for (uint32 addr = myEnv->rlimit+PAGE_SIZE; addr + required_size <= USER_HEAP_MAX - PAGE_SIZE; addr += PAGE_SIZE) + { + uint32 index = (addr - USER_HEAP_START) / PAGE_SIZE; + uint8 is_free = 1; + // // Check if all pages in the range are free + for (uint32 i = 0; i < num_pages; i++) + { + if (page_allocation_status[index + i] != 0) + { + is_free = 0; + break; + } + } + // cprintf("addr: %p , pagestatus[idx] %d\n", addr, page_allocation_status[index]); + // if(page_allocation_status[index ] == 0 ) return (void*)addr; + // found enough space in VM + if (is_free) + { + // Mark the pages as allocated + for (uint32 i = 0; i < num_pages; i++) + { + page_allocation_status[index + i] = index; + } + + uint32 sharedObjId = sys_getSharedObject(ownerEnvID, sharedVarName, (void*)addr); + if(sharedObjId == E_SHARED_MEM_NOT_EXISTS){ + return NULL; + } + + return (void*)addr; + } + } + + // If no space in vm + return NULL; } From 12c4aeab8dd28a2156cb3cf6d0c274c63220bf9c Mon Sep 17 00:00:00 2001 From: Apolo151 Date: Tue, 26 Nov 2024 02:23:29 +0200 Subject: [PATCH 5/6] shared memory mvp done -> all tests eval to 100% --- kern/mem/shared_memory_manager.c | 7 ++++--- lib/uheap.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kern/mem/shared_memory_manager.c b/kern/mem/shared_memory_manager.c index 74003dd..0f38b42 100644 --- a/kern/mem/shared_memory_manager.c +++ b/kern/mem/shared_memory_manager.c @@ -241,7 +241,9 @@ int getSharedObject(int32 ownerID, char* shareName, void* virtual_address) struct Share *requestedObject = get_share(ownerID,shareName); if(requestedObject != NULL) { - uint8 isWrit = requestedObject->isWritable; + uint8 isWrite = 0; + if(requestedObject->isWritable) + isWrite = PERM_WRITEABLE; int count = 0; struct FrameInfo *sharedFrame; uint32 VA = (uint32)virtual_address; @@ -249,9 +251,8 @@ int getSharedObject(int32 ownerID, char* shareName, void* virtual_address) while(count < numOfFrames) { sharedFrame = requestedObject->framesStorage[count]; - //VA += (count * PAGE_SIZE); //map each page to each shared frame with the permission isWritable - map_frame((myenv->env_page_directory), sharedFrame, VA+(count*PAGE_SIZE), PERM_USER | isWrit); + map_frame((myenv->env_page_directory), sharedFrame, VA+(count*PAGE_SIZE), PERM_USER | isWrite); count++; } diff --git a/lib/uheap.c b/lib/uheap.c index a952d3f..f05d8f1 100644 --- a/lib/uheap.c +++ b/lib/uheap.c @@ -185,7 +185,7 @@ void* smalloc(char *sharedVarName, uint32 size, uint8 isWritable) uint32 sharedObjId = sys_createSharedObject(sharedVarName,required_size,isWritable,(void*)addr); if(sharedObjId == E_SHARED_MEM_EXISTS){ - cprintf("exists\n"); + //cprintf("exists\n"); return NULL; } From 6aba29f15126f4809a27921fb360aa4c440bd4b1 Mon Sep 17 00:00:00 2001 From: Apolo151 Date: Tue, 26 Nov 2024 02:38:56 +0200 Subject: [PATCH 6/6] remove panic from createSharedObject --- kern/mem/shared_memory_manager.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kern/mem/shared_memory_manager.c b/kern/mem/shared_memory_manager.c index 0f38b42..bc985c4 100644 --- a/kern/mem/shared_memory_manager.c +++ b/kern/mem/shared_memory_manager.c @@ -194,7 +194,17 @@ int createSharedObject(int32 ownerID, char* shareName, uint32 size, uint8 isWrit int check = allocate_frame(&(objectFrame)); if(check == E_NO_MEM) { - panic("There is no enough memory!"); + //panic("There is no enough memory!"); + // free allocated frames + uint32 startVa = (uint32)virtual_address; + while(currentV >= startVa){ + frameIndex--; + currentV-=PAGE_SIZE; + new_object->framesStorage[frameIndex] = NULL; + unmap_frame((myenv->env_page_directory), currentV); + } + + return E_NO_SHARE; } //map each VA to frame and add the frame to framesStorage array @@ -261,7 +271,7 @@ int getSharedObject(int32 ownerID, char* shareName, void* virtual_address) return requestedObject->ID; } - //return if the object is does not exist + //return if the object does not exist return E_SHARED_MEM_NOT_EXISTS; }