1 : /* ***** BEGIN LICENSE BLOCK *****
2 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 : *
4 : * The contents of this file are subject to the Mozilla Public License Version
5 : * 1.1 (the "License"); you may not use this file except in compliance with
6 : * the License. You may obtain a copy of the License at
7 : * http://www.mozilla.org/MPL/
8 : *
9 : * Software distributed under the License is distributed on an "AS IS" basis,
10 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 : * for the specific language governing rights and limitations under the
12 : * License.
13 : *
14 : * The Original Code is Mozilla.
15 : *
16 : * The Initial Developer of the Original Code is IBM Corporation.
17 : * Portions created by IBM Corporation are Copyright (C) 2004
18 : * IBM Corporation. All Rights Reserved.
19 : *
20 : * Contributor(s):
21 : * Darin Fisher <darin@meer.net>
22 : * Benjamin Smedberg <benjamin@smedbergs.us>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsXPCOM.h"
39 : #include "nsXPCOMPrivate.h"
40 : #include "nsXPCOMStrings.h"
41 : #include "xptcall.h"
42 :
43 : #include <string.h>
44 :
45 : /**
46 : * Private Method to register an exit routine. This method
47 : * used to allow you to setup a callback that will be called from
48 : * the NS_ShutdownXPCOM function after all services and
49 : * components have gone away. It was fatally flawed in that the component
50 : * DLL could be released before the exit function was called; it is now a
51 : * stub implementation that does nothing.
52 : */
53 : XPCOM_API(nsresult)
54 : NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority);
55 :
56 : XPCOM_API(nsresult)
57 : NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine);
58 :
59 : static const XPCOMFunctions kFrozenFunctions = {
60 : XPCOM_GLUE_VERSION,
61 : sizeof(XPCOMFunctions),
62 : &NS_InitXPCOM2_P,
63 : &NS_ShutdownXPCOM_P,
64 : &NS_GetServiceManager_P,
65 : &NS_GetComponentManager_P,
66 : &NS_GetComponentRegistrar_P,
67 : &NS_GetMemoryManager_P,
68 : &NS_NewLocalFile_P,
69 : &NS_NewNativeLocalFile_P,
70 : &NS_RegisterXPCOMExitRoutine,
71 : &NS_UnregisterXPCOMExitRoutine,
72 :
73 : // these functions were added post 1.4
74 : &NS_GetDebug_P,
75 : &NS_GetTraceRefcnt_P,
76 :
77 : // these functions were added post 1.6
78 : &NS_StringContainerInit_P,
79 : &NS_StringContainerFinish_P,
80 : &NS_StringGetData_P,
81 : &NS_StringSetData_P,
82 : &NS_StringSetDataRange_P,
83 : &NS_StringCopy_P,
84 : &NS_CStringContainerInit_P,
85 : &NS_CStringContainerFinish_P,
86 : &NS_CStringGetData_P,
87 : &NS_CStringSetData_P,
88 : &NS_CStringSetDataRange_P,
89 : &NS_CStringCopy_P,
90 : &NS_CStringToUTF16_P,
91 : &NS_UTF16ToCString_P,
92 : &NS_StringCloneData_P,
93 : &NS_CStringCloneData_P,
94 :
95 : // these functions were added post 1.7 (post Firefox 1.0)
96 : &NS_Alloc_P,
97 : &NS_Realloc_P,
98 : &NS_Free_P,
99 : &NS_StringContainerInit2_P,
100 : &NS_CStringContainerInit2_P,
101 : &NS_StringGetMutableData_P,
102 : &NS_CStringGetMutableData_P,
103 : NULL,
104 :
105 : // these functions were added post 1.8
106 : &NS_DebugBreak_P,
107 : &NS_LogInit_P,
108 : &NS_LogTerm_P,
109 : &NS_LogAddRef_P,
110 : &NS_LogRelease_P,
111 : &NS_LogCtor_P,
112 : &NS_LogDtor_P,
113 : &NS_LogCOMPtrAddRef_P,
114 : &NS_LogCOMPtrRelease_P,
115 : &NS_GetXPTCallStub_P,
116 : &NS_DestroyXPTCallStub_P,
117 : &NS_InvokeByIndex_P,
118 : &NS_CycleCollectorSuspect_P,
119 : &NS_CycleCollectorForget_P,
120 : &NS_StringSetIsVoid_P,
121 : &NS_StringGetIsVoid_P,
122 : &NS_CStringSetIsVoid_P,
123 : &NS_CStringGetIsVoid_P,
124 :
125 : // these functions were added post 1.9
126 : &NS_CycleCollectorSuspect2_P,
127 : &NS_CycleCollectorForget2_P
128 : };
129 :
130 : EXPORT_XPCOM_API(nsresult)
131 46 : NS_GetFrozenFunctions(XPCOMFunctions *functions, const char* /* libraryPath */)
132 : {
133 46 : if (!functions)
134 0 : return NS_ERROR_OUT_OF_MEMORY;
135 :
136 46 : if (functions->version != XPCOM_GLUE_VERSION)
137 0 : return NS_ERROR_FAILURE;
138 :
139 46 : PRUint32 size = functions->size;
140 46 : if (size > sizeof(XPCOMFunctions))
141 0 : size = sizeof(XPCOMFunctions);
142 :
143 46 : size -= offsetof(XPCOMFunctions, init);
144 :
145 46 : memcpy(&functions->init, &kFrozenFunctions.init, size);
146 :
147 46 : return NS_OK;
148 : }
149 :
150 : /*
151 : * Stubs for nsXPCOM.h
152 : */
153 :
154 : #undef NS_InitXPCOM2
155 : EXPORT_XPCOM_API(nsresult)
156 1419 : NS_InitXPCOM2(nsIServiceManager **result,
157 : nsIFile *binDirectory,
158 : nsIDirectoryServiceProvider *dirProvider)
159 : {
160 1419 : return NS_InitXPCOM2_P(result, binDirectory, dirProvider);
161 : }
162 :
163 : #undef NS_ShutdownXPCOM
164 : EXPORT_XPCOM_API(nsresult)
165 1419 : NS_ShutdownXPCOM(nsIServiceManager *svcMgr)
166 : {
167 1419 : return NS_ShutdownXPCOM_P(svcMgr);
168 : }
169 :
170 : #undef NS_GetServiceManager
171 : EXPORT_XPCOM_API(nsresult)
172 177855 : NS_GetServiceManager(nsIServiceManager* *result)
173 : {
174 177855 : return NS_GetServiceManager_P(result);
175 : }
176 :
177 : #undef NS_GetComponentManager
178 : EXPORT_XPCOM_API(nsresult)
179 49 : NS_GetComponentManager(nsIComponentManager* *result)
180 : {
181 49 : return NS_GetComponentManager_P(result);
182 : }
183 :
184 : #undef NS_GetComponentRegistrar
185 : EXPORT_XPCOM_API(nsresult)
186 2 : NS_GetComponentRegistrar(nsIComponentRegistrar** result)
187 : {
188 2 : return NS_GetComponentRegistrar_P(result);
189 : }
190 :
191 : #undef NS_GetMemoryManager
192 : EXPORT_XPCOM_API(nsresult)
193 0 : NS_GetMemoryManager(nsIMemory* *result)
194 : {
195 0 : return NS_GetMemoryManager_P(result);
196 : }
197 :
198 : #undef NS_NewLocalFile
199 : EXPORT_XPCOM_API(nsresult)
200 4 : NS_NewLocalFile(const nsAString &path,
201 : bool followLinks,
202 : nsILocalFile **result)
203 : {
204 4 : return NS_NewLocalFile_P(path, followLinks, result);
205 : }
206 :
207 : #undef NS_NewNativeLocalFile
208 : EXPORT_XPCOM_API(nsresult)
209 4 : NS_NewNativeLocalFile(const nsACString &path,
210 : bool followLinks,
211 : nsILocalFile **result)
212 : {
213 4 : return NS_NewNativeLocalFile_P(path, followLinks, result);
214 : }
215 :
216 : #undef NS_GetDebug
217 : EXPORT_XPCOM_API(nsresult)
218 0 : NS_GetDebug(nsIDebug **result)
219 : {
220 0 : return NS_GetDebug_P(result);
221 : }
222 :
223 : #undef NS_GetTraceRefcnt
224 : EXPORT_XPCOM_API(nsresult)
225 0 : NS_GetTraceRefcnt(nsITraceRefcnt **result)
226 : {
227 0 : return NS_GetTraceRefcnt_P(result);
228 : }
229 :
230 : #undef NS_Alloc
231 : EXPORT_XPCOM_API(void*)
232 35 : NS_Alloc(PRSize size)
233 : {
234 35 : return NS_Alloc_P(size);
235 : }
236 :
237 : #undef NS_Realloc
238 : EXPORT_XPCOM_API(void*)
239 0 : NS_Realloc(void* ptr, PRSize size)
240 : {
241 0 : return NS_Realloc_P(ptr, size);
242 : }
243 :
244 : #undef NS_Free
245 : EXPORT_XPCOM_API(void)
246 14 : NS_Free(void* ptr)
247 : {
248 14 : NS_Free_P(ptr);
249 14 : }
250 :
251 : #undef NS_DebugBreak
252 : EXPORT_XPCOM_API(void)
253 0 : NS_DebugBreak(PRUint32 aSeverity, const char *aStr, const char *aExpr,
254 : const char *aFile, PRInt32 aLine)
255 : {
256 0 : NS_DebugBreak_P(aSeverity, aStr, aExpr, aFile, aLine);
257 0 : }
258 :
259 : #undef NS_LogInit
260 : EXPORT_XPCOM_API(void)
261 1388 : NS_LogInit()
262 : {
263 1388 : NS_LogInit_P();
264 1388 : }
265 :
266 : #undef NS_LogTerm
267 : EXPORT_XPCOM_API(void)
268 1388 : NS_LogTerm()
269 : {
270 1388 : NS_LogTerm_P();
271 1388 : }
272 :
273 : #undef NS_LogAddRef
274 : EXPORT_XPCOM_API(void)
275 83360 : NS_LogAddRef(void* aPtr, nsrefcnt aNewRefCnt,
276 : const char *aTypeName, PRUint32 aInstanceSize)
277 : {
278 83360 : NS_LogAddRef_P(aPtr, aNewRefCnt, aTypeName, aInstanceSize);
279 83360 : }
280 :
281 : #undef NS_LogRelease
282 : EXPORT_XPCOM_API(void)
283 83350 : NS_LogRelease(void* aPtr, nsrefcnt aNewRefCnt, const char *aTypeName)
284 : {
285 83350 : NS_LogRelease_P(aPtr, aNewRefCnt, aTypeName);
286 83350 : }
287 :
288 : #undef NS_LogCtor
289 : EXPORT_XPCOM_API(void)
290 2902 : NS_LogCtor(void *aPtr, const char *aTypeName, PRUint32 aInstanceSize)
291 : {
292 2902 : NS_LogCtor_P(aPtr, aTypeName, aInstanceSize);
293 2902 : }
294 :
295 : #undef NS_LogDtor
296 : EXPORT_XPCOM_API(void)
297 2886 : NS_LogDtor(void *aPtr, const char *aTypeName, PRUint32 aInstanceSize)
298 : {
299 2886 : NS_LogDtor_P(aPtr, aTypeName, aInstanceSize);
300 2886 : }
301 :
302 : #undef NS_LogCOMPtrAddRef
303 : EXPORT_XPCOM_API(void)
304 565834 : NS_LogCOMPtrAddRef(void *aCOMPtr, nsISupports* aObject)
305 : {
306 565834 : NS_LogCOMPtrAddRef_P(aCOMPtr, aObject);
307 565834 : }
308 :
309 : #undef NS_LogCOMPtrRelease
310 : EXPORT_XPCOM_API(void)
311 565797 : NS_LogCOMPtrRelease(void *aCOMPtr, nsISupports* aObject)
312 : {
313 565797 : NS_LogCOMPtrRelease_P(aCOMPtr, aObject);
314 565797 : }
315 :
316 : #undef NS_GetXPTCallStub
317 : EXPORT_XPCOM_API(nsresult)
318 0 : NS_GetXPTCallStub(REFNSIID aIID, nsIXPTCProxy* aOuter,
319 : nsISomeInterface* *aStub)
320 : {
321 0 : return NS_GetXPTCallStub_P(aIID, aOuter, aStub);
322 : }
323 :
324 : #undef NS_DestroyXPTCallStub
325 : EXPORT_XPCOM_API(void)
326 0 : NS_DestroyXPTCallStub(nsISomeInterface* aStub)
327 : {
328 0 : NS_DestroyXPTCallStub_P(aStub);
329 0 : }
330 :
331 : #undef NS_InvokeByIndex
332 : EXPORT_XPCOM_API(nsresult)
333 0 : NS_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
334 : PRUint32 paramCount, nsXPTCVariant* params)
335 : {
336 0 : return NS_InvokeByIndex_P(that, methodIndex, paramCount, params);
337 : }
338 :
339 : /*
340 : * Stubs for nsXPCOMPrivate.h
341 : */
342 :
343 : EXPORT_XPCOM_API(nsresult)
344 0 : NS_RegisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine, PRUint32 priority)
345 : {
346 0 : return NS_OK;
347 : }
348 :
349 : EXPORT_XPCOM_API(nsresult)
350 0 : NS_UnregisterXPCOMExitRoutine(XPCOMExitRoutine exitRoutine)
351 : {
352 0 : return NS_OK;
353 : }
354 :
355 : /*
356 : * Stubs for nsStringAPI.h
357 : */
358 :
359 : #undef NS_StringContainerInit
360 : EXPORT_XPCOM_API(nsresult)
361 2803 : NS_StringContainerInit(nsStringContainer &aStr)
362 : {
363 2803 : return NS_StringContainerInit_P(aStr);
364 : }
365 :
366 : #undef NS_StringContainerInit2
367 : EXPORT_XPCOM_API(nsresult)
368 56 : NS_StringContainerInit2(nsStringContainer &aStr,
369 : const PRUnichar *aData,
370 : PRUint32 aDataLength,
371 : PRUint32 aFlags)
372 : {
373 56 : return NS_StringContainerInit2_P(aStr, aData, aDataLength, aFlags);
374 : }
375 :
376 : #undef NS_StringContainerFinish
377 : EXPORT_XPCOM_API(void)
378 2859 : NS_StringContainerFinish(nsStringContainer &aStr)
379 : {
380 2859 : NS_StringContainerFinish_P(aStr);
381 2859 : }
382 :
383 : #undef NS_StringGetData
384 : EXPORT_XPCOM_API(PRUint32)
385 154 : NS_StringGetData(const nsAString &aStr, const PRUnichar **aBuf, bool *aTerm)
386 : {
387 154 : return NS_StringGetData_P(aStr, aBuf, aTerm);
388 : }
389 :
390 : #undef NS_StringGetMutableData
391 : EXPORT_XPCOM_API(PRUint32)
392 30 : NS_StringGetMutableData(nsAString &aStr, PRUint32 aLen, PRUnichar **aBuf)
393 : {
394 30 : return NS_StringGetMutableData_P(aStr, aLen, aBuf);
395 : }
396 :
397 : #undef NS_StringCloneData
398 : EXPORT_XPCOM_API(PRUnichar *)
399 4 : NS_StringCloneData(const nsAString &aStr)
400 : {
401 4 : return NS_StringCloneData_P(aStr);
402 : }
403 :
404 : #undef NS_StringSetData
405 : EXPORT_XPCOM_API(nsresult)
406 3 : NS_StringSetData(nsAString &aStr, const PRUnichar *aBuf, PRUint32 aCount)
407 : {
408 3 : return NS_StringSetData_P(aStr, aBuf, aCount);
409 : }
410 :
411 : #undef NS_StringSetDataRange
412 : EXPORT_XPCOM_API(nsresult)
413 83 : NS_StringSetDataRange(nsAString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
414 : const PRUnichar *aBuf, PRUint32 aCount)
415 : {
416 83 : return NS_StringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
417 : }
418 :
419 : #undef NS_StringCopy
420 : EXPORT_XPCOM_API(nsresult)
421 1395 : NS_StringCopy(nsAString &aDest, const nsAString &aSrc)
422 : {
423 1395 : return NS_StringCopy_P(aDest, aSrc);
424 : }
425 :
426 : #undef NS_StringSetIsVoid
427 : EXPORT_XPCOM_API(void)
428 4 : NS_StringSetIsVoid(nsAString &aStr, const bool aIsVoid)
429 : {
430 4 : NS_StringSetIsVoid_P(aStr, aIsVoid);
431 4 : }
432 :
433 : #undef NS_StringGetIsVoid
434 : EXPORT_XPCOM_API(bool)
435 5 : NS_StringGetIsVoid(const nsAString &aStr)
436 : {
437 5 : return NS_StringGetIsVoid_P(aStr);
438 : }
439 :
440 : #undef NS_CStringContainerInit
441 : EXPORT_XPCOM_API(nsresult)
442 13162 : NS_CStringContainerInit(nsCStringContainer &aStr)
443 : {
444 13162 : return NS_CStringContainerInit_P(aStr);
445 : }
446 :
447 : #undef NS_CStringContainerInit2
448 : EXPORT_XPCOM_API(nsresult)
449 6429 : NS_CStringContainerInit2(nsCStringContainer &aStr,
450 : const char *aData,
451 : PRUint32 aDataLength,
452 : PRUint32 aFlags)
453 : {
454 6429 : return NS_CStringContainerInit2_P(aStr, aData, aDataLength, aFlags);
455 : }
456 :
457 : #undef NS_CStringContainerFinish
458 : EXPORT_XPCOM_API(void)
459 19591 : NS_CStringContainerFinish(nsCStringContainer &aStr)
460 : {
461 19591 : NS_CStringContainerFinish_P(aStr);
462 19591 : }
463 :
464 : #undef NS_CStringGetData
465 : EXPORT_XPCOM_API(PRUint32)
466 16501 : NS_CStringGetData(const nsACString &aStr, const char **aBuf, bool *aTerm)
467 : {
468 16501 : return NS_CStringGetData_P(aStr, aBuf, aTerm);
469 : }
470 :
471 : #undef NS_CStringGetMutableData
472 : EXPORT_XPCOM_API(PRUint32)
473 4180 : NS_CStringGetMutableData(nsACString &aStr, PRUint32 aLen, char **aBuf)
474 : {
475 4180 : return NS_CStringGetMutableData_P(aStr, aLen, aBuf);
476 : }
477 :
478 : #undef NS_CStringCloneData
479 : EXPORT_XPCOM_API(char *)
480 8 : NS_CStringCloneData(const nsACString &aStr)
481 : {
482 8 : return NS_CStringCloneData_P(aStr);
483 : }
484 :
485 : #undef NS_CStringSetData
486 : EXPORT_XPCOM_API(nsresult)
487 7747 : NS_CStringSetData(nsACString &aStr, const char *aBuf, PRUint32 aCount)
488 : {
489 7747 : return NS_CStringSetData_P(aStr, aBuf, aCount);
490 : }
491 :
492 : #undef NS_CStringSetDataRange
493 : EXPORT_XPCOM_API(nsresult)
494 2084 : NS_CStringSetDataRange(nsACString &aStr, PRUint32 aCutStart, PRUint32 aCutLength,
495 : const char *aBuf, PRUint32 aCount)
496 : {
497 2084 : return NS_CStringSetDataRange_P(aStr, aCutStart, aCutLength, aBuf, aCount);
498 : }
499 :
500 : #undef NS_CStringCopy
501 : EXPORT_XPCOM_API(nsresult)
502 11275 : NS_CStringCopy(nsACString &aDest, const nsACString &aSrc)
503 : {
504 11275 : return NS_CStringCopy_P(aDest, aSrc);
505 : }
506 :
507 : #undef NS_CStringSetIsVoid
508 : EXPORT_XPCOM_API(void)
509 0 : NS_CStringSetIsVoid(nsACString &aStr, const bool aIsVoid)
510 : {
511 0 : NS_CStringSetIsVoid_P(aStr, aIsVoid);
512 0 : }
513 :
514 : #undef NS_CStringGetIsVoid
515 : EXPORT_XPCOM_API(bool)
516 0 : NS_CStringGetIsVoid(const nsACString &aStr)
517 : {
518 0 : return NS_CStringGetIsVoid_P(aStr);
519 : }
520 :
521 : #undef NS_CStringToUTF16
522 : EXPORT_XPCOM_API(nsresult)
523 1393 : NS_CStringToUTF16(const nsACString &aSrc, nsCStringEncoding aSrcEncoding, nsAString &aDest)
524 : {
525 1393 : return NS_CStringToUTF16_P(aSrc, aSrcEncoding, aDest);
526 : }
527 :
528 : #undef NS_UTF16ToCString
529 : EXPORT_XPCOM_API(nsresult)
530 2 : NS_UTF16ToCString(const nsAString &aSrc, nsCStringEncoding aDestEncoding, nsACString &aDest)
531 : {
532 2 : return NS_UTF16ToCString_P(aSrc, aDestEncoding, aDest);
533 : }
534 :
535 : #undef NS_CycleCollectorSuspect
536 : EXPORT_XPCOM_API(bool)
537 0 : NS_CycleCollectorSuspect(nsISupports* obj)
538 : {
539 0 : return NS_CycleCollectorSuspect_P(obj);
540 : }
541 :
542 : #undef NS_CycleCollectorForget
543 : EXPORT_XPCOM_API(bool)
544 0 : NS_CycleCollectorForget(nsISupports* obj)
545 : {
546 0 : return NS_CycleCollectorForget_P(obj);
547 : }
548 :
549 : #undef NS_CycleCollectorSuspect2
550 : EXPORT_XPCOM_API(nsPurpleBufferEntry*)
551 0 : NS_CycleCollectorSuspect2(nsISupports* obj)
552 : {
553 0 : return NS_CycleCollectorSuspect2_P(obj);
554 : }
555 :
556 : #undef NS_CycleCollectorForget2
557 : EXPORT_XPCOM_API(bool)
558 0 : NS_CycleCollectorForget2(nsPurpleBufferEntry* e)
559 : {
560 0 : return NS_CycleCollectorForget2_P(e);
561 : }
|