ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

execmem.c
Go to the documentation of this file.
00001 /*
00002  * Mesa 3-D graphics library
00003  * Version:  6.5
00004  *
00005  * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a
00008  * copy of this software and associated documentation files (the "Software"),
00009  * to deal in the Software without restriction, including without limitation
00010  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011  * and/or sell copies of the Software, and to permit persons to whom the
00012  * Software is furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included
00015  * in all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00020  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00021  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00022  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00023  */
00024 
00025 
00034 #include "imports.h"
00035 #include "glapi/glthread.h"
00036 
00037 
00038 
00039 #if defined(__linux__) || defined(__OpenBSD__) || defined(_NetBSD__) || defined(__sun)
00040 
00041 /*
00042  * Allocate a large block of memory which can hold code then dole it out
00043  * in pieces by means of the generic memory manager code.
00044 */
00045 
00046 #include <unistd.h>
00047 #include <sys/mman.h>
00048 #include "mm.h"
00049 
00050 #ifdef MESA_SELINUX
00051 #include <selinux/selinux.h>
00052 #endif
00053 
00054 
00055 #ifndef MAP_ANONYMOUS
00056 #define MAP_ANONYMOUS MAP_ANON
00057 #endif
00058 
00059 
00060 #define EXEC_HEAP_SIZE (10*1024*1024)
00061 
00062 _glthread_DECLARE_STATIC_MUTEX(exec_mutex);
00063 
00064 static struct mem_block *exec_heap = NULL;
00065 static unsigned char *exec_mem = NULL;
00066 
00067 
00068 static int
00069 init_heap(void)
00070 {
00071 #ifdef MESA_SELINUX
00072    if (is_selinux_enabled()) {
00073       if (!security_get_boolean_active("allow_execmem") ||
00074       !security_get_boolean_pending("allow_execmem"))
00075          return 0;
00076    }
00077 #endif
00078 
00079    if (!exec_heap)
00080       exec_heap = mmInit( 0, EXEC_HEAP_SIZE );
00081    
00082    if (!exec_mem)
00083       exec_mem = (unsigned char *) mmap(0, EXEC_HEAP_SIZE, 
00084                     PROT_EXEC | PROT_READ | PROT_WRITE, 
00085                     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
00086 
00087    return (exec_mem != NULL);
00088 }
00089 
00090 
00091 void *
00092 _mesa_exec_malloc(GLuint size)
00093 {
00094    struct mem_block *block = NULL;
00095    void *addr = NULL;
00096 
00097    _glthread_LOCK_MUTEX(exec_mutex);
00098 
00099    if (!init_heap())
00100       goto bail;
00101 
00102    if (exec_heap) {
00103       size = (size + 31) & ~31;
00104       block = mmAllocMem( exec_heap, size, 32, 0 );
00105    }
00106 
00107    if (block)
00108       addr = exec_mem + block->ofs;
00109    else 
00110       _mesa_printf("_mesa_exec_malloc failed\n");
00111 
00112 bail:
00113    _glthread_UNLOCK_MUTEX(exec_mutex);
00114    
00115    return addr;
00116 }
00117 
00118  
00119 void 
00120 _mesa_exec_free(void *addr)
00121 {
00122    _glthread_LOCK_MUTEX(exec_mutex);
00123 
00124    if (exec_heap) {
00125       struct mem_block *block = mmFindBlock(exec_heap, (unsigned char *)addr - exec_mem);
00126    
00127       if (block)
00128      mmFreeMem(block);
00129    }
00130 
00131    _glthread_UNLOCK_MUTEX(exec_mutex);
00132 }
00133 
00134 
00135 #else
00136 
00137 /*
00138  * Just use regular memory.
00139  */
00140 
00141 void *
00142 _mesa_exec_malloc(GLuint size)
00143 {
00144    return _mesa_malloc( size );
00145 }
00146 
00147  
00148 void 
00149 _mesa_exec_free(void *addr)
00150 {
00151    _mesa_free(addr);
00152 }
00153 
00154 
00155 #endif

Generated on Sun May 27 2012 04:20:16 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.