aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/fs.c5
-rw-r--r--kernel/features/mm.c20
-rw-r--r--kernel/inc/mm.h2
3 files changed, 18 insertions, 9 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index c8ad317..c692aac 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -5,6 +5,7 @@
#include <fs.h>
#include <ide.h>
#include <mem.h>
+#include <mm.h>
#include <print.h>
#include <random.h>
#include <str.h>
@@ -240,11 +241,11 @@ s32 vfs_poll(const char **files)
if (!files)
return -1;
- for (const char **p = files; *p && **p; p++)
+ for (const char **p = files; memory_user_valid((u32)*p) && *p && **p; p++)
if (vfs_ready(*p))
return p - files;
- for (const char **p = files; *p && **p; p++)
+ for (const char **p = files; memory_user_valid((u32)*p) && *p && **p; p++)
vfs_wait(*p, (u32)vfs_poll);
return PROC_MAX_WAIT_IDS + 1;
diff --git a/kernel/features/mm.c b/kernel/features/mm.c
index 9eca438..875d752 100644
--- a/kernel/features/mm.c
+++ b/kernel/features/mm.c
@@ -9,7 +9,7 @@
#include <print.h>
static struct page_dir kernel_dir ALIGNED(PAGE_SIZE) = { 0 };
-static struct page_table kernel_tables[256] ALIGNED(PAGE_SIZE) = { 0 };
+static struct page_table kernel_tables[PAGE_KERNEL_COUNT] ALIGNED(PAGE_SIZE) = { 0 };
/**
* Lowlevel paging
@@ -233,8 +233,8 @@ struct memory_range virtual_alloc(struct page_dir *dir, struct memory_range pran
u32 vaddr = 0;
u32 size = 0;
- for (u32 i = (user ? 256 : 1) * PAGE_COUNT; i < (user ? PAGE_COUNT : 256) * PAGE_COUNT;
- i++) {
+ for (u32 i = (user ? PAGE_KERNEL_COUNT : 1) * PAGE_COUNT;
+ i < (user ? PAGE_COUNT : PAGE_KERNEL_COUNT) * PAGE_COUNT; i++) {
u32 addr = i * PAGE_SIZE;
if (!virtual_present(dir, addr)) {
if (size == 0)
@@ -284,7 +284,7 @@ struct page_dir *virtual_create_dir(void)
memset(dir, 0, sizeof(*dir));
- for (u32 i = 0; i < 256; i++) {
+ for (u32 i = 0; i < PAGE_KERNEL_COUNT; i++) {
union page_dir_entry *dir_entry = &dir->entries[i];
dir_entry->bits.present = 1;
@@ -300,7 +300,7 @@ void virtual_destroy_dir(struct page_dir *dir)
{
assert(dir != &kernel_dir);
- for (u32 i = 256; i < PAGE_COUNT; i++) {
+ for (u32 i = PAGE_KERNEL_COUNT; i < PAGE_COUNT; i++) {
union page_dir_entry *dir_entry = &dir->entries[i];
if (dir_entry->bits.present) {
struct page_table *table =
@@ -358,7 +358,7 @@ err:
void *memory_alloc_identity(struct page_dir *dir, u32 flags)
{
- for (u32 i = 1; i < 256 * PAGE_COUNT; i++) {
+ for (u32 i = 1; i < PAGE_KERNEL_COUNT * PAGE_COUNT; i++) {
struct memory_range range = memory_range(i * PAGE_SIZE, PAGE_SIZE);
if (!virtual_present(dir, range.base) && !physical_is_used(range)) {
@@ -411,6 +411,12 @@ void memory_backup_dir(struct page_dir **backup)
*backup = dir;
}
+// TODO: Check memory validity more often
+u8 memory_user_valid(u32 addr)
+{
+ return addr / PAGE_SIZE / PAGE_COUNT >= PAGE_KERNEL_COUNT;
+}
+
struct memory_range memory_range_from(u32 base, u32 size)
{
u32 align = PAGE_SIZE - base % PAGE_SIZE;
@@ -466,7 +472,7 @@ void memory_install(struct mem_info *mem_info, struct vid_info *vid_info)
}
}
- for (u32 i = 0; i < 256; i++) {
+ for (u32 i = 0; i < PAGE_KERNEL_COUNT; i++) {
union page_dir_entry *dir_entry = &kernel_dir.entries[i];
dir_entry->bits.present = 1;
dir_entry->bits.writable = 1;
diff --git a/kernel/inc/mm.h b/kernel/inc/mm.h
index d3e37f6..fa2ebd1 100644
--- a/kernel/inc/mm.h
+++ b/kernel/inc/mm.h
@@ -25,6 +25,7 @@ void physical_free(struct memory_range range);
#define PAGE_SIZE 0x1000
#define PAGE_COUNT 1024
+#define PAGE_KERNEL_COUNT 256
#define PAGE_ALIGN(x) ((x) + PAGE_SIZE - ((x) % PAGE_SIZE))
#define PAGE_ALIGNED(x) ((x) % PAGE_SIZE == 0)
#define PAGE_ALIGN_UP(x) (((x) % PAGE_SIZE == 0) ? (x) : (x) + PAGE_SIZE - ((x) % PAGE_SIZE))
@@ -100,6 +101,7 @@ void memory_map_identity(struct page_dir *dir, struct memory_range prange, u32 f
void memory_free(struct page_dir *dir, struct memory_range vrange);
void memory_switch_dir(struct page_dir *dir);
void memory_backup_dir(struct page_dir **backup);
+u8 memory_user_valid(u32 addr);
void memory_install(struct mem_info *mem_info, struct vid_info *vid_info);