xpcom/base/nscore.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nscore_h___
michael@0 7 #define nscore_h___
michael@0 8
michael@0 9 /**
michael@0 10 * Make sure that we have the proper platform specific
michael@0 11 * c++ definitions needed by nscore.h
michael@0 12 */
michael@0 13 #ifndef _XPCOM_CONFIG_H_
michael@0 14 #include "xpcom-config.h"
michael@0 15 #endif
michael@0 16
michael@0 17 /* Definitions of functions and operators that allocate memory. */
michael@0 18 #if !defined(XPCOM_GLUE) && !defined(NS_NO_XPCOM) && !defined(MOZ_NO_MOZALLOC)
michael@0 19 # include "mozilla/mozalloc.h"
michael@0 20 #endif
michael@0 21
michael@0 22 /**
michael@0 23 * Incorporate the integer data types which XPCOM uses.
michael@0 24 */
michael@0 25 #include <stddef.h>
michael@0 26 #include <stdint.h>
michael@0 27
michael@0 28 #ifdef __cplusplus
michael@0 29 # include "mozilla/NullPtr.h"
michael@0 30 #endif
michael@0 31
michael@0 32 #include "mozilla/RefCountType.h"
michael@0 33
michael@0 34 /* Core XPCOM declarations. */
michael@0 35
michael@0 36 /*----------------------------------------------------------------------*/
michael@0 37 /* Import/export defines */
michael@0 38
michael@0 39 /**
michael@0 40 * Using the visibility("hidden") attribute allows the compiler to use
michael@0 41 * PC-relative addressing to call this function. If a function does not
michael@0 42 * access any global data, and does not call any methods which are not either
michael@0 43 * file-local or hidden, then on ELF systems we avoid loading the address of
michael@0 44 * the PLT into a register at the start of the function, which reduces code
michael@0 45 * size and frees up a register for general use.
michael@0 46 *
michael@0 47 * As a general rule, this should be used for any non-exported symbol
michael@0 48 * (including virtual method implementations). NS_IMETHOD uses this by
michael@0 49 * default; if you need to have your NS_IMETHOD functions exported, you can
michael@0 50 * wrap your class as follows:
michael@0 51 *
michael@0 52 * #undef IMETHOD_VISIBILITY
michael@0 53 * #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
michael@0 54 *
michael@0 55 * class Foo {
michael@0 56 * ...
michael@0 57 * };
michael@0 58 *
michael@0 59 * #undef IMETHOD_VISIBILITY
michael@0 60 * #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
michael@0 61 *
michael@0 62 * Don't forget to change the visibility back to hidden before the end
michael@0 63 * of a header!
michael@0 64 *
michael@0 65 * Other examples:
michael@0 66 *
michael@0 67 * NS_HIDDEN_(int) someMethod();
michael@0 68 * SomeCtor() NS_HIDDEN;
michael@0 69 */
michael@0 70
michael@0 71 #ifdef HAVE_VISIBILITY_HIDDEN_ATTRIBUTE
michael@0 72 #define NS_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
michael@0 73 #else
michael@0 74 #define NS_VISIBILITY_HIDDEN
michael@0 75 #endif
michael@0 76
michael@0 77 #if defined(HAVE_VISIBILITY_ATTRIBUTE)
michael@0 78 #define NS_VISIBILITY_DEFAULT __attribute__ ((visibility ("default")))
michael@0 79 #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
michael@0 80 #define NS_VISIBILITY_DEFAULT __global
michael@0 81 #else
michael@0 82 #define NS_VISIBILITY_DEFAULT
michael@0 83 #endif
michael@0 84
michael@0 85 #define NS_HIDDEN_(type) NS_VISIBILITY_HIDDEN type
michael@0 86 #define NS_EXTERNAL_VIS_(type) NS_VISIBILITY_DEFAULT type
michael@0 87
michael@0 88 #define NS_HIDDEN NS_VISIBILITY_HIDDEN
michael@0 89 #define NS_EXTERNAL_VIS NS_VISIBILITY_DEFAULT
michael@0 90
michael@0 91 #undef IMETHOD_VISIBILITY
michael@0 92 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
michael@0 93
michael@0 94 /**
michael@0 95 * Mark a function as using a potentially non-standard function calling
michael@0 96 * convention. This can be used on functions that are called very
michael@0 97 * frequently, to reduce the overhead of the function call. It is still worth
michael@0 98 * using the macro for C++ functions which take no parameters since it allows
michael@0 99 * passing |this| in a register.
michael@0 100 *
michael@0 101 * - Do not use this on any scriptable interface method since xptcall won't be
michael@0 102 * aware of the different calling convention.
michael@0 103 * - This must appear on the declaration, not the definition.
michael@0 104 * - Adding this to a public function _will_ break binary compatibility.
michael@0 105 * - This may be used on virtual functions but you must ensure it is applied
michael@0 106 * to all implementations - the compiler will _not_ warn but it will crash.
michael@0 107 * - This has no effect for functions which take a variable number of
michael@0 108 * arguments.
michael@0 109 * - __fastcall on windows should not be applied to class
michael@0 110 * constructors/destructors - use the NS_CONSTRUCTOR_FASTCALL macro for
michael@0 111 * constructors/destructors.
michael@0 112 *
michael@0 113 * Examples: int NS_FASTCALL func1(char *foo);
michael@0 114 * NS_HIDDEN_(int) NS_FASTCALL func2(char *foo);
michael@0 115 */
michael@0 116
michael@0 117 #if defined(__i386__) && defined(__GNUC__)
michael@0 118 #define NS_FASTCALL __attribute__ ((regparm (3), stdcall))
michael@0 119 #define NS_CONSTRUCTOR_FASTCALL __attribute__ ((regparm (3), stdcall))
michael@0 120 #elif defined(XP_WIN) && !defined(_WIN64)
michael@0 121 #define NS_FASTCALL __fastcall
michael@0 122 #define NS_CONSTRUCTOR_FASTCALL
michael@0 123 #else
michael@0 124 #define NS_FASTCALL
michael@0 125 #define NS_CONSTRUCTOR_FASTCALL
michael@0 126 #endif
michael@0 127
michael@0 128 #ifdef XP_WIN
michael@0 129
michael@0 130 #define NS_IMPORT __declspec(dllimport)
michael@0 131 #define NS_IMPORT_(type) __declspec(dllimport) type __stdcall
michael@0 132 #define NS_EXPORT __declspec(dllexport)
michael@0 133 #define NS_EXPORT_(type) __declspec(dllexport) type __stdcall
michael@0 134 #define NS_IMETHOD_(type) virtual type __stdcall
michael@0 135 #define NS_IMETHODIMP_(type) type __stdcall
michael@0 136 #define NS_METHOD_(type) type __stdcall
michael@0 137 #define NS_CALLBACK_(_type, _name) _type (__stdcall * _name)
michael@0 138 #ifndef _WIN64
michael@0 139 // Win64 has only one calling convention. __stdcall will be ignored by the compiler.
michael@0 140 #define NS_STDCALL __stdcall
michael@0 141 #define NS_HAVE_STDCALL
michael@0 142 #else
michael@0 143 #define NS_STDCALL
michael@0 144 #endif
michael@0 145 #define NS_FROZENCALL __cdecl
michael@0 146
michael@0 147 /*
michael@0 148 These are needed to mark static members in exported classes, due to
michael@0 149 gcc bug XXX insert bug# here.
michael@0 150 */
michael@0 151
michael@0 152 #define NS_EXPORT_STATIC_MEMBER_(type) type
michael@0 153 #define NS_IMPORT_STATIC_MEMBER_(type) type
michael@0 154
michael@0 155 #else
michael@0 156
michael@0 157 #define NS_IMPORT NS_EXTERNAL_VIS
michael@0 158 #define NS_IMPORT_(type) NS_EXTERNAL_VIS_(type)
michael@0 159 #define NS_EXPORT NS_EXTERNAL_VIS
michael@0 160 #define NS_EXPORT_(type) NS_EXTERNAL_VIS_(type)
michael@0 161 #define NS_IMETHOD_(type) virtual IMETHOD_VISIBILITY type
michael@0 162 #define NS_IMETHODIMP_(type) type
michael@0 163 #define NS_METHOD_(type) type
michael@0 164 #define NS_CALLBACK_(_type, _name) _type (* _name)
michael@0 165 #define NS_STDCALL
michael@0 166 #define NS_FROZENCALL
michael@0 167 #define NS_EXPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type)
michael@0 168 #define NS_IMPORT_STATIC_MEMBER_(type) NS_EXTERNAL_VIS_(type)
michael@0 169
michael@0 170 #endif
michael@0 171
michael@0 172 /**
michael@0 173 * Macro for creating typedefs for pointer-to-member types which are
michael@0 174 * declared with stdcall. It is important to use this for any type which is
michael@0 175 * declared as stdcall (i.e. NS_IMETHOD). For example, instead of writing:
michael@0 176 *
michael@0 177 * typedef nsresult (nsIFoo::*someType)(nsISupports* arg);
michael@0 178 *
michael@0 179 * you should write:
michael@0 180 *
michael@0 181 * typedef
michael@0 182 * NS_STDCALL_FUNCPROTO(nsresult, someType, nsIFoo, typeFunc, (nsISupports*));
michael@0 183 *
michael@0 184 * where nsIFoo::typeFunc is any method declared as
michael@0 185 * NS_IMETHOD typeFunc(nsISupports*);
michael@0 186 *
michael@0 187 * XXX this can be simplified to always use the non-typeof implementation
michael@0 188 * when http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11893 is fixed.
michael@0 189 */
michael@0 190
michael@0 191 #ifdef __GNUC__
michael@0 192 #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \
michael@0 193 typeof(&class::func) name
michael@0 194 #else
michael@0 195 #define NS_STDCALL_FUNCPROTO(ret, name, class, func, args) \
michael@0 196 ret (NS_STDCALL class::*name) args
michael@0 197 #endif
michael@0 198
michael@0 199 /**
michael@0 200 * Deprecated declarations.
michael@0 201 */
michael@0 202 #ifdef __GNUC__
michael@0 203 # define MOZ_DEPRECATED __attribute__((deprecated))
michael@0 204 #elif defined(_MSC_VER)
michael@0 205 # define MOZ_DEPRECATED __declspec(deprecated)
michael@0 206 #else
michael@0 207 # define MOZ_DEPRECATED
michael@0 208 #endif
michael@0 209
michael@0 210 /**
michael@0 211 * Generic API modifiers which return the standard XPCOM nsresult type
michael@0 212 */
michael@0 213 #define NS_IMETHOD NS_IMETHOD_(nsresult)
michael@0 214 #define NS_IMETHODIMP NS_IMETHODIMP_(nsresult)
michael@0 215 #define NS_METHOD NS_METHOD_(nsresult)
michael@0 216 #define NS_CALLBACK(_name) NS_CALLBACK_(nsresult, _name)
michael@0 217
michael@0 218 /**
michael@0 219 * Import/Export macros for XPCOM APIs
michael@0 220 */
michael@0 221
michael@0 222 #ifdef __cplusplus
michael@0 223 #define NS_EXTERN_C extern "C"
michael@0 224 #else
michael@0 225 #define NS_EXTERN_C
michael@0 226 #endif
michael@0 227
michael@0 228 #define EXPORT_XPCOM_API(type) NS_EXTERN_C NS_EXPORT type NS_FROZENCALL
michael@0 229 #define IMPORT_XPCOM_API(type) NS_EXTERN_C NS_IMPORT type NS_FROZENCALL
michael@0 230 #define GLUE_XPCOM_API(type) NS_EXTERN_C NS_HIDDEN_(type) NS_FROZENCALL
michael@0 231
michael@0 232 #ifdef IMPL_LIBXUL
michael@0 233 #define XPCOM_API(type) EXPORT_XPCOM_API(type)
michael@0 234 #elif defined(XPCOM_GLUE)
michael@0 235 #define XPCOM_API(type) GLUE_XPCOM_API(type)
michael@0 236 #else
michael@0 237 #define XPCOM_API(type) IMPORT_XPCOM_API(type)
michael@0 238 #endif
michael@0 239
michael@0 240 #ifdef MOZILLA_INTERNAL_API
michael@0 241 # define NS_COM_GLUE
michael@0 242 /*
michael@0 243 The frozen string API has different definitions of nsAC?String
michael@0 244 classes than the internal API. On systems that explicitly declare
michael@0 245 dllexport symbols this is not a problem, but on ELF systems
michael@0 246 internal symbols can accidentally "shine through"; we rename the
michael@0 247 internal classes to avoid symbol conflicts.
michael@0 248 */
michael@0 249 # define nsAString nsAString_internal
michael@0 250 # define nsACString nsACString_internal
michael@0 251 #else
michael@0 252 # ifdef HAVE_VISIBILITY_ATTRIBUTE
michael@0 253 # define NS_COM_GLUE NS_VISIBILITY_HIDDEN
michael@0 254 # else
michael@0 255 # define NS_COM_GLUE
michael@0 256 # endif
michael@0 257 #endif
michael@0 258
michael@0 259 #if (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
michael@0 260 /* Make refcnt logging part of the build. This doesn't mean that
michael@0 261 * actual logging will occur (that requires a separate enable; see
michael@0 262 * nsTraceRefcnt and nsISupportsImpl.h for more information). */
michael@0 263 #define NS_BUILD_REFCNT_LOGGING
michael@0 264 #endif
michael@0 265
michael@0 266 /* If NO_BUILD_REFCNT_LOGGING is defined then disable refcnt logging
michael@0 267 * in the build. This overrides FORCE_BUILD_REFCNT_LOGGING. */
michael@0 268 #if defined(NO_BUILD_REFCNT_LOGGING)
michael@0 269 #undef NS_BUILD_REFCNT_LOGGING
michael@0 270 #endif
michael@0 271
michael@0 272 /* If a program allocates memory for the lifetime of the app, it doesn't make
michael@0 273 * sense to touch memory pages and free that memory at shutdown,
michael@0 274 * unless we are running leak stats.
michael@0 275 */
michael@0 276 #if defined(NS_TRACE_MALLOC) || defined(NS_BUILD_REFCNT_LOGGING) || defined(MOZ_VALGRIND)
michael@0 277 #define NS_FREE_PERMANENT_DATA
michael@0 278 #endif
michael@0 279
michael@0 280 /**
michael@0 281 * NS_NO_VTABLE is emitted by xpidl in interface declarations whenever
michael@0 282 * xpidl can determine that the interface can't contain a constructor.
michael@0 283 * This results in some space savings and possible runtime savings -
michael@0 284 * see bug 49416. We undefine it first, as xpidl-generated headers
michael@0 285 * define it for IDL uses that don't include this file.
michael@0 286 */
michael@0 287 #ifdef NS_NO_VTABLE
michael@0 288 #undef NS_NO_VTABLE
michael@0 289 #endif
michael@0 290 #if defined(_MSC_VER)
michael@0 291 #define NS_NO_VTABLE __declspec(novtable)
michael@0 292 #else
michael@0 293 #define NS_NO_VTABLE
michael@0 294 #endif
michael@0 295
michael@0 296
michael@0 297 /**
michael@0 298 * Generic XPCOM result data type
michael@0 299 */
michael@0 300 #include "nsError.h"
michael@0 301
michael@0 302 typedef MozRefCountType nsrefcnt;
michael@0 303
michael@0 304 /*
michael@0 305 * Use these macros to do 64bit safe pointer conversions.
michael@0 306 */
michael@0 307
michael@0 308 #define NS_PTR_TO_INT32(x) ((int32_t) (intptr_t) (x))
michael@0 309 #define NS_PTR_TO_UINT32(x) ((uint32_t) (intptr_t) (x))
michael@0 310 #define NS_INT32_TO_PTR(x) ((void *) (intptr_t) (x))
michael@0 311
michael@0 312 /*
michael@0 313 * Use NS_STRINGIFY to form a string literal from the value of a macro.
michael@0 314 */
michael@0 315 #define NS_STRINGIFY_HELPER(x_) #x_
michael@0 316 #define NS_STRINGIFY(x_) NS_STRINGIFY_HELPER(x_)
michael@0 317
michael@0 318 /*
michael@0 319 * If we're being linked as standalone glue, we don't want a dynamic
michael@0 320 * dependency on NSPR libs, so we skip the debug thread-safety
michael@0 321 * checks, and we cannot use the THREADSAFE_ISUPPORTS macros.
michael@0 322 */
michael@0 323 #if defined(XPCOM_GLUE) && !defined(XPCOM_GLUE_USE_NSPR)
michael@0 324 #define XPCOM_GLUE_AVOID_NSPR
michael@0 325 #endif
michael@0 326
michael@0 327 #if defined(HAVE_THREAD_TLS_KEYWORD)
michael@0 328 #define NS_TLS __thread
michael@0 329 #endif
michael@0 330
michael@0 331 /*
michael@0 332 * SEH exception macros.
michael@0 333 */
michael@0 334 #ifdef HAVE_SEH_EXCEPTIONS
michael@0 335 #define MOZ_SEH_TRY __try
michael@0 336 #define MOZ_SEH_EXCEPT(expr) __except(expr)
michael@0 337 #else
michael@0 338 #define MOZ_SEH_TRY if(true)
michael@0 339 #define MOZ_SEH_EXCEPT(expr) else
michael@0 340 #endif
michael@0 341
michael@0 342 #endif /* nscore_h___ */

mercurial