alloc-freebsd.cpp revision 418b9db49fbc652ef9c3f030fdc0f1a322403d95
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * IPRT - Memory Allocation, FreeBSD.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Copyright (C) 2006-2010 Oracle Corporation
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * available from http://www.virtualbox.org. This file is free software;
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * General Public License (GPL) as published by the Free Software
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * The contents of this file may alternatively be used under the terms
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * of the Common Development and Distribution License Version 1.0
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * VirtualBox OSE distribution, in which case the provisions of the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * CDDL are applicable instead of those of the GPL.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * You may elect to license modified versions of this file under the
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * terms and conditions of either the GPL or the CDDL or both.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync/*******************************************************************************
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync* Header Files *
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync*******************************************************************************/
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncRTDECL(void *) RTMemExecAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Allocate first.
5a3672dca0301427a400aec8734acd70e2cf24a4vboxsync AssertMsg(cb, ("Allocating ZERO bytes is really not a good idea! Good luck with the next assertion!\n"));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Add PROT_EXEC flag to the page(s).
dfd08267d2958ae1cd559dd7dc2f36bf5461648dvboxsync int rc = mprotect(pv, cb, PROT_READ | PROT_WRITE | PROT_EXEC);
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync AssertMsgFailed(("mprotect(%p, %#x,,) -> rc=%d, errno=%d\n", pv, cb, rc, errno));
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncRTDECL(void) RTMemExecFree(void *pv, size_t cb) RT_NO_THROW
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncRTDECL(void *) RTMemPageAllocTag(size_t cb, const char *pszTag) RT_NO_THROW
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync AssertReleaseMsgReturn(RT_ALIGN_P(pv, PAGE_SIZE) == pv,
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync ("malloc(%zu) -> %p; expected page aligned!\n", cb, pv),
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncRTDECL(void *) RTMemPageAllocZTag(size_t cb, const char *pszTag) RT_NO_THROW
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncRTDECL(void) RTMemPageFree(void *pv, size_t cb) RT_NO_THROW
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsyncRTDECL(int) RTMemProtect(void *pv, size_t cb, unsigned fProtect) RT_NO_THROW
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Validate input.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync if (fProtect & ~(RTMEM_PROT_NONE | RTMEM_PROT_READ | RTMEM_PROT_WRITE | RTMEM_PROT_EXEC))
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Convert the flags.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Align the request.
14ea49401f3c8c61422aefbda43809e275f60c6cvboxsync * Change the page attributes.