2 * Win32 'syslevel' routines
4 * Copyright 1998 Ulrich Weigand
10 #include "stackframe.h"
13 static CRITICAL_SECTION Win16Mutex
;
14 static SEGPTR segpWin16Mutex
;
16 /* Global variable to save current TEB while in 16-bit code */
17 WORD SYSLEVEL_Win16CurrentTeb
= 0;
19 /* TEB of initial process for emergency use */
20 WORD SYSLEVEL_EmergencyTeb
= 0;
23 /************************************************************************
26 void SYSLEVEL_Init(void)
28 CRITICAL_SECTION
**w16Mutex
= SEGPTR_ALLOC(sizeof(CRITICAL_SECTION
*));
30 *w16Mutex
= &Win16Mutex
;
31 segpWin16Mutex
= SEGPTR_GET(w16Mutex
);
33 InitializeCriticalSection(&Win16Mutex
);
36 /************************************************************************
37 * GetpWin16Lock32 (KERNEL32.93)
39 VOID WINAPI
GetpWin16Lock32(CRITICAL_SECTION
**lock
)
44 /************************************************************************
45 * GetpWin16Lock16 (KERNEL.449)
47 SEGPTR WINAPI
GetpWin16Lock16(void)
49 return segpWin16Mutex
;
52 /************************************************************************
53 * _EnterSysLevel (KERNEL32.97)
55 VOID WINAPI
_EnterSysLevel(CRITICAL_SECTION
*lock
)
57 EnterCriticalSection(lock
);
59 if (lock
== &Win16Mutex
)
60 GET_FS( SYSLEVEL_Win16CurrentTeb
);
63 /************************************************************************
64 * _LeaveSysLevel (KERNEL32.98)
66 VOID WINAPI
_LeaveSysLevel(CRITICAL_SECTION
*lock
)
68 LeaveCriticalSection(lock
);
71 /************************************************************************
74 VOID WINAPI
_KERNEL32_86(CRITICAL_SECTION
*lock
)
79 /************************************************************************
80 * SYSLEVEL_EnterWin16Lock [KERNEL.480]
82 VOID WINAPI
SYSLEVEL_EnterWin16Lock(VOID
)
84 TRACE(win32
, "thread %04x (pid %d) about to enter\n",
85 THREAD_Current()->teb_sel
, getpid());
87 _EnterSysLevel(&Win16Mutex
);
89 TRACE(win32
, "thread %04x (pid %d) entered, count is %ld\n",
90 THREAD_Current()->teb_sel
, getpid(), Win16Mutex
.RecursionCount
);
93 /************************************************************************
94 * SYSLEVEL_LeaveWin16Lock [KERNEL.481]
96 VOID WINAPI
SYSLEVEL_LeaveWin16Lock(VOID
)
98 TRACE(win32
, "thread %04x (pid %d) about to leave, count is %ld\n",
99 THREAD_Current()->teb_sel
, getpid(), Win16Mutex
.RecursionCount
);
101 _LeaveSysLevel(&Win16Mutex
);
104 /************************************************************************
105 * _CheckNotSysLevel (KERNEL32.94)
107 VOID WINAPI
_CheckNotSysLevel(CRITICAL_SECTION
*lock
)
109 FIXME(win32
, "()\n");
112 /************************************************************************
113 * _ConfirmSysLevel (KERNEL32.95)
115 VOID WINAPI
_ConfirmSysLevel(CRITICAL_SECTION
*lock
)
117 FIXME(win32
, "()\n");
120 /************************************************************************
121 * _ConfirmWin16Lock (KERNEL32.96)
123 DWORD WINAPI
_ConfirmWin16Lock(void)
125 FIXME(win32
, "()\n");
129 /************************************************************************
130 * ReleaseThunkLock (KERNEL32.48)
132 VOID WINAPI
ReleaseThunkLock(DWORD
*mutex_count
)
134 DWORD count
= Win16Mutex
.RecursionCount
;
135 *mutex_count
= count
;
138 _LeaveSysLevel(&Win16Mutex
);
141 /************************************************************************
142 * RestoreThunkLock (KERNEL32.49)
144 VOID WINAPI
RestoreThunkLock(DWORD mutex_count
)
146 while (mutex_count
-- > 0)
147 _EnterSysLevel(&Win16Mutex
);
150 /************************************************************************
151 * SYSLEVEL_ReleaseWin16Lock
153 VOID
SYSLEVEL_ReleaseWin16Lock(VOID
)
157 TRACE(win32
, "thread %04x (pid %d) about to release, count is %ld\n",
158 THREAD_Current()->teb_sel
, getpid(), Win16Mutex
.RecursionCount
);
160 ReleaseThunkLock(&count
);
163 ERR(win32
, "Win16Mutex recursion count too large!\n");
165 CURRENT_STACK16
->mutex_count
= (WORD
)count
;
168 /************************************************************************
169 * SYSLEVEL_RestoreWin16Lock
171 VOID
SYSLEVEL_RestoreWin16Lock(VOID
)
173 DWORD count
= CURRENT_STACK16
->mutex_count
;
176 ERR(win32
, "Win16Mutex recursion count is zero!\n");
178 TRACE(win32
, "thread %04x (pid %d) about to restore (count %ld)\n",
179 THREAD_Current()->teb_sel
, getpid(), count
);
181 RestoreThunkLock(count
);
183 TRACE(win32
, "thread %04x (pid %d) restored lock, count is %ld\n",
184 THREAD_Current()->teb_sel
, getpid(), Win16Mutex
.RecursionCount
);