From 2c0146348266498b7539fdc8d679ba24df3e6cac Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Wed, 13 May 2009 16:09:20 +0300 Subject: [PATCH] In FS0 filesystem image buffer was smaller than the memfs-defined maximum. - Now fs size is in sync with memfs max size. --- include/l4/macros.h | 1 + tasks/fs0/include/memfs/memfs.h | 2 +- tasks/fs0/src/bdev.c | 3 +- tasks/fs0/src/memfs/vnode.c | 1 - tasks/fs0/src/syscalls.c | 5 +--- tasks/mm0/include/file.h | 2 ++ tasks/mm0/src/execve.c | 49 ------------------------------- tasks/mm0/src/file.c | 51 +++++++++++++++++++++++++++++++-- tasks/mm0/src/lib/elf/elf.c | 9 +++--- tasks/test0/main.c | 2 +- tasks/test0/src/exectest.c | 7 ++++- 11 files changed, 68 insertions(+), 64 deletions(-) diff --git a/include/l4/macros.h b/include/l4/macros.h index 6da8907..ed41ed1 100644 --- a/include/l4/macros.h +++ b/include/l4/macros.h @@ -42,6 +42,7 @@ #define SZ_32K 0x8000 #define SZ_64K 0x10000 #define SZ_1MB 0x100000 +#define SZ_4MB (4*SZ_1MB) #define SZ_8MB (8*SZ_1MB) #define SZ_16MB (16*SZ_1MB) #define SZ_1K_BITS 10 diff --git a/tasks/fs0/include/memfs/memfs.h b/tasks/fs0/include/memfs/memfs.h index db97560..d7ac9ae 100644 --- a/tasks/fs0/include/memfs/memfs.h +++ b/tasks/fs0/include/memfs/memfs.h @@ -39,7 +39,7 @@ * These fixed filesystem limits make it much easier to implement * filesystem space allocation. */ -#define MEMFS_TOTAL_SIZE SZ_8MB +#define MEMFS_TOTAL_SIZE SZ_4MB #define MEMFS_TOTAL_INODES 128 #define MEMFS_TOTAL_BLOCKS 2000 #define MEMFS_FMAX_BLOCKS 40 diff --git a/tasks/fs0/src/bdev.c b/tasks/fs0/src/bdev.c index f4fbcfa..1f69162 100644 --- a/tasks/fs0/src/bdev.c +++ b/tasks/fs0/src/bdev.c @@ -2,11 +2,12 @@ * This is just to allocate some memory as a block device. */ #include +#include extern char _start_bdev[]; extern char _end_bdev[]; -__attribute__((section(".data.memfs"))) char blockdevice[SZ_1MB*2]; +__attribute__((section(".data.memfs"))) char blockdevice[MEMFS_TOTAL_SIZE]; void *vfs_rootdev_open(void) { diff --git a/tasks/fs0/src/memfs/vnode.c b/tasks/fs0/src/memfs/vnode.c index 61220a0..5581ac6 100644 --- a/tasks/fs0/src/memfs/vnode.c +++ b/tasks/fs0/src/memfs/vnode.c @@ -411,7 +411,6 @@ int memfs_vnode_filldir(void *userbuf, struct vnode *v, int count) return 0; } - struct vnode_ops memfs_vnode_operations = { .readdir = memfs_vnode_readdir, .filldir = memfs_vnode_filldir, diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index a742906..d161978 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -36,8 +36,7 @@ int pager_sys_open(struct tcb *pager, l4id_t opener, int fd) struct tcb *task; struct vnode *v; - // printf("%s/%s\n", __TASKNAME__, __FUNCTION__); - // + //printf("%s/%s\n", __TASKNAME__, __FUNCTION__); if (pager->tid != PAGER_TID) return -EINVAL; @@ -76,8 +75,6 @@ int pager_open_bypath(struct tcb *pager, char *pathname) if (pager->tid != PAGER_TID) return -EINVAL; - // printf("%s/%s\n", __TASKNAME__, __FUNCTION__); - /* Parse path data */ if (IS_ERR(pdata = pathdata_parse(pathname, alloca(strlen(pathname) + 1), diff --git a/tasks/mm0/include/file.h b/tasks/mm0/include/file.h index 077da84..115ed56 100644 --- a/tasks/mm0/include/file.h +++ b/tasks/mm0/include/file.h @@ -17,6 +17,8 @@ int sys_close(struct tcb *sender, int fd); int sys_fsync(struct tcb *sender, int fd); int file_open(struct tcb *opener, int fd); +int vfs_open_bypath(const char *pathname, unsigned long *vnum, unsigned long *length); + struct vm_file *do_open2(struct tcb *task, int fd, unsigned long vnum, unsigned long length); int flush_file_pages(struct vm_file *f); int read_file_pages(struct vm_file *vmfile, unsigned long pfn_start, diff --git a/tasks/mm0/src/execve.c b/tasks/mm0/src/execve.c index ab8ea76..30a8163 100644 --- a/tasks/mm0/src/execve.c +++ b/tasks/mm0/src/execve.c @@ -20,55 +20,6 @@ #include #include -/* - * Different from vfs_open(), which validates an already opened - * file descriptor, this call opens a new vfs file by the pager - * using the given path. The vnum handle and file length is returned - * since the pager uses this information to access file pages. - */ -int vfs_open_bypath(const char *pathname, unsigned long *vnum, unsigned long *length) -{ - int err = 0; - struct tcb *vfs; - - // printf("%s/%s\n", __TASKNAME__, __FUNCTION__); - - if (!(vfs = find_task(VFS_TID))) - return -ESRCH; - - /* - * Copy string to vfs shared page. - * - * FIXME: There's a chance we're overwriting other tasks' - * ipc information that is on the vfs shared page. - */ - strcpy(vfs->shared_page, pathname); - - l4_save_ipcregs(); - - write_mr(L4SYS_ARG0, (unsigned long)vfs->shared_page); - - if ((err = l4_sendrecv(VFS_TID, VFS_TID, - L4_IPC_TAG_PAGER_OPEN_BYPATH)) < 0) { - printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); - goto out; - } - - /* Check if syscall was successful */ - if ((err = l4_get_retval()) < 0) { - printf("%s: VFS open error: %d.\n", - __FUNCTION__, err); - goto out; - } - - /* Read file information */ - *vnum = read_mr(L4SYS_ARG0); - *length = read_mr(L4SYS_ARG1); - -out: - l4_restore_ipcregs(); - return err; -} /* * Probes and parses the low-level executable file format and creates a diff --git a/tasks/mm0/src/file.c b/tasks/mm0/src/file.c index ff89890..d92ebf8 100644 --- a/tasks/mm0/src/file.c +++ b/tasks/mm0/src/file.c @@ -84,6 +84,55 @@ out: return err; } +/* + * Different from vfs_open(), which validates an already opened + * file descriptor, this call opens a new vfs file by the pager + * using the given path. The vnum handle and file length is returned + * since the pager uses this information to access file pages. + */ +int vfs_open_bypath(const char *pathname, unsigned long *vnum, unsigned long *length) +{ + int err = 0; + struct tcb *vfs; + + // printf("%s/%s\n", __TASKNAME__, __FUNCTION__); + + if (!(vfs = find_task(VFS_TID))) + return -ESRCH; + + /* + * Copy string to vfs shared page. + * + * FIXME: There's a chance we're overwriting other tasks' + * ipc information that is on the vfs shared page. + */ + strcpy(vfs->shared_page + 0x200, pathname); + + l4_save_ipcregs(); + + write_mr(L4SYS_ARG0, (unsigned long)vfs->shared_page + 0x200); + + if ((err = l4_sendrecv(VFS_TID, VFS_TID, + L4_IPC_TAG_PAGER_OPEN_BYPATH)) < 0) { + printf("%s: L4 IPC Error: %d.\n", __FUNCTION__, err); + goto out; + } + + /* Check if syscall was successful */ + if ((err = l4_get_retval()) < 0) { + printf("%s: VFS open error: %d.\n", + __FUNCTION__, err); + goto out; + } + + /* Read file information */ + *vnum = read_mr(L4SYS_ARG0); + *length = read_mr(L4SYS_ARG1); + +out: + l4_restore_ipcregs(); + return err; +} /* * When a task does a read/write/mmap request on a file, if @@ -95,8 +144,6 @@ int vfs_open(l4id_t opener, int fd, unsigned long *vnum, unsigned long *length) { int err = 0; - // printf("%s/%s\n", __TASKNAME__, __FUNCTION__); - l4_save_ipcregs(); write_mr(L4SYS_ARG0, opener); diff --git a/tasks/mm0/src/lib/elf/elf.c b/tasks/mm0/src/lib/elf/elf.c index 168b97c..ea805c3 100644 --- a/tasks/mm0/src/lib/elf/elf.c +++ b/tasks/mm0/src/lib/elf/elf.c @@ -97,11 +97,12 @@ int elf_mark_segments(struct elf_section_header *sect_header, int nsections, "bss segment in ELF file.\n", __FUNCTION__); } - /* Data and text are less than page apart */ - if ((task->data_start - task->text_start) < PAGE_SIZE) { + /* Data and text are less than page apart and unaligned */ + if ((task->data_start - task->text_end) < PAGE_SIZE && + !is_page_aligned(task->text_end)) { printf("%s: Error: Distance between data and text" - " sections are less than page size (4K)\n", - __FUNCTION__); + " sections are less than page size (%d bytes)\n", + __FUNCTION__, PAGE_SIZE); return -ENOEXEC; } diff --git a/tasks/test0/main.c b/tasks/test0/main.c index fd34ac1..0563d75 100644 --- a/tasks/test0/main.c +++ b/tasks/test0/main.c @@ -47,7 +47,7 @@ void main(void) clonetest(); - // exectest(); + exectest(); while (1) wait_pager(0); diff --git a/tasks/test0/src/exectest.c b/tasks/test0/src/exectest.c index 34de4cc..5bbb74d 100644 --- a/tasks/test0/src/exectest.c +++ b/tasks/test0/src/exectest.c @@ -21,14 +21,19 @@ int exectest(void) unsigned long size = _end_test1 - _start_test1; int left, cnt; char *argv[5]; + char filename[128]; + + memset(filename, 0, 128); + sprintf(filename, "/home/bahadir/execfile%d.txt", getpid()); /* First create a new file and write the executable data to that file */ - if ((fd = open("/home/bahadir/test1.axf", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) { + if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) { test_printf("OPEN: %d\n", errno); goto out_err; } left = size; + printf("Writing %d bytes to %s\n", left, filename); while (left != 0) { if ((cnt = write(fd, exec_start, left)) < 0) goto out_err;