~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r0drv/freebsd/alloc-r0drv-freebsd.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: alloc-r0drv-freebsd.c $ */
 
1
/* $Id: alloc-r0drv-freebsd.c 33540 2010-10-28 09:27:05Z vboxsync $ */
2
2
/** @file
3
3
 * IPRT - Memory Allocation, Ring-0 Driver, FreeBSD.
4
4
 */
32
32
*   Header Files                                                               *
33
33
*******************************************************************************/
34
34
#include "the-freebsd-kernel.h"
 
35
#include "internal/iprt.h"
 
36
#include <iprt/mem.h>
35
37
 
36
 
#include <iprt/alloc.h>
37
38
#include <iprt/assert.h>
 
39
#include <iprt/err.h>
38
40
#include <iprt/param.h>
39
41
 
40
42
#include "r0drv/alloc-r0drv.h"
49
51
MALLOC_DEFINE(M_IPRTCONT, "iprtcont", "IPRT - contiguous");
50
52
 
51
53
 
52
 
PRTMEMHDR rtR0MemAlloc(size_t cb, uint32_t fFlags)
 
54
int rtR0MemAllocEx(size_t cb, uint32_t fFlags, PRTMEMHDR *ppHdr)
53
55
{
54
 
    size_t cbAllocated = cb;
55
 
    PRTMEMHDR pHdr = NULL;
 
56
    size_t      cbAllocated = cb;
 
57
    PRTMEMHDR   pHdr        = NULL;
56
58
 
 
59
#ifdef RT_ARCH_AMD64
57
60
    /*
58
61
     * Things are a bit more complicated on AMD64 for executable memory
59
62
     * because we need to be in the ~2GB..~0 range for code.
60
63
     */
61
 
#ifdef RT_ARCH_AMD64
62
64
    if (fFlags & RTMEMHDR_FLAG_EXEC)
63
65
    {
 
66
        if (fFlags & RTMEMHDR_FLAG_ANY_CTX)
 
67
            return VERR_NOT_SUPPORTED;
 
68
 
64
69
# ifdef USE_KMEM_ALLOC_PROT
65
70
        pHdr = (PRTMEMHDR)kmem_alloc_prot(kernel_map, cb + sizeof(*pHdr),
66
71
                                          VM_PROT_ALL, VM_PROT_ALL, KERNBASE);
71
76
 
72
77
        pVmObject = vm_object_allocate(OBJT_DEFAULT, cbAllocated >> PAGE_SHIFT);
73
78
        if (!pVmObject)
74
 
            return NULL;
 
79
            return VERR_NO_EXEC_MEMORY;
75
80
 
76
81
        /* Addr contains a start address vm_map_find will start searching for suitable space at. */
77
82
        int rc = vm_map_find(kernel_map, pVmObject, 0, &Addr,
103
108
                                 fFlags & RTMEMHDR_FLAG_ZEROED ? M_NOWAIT | M_ZERO : M_NOWAIT);
104
109
    }
105
110
 
106
 
    if (pHdr)
107
 
    {
108
 
        pHdr->u32Magic   = RTMEMHDR_MAGIC;
109
 
        pHdr->fFlags     = fFlags;
110
 
        pHdr->cb         = cbAllocated;
111
 
        pHdr->cbReq      = cb;
112
 
        return pHdr;
113
 
    }
114
 
    return NULL;
 
111
    if (RT_UNLIKELY(!pHdr))
 
112
        return VERR_NO_MEMORY;
 
113
 
 
114
    pHdr->u32Magic   = RTMEMHDR_MAGIC;
 
115
    pHdr->fFlags     = fFlags;
 
116
    pHdr->cb         = cbAllocated;
 
117
    pHdr->cbReq      = cb;
 
118
 
 
119
    *ppHdr = pHdr;
 
120
    return VINF_SUCCESS;
115
121
}
116
122
 
117
123
 
151
157
                      0,                    /* lowest physical address*/
152
158
                      _4G-1,                /* highest physical address */
153
159
                      PAGE_SIZE,            /* alignment. */
154
 
                      0);                   /* boundrary */
 
160
                      0);                   /* boundary */
155
161
    if (pv)
156
162
    {
157
163
        Assert(!((uintptr_t)pv & PAGE_OFFSET_MASK));