[21273] | 1 | /* $Id: memuserkernel-r0drv-darwin.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * IPRT - User & Kernel Memory, Ring-0 Driver, Darwin.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
[21273] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[21273] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[21273] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[21273] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[21273] | 35 | */
|
---|
| 36 |
|
---|
| 37 |
|
---|
[57358] | 38 | /*********************************************************************************************************************************
|
---|
| 39 | * Header Files *
|
---|
| 40 | *********************************************************************************************************************************/
|
---|
[21273] | 41 | #include "the-darwin-kernel.h"
|
---|
[22052] | 42 | #include "internal/iprt.h"
|
---|
| 43 | #include <iprt/mem.h>
|
---|
[36540] | 44 | #include <iprt/assert.h>
|
---|
[21273] | 45 |
|
---|
[29255] | 46 | #if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
|
---|
| 47 | # include <iprt/asm-amd64-x86.h>
|
---|
| 48 | #endif
|
---|
[76452] | 49 | #include <iprt/errcore.h>
|
---|
[21273] | 50 |
|
---|
| 51 |
|
---|
| 52 | RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb)
|
---|
| 53 | {
|
---|
[22052] | 54 | RT_ASSERT_INTS_ON();
|
---|
[57074] | 55 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[21273] | 56 | int rc = copyin((const user_addr_t)R3PtrSrc, pvDst, cb);
|
---|
[57074] | 57 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[21273] | 58 | if (RT_LIKELY(rc == 0))
|
---|
| 59 | return VINF_SUCCESS;
|
---|
| 60 | return VERR_ACCESS_DENIED;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb)
|
---|
| 65 | {
|
---|
[22052] | 66 | RT_ASSERT_INTS_ON();
|
---|
[57074] | 67 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
[21273] | 68 | int rc = copyout(pvSrc, R3PtrDst, cb);
|
---|
[57074] | 69 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[21273] | 70 | if (RT_LIKELY(rc == 0))
|
---|
| 71 | return VINF_SUCCESS;
|
---|
| 72 | return VERR_ACCESS_DENIED;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr)
|
---|
| 77 | {
|
---|
| 78 | /* the commpage is above this. */
|
---|
| 79 | #ifdef RT_ARCH_X86
|
---|
[21274] | 80 | return R3Ptr < VM_MAX_ADDRESS;
|
---|
[21273] | 81 | #else
|
---|
[21274] | 82 | return R3Ptr < VM_MAX_PAGE_ADDRESS;
|
---|
[21273] | 83 | #endif
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv)
|
---|
| 88 | {
|
---|
| 89 | /* Found no public #define or symbol for checking this, so we'll
|
---|
| 90 | have to make do with thing found in the debugger and the sources. */
|
---|
| 91 | #ifdef RT_ARCH_X86
|
---|
| 92 | NOREF(pv);
|
---|
| 93 | return true; /* Almost anything is a valid kernel address here. */
|
---|
| 94 |
|
---|
| 95 | #elif defined(RT_ARCH_AMD64)
|
---|
| 96 | return (uintptr_t)pv >= UINT64_C(0xffff800000000000);
|
---|
| 97 |
|
---|
| 98 | #else
|
---|
| 99 | # error "PORTME"
|
---|
| 100 | #endif
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 |
|
---|
[21284] | 104 | RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void)
|
---|
[21282] | 105 | {
|
---|
| 106 | /* As mentioned in RTR0MemKernelIsValidAddr, found no way of checking
|
---|
| 107 | this at compiler or runtime. */
|
---|
| 108 | #ifdef RT_ARCH_X86
|
---|
| 109 | return false;
|
---|
| 110 | #else
|
---|
| 111 | return true;
|
---|
| 112 | #endif
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[41169] | 115 |
|
---|
| 116 | RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb)
|
---|
| 117 | {
|
---|
[63509] | 118 | RT_NOREF(pvDst, pvSrc, cb);
|
---|
[41169] | 119 | return VERR_NOT_SUPPORTED;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb)
|
---|
| 124 | {
|
---|
[63509] | 125 | RT_NOREF(pvDst, pvSrc, cb);
|
---|
[41169] | 126 | return VERR_NOT_SUPPORTED;
|
---|
| 127 | }
|
---|
| 128 |
|
---|