1 /*
2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef WEBRTC_BASE_BASICTYPES_H_
12 #define WEBRTC_BASE_BASICTYPES_H_
13 
14 #include <sys/types.h> // for pid_t
15 #include <stddef.h>  // for NULL, size_t
16 #include <stdint.h>  // for uintptr_t and (u)int_t types.
17 
18 // Detect compiler is for x86 or x64.
19 #if defined(__x86_64__) || defined(_M_X64) || \
20     defined(__i386__) || defined(_M_IX86)
21 #define CPU_X86 1
22 #endif
23 
24 // Detect compiler is for arm.
25 #if defined(__arm__) || defined(_M_ARM)
26 #define CPU_ARM 1
27 #endif
28 
29 #if defined(CPU_X86) && defined(CPU_ARM)
30 #error CPU_X86 and CPU_ARM both defined.
31 #endif
32 
33 #if !defined(RTC_ARCH_CPU_BIG_ENDIAN) && !defined(RTC_ARCH_CPU_LITTLE_ENDIAN)
34 // x86, arm or GCC provided __BYTE_ORDER__ macros
35 #if defined(CPU_X86) || defined(CPU_ARM) ||                             \
36   (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
37 #define RTC_ARCH_CPU_LITTLE_ENDIAN
38 #elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
39 #define RTC_ARCH_CPU_BIG_ENDIAN
40 #else
41 #error RTC_ARCH_CPU_BIG_ENDIAN or RTC_ARCH_CPU_LITTLE_ENDIAN should be defined.
42 #endif
43 #endif
44 
45 #if defined(RTC_ARCH_CPU_BIG_ENDIAN) && defined(RTC_ARCH_CPU_LITTLE_ENDIAN)
46 #error RTC_ARCH_CPU_BIG_ENDIAN and RTC_ARCH_CPU_LITTLE_ENDIAN both defined.
47 #endif
48 
49 #if defined(WEBRTC_WIN)
50 typedef int socklen_t;
51 #endif
52 
53 // The following only works for C++
54 #ifdef __cplusplus
55 
56 #ifndef ALIGNP
57 #define ALIGNP(p, t)                                             \
58   (reinterpret_cast<uint8_t*>(((reinterpret_cast<uintptr_t>(p) + \
59   ((t) - 1)) & ~((t) - 1))))
60 #endif
61 
62 #define RTC_IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1)))
63 
64 // Use these to declare and define a static local variable that gets leaked so
65 // that its destructors are not called at exit.
66 #define RTC_DEFINE_STATIC_LOCAL(type, name, arguments) \
67   static type& name = *new type arguments
68 
69 #endif  // __cplusplus
70 
71 #endif  // WEBRTC_BASE_BASICTYPES_H_
72