/
common.h
119 lines (93 loc) · 3.58 KB
/
common.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#pragma once
#include <stdint.h>
#include <CoreFoundation/CoreFoundation.h>
typedef struct {
int oid;
char str_data[0];
} idp_t;
typedef struct _NPStream *stream_t;
#define IOSFC_BUILDING_IOSFC
#include <IOSurface/IOSurface.h>
#ifndef android_npapi_H
// android_npapi.h requires C++ so here are some defs
#define kSupportedDrawingModel_ANPGetValue ((NPNVariable)2000)
#define kJavaContext_ANPGetValue ((NPNVariable)2001)
#define kAcceptEvents_ANPSetValue ((NPPVariable)1001)
#define kRequestDrawingModel_ANPSetValue ((NPPVariable)1000)
#define kJavaSurface_ANPGetValue ((NPPVariable)2000)
enum ANPDrawingModels {
kBitmap_ANPDrawingModel = 1 << 0,
kSurface_ANPDrawingModel = 1 << 1,
};
enum ANPLifecycleActions {
kPause_ANPLifecycleAction = 0,
kResume_ANPLifecycleAction = 1,
kGainFocus_ANPLifecycleAction = 2,
kLoseFocus_ANPLifecycleAction = 3,
kFreeMemory_ANPLifecycleAction = 4,
kOnLoad_ANPLifecycleAction = 5,
kEnterFullScreen_ANPLifecycleAction = 6,
kExitFullScreen_ANPLifecycleAction = 7,
kOnScreen_ANPLifecycleAction = 8,
kOffScreen_ANPLifecycleAction = 9,
};
typedef uint32_t ANPLifecycleAction;
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <food_rpc1.h>
extern boolean_t Doof_server(
mach_msg_header_t *InHeadP,
mach_msg_header_t *OutHeadP);
extern boolean_t Stuff_server(
mach_msg_header_t *InHeadP,
mach_msg_header_t *OutHeadP);
#define padd(a, b) ((void *) ((char *)(a) + b))
void pattern(void *stuff, uint32_t base, int len);
CFMutableDictionaryRef new_dict();
//#define stub(x) stubify((void *) (x), NULL, true)
#define stub(x) stubify((void *) (x), #x, true)
#define s(a, b, c) CFDictionarySetValue(a, CFSTR(b), c)
#define g(a, b) CFDictionaryGetValue(a, CFSTR(b))
typedef CFMutableDictionaryRef dict;
void *RawDataCreate(int size);
void *RawDataGetPtr(const void *raw);
int RawDataGetSize(const void *raw);
void *RawPtrCreate(void *ptr);
void *RawPtrGet(const void *raw);
void *stubify(void *addy, const char *id, bool needs_mprotect);
void logreal_(CFStringRef str);
void do_later(void (*func)(CFRunLoopTimerRef, void *), void *info);
void rpc_init(const char *rpcname);
void sandbox_me();
__attribute__((noreturn))
void _abort_(const char *file, int line);
#define _abort() _abort_(__FILE__, __LINE__)
__attribute__((noreturn))
void _abortWithError_(const char *file, int line, const char *error);
#define _abortWithError(error) _abortWithError_(__FILE__, __LINE__, error)
void _assert_(bool test, const char *label, const char *file, int line, const char *func);
void _assertZero_(int test, const char *label, const char *file, int line, const char *func);
#define _assert(x) _assert_((x), #x, __FILE__, __LINE__, __func__)
#define _assertZero(x) _assertZero_((int) (x), #x, __FILE__, __LINE__, __func__)
#ifdef __cplusplus
}
#endif
extern IOSurfaceRef sfc;
extern int food;
extern int movie_w, movie_h, pending_movie_w, pending_movie_h;
#define logreal(fmt, args...) logreal_(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR(fmt), ##args))
#define logx(level, args...) (LOG_LEVEL >= (level) ? (logreal(args)) : (void)0)
#define LOG_LEVEL 1
#define warn(args...) logx(2, args)
#define notice(args...) logx(3, args)
#define log(args...) logx(1, args)
#define err(args...) logx(0, args)
#define TIMING 1
#if TIMING
uint64_t getus();
#define TIME(thing) do { uint64_t _ta = getus(); thing; uint64_t _tb = getus(); log("[%.4ld us] %s", (long int) (_tb - _ta), #thing); } while(0)
#else
#define TIME(thing) thing
#endif