Debian Codegraph @

rpython/translator/c/src/support.h

raw symbols SCIP
1
2 /************************************************************/
3 /*** C header subsection: support functions ***/
4
5 #ifndef _SRC_SUPPORT_H
6 #define _SRC_SUPPORT_H
7
8 #define RUNNING_ON_LLINTERP 0
9 #define OP_JIT_RECORD_EXACT_CLASS(i, c, r) /* nothing */
10 #define OP_JIT_RECORD_EXACT_VALUE(i, c, r) /* nothing */
11 #define OP_JIT_RECORD_KNOWN_RESULT(r, f, ...) /* nothing */
12
13 #define FAIL_OVF(msg) _RPyRaiseSimpleException(RPyExc_OverflowError)
14
15 /* Extra checks can be enabled with the RPY_ASSERT or RPY_LL_ASSERT
16 * macros. They differ in the level at which the tests are made.
17 * Remember that RPython lists, for example, are implemented as a
18 * GcStruct pointing to an over-allocated GcArray. With RPY_ASSERT you
19 * get list index out of bound checks from rlist.py; such tests must be
20 * manually written so made we've forgotten a case. Conversely, with
21 * RPY_LL_ASSERT, all GcArray indexing are checked, which is safer
22 * against attacks and segfaults - but less precise in the case of
23 * lists, because of the overallocated bit.
24 *
25 * For extra safety, in programs translated with --sandbox we always
26 * assume that we want RPY_LL_ASSERT. You can change it below to trade
27 * safety for performance, though the hit is not huge (~10%?).
28 */
29 #ifdef RPY_ASSERT
30 # define RPyAssert(x, msg) \
31 if (!(x)) RPyAssertFailed(__FILE__, __LINE__, __FUNCTION__, msg)
32
33 RPY_EXTERN
34 void RPyAssertFailed(const char* filename, long lineno,
35 const char* function, const char *msg);
36 #else
37 # define RPyAssert(x, msg) /* nothing */
38 #endif
39
40 RPY_EXTERN
41 void RPyAbort(void);
42
43 RPY_EXTERN
44 double _PyPy_dg_stdnan(int sign);
45
46 #if defined(RPY_LL_ASSERT) || defined(RPY_SANDBOXED)
47 /* obscure macros that can be used as expressions and lvalues to refer
48 * to a field of a structure or an item in an array in a "safe" way --
49 * they abort() in case of null pointer or out-of-bounds index. As a
50 * speed trade-off, RPyItem actually segfaults if the array is null, but
51 * it's a "guaranteed" segfault and not one that can be used by
52 * attackers.
53 */
54 # define RPyCHECK(x) ((x)?(void)0:RPyAbort())
55 # define RPyField(ptr, name) ((RPyCHECK(ptr), (ptr))->name)
56 # define RPyItem(array, index) \
57 ((RPyCHECK((index) >= 0 && (index) < (array)->length), \
58 (array))->items[index])
59 # define RPyFxItem(ptr, index, fixedsize) \
60 ((RPyCHECK((ptr) != NULL && (index) >= 0 && (index) < (fixedsize)), \
61 (ptr))[index])
62 # define RPyNLenItem(array, index) \
63 ((RPyCHECK((array) != NULL && (index) >= 0), (array))->items[index])
64 # define RPyBareItem(array, index) \
65 ((RPyCHECK((array) != NULL && (index) >= 0), (array))[index])
66
67 #else
68 # define RPyField(ptr, name) ((ptr)->name)
69 # define RPyItem(array, index) ((array)->items[index])
70 # define RPyFxItem(ptr, index, fixedsize) ((ptr)[index])
71 # define RPyNLenItem(array, index) ((array)->items[index])
72 # define RPyBareItem(array, index) ((array)[index])
73 #endif /* RPY_LL_ASSERT || RPY_SANDBOXED */
74
75 #endif /* _SRC_SUPPORT_H */