1 | /* $Id: thread2-r0drv-solaris.c 56290 2015-06-09 14:01:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Threads (Part 2), Ring-0 Driver, Solaris.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-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 "the-solaris-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 | #include <iprt/thread.h>
|
---|
34 | #include <iprt/process.h>
|
---|
35 |
|
---|
36 | #include <iprt/assert.h>
|
---|
37 | #include <iprt/err.h>
|
---|
38 | #include "internal/thread.h"
|
---|
39 |
|
---|
40 | #define SOL_THREAD_ID_PTR ((uint64_t *)((char *)curthread + g_offrtSolThreadId))
|
---|
41 | #define SOL_THREAD_LOCKP_PTR ((disp_lock_t **)((char *)curthread + g_offrtSolThreadLock))
|
---|
42 |
|
---|
43 | DECLHIDDEN(int) rtThreadNativeInit(void)
|
---|
44 | {
|
---|
45 | return VINF_SUCCESS;
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | RTDECL(RTTHREAD) RTThreadSelf(void)
|
---|
50 | {
|
---|
51 | return rtThreadGetByNative(RTThreadNativeSelf());
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
|
---|
56 | {
|
---|
57 | int iPriority;
|
---|
58 | disp_lock_t **ppDispLock;
|
---|
59 | switch (enmType)
|
---|
60 | {
|
---|
61 | case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = 60; break;
|
---|
62 | case RTTHREADTYPE_EMULATION: iPriority = 66; break;
|
---|
63 | case RTTHREADTYPE_DEFAULT: iPriority = 72; break;
|
---|
64 | case RTTHREADTYPE_MSG_PUMP: iPriority = 78; break;
|
---|
65 | case RTTHREADTYPE_IO: iPriority = 84; break;
|
---|
66 | case RTTHREADTYPE_TIMER: iPriority = 99; break;
|
---|
67 | default:
|
---|
68 | AssertMsgFailed(("enmType=%d\n", enmType));
|
---|
69 | return VERR_INVALID_PARAMETER;
|
---|
70 | }
|
---|
71 |
|
---|
72 | Assert(curthread);
|
---|
73 | thread_lock(curthread);
|
---|
74 | thread_change_pri(curthread, iPriority, 0);
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * thread_unlock() is a macro calling disp_lock_exit() with the thread's dispatcher lock.
|
---|
78 | * We need to dereference the offset manually here (for S10, S11 compatibility) rather than
|
---|
79 | * using the macro.
|
---|
80 | */
|
---|
81 | ppDispLock = SOL_THREAD_LOCKP_PTR;
|
---|
82 | disp_lock_exit(*ppDispLock);
|
---|
83 |
|
---|
84 | return VINF_SUCCESS;
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
|
---|
89 | {
|
---|
90 | NOREF(pThread);
|
---|
91 | /* There is nothing special that needs doing here, but the
|
---|
92 | user really better know what he's cooking. */
|
---|
93 | return VINF_SUCCESS;
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
|
---|
98 | {
|
---|
99 | thread_join(pThread->tid);
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
|
---|
104 | {
|
---|
105 | NOREF(pThread);
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Native thread main function.
|
---|
111 | *
|
---|
112 | * @param pvThreadInt The thread structure.
|
---|
113 | */
|
---|
114 | static void rtThreadNativeMain(void *pvThreadInt)
|
---|
115 | {
|
---|
116 | PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
|
---|
117 |
|
---|
118 | AssertCompile(sizeof(kt_did_t) == sizeof(pThreadInt->tid));
|
---|
119 | uint64_t *pu64ThrId = SOL_THREAD_ID_PTR;
|
---|
120 | pThreadInt->tid = *pu64ThrId;
|
---|
121 | rtThreadMain(pThreadInt, RTThreadNativeSelf(), &pThreadInt->szName[0]);
|
---|
122 | thread_exit();
|
---|
123 | }
|
---|
124 |
|
---|
125 |
|
---|
126 | DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
|
---|
127 | {
|
---|
128 | kthread_t *pThread;
|
---|
129 | RT_ASSERT_PREEMPTIBLE();
|
---|
130 |
|
---|
131 | pThreadInt->tid = UINT64_MAX;
|
---|
132 |
|
---|
133 | pThread = thread_create(NULL, /* Stack, use base */
|
---|
134 | 0, /* Stack size */
|
---|
135 | rtThreadNativeMain, /* Thread function */
|
---|
136 | pThreadInt, /* Function data */
|
---|
137 | 0, /* Data size */
|
---|
138 | &p0, /* Process 0 handle */
|
---|
139 | TS_RUN, /* Ready to run */
|
---|
140 | minclsyspri /* Priority */
|
---|
141 | );
|
---|
142 | if (RT_LIKELY(pThread))
|
---|
143 | {
|
---|
144 | *pNativeThread = (RTNATIVETHREAD)pThread;
|
---|
145 | return VINF_SUCCESS;
|
---|
146 | }
|
---|
147 |
|
---|
148 | return VERR_OUT_OF_RESOURCES;
|
---|
149 | }
|
---|
150 |
|
---|