Tue, 06 Jan 2015 21:39:09 +0100
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 | #ifndef _OS_H |
michael@0 | 2 | #define _OS_H |
michael@0 | 3 | /******************************************************************** |
michael@0 | 4 | * * |
michael@0 | 5 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * |
michael@0 | 6 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * |
michael@0 | 7 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * |
michael@0 | 8 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * |
michael@0 | 9 | * * |
michael@0 | 10 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * |
michael@0 | 11 | * by the Xiph.Org Foundation http://www.xiph.org/ * |
michael@0 | 12 | * * |
michael@0 | 13 | ******************************************************************** |
michael@0 | 14 | |
michael@0 | 15 | function: #ifdef jail to whip a few platforms into the UNIX ideal. |
michael@0 | 16 | last mod: $Id: os.h 19031 2013-12-03 19:20:50Z tterribe $ |
michael@0 | 17 | |
michael@0 | 18 | ********************************************************************/ |
michael@0 | 19 | |
michael@0 | 20 | #ifdef HAVE_CONFIG_H |
michael@0 | 21 | #include "config.h" |
michael@0 | 22 | #endif |
michael@0 | 23 | |
michael@0 | 24 | #include <math.h> |
michael@0 | 25 | #include <ogg/os_types.h> |
michael@0 | 26 | |
michael@0 | 27 | #include "misc.h" |
michael@0 | 28 | |
michael@0 | 29 | #ifndef _V_IFDEFJAIL_H_ |
michael@0 | 30 | # define _V_IFDEFJAIL_H_ |
michael@0 | 31 | |
michael@0 | 32 | # ifdef __GNUC__ |
michael@0 | 33 | # define STIN static __inline__ |
michael@0 | 34 | # elif _WIN32 |
michael@0 | 35 | # define STIN static __inline |
michael@0 | 36 | # else |
michael@0 | 37 | # define STIN static |
michael@0 | 38 | # endif |
michael@0 | 39 | |
michael@0 | 40 | #ifdef DJGPP |
michael@0 | 41 | # define rint(x) (floor((x)+0.5f)) |
michael@0 | 42 | #endif |
michael@0 | 43 | |
michael@0 | 44 | #ifndef M_PI |
michael@0 | 45 | # define M_PI (3.1415926536f) |
michael@0 | 46 | #endif |
michael@0 | 47 | |
michael@0 | 48 | #if defined(_WIN32) && !defined(__SYMBIAN32__) |
michael@0 | 49 | # include <malloc.h> |
michael@0 | 50 | # define rint(x) (floor((x)+0.5f)) |
michael@0 | 51 | # define NO_FLOAT_MATH_LIB |
michael@0 | 52 | # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b)) |
michael@0 | 53 | #endif |
michael@0 | 54 | |
michael@0 | 55 | #if defined(__SYMBIAN32__) && defined(__WINS__) |
michael@0 | 56 | void *_alloca(size_t size); |
michael@0 | 57 | # define alloca _alloca |
michael@0 | 58 | #endif |
michael@0 | 59 | |
michael@0 | 60 | #ifndef FAST_HYPOT |
michael@0 | 61 | # define FAST_HYPOT hypot |
michael@0 | 62 | #endif |
michael@0 | 63 | |
michael@0 | 64 | #endif |
michael@0 | 65 | |
michael@0 | 66 | #ifdef HAVE_ALLOCA_H |
michael@0 | 67 | # include <alloca.h> |
michael@0 | 68 | #endif |
michael@0 | 69 | |
michael@0 | 70 | #ifdef USE_MEMORY_H |
michael@0 | 71 | # include <memory.h> |
michael@0 | 72 | #endif |
michael@0 | 73 | |
michael@0 | 74 | #ifndef min |
michael@0 | 75 | # define min(x,y) ((x)>(y)?(y):(x)) |
michael@0 | 76 | #endif |
michael@0 | 77 | |
michael@0 | 78 | #ifndef max |
michael@0 | 79 | # define max(x,y) ((x)<(y)?(y):(x)) |
michael@0 | 80 | #endif |
michael@0 | 81 | |
michael@0 | 82 | |
michael@0 | 83 | /* Special i386 GCC implementation */ |
michael@0 | 84 | #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__) |
michael@0 | 85 | # define VORBIS_FPU_CONTROL |
michael@0 | 86 | /* both GCC and MSVC are kinda stupid about rounding/casting to int. |
michael@0 | 87 | Because of encapsulation constraints (GCC can't see inside the asm |
michael@0 | 88 | block and so we end up doing stupid things like a store/load that |
michael@0 | 89 | is collectively a noop), we do it this way */ |
michael@0 | 90 | |
michael@0 | 91 | /* we must set up the fpu before this works!! */ |
michael@0 | 92 | |
michael@0 | 93 | typedef ogg_int16_t vorbis_fpu_control; |
michael@0 | 94 | |
michael@0 | 95 | static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ |
michael@0 | 96 | ogg_int16_t ret; |
michael@0 | 97 | ogg_int16_t temp; |
michael@0 | 98 | __asm__ __volatile__("fnstcw %0\n\t" |
michael@0 | 99 | "movw %0,%%dx\n\t" |
michael@0 | 100 | "andw $62463,%%dx\n\t" |
michael@0 | 101 | "movw %%dx,%1\n\t" |
michael@0 | 102 | "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx"); |
michael@0 | 103 | *fpu=ret; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ |
michael@0 | 107 | __asm__ __volatile__("fldcw %0":: "m"(fpu)); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | /* assumes the FPU is in round mode! */ |
michael@0 | 111 | static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise, |
michael@0 | 112 | we get extra fst/fld to |
michael@0 | 113 | truncate precision */ |
michael@0 | 114 | int i; |
michael@0 | 115 | __asm__("fistl %0": "=m"(i) : "t"(f)); |
michael@0 | 116 | return(i); |
michael@0 | 117 | } |
michael@0 | 118 | #endif /* Special i386 GCC implementation */ |
michael@0 | 119 | |
michael@0 | 120 | |
michael@0 | 121 | /* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the |
michael@0 | 122 | * 64 bit compiler */ |
michael@0 | 123 | #if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE) |
michael@0 | 124 | # define VORBIS_FPU_CONTROL |
michael@0 | 125 | |
michael@0 | 126 | typedef ogg_int16_t vorbis_fpu_control; |
michael@0 | 127 | |
michael@0 | 128 | static __inline int vorbis_ftoi(double f){ |
michael@0 | 129 | int i; |
michael@0 | 130 | __asm{ |
michael@0 | 131 | fld f |
michael@0 | 132 | fistp i |
michael@0 | 133 | } |
michael@0 | 134 | return i; |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ |
michael@0 | 138 | (void)fpu; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ |
michael@0 | 142 | (void)fpu; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | #endif /* Special MSVC 32 bit implementation */ |
michael@0 | 146 | |
michael@0 | 147 | |
michael@0 | 148 | /* Optimized code path for x86_64 builds. Uses SSE2 intrinsics. This can be |
michael@0 | 149 | done safely because all x86_64 CPUs supports SSE2. */ |
michael@0 | 150 | #if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__GNUC__) && defined (__x86_64__)) |
michael@0 | 151 | # define VORBIS_FPU_CONTROL |
michael@0 | 152 | |
michael@0 | 153 | typedef ogg_int16_t vorbis_fpu_control; |
michael@0 | 154 | |
michael@0 | 155 | #include <emmintrin.h> |
michael@0 | 156 | static __inline int vorbis_ftoi(double f){ |
michael@0 | 157 | return _mm_cvtsd_si32(_mm_load_sd(&f)); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ |
michael@0 | 161 | (void)fpu; |
michael@0 | 162 | } |
michael@0 | 163 | |
michael@0 | 164 | static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ |
michael@0 | 165 | (void)fpu; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | #endif /* Special MSVC x64 implementation */ |
michael@0 | 169 | |
michael@0 | 170 | |
michael@0 | 171 | /* If no special implementation was found for the current compiler / platform, |
michael@0 | 172 | use the default implementation here: */ |
michael@0 | 173 | #ifndef VORBIS_FPU_CONTROL |
michael@0 | 174 | |
michael@0 | 175 | typedef int vorbis_fpu_control; |
michael@0 | 176 | |
michael@0 | 177 | static int vorbis_ftoi(double f){ |
michael@0 | 178 | /* Note: MSVC and GCC (at least on some systems) round towards zero, thus, |
michael@0 | 179 | the floor() call is required to ensure correct roudning of |
michael@0 | 180 | negative numbers */ |
michael@0 | 181 | return (int)floor(f+.5); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | /* We don't have special code for this compiler/arch, so do it the slow way */ |
michael@0 | 185 | # define vorbis_fpu_setround(vorbis_fpu_control) {} |
michael@0 | 186 | # define vorbis_fpu_restore(vorbis_fpu_control) {} |
michael@0 | 187 | |
michael@0 | 188 | #endif /* default implementation */ |
michael@0 | 189 | |
michael@0 | 190 | #endif /* _OS_H */ |