1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/base/nscore.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,342 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nscore_h___ 1.10 +#define nscore_h___ 1.11 + 1.12 +/** 1.13 + * Make sure that we have the proper platform specific 1.14 + * c++ definitions needed by nscore.h 1.15 + */ 1.16 +#ifndef _XPCOM_CONFIG_H_ 1.17 +#include "xpcom-config.h" 1.18 +#endif 1.19 + 1.20 +/* Definitions of functions and operators that allocate memory. */ 1.21 +#if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC) 1.22 +# include "mozilla/mozalloc.h" 1.23 +#endif 1.24 + 1.25 +/** 1.26 + * Incorporate the integer data types which XPCOM uses. 1.27 + */ 1.28 +#include <stddef.h> 1.29 +#include <stdint.h> 1.30 + 1.31 +#ifdef __cplusplus 1.32 +# include "mozilla/NullPtr.h" 1.33 +#endif 1.34 + 1.35 +#include "mozilla/RefCountType.h" 1.36 + 1.37 +/* Core XPCOM declarations. */ 1.38 + 1.39 +/*----------------------------------------------------------------------*/ 1.40 +/* Import/export defines */ 1.41 + 1.42 +/** 1.43 + * Using the visibility("hidden") attribute allows the compiler to use 1.44 + * PC-relative addressing to call this function. If a function does not 1.45 + * access any global data, and does not call any methods which are not either 1.46 + * file-local or hidden, then on ELF systems we avoid loading the address of 1.47 + * the PLT into a register at the start of the function, which reduces code 1.48 + * size and frees up a register for general use. 1.49 + * 1.50 + * As a general rule, this should be used for any non-exported symbol 1.51 + * (including virtual method implementations). NS_IMETHOD uses this by 1.52 + * default; if you need to have your NS_IMETHOD functions exported, you can 1.53 + * wrap your class as follows: 1.54 + * 1.55 + * #undef IMETHOD_VISIBILITY 1.56 + * #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT 1.57 + * 1.58 + * class Foo { 1.59 + * ... 1.60 + * }; 1.61 + * 1.62 + * #undef IMETHOD_VISIBILITY 1.63 + * #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN 1.64 + * 1.65 + * Don't forget to change the visibility back to hidden before the end 1.66 + * of a header! 1.67 + * 1.68 + * Other examples: 1.69 + * 1.70 + * NS_HIDDEN_(int) someMethod(); 1.71 + * SomeCtor() NS_HIDDEN; 1.72 + */ 1.73 + 1.74 +#ifdef HAVE_VISIBILITY_HIDDEN_ATTRIBUTE 1.75 +#define NS_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden"))) 1.76 +#else 1.77 +#define NS_VISIBILITY_HIDDEN 1.78 +#endif 1.79 + 1.80 +#if defined(HAVE_VISIBILITY_ATTRIBUTE) 1.81 +#define NS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default"))) 1.82 +#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) 1.83 +#define NS_VISIBILITY_DEFAULT __global 1.84 +#else 1.85 +#define NS_VISIBILITY_DEFAULT 1.86 +#endif 1.87 + 1.88 +#define NS_HIDDEN_(type) NS_VISIBILITY_HIDDEN type 1.89 +#define NS_EXTERNAL_VIS_(type) NS_VISIBILITY_DEFAULT type 1.90 + 1.91 +#define NS_HIDDEN NS_VISIBILITY_HIDDEN 1.92 +#define NS_EXTERNAL_VIS NS_VISIBILITY_DEFAULT 1.93 + 1.94 +#undef IMETHOD_VISIBILITY 1.95 +#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN 1.96 + 1.97 +/** 1.98 + * Mark a function as using a potentially non-standard function calling 1.99 + * convention. This can be used on functions that are called very 1.100 + * frequently, to reduce the overhead of the function call. It is still worth 1.101 + * using the macro for C++ functions which take no parameters since it allows 1.102 + * passing |this| in a register. 1.103 + * 1.104 + * - Do not use this on any scriptable interface method since xptcall won't be 1.105 + * aware of the different calling convention. 1.106 + * - This must appear on the declaration, not the definition. 1.107 + * - Adding this to a public function _will_ break binary compatibility. 1.108 + * - This may be used on virtual functions but you must ensure it is applied 1.109 + * to all implementations - the compiler will _not_ warn but it will crash. 1.110 + * - This has no effect for functions which take a variable number of 1.111 + * arguments. 1.112 + * - __fastcall on windows should not be applied to class 1.113 + * constructors/destructors - use the NS_CONSTRUCTOR_FASTCALL macro for 1.114 + * constructors/destructors. 1.115 + * 1.116 + * Examples: int NS_FASTCALL func1(char *foo); 1.117 + * NS_HIDDEN_(int) NS_FASTCALL func2(char *foo); 1.118 + */ 1.119 + 1.120 +#if defined(__i386__) && defined(__GNUC__) 1.121 +#define NS_FASTCALL __attribute__ ((regparm (3), stdcall)) 1.122 +#define NS_CONSTRUCTOR_FASTCALL __attribute__ ((regparm (3), stdcall)) 1.123 +#elif defined(XP_WIN) && !defined(_WIN64) 1.124 +#define NS_FASTCALL __fastcall 1.125 +#define NS_CONSTRUCTOR_FASTCALL 1.126 +#else 1.127 +#define NS_FASTCALL 1.128 +#define NS_CONSTRUCTOR_FASTCALL 1.129 +#endif 1.130 + 1.131 +#ifdef XP_WIN 1.132 + 1.133 +#define NS_IMPORT __declspec(dllimport) 1.134 +#define NS_IMPORT_(type) __declspec(dllimport) type __stdcall 1.135 +#define NS_EXPORT __declspec(dllexport) 1.136 +#define NS_EXPORT_(type) __declspec(dllexport) type __stdcall 1.137 +#define NS_IMETHOD_(type) virtual type __stdcall 1.138 +#define NS_IMETHODIMP_(type) type __stdcall 1.139 +#define NS_METHOD_(type) type __stdcall 1.140 +#define NS_CALLBACK_(_type, _name) _type (__stdcall * _name) 1.141 +#ifndef _WIN64 1.142 +// Win64 has only one calling convention. __stdcall will be ignored by the compiler. 1.143 +#define NS_STDCALL __stdcall 1.144 +#define NS_HAVE_STDCALL 1.145 +#else 1.146 +#define NS_STDCALL 1.147 +#endif 1.148 +#define NS_FROZENCALL __cdecl 1.149 + 1.150 +/* 1.151 + These are needed to mark static members in exported classes, due to 1.152 + gcc bug XXX insert bug# here. 1.153 + */ 1.154 + 1.155 +#define NS_EXPORT_STATIC_MEMBER_(type) type 1.156 +#define NS_IMPORT_STATIC_MEMBER_(type) type 1.157 + 1.158 +#else 1.159 + 1.160 +#define NS_IMPORT NS_EXTERNAL_VIS 1.161 +#define NS_IMPORT_(type) NS_EXTERNAL_VIS_(type) 1.162 +#define NS_EXPORT NS_EXTERNAL_VIS 1.163 +#define NS_EXPORT_(type) NS_EXTERNAL_VIS_(type) 1.164 +#define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type 1.165 +#define NS_IMETHODIMP_(type) type 1.166 +#define NS_METHOD_(type) type 1.167 +#define NS_CALLBACK_(_type, _name) _type (* _name) 1.168 +#define NS_STDCALL 1.169 +#define NS_FROZENCALL 1.170 +#define NS_EXPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) 1.171 +#define NS_IMPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type) 1.172 + 1.173 +#endif 1.174 + 1.175 +/** 1.176 + * Macro for creating typedefs for pointer-to-member types which are 1.177 + * declared with stdcall. It is important to use this for any type which is 1.178 + * declared as stdcall (i.e. NS_IMETHOD). For example, instead of writing: 1.179 + * 1.180 + * typedef nsresult (nsIFoo::*someType)(nsISupports* arg); 1.181 + * 1.182 + * you should write: 1.183 + * 1.184 + * typedef 1.185 + * NS_STDCALL_FUNCPROTO(nsresult, someType, nsIFoo, typeFunc, (nsISupports*)); 1.186 + * 1.187 + * where nsIFoo::typeFunc is any method declared as 1.188 + * NS_IMETHOD typeFunc(nsISupports*); 1.189 + * 1.190 + * XXX this can be simplified to always use the non-typeof implementation 1.191 + * when http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11893 is fixed. 1.192 + */ 1.193 + 1.194 +#ifdef __GNUC__ 1.195 +#define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \ 1.196 + typeof(&class::func) name 1.197 +#else 1.198 +#define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \ 1.199 + ret (NS_STDCALL class::*name) args 1.200 +#endif 1.201 + 1.202 +/** 1.203 + * Deprecated declarations. 1.204 + */ 1.205 +#ifdef __GNUC__ 1.206 +# define MOZ_DEPRECATED __attribute__((deprecated)) 1.207 +#elif defined(_MSC_VER) 1.208 +# define MOZ_DEPRECATED __declspec(deprecated) 1.209 +#else 1.210 +# define MOZ_DEPRECATED 1.211 +#endif 1.212 + 1.213 +/** 1.214 + * Generic API modifiers which return the standard XPCOM nsresult type 1.215 + */ 1.216 +#define NS_IMETHOD NS_IMETHOD_(nsresult) 1.217 +#define NS_IMETHODIMP NS_IMETHODIMP_(nsresult) 1.218 +#define NS_METHOD NS_METHOD_(nsresult) 1.219 +#define NS_CALLBACK(_name) NS_CALLBACK_(nsresult, _name) 1.220 + 1.221 +/** 1.222 + * Import/Export macros for XPCOM APIs 1.223 + */ 1.224 + 1.225 +#ifdef __cplusplus 1.226 +#define NS_EXTERN_C extern "C" 1.227 +#else 1.228 +#define NS_EXTERN_C 1.229 +#endif 1.230 + 1.231 +#define EXPORT_XPCOM_API(type) NS_EXTERN_C NS_EXPORT type NS_FROZENCALL 1.232 +#define IMPORT_XPCOM_API(type) NS_EXTERN_C NS_IMPORT type NS_FROZENCALL 1.233 +#define GLUE_XPCOM_API(type) NS_EXTERN_C NS_HIDDEN_(type) NS_FROZENCALL 1.234 + 1.235 +#ifdef IMPL_LIBXUL 1.236 +#define XPCOM_API(type) EXPORT_XPCOM_API(type) 1.237 +#elif defined(XPCOM_GLUE) 1.238 +#define XPCOM_API(type) GLUE_XPCOM_API(type) 1.239 +#else 1.240 +#define XPCOM_API(type) IMPORT_XPCOM_API(type) 1.241 +#endif 1.242 + 1.243 +#ifdef MOZILLA_INTERNAL_API 1.244 +# define NS_COM_GLUE 1.245 + /* 1.246 + The frozen string API has different definitions of nsAC?String 1.247 + classes than the internal API. On systems that explicitly declare 1.248 + dllexport symbols this is not a problem, but on ELF systems 1.249 + internal symbols can accidentally "shine through"; we rename the 1.250 + internal classes to avoid symbol conflicts. 1.251 + */ 1.252 +# define nsAString nsAString_internal 1.253 +# define nsACString nsACString_internal 1.254 +#else 1.255 +# ifdef HAVE_VISIBILITY_ATTRIBUTE 1.256 +# define NS_COM_GLUE NS_VISIBILITY_HIDDEN 1.257 +# else 1.258 +# define NS_COM_GLUE 1.259 +# endif 1.260 +#endif 1.261 + 1.262 +#if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING)) 1.263 +/* Make refcnt logging part of the build. This doesn't mean that 1.264 + * actual logging will occur (that requires a separate enable; see 1.265 + * nsTraceRefcnt and nsISupportsImpl.h for more information). */ 1.266 +#define NS_BUILD_REFCNT_LOGGING 1.267 +#endif 1.268 + 1.269 +/* If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging 1.270 + * in the build. This overrides FORCE_BUILD_REFCNT_LOGGING. */ 1.271 +#if defined(NO_BUILD_REFCNT_LOGGING) 1.272 +#undef NS_BUILD_REFCNT_LOGGING 1.273 +#endif 1.274 + 1.275 +/* If a program allocates memory for the lifetime of the app, it doesn't make 1.276 + * sense to touch memory pages and free that memory at shutdown, 1.277 + * unless we are running leak stats. 1.278 + */ 1.279 +#if defined(NS_TRACE_MALLOC) || defined(NS_BUILD_REFCNT_LOGGING) || defined(MOZ_VALGRIND) 1.280 +#define NS_FREE_PERMANENT_DATA 1.281 +#endif 1.282 + 1.283 +/** 1.284 + * NS_NO_VTABLE is emitted by xpidl in interface declarations whenever 1.285 + * xpidl can determine that the interface can't contain a constructor. 1.286 + * This results in some space savings and possible runtime savings - 1.287 + * see bug 49416. We undefine it first, as xpidl-generated headers 1.288 + * define it for IDL uses that don't include this file. 1.289 + */ 1.290 +#ifdef NS_NO_VTABLE 1.291 +#undef NS_NO_VTABLE 1.292 +#endif 1.293 +#if defined(_MSC_VER) 1.294 +#define NS_NO_VTABLE __declspec(novtable) 1.295 +#else 1.296 +#define NS_NO_VTABLE 1.297 +#endif 1.298 + 1.299 + 1.300 +/** 1.301 + * Generic XPCOM result data type 1.302 + */ 1.303 +#include "nsError.h" 1.304 + 1.305 +typedef MozRefCountType nsrefcnt; 1.306 + 1.307 +/* 1.308 + * Use these macros to do 64bit safe pointer conversions. 1.309 + */ 1.310 + 1.311 +#define NS_PTR_TO_INT32(x) ((int32_t) (intptr_t) (x)) 1.312 +#define NS_PTR_TO_UINT32(x) ((uint32_t) (intptr_t) (x)) 1.313 +#define NS_INT32_TO_PTR(x) ((void *) (intptr_t) (x)) 1.314 + 1.315 +/* 1.316 + * Use NS_STRINGIFY to form a string literal from the value of a macro. 1.317 + */ 1.318 +#define NS_STRINGIFY_HELPER(x_) #x_ 1.319 +#define NS_STRINGIFY(x_) NS_STRINGIFY_HELPER(x_) 1.320 + 1.321 + /* 1.322 + * If we're being linked as standalone glue, we don't want a dynamic 1.323 + * dependency on NSPR libs, so we skip the debug thread-safety 1.324 + * checks, and we cannot use the THREADSAFE_ISUPPORTS macros. 1.325 + */ 1.326 +#if defined(XPCOM_GLUE) && !defined(XPCOM_GLUE_USE_NSPR) 1.327 +#define XPCOM_GLUE_AVOID_NSPR 1.328 +#endif 1.329 + 1.330 +#if defined(HAVE_THREAD_TLS_KEYWORD) 1.331 +#define NS_TLS __thread 1.332 +#endif 1.333 + 1.334 +/* 1.335 + * SEH exception macros. 1.336 + */ 1.337 +#ifdef HAVE_SEH_EXCEPTIONS 1.338 +#define MOZ_SEH_TRY __try 1.339 +#define MOZ_SEH_EXCEPT(expr) __except(expr) 1.340 +#else 1.341 +#define MOZ_SEH_TRY if(true) 1.342 +#define MOZ_SEH_EXCEPT(expr) else 1.343 +#endif 1.344 + 1.345 +#endif /* nscore_h___ */