Added check for st_blocks in struct stat.
[wine/multimedia.git] / loader / task.c
blobc457039edc83ba44de5a4301fd3b564cf5a363a9
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 * GetCurrentTask (KERNEL32.@)
73 HTASK16 WINAPI GetCurrentTask(void)
75 return NtCurrentTeb()->htask16;
78 /***********************************************************************
79 * GetExePtrHelper
81 static inline HMODULE16 GetExePtrHelper( HANDLE16 handle, HTASK16 *hTask )
83 char *ptr;
84 HANDLE16 owner;
86 /* Check for module handle */
88 if (!(ptr = GlobalLock16( handle ))) return 0;
89 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return handle;
91 /* Search for this handle inside all tasks */
93 *hTask = hFirstTask;
94 while (*hTask)
96 TDB *pTask = TASK_GetPtr( *hTask );
97 if ((*hTask == handle) ||
98 (pTask->hInstance == handle) ||
99 (pTask->hQueue == handle) ||
100 (pTask->hPDB == handle)) return pTask->hModule;
101 *hTask = pTask->hNext;
104 /* Check the owner for module handle */
106 owner = FarGetOwner16( handle );
107 if (!(ptr = GlobalLock16( owner ))) return 0;
108 if (((NE_MODULE *)ptr)->magic == IMAGE_OS2_SIGNATURE) return owner;
110 /* Search for the owner inside all tasks */
112 *hTask = hFirstTask;
113 while (*hTask)
115 TDB *pTask = TASK_GetPtr( *hTask );
116 if ((*hTask == owner) ||
117 (pTask->hInstance == owner) ||
118 (pTask->hQueue == owner) ||
119 (pTask->hPDB == owner)) return pTask->hModule;
120 *hTask = pTask->hNext;
123 return 0;
126 /***********************************************************************
127 * K228 (KERNEL.228)
129 HMODULE16 WINAPI GetExePtr( HANDLE16 handle )
131 HTASK16 hTask = 0;
132 return GetExePtrHelper( handle, &hTask );