1 | /* $Id: tstRTR0Thread.cpp 57358 2015-08-14 15:16:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT R0 Testcase - Kernel thread.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2015 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 <iprt/thread.h>
|
---|
32 |
|
---|
33 | #include <iprt/asm-amd64-x86.h>
|
---|
34 | #include <iprt/err.h>
|
---|
35 | #include <VBox/sup.h>
|
---|
36 | #include "tstRTR0Thread.h"
|
---|
37 | #include "tstRTR0Common.h"
|
---|
38 |
|
---|
39 | #define TSTRTR0THREADDATA_MAGIC 0xcececece
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * State structure for tstRTR0ThreadCallback().
|
---|
43 | */
|
---|
44 | typedef struct TSTRTR0THREADDATA
|
---|
45 | {
|
---|
46 | /** The magic value. */
|
---|
47 | uint32_t uMagic;
|
---|
48 | /** Sample counter. */
|
---|
49 | uint32_t volatile cCounter;
|
---|
50 | /** The thread handle. */
|
---|
51 | RTTHREAD hThread;
|
---|
52 | } TSTRTR0THREADDATA;
|
---|
53 | /** Pointer to state structure for tstRTR0ThreadCallback(). */
|
---|
54 | typedef TSTRTR0THREADDATA *PTSTRTR0THREADDATA;
|
---|
55 |
|
---|
56 |
|
---|
57 | static DECLCALLBACK(int) tstRTR0ThreadCallback(RTTHREAD hThread, void *pvUser)
|
---|
58 | {
|
---|
59 | PTSTRTR0THREADDATA pData = (PTSTRTR0THREADDATA)pvUser;
|
---|
60 | if (RT_LIKELY(pData))
|
---|
61 | {
|
---|
62 | if (pData->uMagic == TSTRTR0THREADDATA_MAGIC)
|
---|
63 | pData->uMagic = ~pData->uMagic;
|
---|
64 | if (pData->cCounter == 127)
|
---|
65 | pData->cCounter = 196;
|
---|
66 | }
|
---|
67 | RTThreadUserSignal(RTThreadSelf());
|
---|
68 | return VINF_SUCCESS;
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Service request callback function.
|
---|
74 | *
|
---|
75 | * @returns VBox status code.
|
---|
76 | * @param pSession The caller's session.
|
---|
77 | * @param u64Arg 64-bit integer argument.
|
---|
78 | * @param pReqHdr The request header. Input / Output. Optional.
|
---|
79 | */
|
---|
80 | DECLEXPORT(int) TSTRTR0ThreadSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
|
---|
81 | uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
|
---|
82 | {
|
---|
83 | RTR0TESTR0_SRV_REQ_PROLOG_RET(pReqHdr);
|
---|
84 |
|
---|
85 | /*
|
---|
86 | * The big switch.
|
---|
87 | */
|
---|
88 | switch (uOperation)
|
---|
89 | {
|
---|
90 | RTR0TESTR0_IMPLEMENT_SANITY_CASES();
|
---|
91 | RTR0TESTR0_IMPLEMENT_DEFAULT_CASE(uOperation);
|
---|
92 |
|
---|
93 | case TSTRTR0THREAD_BASIC:
|
---|
94 | {
|
---|
95 | TSTRTR0THREADDATA Data;
|
---|
96 | RT_ZERO(Data);
|
---|
97 | Data.uMagic = TSTRTR0THREADDATA_MAGIC;
|
---|
98 | Data.cCounter = 127;
|
---|
99 |
|
---|
100 | /* Create the kernel thread. */
|
---|
101 | RTR0TESTR0_CHECK_RC_BREAK(RTThreadCreate(&Data.hThread, tstRTR0ThreadCallback, &Data, 0 /* cbStack */,
|
---|
102 | RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "tstRTR0Thr"), VINF_SUCCESS);
|
---|
103 |
|
---|
104 | /* Wait for thread to signal. */
|
---|
105 | RTR0TESTR0_CHECK_RC(RTThreadUserWait(Data.hThread, 500 /* ms */), VINF_SUCCESS);
|
---|
106 |
|
---|
107 | /* Reset the semaphore. */
|
---|
108 | RTR0TESTR0_CHECK_RC(RTThreadUserReset(Data.hThread), VINF_SUCCESS);
|
---|
109 |
|
---|
110 | /* Check if the thread has modified data as expected. */
|
---|
111 | RTR0TESTR0_CHECK_MSG_BREAK(Data.cCounter = 196 && Data.uMagic == ~TSTRTR0THREADDATA_MAGIC,
|
---|
112 | ("Thread didn't modify data as expected.\n"));
|
---|
113 | break;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | RTR0TESTR0_SRV_REQ_EPILOG(pReqHdr);
|
---|
118 | /* The error indicator is the '!' in the message buffer. */
|
---|
119 | return VINF_SUCCESS;
|
---|
120 | }
|
---|
121 |
|
---|