1 | /* $Id: memuserkernel-r0drv-linux.c 28800 2010-04-27 08:22:32Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - User & Kernel Memory, Ring-0 Driver, Linux.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009 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-linux-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/mem.h>
|
---|
35 | #include <iprt/err.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | RTR0DECL(int) RTR0MemUserCopyFrom(void *pvDst, RTR3PTR R3PtrSrc, size_t cb)
|
---|
39 | {
|
---|
40 | if (RT_LIKELY(copy_from_user(pvDst, (void *)R3PtrSrc, cb) == 0))
|
---|
41 | return VINF_SUCCESS;
|
---|
42 | return VERR_ACCESS_DENIED;
|
---|
43 | }
|
---|
44 | RT_EXPORT_SYMBOL(RTR0MemUserCopyFrom);
|
---|
45 |
|
---|
46 |
|
---|
47 | RTR0DECL(int) RTR0MemUserCopyTo(RTR3PTR R3PtrDst, void const *pvSrc, size_t cb)
|
---|
48 | {
|
---|
49 | if (RT_LIKELY(copy_to_user((void *)R3PtrDst, pvSrc, cb) == 0))
|
---|
50 | return VINF_SUCCESS;
|
---|
51 | return VERR_ACCESS_DENIED;
|
---|
52 | }
|
---|
53 | RT_EXPORT_SYMBOL(RTR0MemUserCopyTo);
|
---|
54 |
|
---|
55 |
|
---|
56 | RTR0DECL(bool) RTR0MemUserIsValidAddr(RTR3PTR R3Ptr)
|
---|
57 | {
|
---|
58 | return access_ok(VERIFY_READ, (void *)R3Ptr, 1);
|
---|
59 | }
|
---|
60 | RT_EXPORT_SYMBOL(RTR0MemUserIsValidAddr);
|
---|
61 |
|
---|
62 |
|
---|
63 | RTR0DECL(bool) RTR0MemKernelIsValidAddr(void *pv)
|
---|
64 | {
|
---|
65 | /* Couldn't find a straight forward way of doing this... */
|
---|
66 | #ifdef RT_ARCH_X86
|
---|
67 | # ifdef CONFIG_X86_HIGH_ENTRY
|
---|
68 | return true; /* ?? */
|
---|
69 | # else
|
---|
70 | return (uintptr_t)pv >= PAGE_OFFSET;
|
---|
71 | # endif
|
---|
72 |
|
---|
73 | #elif defined(RT_ARCH_AMD64)
|
---|
74 | # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
|
---|
75 | /* Linux 2.6.0 ... 2.6.10 set PAGE_OFFSET to 0x0000010000000000.
|
---|
76 | * Linux 2.6.11 sets PAGE_OFFSET to 0xffff810000000000.
|
---|
77 | * Linux 2.6.33 sets PAGE_OFFSET to 0xffff880000000000. */
|
---|
78 | return (uintptr_t)pv >= PAGE_OFFSET;
|
---|
79 | # else
|
---|
80 | /* Not correct (KERNEL_TEXT_START=0xffffffff80000000),
|
---|
81 | * VMALLOC_START (0xffffff0000000000) would be better */
|
---|
82 | return (uintptr_t)pv >= KERNEL_TEXT_START;
|
---|
83 | # endif
|
---|
84 |
|
---|
85 | #else
|
---|
86 | # error "PORT ME"
|
---|
87 | return !access_ok(VERIFY_READ, pv, 1);
|
---|
88 | #endif
|
---|
89 | }
|
---|
90 | RT_EXPORT_SYMBOL(RTR0MemKernelIsValidAddr);
|
---|
91 |
|
---|
92 |
|
---|
93 | RTR0DECL(bool) RTR0MemAreKrnlAndUsrDifferent(void)
|
---|
94 | {
|
---|
95 | #if defined(RT_ARCH_X86) && defined(CONFIG_X86_HIGH_ENTRY) /* ?? */
|
---|
96 | return false;
|
---|
97 | #else
|
---|
98 | return true;
|
---|
99 | #endif
|
---|
100 | }
|
---|
101 | RT_EXPORT_SYMBOL(RTR0MemAreKrnlAndUsrDifferent);
|
---|
102 |
|
---|