1 | /* $Id: DosLoadModuleEx.c 2254 2005-07-17 12:25:44Z bird $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * DosCreateEventSemEx.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This file is part of InnoTek LIBC.
|
---|
10 | *
|
---|
11 | * InnoTek LIBC is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU Lesser General Public License as published
|
---|
13 | * by the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * InnoTek LIBC is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU Lesser General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU Lesser General Public License
|
---|
22 | * along with InnoTek LIBC; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*******************************************************************************
|
---|
28 | * Header Files *
|
---|
29 | *******************************************************************************/
|
---|
30 | #include "libc-alias.h"
|
---|
31 | #define INCL_ERRORS
|
---|
32 | #define INCL_DOSMODULEMGR
|
---|
33 | #define INCL_FSMACROS
|
---|
34 | #define INCL_EXAPIS
|
---|
35 | #include <os2emx.h>
|
---|
36 | #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_DOSEX
|
---|
37 | #include <InnoTekLIBC/logstrict.h>
|
---|
38 | #include "DosEx.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Extended DosLoadModule() which will make sure the loaded module is
|
---|
43 | * loaded in a forked process.
|
---|
44 | */
|
---|
45 | APIRET APIENTRY DosLoadModuleEx(PSZ pszObject, ULONG cbObject, PCSZ pszModule, PHMODULE phmod)
|
---|
46 | {
|
---|
47 | LIBCLOG_ENTER("pszObject=%p cbObject=%ld pszModule=%p:{'%s'} phmod=%p\n", pszObject, cbObject, (void *)pszModule, pszModule, (void *)phmod);
|
---|
48 | DOSEXTYPE enmType;
|
---|
49 | PDOSEX pDosEx;
|
---|
50 | HMODULE hmte;
|
---|
51 | int rc;
|
---|
52 | FS_VAR();
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * Create the semaphore.
|
---|
56 | */
|
---|
57 | FS_SAVE_LOAD();
|
---|
58 | rc = DosLoadModule(pszObject, cbObject, pszModule, phmod);
|
---|
59 | if (rc)
|
---|
60 | {
|
---|
61 | FS_RESTORE();
|
---|
62 | LIBCLOG_ERROR_RETURN_INT(rc);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /*
|
---|
66 | * Check if already loaded.
|
---|
67 | */
|
---|
68 | hmte = *phmod;
|
---|
69 | pDosEx = __libc_dosexFind(DOSEX_TYPE_LOAD_MODULE, (unsigned)hmte);
|
---|
70 | if (pDosEx)
|
---|
71 | {
|
---|
72 | pDosEx->u.LoadModule.cLoads++;
|
---|
73 | __libc_dosexRelease(pDosEx);
|
---|
74 | }
|
---|
75 | else
|
---|
76 | {
|
---|
77 | /*
|
---|
78 | * Allocate record.
|
---|
79 | */
|
---|
80 | enmType = DOSEX_TYPE_LOAD_MODULE;
|
---|
81 | pDosEx = __libc_dosexAlloc(enmType);
|
---|
82 | if (!pDosEx)
|
---|
83 | {
|
---|
84 | DosFreeModule(hmte);
|
---|
85 | FS_RESTORE();
|
---|
86 | LIBCLOG_ERROR_RETURN_INT(ERROR_NOT_ENOUGH_MEMORY);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /*
|
---|
90 | * Initialize record.
|
---|
91 | */
|
---|
92 | pDosEx->u.LoadModule.hmte = hmte;
|
---|
93 | pDosEx->u.LoadModule.cLoads = 1;
|
---|
94 | }
|
---|
95 |
|
---|
96 | FS_RESTORE();
|
---|
97 | LIBCLOG_RETURN_MSG(0, "ret 0 *phmod=%#lx\n", hmte);
|
---|
98 | }
|
---|
99 |
|
---|