VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/nt/memuserkernel-r0drv-nt.cpp@ 78365

Last change on this file since 78365 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: memuserkernel-r0drv-nt.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT - User & Kernel Memory, Ring-0 Driver, NT.
4 */
5
6/*
7 * Copyright (C) 2009-2019 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include "the-nt-kernel.h"
32
33#include <iprt/mem.h>
34#include <iprt/errcore.h>
35
36#include "internal-r0drv-nt.h"
37
38
39RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb)
40{
41 __try
42 {
43 ProbeForRead((PVOID)R3PtrSrc, cb, 1);
44 memcpy(pvDst, (void const *)R3PtrSrc, cb);
45 }
46 __except(EXCEPTION_EXECUTE_HANDLER)
47 {
48 return VERR_ACCESS_DENIED;
49 }
50 return VINF_SUCCESS;
51}
52
53
54RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb)
55{
56 __try
57 {
58 ProbeForWrite((PVOID)R3PtrDst, cb, 1);
59 memcpy((void *)R3PtrDst, pvSrc, cb);
60 }
61 __except(EXCEPTION_EXECUTE_HANDLER)
62 {
63 return VERR_ACCESS_DENIED;
64 }
65 return VINF_SUCCESS;
66}
67
68
69RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr)
70{
71#ifdef IPRT_TARGET_NT4
72 uintptr_t const uLast = g_puRtMmHighestUserAddress ? *g_puRtMmHighestUserAddress : ~(uintptr_t)0 / 2;
73#else
74 uintptr_t const uLast = (uintptr_t)MM_HIGHEST_USER_ADDRESS;
75#endif
76 return R3Ptr <= uLast;
77}
78
79
80RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv)
81{
82#ifdef IPRT_TARGET_NT4
83 uintptr_t const uFirst = g_puRtMmSystemRangeStart ? *g_puRtMmSystemRangeStart : ~(uintptr_t)0 / 2 + 1;
84#else
85 uintptr_t const uFirst = (uintptr_t)MM_SYSTEM_RANGE_START;
86#endif
87 return (uintptr_t)pv >= uFirst;
88}
89
90
91RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void)
92{
93 return true;
94}
95
96
97RTR0DECL(int) RTR0MemKernelCopyFrom(void *pvDst, void const *pvSrc, size_t cb)
98{
99 __try
100 {
101 memcpy(pvDst, pvSrc, cb);
102 }
103 __except(EXCEPTION_EXECUTE_HANDLER)
104 {
105 return VERR_ACCESS_DENIED;
106 }
107 return VINF_SUCCESS;
108}
109
110
111RTR0DECL(int) RTR0MemKernelCopyTo(void *pvDst, void const *pvSrc, size_t cb)
112{
113 __try
114 {
115 memcpy(pvDst, pvSrc, cb);
116 }
117 __except(EXCEPTION_EXECUTE_HANDLER)
118 {
119 return VERR_ACCESS_DENIED;
120 }
121 return VINF_SUCCESS;
122}
123
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