forked from TunSafe/TunSafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tunsafe_types.h
73 lines (61 loc) · 1.81 KB
/
tunsafe_types.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: AGPL-1.0-only
// Copyright (C) 2018 Ludvig Strigeus <info@tunsafe.com>. All Rights Reserved.
#ifndef TINYVPN_TYPES_H_
#define TINYVPN_TYPES_H_
#include <stdint.h>
#include "build_config.h"
#include "tunsafe_config.h"
typedef uint8_t byte;
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef int64_t int64;
typedef int8_t int8;
typedef int16_t int16;
typedef int32_t int32;
typedef unsigned int in_addr_t;
#define CTASTR2(pre,post) pre ## post
#define CTASTR(pre,post) CTASTR2(pre,post)
#define STATIC_ASSERT(cond,msg) \
typedef struct { int CTASTR(static_assertion_failed_,msg) : !!(cond); } \
CTASTR(static_assertion_failed_x_,msg)
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
#endif
void printhex(const char *name, const void *a, size_t l);
#if defined(COMPILER_MSVC)
#define FORCEINLINE __forceinline
#define NOINLINE __declspec(noinline)
#define SAFEBUFFERS __declspec(safebuffers)
#define __aligned(x) __declspec(align(x))
#define rol32 _rotl
#define rol64 _rotl64
#elif defined(COMPILER_GCC)
#define FORCEINLINE inline __attribute__((always_inline))
#define NOINLINE
#define SAFEBUFFERS
#define _stricmp strcasecmp
#define _strdup strdup
#define _cdecl
#define __aligned(x) __attribute__((__aligned__(x)))
#else
#define FORCEINLINE inline
#define NOINLINE
#define SAFEBUFFERS
#define __aligned(x)
#endif
#define likely(x) (x)
#define unlikely(x) (x)
#if !defined(COMPILER_MSVC)
static inline uint64 rol64(uint64 x, int8_t r) {
return (x << r) | (x >> (64 - r));
}
static inline uint32 rol32(uint32 x, int8_t r) {
return (x << r) | (x >> (32 - r));
}
#endif // !defined(COMPILER_MSVC)
void RERROR(const char *msg, ...);
void RINFO(const char *msg, ...);
void tunsafe_die(const char *msg);
#endif // TINYVPN_TYPES_H_