⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uservm.c

📁 GEEKOS是一个免费的操作系统内核
💻 C
字号:
/* * Paging-based user mode implementation * Copyright (c) 2003,2004 David H. Hovemeyer <daveho@cs.umd.edu> * $Revision: 1.50 $ *  * This is free software.  You are permitted to use, * redistribute, and modify it as specified in the file "COPYING". */#include <geekos/int.h>#include <geekos/mem.h>#include <geekos/paging.h>#include <geekos/malloc.h>#include <geekos/string.h>#include <geekos/argblock.h>#include <geekos/kthread.h>#include <geekos/range.h>#include <geekos/vfs.h>#include <geekos/user.h>/* ---------------------------------------------------------------------- * Private functions * ---------------------------------------------------------------------- */// TODO: Add private functions/* ---------------------------------------------------------------------- * Public functions * ---------------------------------------------------------------------- *//* * Destroy a User_Context object, including all memory * and other resources allocated within it. */void Destroy_User_Context(struct User_Context* context){    /*     * Hints:     * - Free all pages, page tables, and page directory for     *   the process (interrupts must be disabled while you do this,     *   otherwise those pages could be stolen by other processes)     * - Free semaphores, files, and other resources used     *   by the process     */    TODO("Destroy User_Context data structure after process exits");}/* * Load a user executable into memory by creating a User_Context * data structure. * Params: * exeFileData - a buffer containing the executable to load * exeFileLength - number of bytes in exeFileData * exeFormat - parsed ELF segment information describing how to *   load the executable's text and data segments, and the *   code entry point address * command - string containing the complete command to be executed: *   this should be used to create the argument block for the *   process * pUserContext - reference to the pointer where the User_Context *   should be stored * * Returns: *   0 if successful, or an error code (< 0) if unsuccessful */int Load_User_Program(char *exeFileData, ulong_t exeFileLength,    struct Exe_Format *exeFormat, const char *command,    struct User_Context **pUserContext){    /*     * Hints:     * - This will be similar to the same function in userseg.c     * - Determine space requirements for code, data, argument block,     *   and stack     * - Allocate pages for above, map them into user address     *   space (allocating page directory and page tables as needed)     * - Fill in initial stack pointer, argument block address,     *   and code entry point fields in User_Context     */    TODO("Load user program into address space");}/* * Copy data from user buffer into kernel buffer. * Returns true if successful, false otherwise. */bool Copy_From_User(void* destInKernel, ulong_t srcInUser, ulong_t numBytes){    /*     * Hints:     * - Make sure that user page is part of a valid region     *   of memory     * - Remember that you need to add 0x80000000 to user addresses     *   to convert them to kernel addresses, because of how the     *   user code and data segments are defined     * - User pages may need to be paged in from disk before being accessed.     * - Before you touch (read or write) any data in a user     *   page, **disable the PAGE_PAGEABLE bit**.     *     * Be very careful with race conditions in reading a page from disk.     * Kernel code must always assume that if the struct Page for     * a page of memory has the PAGE_PAGEABLE bit set,     * IT CAN BE STOLEN AT ANY TIME.  The only exception is if     * interrupts are disabled; because no other process can run,     * the page is guaranteed not to be stolen.     */    TODO("Copy user data to kernel buffer");}/* * Copy data from kernel buffer into user buffer. * Returns true if successful, false otherwise. */bool Copy_To_User(ulong_t destInUser, void* srcInKernel, ulong_t numBytes){    /*     * Hints:     * - Same as for Copy_From_User()     * - Also, make sure the memory is mapped into the user     *   address space with write permission enabled     */    TODO("Copy kernel data to user buffer");}/* * Switch to user address space. */void Switch_To_Address_Space(struct User_Context *userContext){    /*     * - If you are still using an LDT to define your user code and data     *   segments, switch to the process's LDT     * -      */    TODO("Switch_To_Address_Space() using paging");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -