VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/darwin/memuserkernel-r0drv-darwin.cpp

Last change on this file was 109128, checked in by vboxsync, 10 days ago

IPRT/r0drv: Build adjustments for darwin.arm64. jiraref:VBP-1653

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/* $Id: memuserkernel-r0drv-darwin.cpp 109128 2025-05-01 01:31:56Z vboxsync $ */
2/** @file
3 * IPRT - User & Kernel Memory, Ring-0 Driver, Darwin.
4 */
5
6/*
7 * Copyright (C) 2009-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.215389.xyz.
11 *
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 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
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
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.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "the-darwin-kernel.h"
42#include "internal/iprt.h"
43#include <iprt/mem.h>
44#include <iprt/assert.h>
45
46#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
47# include <iprt/asm-amd64-x86.h>
48#else
49# include <iprt/thread.h>
50#endif
51#include <iprt/errcore.h>
52
53
54RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb)
55{
56 RT_ASSERT_INTS_ON();
57 IPRT_DARWIN_SAVE_EFL_AC();
58 int rc = copyin((const user_addr_t)R3PtrSrc, pvDst, cb);
59 IPRT_DARWIN_RESTORE_EFL_AC();
60 if (RT_LIKELY(rc == 0))
61 return VINF_SUCCESS;
62 return VERR_ACCESS_DENIED;
63}
64
65
66RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb)
67{
68 RT_ASSERT_INTS_ON();
69 IPRT_DARWIN_SAVE_EFL_AC();
70 int rc = copyout(pvSrc, R3PtrDst, cb);
71 IPRT_DARWIN_RESTORE_EFL_AC();
72 if (RT_LIKELY(rc == 0))
73 return VINF_SUCCESS;
74 return VERR_ACCESS_DENIED;
75}
76
77
78RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr)
79{
80 /* the commpage is above this. */
81#ifdef RT_ARCH_X86
82 return R3Ptr < VM_MAX_ADDRESS;
83#else
84 return R3Ptr < VM_MAX_PAGE_ADDRESS;
85#endif
86}
87
88
89RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv)
90{
91 /* Found no public #define or symbol for checking this, so we'll
92 have to make do with thing found in the debugger and the sources. */
93#ifdef RT_ARCH_X86
94 NOREF(pv);
95 return true; /* Almost anything is a valid kernel address here. */
96
97#elif defined(RT_ARCH_AMD64)
98 return (uintptr_t)pv >= UINT64_C(0xffff800000000000);
99
100#elif defined(RT_ARCH_ARM64)
101 return (uintptr_t)pv >= UINT64_C(0xfff0000000000000); /** @todo get the actual size. this is the max. */
102
103#else
104# error "PORTME"
105#endif
106}
107
108
109RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void)
110{
111 /* As mentioned in RTR0MemKernelIsValidAddr, found no way of checking
112 this at compiler or runtime. */
113#ifdef RT_ARCH_X86
114 return false;
115#else
116 return true;
117#endif
118}
119
120
121RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb)
122{
123 RT_NOREF(pvDst, pvSrc, cb);
124 return VERR_NOT_SUPPORTED;
125}
126
127
128RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb)
129{
130 RT_NOREF(pvDst, pvSrc, cb);
131 return VERR_NOT_SUPPORTED;
132}
133
Note: See TracBrowser for help on using the repository browser.

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