1 | /* $Id: tstRTR0Timer.cpp 32611 2010-09-17 15:15:22Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT R0 Testcase - Timers.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2010 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 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include <iprt/mem.h>
|
---|
31 |
|
---|
32 | #include <iprt/err.h>
|
---|
33 | #include <iprt/param.h>
|
---|
34 | #include <iprt/time.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 | #include <VBox/sup.h>
|
---|
37 | #include "tstRTR0Timer.h"
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Service request callback function.
|
---|
43 | *
|
---|
44 | * @returns VBox status code.
|
---|
45 | * @param pSession The caller's session.
|
---|
46 | * @param u64Arg 64-bit integer argument.
|
---|
47 | * @param pReqHdr The request header. Input / Output. Optional.
|
---|
48 | */
|
---|
49 | DECLEXPORT(int) TSTRTR0TimerSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
|
---|
50 | uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
|
---|
51 | {
|
---|
52 | if (!VALID_PTR(pReqHdr))
|
---|
53 | return VERR_INVALID_PARAMETER;
|
---|
54 | char *pszErr = (char *)(pReqHdr + 1);
|
---|
55 | size_t cchErr = pReqHdr->cbReq - sizeof(*pReqHdr);
|
---|
56 | if (cchErr < 32 || cchErr >= 0x10000)
|
---|
57 | return VERR_INVALID_PARAMETER;
|
---|
58 | *pszErr = '\0';
|
---|
59 |
|
---|
60 | if (u64Arg)
|
---|
61 | return VERR_INVALID_PARAMETER;
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * The big switch.
|
---|
65 | */
|
---|
66 | switch (uOperation)
|
---|
67 | {
|
---|
68 | case TSTRTR0TIMER_SANITY_OK:
|
---|
69 | break;
|
---|
70 |
|
---|
71 | case TSTRTR0TIMER_SANITY_FAILURE:
|
---|
72 | RTStrPrintf(pszErr, cchErr, "!42failure42%1024s", "");
|
---|
73 | break;
|
---|
74 |
|
---|
75 | #if 0
|
---|
76 | case TSTRTR0TIMER_BASIC:
|
---|
77 | {
|
---|
78 | int rc = RTR0MemUserCopyFrom(pbKrnlBuf, R3Ptr, PAGE_SIZE);
|
---|
79 | if (rc == VINF_SUCCESS)
|
---|
80 | {
|
---|
81 | rc = RTR0MemUserCopyTo(R3Ptr, pbKrnlBuf, PAGE_SIZE);
|
---|
82 | if (rc == VINF_SUCCESS)
|
---|
83 | {
|
---|
84 | if (RTR0MemUserIsValidAddr(R3Ptr))
|
---|
85 | {
|
---|
86 | if (RTR0MemKernelIsValidAddr(pbKrnlBuf))
|
---|
87 | {
|
---|
88 | if (RTR0MemAreKrnlAndUsrDifferent())
|
---|
89 | {
|
---|
90 | RTStrPrintf(pszErr, cchErr, "RTR0MemAreKrnlAndUsrDifferent returns true");
|
---|
91 | if (!RTR0MemUserIsValidAddr((uintptr_t)pbKrnlBuf))
|
---|
92 | {
|
---|
93 | if (!RTR0MemKernelIsValidAddr((void *)R3Ptr))
|
---|
94 | {
|
---|
95 | /* done */
|
---|
96 | }
|
---|
97 | else
|
---|
98 | RTStrPrintf(pszErr, cchErr, "! #5 - RTR0MemKernelIsValidAddr -> true, expected false");
|
---|
99 | }
|
---|
100 | else
|
---|
101 | RTStrPrintf(pszErr, cchErr, "! #5 - RTR0MemUserIsValidAddr -> true, expected false");
|
---|
102 | }
|
---|
103 | else
|
---|
104 | RTStrPrintf(pszErr, cchErr, "RTR0MemAreKrnlAndUsrDifferent returns false");
|
---|
105 | }
|
---|
106 | else
|
---|
107 | RTStrPrintf(pszErr, cchErr, "! #4 - RTR0MemKernelIsValidAddr -> false, expected true");
|
---|
108 | }
|
---|
109 | else
|
---|
110 | RTStrPrintf(pszErr, cchErr, "! #3 - RTR0MemUserIsValidAddr -> false, expected true");
|
---|
111 | }
|
---|
112 | else
|
---|
113 | RTStrPrintf(pszErr, cchErr, "! #2 - RTR0MemUserCopyTo -> %Rrc expected %Rrc", rc, VINF_SUCCESS);
|
---|
114 | }
|
---|
115 | else
|
---|
116 | RTStrPrintf(pszErr, cchErr, "! #1 - RTR0MemUserCopyFrom -> %Rrc expected %Rrc", rc, VINF_SUCCESS);
|
---|
117 | break;
|
---|
118 | }
|
---|
119 |
|
---|
120 | case TSTRTR0TIMER_GOOD:
|
---|
121 | {
|
---|
122 | for (unsigned off = 0; off < 16 && !*pszErr; off++)
|
---|
123 | for (unsigned cb = 0; cb < PAGE_SIZE - 16; cb++)
|
---|
124 | TEST_OFF_SIZE(off, cb, VINF_SUCCESS);
|
---|
125 | break;
|
---|
126 | }
|
---|
127 |
|
---|
128 | case TSTRTR0TIMER_BAD:
|
---|
129 | {
|
---|
130 | for (unsigned off = 0; off < 16 && !*pszErr; off++)
|
---|
131 | for (unsigned cb = 0; cb < PAGE_SIZE - 16; cb++)
|
---|
132 | TEST_OFF_SIZE(off, cb, cb > 0 ? VERR_ACCESS_DENIED : VINF_SUCCESS);
|
---|
133 | break;
|
---|
134 | }
|
---|
135 |
|
---|
136 | case TSTRTR0TIMER_INVALID_ADDRESS:
|
---|
137 | {
|
---|
138 | if ( !RTR0MemUserIsValidAddr(R3Ptr)
|
---|
139 | && RTR0MemKernelIsValidAddr((void *)R3Ptr))
|
---|
140 | {
|
---|
141 | for (unsigned off = 0; off < 16 && !*pszErr; off++)
|
---|
142 | for (unsigned cb = 0; cb < PAGE_SIZE - 16; cb++)
|
---|
143 | TEST_OFF_SIZE(off, cb, cb > 0 ? VERR_ACCESS_DENIED : VINF_SUCCESS); /* ... */
|
---|
144 | }
|
---|
145 | else
|
---|
146 | RTStrPrintf(pszErr, cchErr, "RTR0MemUserIsValidAddr returns true");
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | #endif
|
---|
150 |
|
---|
151 | default:
|
---|
152 | RTStrPrintf(pszErr, cchErr, "!Unknown test #%d", uOperation);
|
---|
153 | break;
|
---|
154 | }
|
---|
155 |
|
---|
156 | /* The error indicator is the '!' in the message buffer. */
|
---|
157 | return VINF_SUCCESS;
|
---|
158 | }
|
---|
159 |
|
---|