add a VMA list, which holds each virtual memory region of a user-level process
This commit is contained in:
parent
a178734377
commit
3aaa2406de
3 changed files with 152 additions and 1 deletions
50
include/metalsvm/vma.h
Normal file
50
include/metalsvm/vma.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2011 Stefan Lankes, Chair for Operating Systems,
|
||||
* RWTH Aachen University
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#ifndef __VMA_H__
|
||||
#define __VMA_H__
|
||||
|
||||
#include <metalsvm/stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define VMA_READ 0x01
|
||||
#define VMA_WRITE 0x02
|
||||
#define VMA_EXECUTE 0x04
|
||||
#define VMA_CACHEABLE 0x08
|
||||
|
||||
struct vma;
|
||||
|
||||
typedef struct vma {
|
||||
size_t start, end;
|
||||
uint32_t type;
|
||||
struct vma* next;
|
||||
struct vma* prev;
|
||||
} vma_t;
|
||||
|
||||
int vma_add(struct task* task, size_t start, size_t end, uint32_t type);
|
||||
int vma_dump(struct task* task);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
C_source := memory.c
|
||||
C_source := memory.c vma.c
|
||||
MODULE := mm
|
||||
|
||||
include $(TOPDIR)/Makefile.inc
|
||||
|
|
101
mm/vma.c
Normal file
101
mm/vma.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright 2011 Stefan Lankes, Chair for Operating Systems,
|
||||
* RWTH Aachen University
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#include <metalsvm/stdlib.h>
|
||||
#include <metalsvm/stdio.h>
|
||||
#include <metalsvm/tasks_types.h>
|
||||
#include <metalsvm/spinlock.h>
|
||||
#include <metalsvm/vma.h>
|
||||
#include <metalsvm/errno.h>
|
||||
|
||||
/*
|
||||
* add a new virtual memory region to the list of VMAs
|
||||
*/
|
||||
int vma_add(task_t* task, size_t start, size_t end, uint32_t type)
|
||||
{
|
||||
vma_t* new_vma;
|
||||
|
||||
if (BUILTIN_EXPECT(!task || start > end, 0))
|
||||
return -EINVAL;
|
||||
|
||||
new_vma = kmalloc(sizeof(new_vma));
|
||||
if (!new_vma)
|
||||
return -ENOMEM;
|
||||
|
||||
spinlock_lock(&task->vma_lock);
|
||||
|
||||
new_vma->start = start;
|
||||
new_vma->end = end;
|
||||
new_vma->type = type;
|
||||
|
||||
if (!(task->vma_list)) {
|
||||
new_vma->next = new_vma->prev = NULL;
|
||||
task->vma_list = new_vma;
|
||||
} else {
|
||||
vma_t* tmp = task->vma_list;
|
||||
|
||||
while (tmp->next && tmp->start < start)
|
||||
tmp = tmp->next;
|
||||
|
||||
new_vma->next = tmp->next;
|
||||
new_vma->prev = tmp;
|
||||
tmp->next = new_vma;
|
||||
}
|
||||
|
||||
spinlock_unlock(&task->vma_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vma_dump(task_t* task)
|
||||
{
|
||||
vma_t* tmp;
|
||||
|
||||
if (BUILTIN_EXPECT(!task, 0))
|
||||
return -EINVAL;
|
||||
|
||||
spinlock_lock(&task->vma_lock);
|
||||
|
||||
tmp = task->vma_list;
|
||||
while (tmp) {
|
||||
kprintf("%8x - %8x: ", tmp->start, tmp->end);
|
||||
|
||||
if (tmp->type & VMA_READ)
|
||||
kputs("r");
|
||||
else
|
||||
kputs("-");
|
||||
|
||||
if (tmp->type & VMA_WRITE)
|
||||
kputs("w");
|
||||
else
|
||||
kputs("-");
|
||||
|
||||
if (tmp->type & VMA_EXECUTE)
|
||||
kputs("x");
|
||||
else
|
||||
kputs("-");
|
||||
kputs("\n");
|
||||
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
spinlock_unlock(&task->vma_lock);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue