Commit 89c9c8c1 authored by Léo Grange's avatar Léo Grange

better handling of memory areas duplication

parent 4a8098db
......@@ -18,7 +18,8 @@ const struct file_operations smemfs_file_operations = {
const struct mem_area_ops smemfs_mem_ops = {
.area_pagefault = smemfs_area_pagefault,
.area_release = smemfs_area_release
.area_release = smemfs_area_release,
.area_duplicate = smemfs_area_duplicate
};
......@@ -204,3 +205,10 @@ void smemfs_area_release(struct mem_area *area) {
// release the file, by closing it at vfs level?
vfs_close(area->file.filep);
}
int smemfs_area_duplicate(struct mem_area *orig, struct mem_area *copy) {
copy->file.filep->count++;
return 0;
}
......@@ -32,5 +32,6 @@ int smemfs_area_resize(struct mem_area *area, const struct mem_area *new_area);
void smemfs_area_release(struct mem_area *area);
int smemfs_area_duplicate(struct mem_area *orig, struct mem_area *copy);
#endif //_FS_SMEMFS_FILE_H
......@@ -95,6 +95,11 @@ struct mem_area_ops {
* Called when the area is no longer used.
*/
void (*area_release)(struct mem_area *area);
/**
* Called when the area is duplicated, like during a fork.
*/
int (*area_duplicate)(struct mem_area *orig, struct mem_area *copy);
};
......@@ -181,6 +186,20 @@ extern inline void mem_area_release(struct mem_area *area) {
int mem_area_resize(struct mem_area *area, size_t new_size, struct process *proc);
/**
* Duplicate an area.
*/
extern inline struct mem_area *mem_area_clone(struct mem_area *area) {
struct mem_area *ret = mem_area_alloc();
if(ret != NULL) {
*ret = *area;
if(area->ops != NULL && area->ops->area_duplicate != NULL)
area->ops->area_duplicate(area, ret);
}
return ret;
}
/**
* Helper for filesystem implementations, to handle MEM_AREA_PARTIAL.
* Check for a given page to fill with 0 when needed, and return the number of
......
......@@ -279,15 +279,14 @@ pid_t sys_fork() {
// copy each memory area
struct list_head *area_list;
newproc->heap_area = NULL;
list_for_each(area_list, & cur->mem_areas) {
// duplicate it
// FIXME file should be duplicated? Or a counter need to be used?
struct mem_area *old_area = container_of(area_list, struct mem_area, list);
struct mem_area *new_area;
new_area = mem_area_alloc();
*new_area = *old_area;
new_area = mem_area_clone(old_area);
mem_area_insert(newproc, new_area);
// check for heap, and translate to corresponding area
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment