mfbt/Types.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 /* mfbt foundational types and macros. */
michael@0 8
michael@0 9 #ifndef mozilla_Types_h
michael@0 10 #define mozilla_Types_h
michael@0 11
michael@0 12 /*
michael@0 13 * This header must be valid C and C++, includable by code embedding either
michael@0 14 * SpiderMonkey or Gecko.
michael@0 15 */
michael@0 16
michael@0 17 /* Expose all <stdint.h> types and size_t. */
michael@0 18 #include <stddef.h>
michael@0 19 #include <stdint.h>
michael@0 20
michael@0 21 /* Implement compiler and linker macros needed for APIs. */
michael@0 22
michael@0 23 /*
michael@0 24 * MOZ_EXPORT is used to declare and define a symbol or type which is externally
michael@0 25 * visible to users of the current library. It encapsulates various decorations
michael@0 26 * needed to properly export the method's symbol.
michael@0 27 *
michael@0 28 * api.h:
michael@0 29 * extern MOZ_EXPORT int MeaningOfLife(void);
michael@0 30 * extern MOZ_EXPORT int LuggageCombination;
michael@0 31 *
michael@0 32 * api.c:
michael@0 33 * int MeaningOfLife(void) { return 42; }
michael@0 34 * int LuggageCombination = 12345;
michael@0 35 *
michael@0 36 * If you are merely sharing a method across files, just use plain |extern|.
michael@0 37 * These macros are designed for use by library interfaces -- not for normal
michael@0 38 * methods or data used cross-file.
michael@0 39 */
michael@0 40 #if defined(WIN32)
michael@0 41 # define MOZ_EXPORT __declspec(dllexport)
michael@0 42 #else /* Unix */
michael@0 43 # ifdef HAVE_VISIBILITY_ATTRIBUTE
michael@0 44 # define MOZ_EXPORT __attribute__((visibility("default")))
michael@0 45 # elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
michael@0 46 # define MOZ_EXPORT __global
michael@0 47 # else
michael@0 48 # define MOZ_EXPORT /* nothing */
michael@0 49 # endif
michael@0 50 #endif
michael@0 51
michael@0 52
michael@0 53 /*
michael@0 54 * Whereas implementers use MOZ_EXPORT to declare and define library symbols,
michael@0 55 * users use MOZ_IMPORT_API and MOZ_IMPORT_DATA to access them. Most often the
michael@0 56 * implementer of the library will expose an API macro which expands to either
michael@0 57 * the export or import version of the macro, depending upon the compilation
michael@0 58 * mode.
michael@0 59 */
michael@0 60 #ifdef _WIN32
michael@0 61 # if defined(__MWERKS__)
michael@0 62 # define MOZ_IMPORT_API /* nothing */
michael@0 63 # else
michael@0 64 # define MOZ_IMPORT_API __declspec(dllimport)
michael@0 65 # endif
michael@0 66 #else
michael@0 67 # define MOZ_IMPORT_API MOZ_EXPORT
michael@0 68 #endif
michael@0 69
michael@0 70 #if defined(_WIN32) && !defined(__MWERKS__)
michael@0 71 # define MOZ_IMPORT_DATA __declspec(dllimport)
michael@0 72 #else
michael@0 73 # define MOZ_IMPORT_DATA MOZ_EXPORT
michael@0 74 #endif
michael@0 75
michael@0 76 /*
michael@0 77 * Consistent with the above comment, the MFBT_API and MFBT_DATA macros expose
michael@0 78 * export mfbt declarations when building mfbt, and they expose import mfbt
michael@0 79 * declarations when using mfbt.
michael@0 80 */
michael@0 81 #if defined(IMPL_MFBT)
michael@0 82 # define MFBT_API MOZ_EXPORT
michael@0 83 # define MFBT_DATA MOZ_EXPORT
michael@0 84 #else
michael@0 85 /*
michael@0 86 * On linux mozglue is linked in the program and we link libxul.so with
michael@0 87 * -z,defs. Normally that causes the linker to reject undefined references in
michael@0 88 * libxul.so, but as a loophole it allows undefined references to weak
michael@0 89 * symbols. We add the weak attribute to the import version of the MFBT API
michael@0 90 * macros to exploit this.
michael@0 91 */
michael@0 92 # if defined(MOZ_GLUE_IN_PROGRAM)
michael@0 93 # define MFBT_API __attribute__((weak)) MOZ_IMPORT_API
michael@0 94 # define MFBT_DATA __attribute__((weak)) MOZ_IMPORT_DATA
michael@0 95 # else
michael@0 96 # define MFBT_API MOZ_IMPORT_API
michael@0 97 # define MFBT_DATA MOZ_IMPORT_DATA
michael@0 98 # endif
michael@0 99 #endif
michael@0 100
michael@0 101 /*
michael@0 102 * C symbols in C++ code must be declared immediately within |extern "C"|
michael@0 103 * blocks. However, in C code, they need not be declared specially. This
michael@0 104 * difference is abstracted behind the MOZ_BEGIN_EXTERN_C and MOZ_END_EXTERN_C
michael@0 105 * macros, so that the user need not know whether he is being used in C or C++
michael@0 106 * code.
michael@0 107 *
michael@0 108 * MOZ_BEGIN_EXTERN_C
michael@0 109 *
michael@0 110 * extern MOZ_EXPORT int MostRandomNumber(void);
michael@0 111 * ...other declarations...
michael@0 112 *
michael@0 113 * MOZ_END_EXTERN_C
michael@0 114 *
michael@0 115 * This said, it is preferable to just use |extern "C"| in C++ header files for
michael@0 116 * its greater clarity.
michael@0 117 */
michael@0 118 #ifdef __cplusplus
michael@0 119 # define MOZ_BEGIN_EXTERN_C extern "C" {
michael@0 120 # define MOZ_END_EXTERN_C }
michael@0 121 #else
michael@0 122 # define MOZ_BEGIN_EXTERN_C
michael@0 123 # define MOZ_END_EXTERN_C
michael@0 124 #endif
michael@0 125
michael@0 126 /*
michael@0 127 * GCC's typeof is available when decltype is not.
michael@0 128 */
michael@0 129 #if defined(__GNUC__) && defined(__cplusplus) && \
michael@0 130 !defined(__GXX_EXPERIMENTAL_CXX0X__) && __cplusplus < 201103L
michael@0 131 # define decltype __typeof__
michael@0 132 #endif
michael@0 133
michael@0 134 #endif /* mozilla_Types_h */

mercurial