forked from luainkernel/lunatik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlunatik_conf.h
103 lines (81 loc) · 2.79 KB
/
lunatik_conf.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
/*
* SPDX-FileCopyrightText: (c) 2023-2024 Ring Zero Desenvolvimento de Software LTDA
* SPDX-License-Identifier: MIT OR GPL-2.0-only
*/
#ifndef lunatik_conf_h
#define lunatik_conf_h
#undef LUA_INTEGER
#undef LUA_INTEGER_FRMLEN
#undef LUA_UNSIGNED
#undef LUA_MAXUNSIGNED
#undef LUA_MAXINTEGER
#undef LUA_MININTEGER
#ifdef __LP64__
#define LUA_INTEGER long long
#define LUA_INTEGER_FRMLEN "ll"
#define LUA_UNSIGNED unsigned long long
#define LUA_MAXUNSIGNED ULLONG_MAX
#define LUA_MAXINTEGER LLONG_MAX
#define LUA_MININTEGER LLONG_MIN
#else
#define LUA_INTEGER long
#define LUA_INTEGER_FRMLEN "l"
#define LUA_UNSIGNED unsigned long
#define LUA_MAXUNSIGNED ULONG_MAX
#define LUA_MAXINTEGER LONG_MAX
#define LUA_MININTEGER LONG_MIN
#endif /* __LP64__ */
#define LUAI_UACNUMBER LUA_INTEGER
#define LUA_NUMBER LUA_INTEGER
#define LUA_NUMBER_FMT LUA_INTEGER_FMT
#define l_randomizePivot() (~0)
#include <linux/random.h>
#define luai_makeseed(L) get_random_u32()
#define lua_writestring(s,l) printk("%s",(s))
#define lua_writeline() pr_cont("\n")
#define lua_writestringerror(...) pr_err(__VA_ARGS__)
/* see https://www.gnu.org/software/libc/manual/html_node/Atomic-Types.html */
#define l_signalT int
/* frame size shouldn't be larger than 1024 bytes; thus, LUAL_BUFFERSIZE
* must be adjusted for the stack of functions that use luaL_Buffer */
#undef LUAL_BUFFERSIZE
#define LUAL_BUFFERSIZE (256) /* {laux,load,lstr,ltab,lutf8}lib.c */
#ifdef lauxlib_c
#define panic lua_panic
#endif
#include <linux/module.h>
#ifdef MODULE /* see https://lwn.net/Articles/813350/ */
void *lunatik_lookup(const char *symbol);
#define lsys_loadlib(l) __symbol_get((l))
#define lsys_unloadlib(l) symbol_put_addr((l))
#else
#include <linux/kallsyms.h>
#define lunatik_lookup(s) ((void *)kallsyms_lookup_name((l)))
#define lsys_loadlib(l) lunatik_lookup(l)
#define lsys_unloadlib(l)
#endif
#define lsys_sym(L,l,s) ((lua_CFunction)(l))
typedef struct lua_State lua_State;
const char *lua_pushfstring(lua_State *L, const char *fmt, ...);
static inline void *lsys_load(lua_State *L, const char *symbol, int seeglb)
{
void *lib;
(void)(seeglb); /* not used */
if ((lib = lsys_loadlib(symbol)) == NULL)
lua_pushfstring(L, "%s not found in kernel symbol table", symbol);
return lib;
}
int lunatik_loadfile(lua_State *L, const char *filename, const char *mode);
#define luaL_loadfilex(L,f,m) lunatik_loadfile((L),(f),(m))
#undef LUA_ROOT
#define LUA_ROOT "/lib/modules/lua/"
#undef LUA_PATH_DEFAULT
#define LUA_PATH_DEFAULT LUA_ROOT"?.lua;" LUA_ROOT"?/init.lua"
#undef LUAI_MAXSTACK
#define LUAI_MAXSTACK 200
#if defined(lcode_c) || defined(ldebug_c) || defined(llex_c) || defined(lparser_c) || defined(lstate_c)
#ifdef current /* defined by asm/current.h */
#undef current /* conflicts with Lua namespace */
#endif
#endif
#endif