alloc-r0drv-linux.c revision 3fd91563c08f83c14d6e266bd203a753422e2c2c
/* $Id$ */
/** @file
* InnoTek Portable Runtime - Memory Allocation, Ring-0 Driver, Linux.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-linux-kernel.h"
#include "r0drv/alloc-r0drv.h"
#if defined(__AMD64__) || defined(__DOXYGEN__)
/**
* We need memory in the module range (~2GB to ~0) this can only be obtained
* thru APIs that are not exported (see module_alloc()).
*
* So, we'll have to create a quick and dirty heap here using BSS memory.
* Very annoying and it's going to restrict us!
*/
# define RTMEMALLOC_EXEC_HEAP
#endif
#ifdef RTMEMALLOC_EXEC_HEAP
# include <iprt/spinlock.h>
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
#ifdef RTMEMALLOC_EXEC_HEAP
/** The heap. */
/** Spinlock protecting the heap. */
/**
* API for cleaning up the heap spinlock on IPRT termination.
*/
RTDECL(void) RTMemExecCleanup(void)
{
}
/**
* Donate read+write+execute memory to the exec heap.
*
* allocated memory in the module if it wishes for GCC generated code to work.
* GCC can only generate modules that work in the address range ~2GB to ~0
* currently.
*
* The API only accept one single donation.
*
* @returns IPRT status code.
* @param pvMemory Pointer to the memory block.
* @param cb The size of the memory block.
*/
{
if (RT_SUCCESS(rc))
{
if (RT_FAILURE(rc))
}
return rc;
}
#endif /* RTMEMALLOC_EXEC_HEAP */
/**
* OS specific allocation function.
*/
{
/*
* Allocate.
*/
if (fFlags & RTMEMHDR_FLAG_EXEC)
{
#if defined(__AMD64__)
# ifdef RTMEMALLOC_EXEC_HEAP
if (g_HeapExec != NIL_RTHEAPSIMPLE)
{
}
else
# endif
#else
#endif
}
else
{
{
}
else
}
/*
* Initialize.
*/
if (pHdr)
{
pHdr->u32Padding= 0;
}
return pHdr;
}
/**
* OS specific free function.
*/
{
#ifdef RTMEMALLOC_EXEC_HEAP
{
}
#endif
else
}
/**
* Compute order. Some functions allocate 2^order pages.
*
* @returns order.
* @param cPages Number of pages.
*/
static int CalcPowerOf2Order(unsigned long cPages)
{
int iOrder;
unsigned long cTmp;
;
++iOrder;
return iOrder;
}
/**
* Allocates physical contiguous memory (below 4GB).
* The allocation is page aligned and the content is undefined.
*
* @returns Pointer to the memory block. This is page aligned.
* @param pPhys Where to store the physical address.
* @param cb The allocation size in bytes. This is always
* rounded up to PAGE_SIZE.
*/
{
int cOrder;
unsigned cPages;
/*
* validate input.
*/
/*
* Allocate page pointer array.
*/
#ifdef __AMD64__ /** @todo check out if there is a correct way of getting memory below 4GB (physically). */
#else
#endif
if (paPages)
{
/*
* Reserve the pages and mark them executable.
*/
unsigned iPage;
{
{
}
}
}
return NULL;
}
/**
* Frees memory allocated ysing RTMemContAlloc().
*
* @param pv Pointer to return from RTMemContAlloc().
* @param cb The cb parameter passed to RTMemContAlloc().
*/
{
if (pv)
{
int cOrder;
unsigned cPages;
unsigned iPage;
/* validate */
/* calc order and get pages */
/*
* Restore page attributes freeing the pages.
*/
{
}
}
}