On x86 compilers without fastcall, simulate it when invoking traces and un-simulate...
[wine-gecko.git] / xpcom / glue / standalone / nsGlueLinkingOS2.cpp
blobc2f3856810098bc24f021ada20422b881aaf9469
1 /* -*- Mode: C++; tab-width: 6; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla XPCOM.
17 * The Initial Developer of the Original Code is
18 * Benjamin Smedberg <benjamin@smedbergs.us>
20 * Portions created by the Initial Developer are Copyright (C) 2005
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsGlueLinking.h"
40 #include "nsXPCOMGlue.h"
42 #define INCL_DOS
43 #define INCL_DOSERRORS
44 #include <os2.h>
45 #include <stdlib.h>
46 #include <stdio.h>
48 struct DependentLib
50 HMODULE libHandle;
51 DependentLib *next;
54 static DependentLib *sTop;
55 HMODULE sXULLibrary = NULLHANDLE;
57 static void
58 AppendDependentLib(HMODULE libHandle)
60 DependentLib *d = new DependentLib;
61 if (!d)
62 return;
64 d->next = sTop;
65 d->libHandle = libHandle;
67 sTop = d;
70 static void
71 ReadDependentCB(const char *aDependentLib)
73 CHAR pszError[_MAX_PATH];
74 ULONG ulrc = NO_ERROR;
75 HMODULE h;
77 ulrc = DosLoadModule(pszError, _MAX_PATH, aDependentLib, &h);
79 if (ulrc != NO_ERROR)
80 return;
82 AppendDependentLib(h);
85 // like strpbrk but finds the *last* char, not the first
86 static char*
87 ns_strrpbrk(char *string, const char *strCharSet)
89 char *found = NULL;
90 for (; *string; ++string) {
91 for (const char *search = strCharSet; *search; ++search) {
92 if (*search == *string) {
93 found = string;
94 // Since we're looking for the last char, we save "found"
95 // until we're at the end of the string.
100 return found;
103 GetFrozenFunctionsFunc
104 XPCOMGlueLoad(const char *xpcomFile)
106 CHAR pszError[_MAX_PATH];
107 ULONG ulrc = NO_ERROR;
108 HMODULE h;
110 if (xpcomFile[0] == '.' && xpcomFile[1] == '\0') {
111 xpcomFile = XPCOM_DLL;
113 else {
114 char xpcomDir[MAXPATHLEN];
116 _fullpath(xpcomDir, xpcomFile, sizeof(xpcomDir));
117 char *lastSlash = ns_strrpbrk(xpcomDir, "/\\");
118 if (lastSlash) {
119 *lastSlash = '\0';
121 XPCOMGlueLoadDependentLibs(xpcomDir, ReadDependentCB);
123 snprintf(lastSlash, MAXPATHLEN - strlen(xpcomDir), "\\" XUL_DLL);
125 DosLoadModule(pszError, _MAX_PATH, xpcomDir, &sXULLibrary);
129 ulrc = DosLoadModule(pszError, _MAX_PATH, xpcomFile, &h);
131 if (ulrc != NO_ERROR)
132 return nsnull;
134 AppendDependentLib(h);
136 GetFrozenFunctionsFunc sym;
138 ulrc = DosQueryProcAddr(h, 0, "_NS_GetFrozenFunctions", (PFN*)&sym);
140 if (ulrc != NO_ERROR)
141 XPCOMGlueUnload();
143 return sym;
146 void
147 XPCOMGlueUnload()
149 while (sTop) {
150 DosFreeModule(sTop->libHandle);
152 DependentLib *temp = sTop;
153 sTop = sTop->next;
155 delete temp;
158 if (sXULLibrary) {
159 DosFreeModule(sXULLibrary);
160 sXULLibrary = nsnull;
164 nsresult
165 XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad *symbols)
167 ULONG ulrc = NO_ERROR;
169 if (!sXULLibrary)
170 return NS_ERROR_NOT_INITIALIZED;
172 nsresult rv = NS_OK;
173 while (symbols->functionName) {
174 char buffer[512];
175 snprintf(buffer, sizeof(buffer), "_%s", symbols->functionName);
176 ulrc = DosQueryProcAddr(sXULLibrary, 0, buffer, (PFN*)symbols->function);
178 if (ulrc != NO_ERROR)
179 rv = NS_ERROR_LOSS_OF_SIGNIFICANT_DATA;
181 ++symbols;
184 return rv;