mirror of
https://github.com/drasko/codezero.git
synced 2026-09-27 15:50:22 +02:00
Added MAP_GROWSDOWN feature to do_mmap. Fixed sys_mmap return.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#define MAP_FIXED 0x10
|
#define MAP_FIXED 0x10
|
||||||
#define MAP_SHARED 0x01
|
#define MAP_SHARED 0x01
|
||||||
#define MAP_PRIVATE 0x02
|
#define MAP_PRIVATE 0x02
|
||||||
|
#define MAP_GROWSDOWN 0x00100
|
||||||
|
|
||||||
struct vm_area *vma_new(unsigned long pfn_start, unsigned long npages,
|
struct vm_area *vma_new(unsigned long pfn_start, unsigned long npages,
|
||||||
unsigned int flags, unsigned long file_offset);
|
unsigned int flags, unsigned long file_offset);
|
||||||
|
|||||||
@@ -36,8 +36,11 @@
|
|||||||
#define VMA_PRIVATE (1 << 6)
|
#define VMA_PRIVATE (1 << 6)
|
||||||
/* For wired pages */
|
/* For wired pages */
|
||||||
#define VMA_FIXED (1 << 7)
|
#define VMA_FIXED (1 << 7)
|
||||||
|
/* For stack, where mmap returns end address */
|
||||||
|
#define VMA_GROWSDOWN (1 << 8)
|
||||||
|
|
||||||
/* Set when the page is dirty in cache but not written to disk */
|
/* Set when the page is dirty in cache but not written to disk */
|
||||||
#define VM_DIRTY (1 << 8)
|
#define VM_DIRTY (1 << 9)
|
||||||
|
|
||||||
/* Defines the type of file. A device file? Regular file? One used at boot? */
|
/* Defines the type of file. A device file? Regular file? One used at boot? */
|
||||||
enum VM_FILE_TYPE {
|
enum VM_FILE_TYPE {
|
||||||
|
|||||||
+5
-3
@@ -20,6 +20,7 @@
|
|||||||
#include <file.h>
|
#include <file.h>
|
||||||
#include <shm.h>
|
#include <shm.h>
|
||||||
#include <utcb.h>
|
#include <utcb.h>
|
||||||
|
#include <mmap.h>
|
||||||
|
|
||||||
void handle_requests(void)
|
void handle_requests(void)
|
||||||
{
|
{
|
||||||
@@ -153,6 +154,7 @@ int self_spawn(void)
|
|||||||
{
|
{
|
||||||
struct task_ids ids;
|
struct task_ids ids;
|
||||||
struct tcb *self, *self_child;
|
struct tcb *self, *self_child;
|
||||||
|
// void *stack;
|
||||||
|
|
||||||
BUG_ON(!(self = find_task(self_tid())));
|
BUG_ON(!(self = find_task(self_tid())));
|
||||||
|
|
||||||
@@ -164,9 +166,6 @@ int self_spawn(void)
|
|||||||
self_child = task_create(self, &ids, THREAD_CREATE_SAMESPC,
|
self_child = task_create(self, &ids, THREAD_CREATE_SAMESPC,
|
||||||
TCB_SHARED_VM | TCB_SHARED_FILES);
|
TCB_SHARED_VM | TCB_SHARED_FILES);
|
||||||
|
|
||||||
/* Copy self tcb to child. TODO: ??? Not sure about this */
|
|
||||||
copy_tcb(self_child, self, TCB_SHARED_VM | TCB_SHARED_FILES);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new utcb. Every pager thread will
|
* Create a new utcb. Every pager thread will
|
||||||
* need its own utcb to answer calls.
|
* need its own utcb to answer calls.
|
||||||
@@ -180,6 +179,9 @@ int self_spawn(void)
|
|||||||
* TODO: Set up a child stack by mmapping an anonymous
|
* TODO: Set up a child stack by mmapping an anonymous
|
||||||
* region of mmap's choice. TODO: Time to add MAP_GROWSDOWN ???
|
* region of mmap's choice. TODO: Time to add MAP_GROWSDOWN ???
|
||||||
*/
|
*/
|
||||||
|
if (do_mmap(0, 0, self, 0,
|
||||||
|
VM_READ | VM_WRITE | VMA_ANONYMOUS | VMA_PRIVATE, 1) < 0)
|
||||||
|
BUG();
|
||||||
|
|
||||||
/* TODO: Notify vfs ??? */
|
/* TODO: Notify vfs ??? */
|
||||||
|
|
||||||
|
|||||||
+14
-6
@@ -11,7 +11,7 @@
|
|||||||
#include <mmap.h>
|
#include <mmap.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
#include <l4lib/arch/syscalls.h>
|
#include <l4lib/arch/syscalls.h>
|
||||||
|
#include <l4lib/arch/syslib.h>
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* TODO: This is to be implemented when fs0 is ready. */
|
/* TODO: This is to be implemented when fs0 is ready. */
|
||||||
@@ -568,7 +568,14 @@ int do_mmap(struct vm_file *mapfile, unsigned long file_offset,
|
|||||||
map_address, map_address + npages * PAGE_SIZE);
|
map_address, map_address + npages * PAGE_SIZE);
|
||||||
task_add_vma(task, new);
|
task_add_vma(task, new);
|
||||||
|
|
||||||
return 0;
|
/*
|
||||||
|
* If area is going to be used going downwards, (i.e. as a stack)
|
||||||
|
* we return the *end* of the area as the start address.
|
||||||
|
*/
|
||||||
|
if (flags & VMA_GROWSDOWN)
|
||||||
|
map_address += npages;
|
||||||
|
|
||||||
|
return map_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mmap system call implementation */
|
/* mmap system call implementation */
|
||||||
@@ -580,7 +587,6 @@ int sys_mmap(l4id_t sender, void *start, size_t length, int prot,
|
|||||||
struct vm_file *file = 0;
|
struct vm_file *file = 0;
|
||||||
unsigned int vmflags = 0;
|
unsigned int vmflags = 0;
|
||||||
struct tcb *task;
|
struct tcb *task;
|
||||||
int err;
|
|
||||||
|
|
||||||
BUG_ON(!(task = find_task(sender)));
|
BUG_ON(!(task = find_task(sender)));
|
||||||
|
|
||||||
@@ -619,6 +625,9 @@ int sys_mmap(l4id_t sender, void *start, size_t length, int prot,
|
|||||||
else /* This also means COW, if writeable and anonymous */
|
else /* This also means COW, if writeable and anonymous */
|
||||||
vmflags |= VMA_SHARED;
|
vmflags |= VMA_SHARED;
|
||||||
|
|
||||||
|
if (flags & MAP_GROWSDOWN)
|
||||||
|
vmflags |= VMA_GROWSDOWN;
|
||||||
|
|
||||||
if (prot & PROT_READ)
|
if (prot & PROT_READ)
|
||||||
vmflags |= VM_READ;
|
vmflags |= VM_READ;
|
||||||
if (prot & PROT_WRITE)
|
if (prot & PROT_WRITE)
|
||||||
@@ -626,10 +635,9 @@ int sys_mmap(l4id_t sender, void *start, size_t length, int prot,
|
|||||||
if (prot & PROT_EXEC)
|
if (prot & PROT_EXEC)
|
||||||
vmflags |= VM_EXEC;
|
vmflags |= VM_EXEC;
|
||||||
|
|
||||||
if ((err = do_mmap(file, __pfn_to_addr(pfn), task,
|
base = do_mmap(file, __pfn_to_addr(pfn), task, base, vmflags, npages);
|
||||||
base, vmflags, npages)) < 0)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
|
l4_ipc_return(base);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user