createvirtualspace.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002 The UbixOS Project
00003  All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are
00006 permitted provided that the following conditions are met:
00007 
00008 Redistributions of source code must retain the above copyright notice, this list of
00009 conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010 form must reproduce the above copyright notice, this list of conditions, the following
00011 disclaimer and the list of authors in the documentation and/or other materials provided
00012 with the distribution. Neither the name of the UbixOS Project nor the names of its
00013 contributors may be used to endorse or promote products derived from this software
00014 without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021 OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023 TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Log: createvirtualspace_8c-source.html,v $
00026  Revision 1.7  2006/12/15 17:47:04  reddawg
00026  Updates
00026 
00027  Revision 1.1.1.1  2006/06/01 12:46:13  reddawg
00028  ubix2
00029 
00030  Revision 1.2  2005/10/12 00:13:38  reddawg
00031  Removed
00032 
00033  Revision 1.1.1.1  2005/09/26 17:24:50  reddawg
00034  no message
00035 
00036  Revision 1.2  2004/07/28 15:05:43  reddawg
00037  Major:
00038    Pages now have strict security enforcement.
00039    Many null dereferences have been resolved.
00040    When apps loaded permissions set for pages rw and ro
00041 
00042  Revision 1.1.1.1  2004/04/15 12:06:51  reddawg
00043  UbixOS v1.0
00044 
00045  Revision 1.8  2004/04/13 16:36:34  reddawg
00046  Changed our copyright, it is all now under a BSD-Style license
00047 
00048 
00049 
00050  $Id: createvirtualspace_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
00051 
00052 *****************************************************************************************/
00053 
00054 #include <vmm/vmm.h>
00055 
00056 
00057 /************************************************************************
00058 
00059 Function: void *vmmCreateVirtualSpace(pid_t);
00060 Description: Creates A Virtual Space For A New Task
00061 Notes:
00062 
00063 07/30/02 - This Is Going To Create A New VM Space However Its Going To
00064            Share The Same Top 1GB Space With The Kernels VM And Lower
00065            1MB Of VM Space With The Kernel
00066 
00067 07/30/02 - Note This Is Going To Get The Top 1Gig And Lower 1MB Region
00068            From The Currently Loaded Page Directory This Is Safe Because
00069            All VM Spaces Will Share These Regions
00070 
00071 07/30/02 - Note I Realized A Mistake The First Page Table Will Need To Be
00072            A Copy But The Page Tables For The Top 1GB Will Not Reason For
00073            This Is That We Just Share The First 1MB In The First Page Table
00074            So We Will Just Share Physical Pages.
00075 
00076 08/02/02 - Added Passing Of pid_t pid For Better Tracking Of Who Has Which
00077            Set Of Pages
00078 
00079 ************************************************************************/
00080 void           *
00081 vmmCreateVirtualSpace(pid_t pid)
00082 {
00083   void           *newPageDirectoryAddress = 0x0;
00084   uInt32         *parentPageDirectory = 0x0, *newPageDirectory = 0x0;
00085   uInt32         *parentPageTable = 0x0, *newPageTable = 0x0;
00086   int             x = 0;
00087 
00088   /* Set Address Of Parent Page Directory */
00089   parentPageDirectory = (uInt32 *) parentPageDirAddr;
00090   /* Allocate A New Page For The New Page Directory */
00091   newPageDirectory = (uInt32 *) vmmGetFreePage(pid);
00092   /* Set newPageDirectoryAddress To The Newly Created Page Directories Page */
00093   newPageDirectoryAddress = (void *)vmm_getPhysicalAddr((uInt32) newPageDirectory);
00094   /* First Set Up A Flushed Page Directory */
00095   for (x = 0; x < pageEntries; x++) {
00096     (uInt32) newPageDirectory[x] = (uInt32) 0x0;
00097   }
00098   /* Map The Top 1GB Region Of The VM Space */
00099   for (x = 768; x < pageEntries; x++) {
00100     newPageDirectory[x] = parentPageDirectory[x];
00101   }
00102   /*
00103    * Allocate A New Page For The The First Page Table Where We Will Map The
00104    * Lower Region
00105    */
00106   newPageTable = (uInt32 *) vmmGetFreePage(pid);
00107   /* Flush The Page From Garbage In Memory */
00108   for (x = 0; x < pageEntries; x++) {
00109     (uInt32) newPageTable[x] = (uInt32) 0x0;
00110   }
00111   /* Map This Into The Page Directory */
00112   newPageDirectory[0] = (vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT);
00113   /* Set Address Of Parents Page Table */
00114   parentPageTable = (uInt32 *) tablesBaseAddress;
00115   /* Map The First 1MB Worth Of Pages */
00116   for (x = 0; x < (pageEntries / 4); x++) {
00117     newPageTable[x] = parentPageTable[x];
00118   }
00119   /* Set Virtual Mapping For Page Directory */
00120   newPageTable[256] = (vmm_getPhysicalAddr((uInt32) newPageDirectory) | PAGE_DEFAULT);
00121 
00122   /*
00123    * Now The Fun Stuff Build The Initial Virtual Page Space So We Don't Have
00124    * To Worry About Mapping Them In Later How Ever I'm Concerned This May
00125    * Become A Security Issue
00126    */
00127   /* First Lets Unmap The Previously Allocated Page Table */
00128   vmmUnmapPage((uInt32) newPageTable, 1);
00129   /* Allocate A New Page Table */
00130   newPageTable = (uInt32 *) vmmGetFreePage(pid);
00131   /* First Set Our Page Directory To Contain This */
00132   newPageDirectory[767] = vmm_getPhysicalAddr((uInt32) newPageTable) | PAGE_DEFAULT;
00133   /* Now Lets Build The Page Table */
00134   for (x = 0; x < pageEntries; x++) {
00135     newPageTable[x] = newPageDirectory[x];
00136   }
00137   /* Now We Are Done So Lets Unmap This Page */
00138   vmmUnmapPage((uInt32) newPageTable, 1);
00139   /* Now We Are Done With The Page Directory So Lets Unmap That Too */
00140   vmmUnmapPage((uInt32) newPageDirectory, 1);
00141   /* Return Physical Address Of Page Directory */
00142   return (newPageDirectoryAddress);
00143 }
00144 
00145 /***
00146  END
00147  ***/
00148 

Generated on Fri Dec 15 11:18:55 2006 for UbixOS V2 by  doxygen 1.4.7