- Moved Wine extension to get DSound interface from a wave device from
[wine.git] / loader / task.c
blob245ab13f887d77bab3636ec940e0aa3b8f5d284c
1 /*
2 * Task functions
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <assert.h>
28 #ifdef HAVE_UNISTD_H
29 # include <unistd.h>
30 #endif
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winnt.h"
36 #include "winuser.h"
38 #include "wine/winbase16.h"
39 #include "drive.h"
40 #include "file.h"
41 #include "global.h"
42 #include "instance.h"
43 #include "module.h"
44 #include "winternl.h"
45 #include "selectors.h"
46 #include "wine/server.h"
47 #include "stackframe.h"
48 #include "task.h"
49 #include "thread.h"
50 #include "toolhelp.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(task);
56 static THHOOK DefaultThhook;
57 THHOOK *pThhook = &DefaultThhook;
59 #define hFirstTask (pThhook->HeadTDB)
61 /***********************************************************************
62 * TASK_GetPtr
64 static TDB *TASK_GetPtr( HTASK16 hTask )
66 return GlobalLock16( hTask );
70 /***********************************************************************
71 * TASK_GetCurrent
73 TDB *TASK_GetCurrent(void)
75 return TASK_GetPtr( GetCurrentTask() );
79 /***********************************************************************
80 * GetCurrentTask (KERNEL32.@)
82 HTASK16 WINAPI GetCurrentTask(void)
84 return NtCurrentTeb()->htask16;
87 /***********************************************************************
88 * GetCurrentPDB (KERNEL.37)
90 * UNDOC: returns PSP of KERNEL in high word
92 DWORD WINAPI GetCurrentPDB16(void)
94 TDB *pTask;
96 if (!(pTask = TASK_GetCurrent())) return 0;
97 return MAKELONG(pTask->hPDB, 0); /* FIXME */
101 /***********************************************************************
102 * GetExePtrHelper
104 static inline HMODULE16 GetExePtrHelper( HANDLE16 handle, HTASK16 *hTask )
106 char *ptr;
107 HANDLE16 owner;
109 /* Check for module handle */
111 if (!(ptr = GlobalLock16( handle ))) return 0;
112 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return handle;
114 /* Search for this handle inside all tasks */
116 *hTask = hFirstTask;
117 while (*hTask)
119 TDB *pTask = TASK_GetPtr( *hTask );
120 if ((*hTask == handle) ||
121 (pTask->hInstance == handle) ||
122 (pTask->hQueue == handle) ||
123 (pTask->hPDB == handle)) return pTask->hModule;
124 *hTask = pTask->hNext;
127 /* Check the owner for module handle */
129 owner = FarGetOwner16( handle );
130 if (!(ptr = GlobalLock16( owner ))) return 0;
131 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return owner;
133 /* Search for the owner inside all tasks */
135 *hTask = hFirstTask;
136 while (*hTask)
138 TDB *pTask = TASK_GetPtr( *hTask );
139 if ((*hTask == owner) ||
140 (pTask->hInstance == owner) ||
141 (pTask->hQueue == owner) ||
142 (pTask->hPDB == owner)) return pTask->hModule;
143 *hTask = pTask->hNext;
146 return 0;
149 /***********************************************************************
150 * GetExePtr (KERNEL.133)
152 HMODULE16 WINAPI WIN16_GetExePtr( HANDLE16 handle )
154 HTASK16 hTask = 0;
155 HMODULE16 hModule = GetExePtrHelper( handle, &hTask );
156 STACK16FRAME *frame = CURRENT_STACK16;
157 frame->ecx = hModule;
158 if (hTask) frame->es = hTask;
159 return hModule;
163 /***********************************************************************
164 * K228 (KERNEL.228)
166 HMODULE16 WINAPI GetExePtr( HANDLE16 handle )
168 HTASK16 hTask = 0;
169 return GetExePtrHelper( handle, &hTask );