VirtualBox

source: vbox/trunk/src/libs/kStuff/iprt/kHlpPage-iprt.cpp@ 5881

Last change on this file since 5881 was 5775, checked in by vboxsync, 17 years ago

Corrected the copyright header.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 2.3 KB
Line 
1/* $Id: kHlpPage-iprt.cpp 5775 2007-11-16 15:47:20Z vboxsync $ */
2/** @file
3 * kHlpPage - Page Memory Allocation, IPRT based implementation.
4 */
5
6/*
7 * Copyright (C) 2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 */
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <k/kHlpAlloc.h>
23#include <k/kErrors.h>
24#include <iprt/mem.h>
25#include <iprt/assert.h>
26#include <iprt/err.h>
27
28
29
30static unsigned kHlpPageProtToNative(KPROT enmProt)
31{
32 switch (enmProt)
33 {
34 case KPROT_NOACCESS: return RTMEM_PROT_NONE;
35 case KPROT_READONLY: return RTMEM_PROT_READ;
36 case KPROT_READWRITE: return RTMEM_PROT_READ | RTMEM_PROT_WRITE;
37 case KPROT_EXECUTE: return RTMEM_PROT_EXEC;
38 case KPROT_EXECUTE_READ: return RTMEM_PROT_EXEC | RTMEM_PROT_READ;
39 case KPROT_EXECUTE_READWRITE: return RTMEM_PROT_EXEC | RTMEM_PROT_READ | RTMEM_PROT_WRITE;
40 default:
41 AssertFailed();
42 return ~0U;
43 }
44}
45
46
47KHLP_DECL(int) kHlpPageAlloc(void **ppv, KSIZE cb, KPROT enmProt, KBOOL fFixed)
48{
49 AssertReturn(fFixed, KERR_NOT_IMPLEMENTED);
50
51 int rc = VINF_SUCCESS;
52 void *pv = RTMemPageAlloc(cb);
53 if (pv)
54 {
55 rc = RTMemProtect(pv, cb, kHlpPageProtToNative(enmProt));
56 if (RT_SUCCESS(rc))
57 *ppv = pv;
58 else
59 RTMemPageFree(pv);
60 }
61 return rc;
62}
63
64
65KHLP_DECL(int) kHlpPageProtect(void *pv, KSIZE cb, KPROT enmProt)
66{
67 int rc = RTMemProtect(pv, cb, kHlpPageProtToNative(enmProt));
68 if (!rc)
69 return 0;
70 /** @todo convert iprt status code -> kErrors */
71 return rc;
72}
73
74
75KHLP_DECL(int) kHlpPageFree(void *pv, KSIZE cb)
76{
77 RTMemPageFree(pv);
78 return 0;
79}
80
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette