VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/thread2-r0drv-solaris.c

Last change on this file was 98103, checked in by vboxsync, 17 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: thread2-r0drv-solaris.c 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Threads (Part 2), Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "the-solaris-kernel.h"
42#include "internal/iprt.h"
43#include <iprt/thread.h>
44#include <iprt/process.h>
45
46#include <iprt/assert.h>
47#include <iprt/errcore.h>
48#include "internal/thread.h"
49
50#define SOL_THREAD_ID_PTR ((uint64_t *)((char *)curthread + g_offrtSolThreadId))
51#define SOL_THREAD_LOCKP_PTR ((disp_lock_t **)((char *)curthread + g_offrtSolThreadLock))
52
53DECLHIDDEN(int) rtThreadNativeInit(void)
54{
55 return VINF_SUCCESS;
56}
57
58
59RTDECL(RTTHREAD) RTThreadSelf(void)
60{
61 return rtThreadGetByNative(RTThreadNativeSelf());
62}
63
64
65DECLHIDDEN(int) rtThreadNativeSetPriority(PRTTHREADINT pThread, RTTHREADTYPE enmType)
66{
67 int iPriority;
68 disp_lock_t **ppDispLock;
69 switch (enmType)
70 {
71 case RTTHREADTYPE_INFREQUENT_POLLER: iPriority = 60; break;
72 case RTTHREADTYPE_EMULATION: iPriority = 66; break;
73 case RTTHREADTYPE_DEFAULT: iPriority = 72; break;
74 case RTTHREADTYPE_MSG_PUMP: iPriority = 78; break;
75 case RTTHREADTYPE_IO: iPriority = 84; break;
76 case RTTHREADTYPE_TIMER: iPriority = 99; break;
77 default:
78 AssertMsgFailed(("enmType=%d\n", enmType));
79 return VERR_INVALID_PARAMETER;
80 }
81
82 Assert(curthread);
83 thread_lock(curthread);
84 thread_change_pri(curthread, iPriority, 0);
85
86 /*
87 * thread_unlock() is a macro calling disp_lock_exit() with the thread's dispatcher lock.
88 * We need to dereference the offset manually here (for S10, S11 compatibility) rather than
89 * using the macro.
90 */
91 ppDispLock = SOL_THREAD_LOCKP_PTR;
92 disp_lock_exit(*ppDispLock);
93
94 return VINF_SUCCESS;
95}
96
97
98DECLHIDDEN(int) rtThreadNativeAdopt(PRTTHREADINT pThread)
99{
100 NOREF(pThread);
101 /* There is nothing special that needs doing here, but the
102 user really better know what he's cooking. */
103 return VINF_SUCCESS;
104}
105
106
107DECLHIDDEN(void) rtThreadNativeWaitKludge(PRTTHREADINT pThread)
108{
109 thread_join(pThread->tid);
110}
111
112
113DECLHIDDEN(void) rtThreadNativeDestroy(PRTTHREADINT pThread)
114{
115 NOREF(pThread);
116}
117
118
119/**
120 * Native thread main function.
121 *
122 * @param pvThreadInt The thread structure.
123 */
124static void rtThreadNativeMain(void *pvThreadInt)
125{
126 PRTTHREADINT pThreadInt = (PRTTHREADINT)pvThreadInt;
127
128 AssertCompile(sizeof(kt_did_t) == sizeof(pThreadInt->tid));
129 uint64_t *pu64ThrId = SOL_THREAD_ID_PTR;
130 pThreadInt->tid = *pu64ThrId;
131 rtThreadMain(pThreadInt, RTThreadNativeSelf(), &pThreadInt->szName[0]);
132 thread_exit();
133}
134
135
136DECLHIDDEN(int) rtThreadNativeCreate(PRTTHREADINT pThreadInt, PRTNATIVETHREAD pNativeThread)
137{
138 kthread_t *pThread;
139 RT_ASSERT_PREEMPTIBLE();
140
141 pThreadInt->tid = UINT64_MAX;
142
143 pThread = thread_create(NULL, /* Stack, use base */
144 0, /* Stack size */
145 rtThreadNativeMain, /* Thread function */
146 pThreadInt, /* Function data */
147 0, /* Data size */
148 &p0, /* Process 0 handle */
149 TS_RUN, /* Ready to run */
150 minclsyspri /* Priority */
151 );
152 if (RT_LIKELY(pThread))
153 {
154 *pNativeThread = (RTNATIVETHREAD)pThread;
155 return VINF_SUCCESS;
156 }
157
158 return VERR_OUT_OF_RESOURCES;
159}
160
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use