forked from luainkernel/lunatik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lunatik_conf.h
118 lines (97 loc) · 3.69 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (c) 2023-2024 ring-0 Ltda.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#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() printk("\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"
#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