1 /*
2  * (c) 2015 Alexander Warg <alexander.warg@kernkonzept.com>
3  */
4 
5 #include <lua.h>
6 #include <lauxlib.h>
7 #include <lualib.h>
8 
9 #include <l4/re/env>
10 #include <l4/sys/platform_control>
11 
12 #include "lua_cap.h"
13 #include "lua.h"
14 
15 #include <cstring>
16 #include <cstdio>
17 
18 namespace Lua { namespace {
19 
20 static int
__system_suspend(lua_State * l)21 __system_suspend(lua_State *l)
22 {
23   Lua::Cap *n = check_cap(l, 1);
24   l4_umword_t extras = luaL_checkinteger(l, 2);
25   auto pfc = n->cap<L4::Platform_control>().get();
26   l4_msgtag_t t = pfc->system_suspend(extras);
27   int r = l4_error(t);
28 
29   if (r < 0)
30     luaL_error(l, "runtime error %s (%d)", l4sys_errtostr(r), r);
31 
32   return 0;
33 }
34 
35 static int
__system_shutdown(lua_State * l)36 __system_shutdown(lua_State *l)
37 {
38   Lua::Cap *n = check_cap(l, 1);
39   l4_umword_t reboot = luaL_checkinteger(l, 2);
40   auto pfc = n->cap<L4::Platform_control>().get();
41   l4_msgtag_t t = pfc->system_shutdown(reboot);
42   int r = l4_error(t);
43 
44   if (r < 0)
45     luaL_error(l, "runtime error %s (%d)", l4sys_errtostr(r), r);
46 
47   return 0;
48 }
49 
50 struct Pfc_model
51 {
52   static void
register_methodsLua::__anon2fb6f1280111::Pfc_model53   register_methods(lua_State *l)
54   {
55     static const luaL_Reg l4_cap_class[] =
56     {
57       { "system_suspend", __system_suspend },
58       { "system_shutdown", __system_shutdown },
59       { NULL, NULL }
60     };
61     luaL_setfuncs(l, l4_cap_class, 0);
62     Cap::add_class_metatable(l);
63   }
64 };
65 
66 static Lua::Cap_type_lib<L4::Platform_control, Pfc_model> __lib;
67 
68 }}
69