Permalink
Browse files

new file: ctest.lua

	modified:   desktop.ppm
	new file:   ev.lua
	new file:   ev_utils.lua
	new file:   include/constants-arm.lua
	new file:   include/constants-mips.lua
	new file:   include/constants-ppc.lua
	new file:   include/constants-x64.lua
	new file:   include/constants-x86.lua
	new file:   include/constants.lua
	new file:   include/headers-x64.lua
	new file:   include/headers-x86.lua
	new file:   include/headers.lua
	new file:   include/types.lua
	new file:   input.lua
	new file:   libev.lua
	new file:   luaunit.lua
	new file:   nl.lua
	new file:   strict.lua
	new file:   syscall.lua
	new file:   test_libev.lua
	new file:   test_syscall.lua
	new file:   userland/metadata_fourcc.lua
  • Loading branch information...
1 parent 65e45c6 commit 2ed3d085af4989235a3f67e3e2416c964953ef14 @Wiladams committed Oct 27, 2012
Showing with 13,510 additions and 0 deletions.
  1. +123 −0 ctest.lua
  2. BIN desktop.ppm
  3. +256 −0 ev.lua
  4. +343 −0 ev_utils.lua
  5. +71 −0 include/constants-arm.lua
  6. +381 −0 include/constants-mips.lua
  7. +12 −0 include/constants-ppc.lua
  8. +337 −0 include/constants-x64.lua
  9. +352 −0 include/constants-x86.lua
  10. +1,931 −0 include/constants.lua
  11. +17 −0 include/headers-x64.lua
  12. +22 −0 include/headers-x86.lua
  13. +967 −0 include/headers.lua
  14. +864 −0 include/types.lua
  15. +1,144 −0 input.lua
  16. +262 −0 libev.lua
  17. +553 −0 luaunit.lua
  18. +1,078 −0 nl.lua
  19. +41 −0 strict.lua
  20. +2,454 −0 syscall.lua
  21. +86 −0 test_libev.lua
  22. +2,146 −0 test_syscall.lua
  23. +70 −0 userland/metadata_fourcc.lua
View
123 ctest.lua
@@ -0,0 +1,123 @@
+-- generate C test file to check type sizes etc
+
+local S = require "syscall"
+local ffi = require "ffi"
+
+local s, t = S.s, S.t
+
+-- TODO fix these, various naming issues
+S.ctypes["struct linux_dirent64"] = nil
+S.ctypes["struct statfs64"] = nil
+S.ctypes["struct flock64"] = nil
+S.ctypes["struct stat64"] = nil
+S.ctypes["struct fdb_entry"] = nil
+S.ctypes["struct seccomp_data"] = nil
+S.ctypes["sighandler_t"] = nil
+S.ctypes["struct rlimit64"] = nil
+S.ctypes["struct mq_attr"] = nil
+
+-- fixes for constants
+S.__WALL = S.WALL; S.WALL = nil
+S.__WCLONE = S.WCLONE; S.WCLONE = nil
+
+-- remove seccomp for now as no support on the ARM box
+for k, _ in pairs(S) do
+ if k:sub(1, 8) == 'SECCOMP_' then S[k] = nil end
+end
+
+-- fake constants
+S.MS_RO = nil
+S.MS_RW = nil
+S.IFF_ALL = nil
+S.IFF_NONE = nil
+
+-- TODO find the headers/flags for these if exist, or remove
+S.SA_RESTORER = nil
+S.AF_DECNET = nil
+S.SIG_HOLD = nil
+S.NOTHREAD = nil
+S.RTF_PREFIX_RT = nil
+S.RTF_EXPIRES = nil
+S.RTF_ROUTEINFO = nil
+S.RTF_ANYCAST = nil
+
+-- include kitchen sink, garbage can etc
+print [[
+#include "assert.h"
+
+#define _GNU_SOURCE
+#define __USE_GNU
+#define _FILE_OFFSET_BITS 64
+#define _LARGE_FILES 1
+#define __USE_FILE_OFFSET64
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/epoll.h>
+#include <signal.h>
+#include <sys/utsname.h>
+#include <time.h>
+#include <linux/aio_abi.h>
+#include <sys/resource.h>
+#include <sys/sysinfo.h>
+#include <sys/time.h>
+#include <sys/un.h>
+#include <netinet/ip.h>
+#include <poll.h>
+#include <sys/signalfd.h>
+#include <linux/rtnetlink.h>
+#include <sys/vfs.h>
+#include <sys/timex.h>
+#include <linux/posix_types.h>
+#include <linux/if.h>
+#include <linux/if_bridge.h>
+#include <sys/mman.h>
+#include <sched.h>
+#include <sys/xattr.h>
+#include <linux/if_arp.h>
+#include <sys/capability.h>
+#include <linux/sched.h>
+#include <termios.h>
+#include <unistd.h>
+#include <sys/prctl.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
+#include <net/route.h>
+#include <sys/inotify.h>
+#include <sys/wait.h>
+#include <linux/mman.h>
+#include <linux/veth.h>
+#include <linux/sockios.h>
+#include <dirent.h>
+#include <linux/reboot.h>
+#include <sys/timerfd.h>
+#include <linux/falloc.h>
+#include <sys/eventfd.h>
+
+int main(int argc, char **argv) {
+]]
+
+-- iterate over S.ctypes
+for k, v in pairs(S.ctypes) do
+ print("assert(sizeof(" .. k .. ") == " .. ffi.sizeof(v) .. ");")
+end
+
+-- test all the constants
+
+for k, v in pairs(S) do
+ if type(S[k]) == "number" then
+ print("assert(" .. k .. " == " .. v .. ");")
+ end
+end
+
+-- TODO test error codes
+
+print [[
+}
+]]
+
View
BIN desktop.ppm
Binary file not shown.
View
256 ev.lua
@@ -0,0 +1,256 @@
+-- LuaJIT binding to libev (http://libev.schmorp.de/)
+--
+-- uses almost-identical API to lua-ev (https://github.com/brimworks/lua-ev)
+--
+-- Author: Evan Wies <evan@neomantra.net>
+--
+
+local ffi = require('ffi')
+
+local bit = require("bit")
+local band, bor = bit.band, bit.bor
+
+
+
+-- extracted from preprocessing <ev.h>
+ffi.cdef[[
+
+/* eventmask, revents, events... */
+enum {
+ EV_UNDEF = 0xFFFFFFFF, /* guaranteed to be invalid */
+ EV_NONE = 0x00, /* no events */
+ EV_READ = 0x01, /* ev_io detected read will not block */
+ EV_WRITE = 0x02, /* ev_io detected write will not block */
+ EV__IOFDSET = 0x80, /* internal use only */
+ EV_IO = EV_READ, /* alias for type-detection */
+ EV_TIMER = 0x00000100, /* timer timed out */
+ EV_PERIODIC = 0x00000200, /* periodic timer timed out */
+ EV_SIGNAL = 0x00000400, /* signal was received */
+ EV_CHILD = 0x00000800, /* child/pid had status change */
+ EV_STAT = 0x00001000, /* stat data changed */
+ EV_IDLE = 0x00002000, /* event loop is idling */
+ EV_PREPARE = 0x00004000, /* event loop about to poll */
+ EV_CHECK = 0x00008000, /* event loop finished poll */
+ EV_EMBED = 0x00010000, /* embedded event loop needs sweep */
+ EV_FORK = 0x00020000, /* event loop resumed in child */
+ EV_CLEANUP = 0x00040000, /* event loop resumed in child */
+ EV_ASYNC = 0x00080000, /* async intra-loop signal */
+ EV_CUSTOM = 0x01000000, /* for use by user code */
+ EV_ERROR = 0x80000000 /* sent when an error occurs */
+};
+
+/* flag bits for ev_default_loop and ev_loop_new */
+enum {
+ /* the default */
+ EVFLAG_AUTO = 0x00000000U, /* not quite a mask */
+ /* flag bits */
+ EVFLAG_NOENV = 0x01000000U, /* do NOT consult environment */
+ EVFLAG_FORKCHECK = 0x02000000U, /* check for a fork in each iteration */
+ /* debugging/feature disable */
+ EVFLAG_NOINOTIFY = 0x00100000U, /* do not attempt to use inotify */
+ EVFLAG_SIGNALFD = 0x00200000U, /* attempt to use signalfd */
+ EVFLAG_NOSIGMASK = 0x00400000U /* avoid modifying the signal mask */
+};
+
+/* method bits to be ored together */
+enum {
+ EVBACKEND_SELECT = 0x00000001U, /* about anywhere */
+ EVBACKEND_POLL = 0x00000002U, /* !win */
+ EVBACKEND_EPOLL = 0x00000004U, /* linux */
+ EVBACKEND_KQUEUE = 0x00000008U, /* bsd */
+ EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */
+ EVBACKEND_PORT = 0x00000020U, /* solaris 10 */
+ EVBACKEND_ALL = 0x0000003FU, /* all known backends */
+ EVBACKEND_MASK = 0x0000FFFFU /* all future backends */
+};
+
+typedef double ev_tstamp;
+
+ev_tstamp ev_time (void);
+void ev_sleep (ev_tstamp delay); /* sleep for a while */
+
+/* ev_run flags values */
+enum {
+ EVRUN_NOWAIT = 1, /* do not block/wait */
+ EVRUN_ONCE = 2 /* block *once* only */
+};
+
+/* ev_break how values */
+enum {
+ EVBREAK_CANCEL = 0, /* undo unloop */
+ EVBREAK_ONE = 1, /* unloop once */
+ EVBREAK_ALL = 2 /* unloop all loops */
+};
+
+typedef struct ev_loop ev_loop;
+
+typedef struct ev_watcher
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_watcher *w, int revents);
+} ev_watcher;
+
+typedef struct ev_watcher_list
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_watcher_list *w, int revents);
+ struct ev_watcher_list *next;
+} ev_watcher_list;
+
+typedef struct ev_watcher_time
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_watcher_time *w, int revents);
+ ev_tstamp at;
+} ev_watcher_time;
+
+typedef struct ev_io
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_io *w, int revents);
+ struct ev_watcher_list *next;
+ int fd;
+ int events;
+} ev_io;
+
+typedef struct ev_timer
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_timer *w, int revents);
+ ev_tstamp at;
+ ev_tstamp repeat_;
+} ev_timer;
+
+typedef struct ev_periodic
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_periodic *w, int revents);
+ ev_tstamp at;
+ ev_tstamp offset;
+ ev_tstamp interval;
+ ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now);
+} ev_periodic;
+
+typedef struct ev_signal
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_signal *w, int revents);
+ struct ev_watcher_list *next;
+ int signum;
+} ev_signal;
+
+typedef struct ev_child
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_child *w, int revents);
+ struct ev_watcher_list *next;
+ int flags;
+ int pid;
+ int rpid;
+ int rstatus;
+} ev_child;
+
+typedef struct ev_idle
+{
+ int active;
+ int pending;
+ int priority;
+ void *data;
+ void (*cb)(struct ev_loop *loop, struct ev_idle *w, int revents);
+} ev_idle;
+
+typedef struct ev_prepare
+{
+ int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_prepare *w, int revents);
+} ev_prepare;
+
+typedef struct ev_check
+{
+ int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_check *w, int revents);
+} ev_check;
+
+typedef struct ev_fork
+{
+ int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_fork *w, int revents);
+} ev_fork;
+
+typedef struct ev_cleanup
+{
+ int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_cleanup *w, int revents);
+} ev_cleanup;
+
+typedef struct ev_embed
+{
+ int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_embed *w, int revents);
+ struct ev_loop *other;
+ ev_io io;
+ ev_prepare prepare;
+ ev_check check;
+ ev_timer timer;
+ ev_periodic periodic;
+ ev_idle idle;
+ ev_fork fork;
+ ev_cleanup cleanup;
+} ev_embed;
+
+typedef int sig_atomic_t;
+typedef struct ev_async
+{
+ int active; int pending; int priority; void *data; void (*cb)(struct ev_loop *loop, struct ev_async *w, int revents);
+ sig_atomic_t volatile sent;
+} ev_async;
+
+void ev_signal_start (struct ev_loop *loop, ev_signal *w);
+void ev_signal_stop (struct ev_loop *loop, ev_signal *w);
+
+struct ev_loop *ev_default_loop (unsigned int flags );
+struct ev_loop *ev_loop_new (unsigned int flags );
+ev_tstamp ev_now (struct ev_loop *loop);
+void ev_loop_destroy (struct ev_loop *loop);
+unsigned int ev_iteration (struct ev_loop *loop);
+unsigned int ev_depth (struct ev_loop *loop);
+
+void ev_io_start (struct ev_loop *loop, ev_io *w);
+void ev_io_stop (struct ev_loop *loop, ev_io *w);
+
+void ev_run (struct ev_loop *loop, int flags );
+void ev_break (struct ev_loop *loop, int how );
+void ev_suspend (struct ev_loop *loop);
+void ev_resume (struct ev_loop *loop);
+int ev_clear_pending (struct ev_loop *loop, void *w);
+
+void ev_timer_start (struct ev_loop *loop, ev_timer *w);
+void ev_timer_stop (struct ev_loop *loop, ev_timer *w);
+void ev_timer_again (struct ev_loop *loop, ev_timer *w);
+ev_tstamp ev_timer_remaining (struct ev_loop *loop, ev_timer *w);
+
+void ev_idle_start (struct ev_loop *loop, ev_idle *w);
+void ev_idle_stop (struct ev_loop *loop, ev_idle *w);
+
+]]
+
+
View
343 ev_utils.lua
@@ -0,0 +1,343 @@
+
+local ffi = require "ffi"
+local bit = require "bit"
+local bor = bit.bor
+
+require "ev"
+
+local libev = ffi.load('libev.so.4.0.0')
+--local libev = ffi.load("libev");
+--local libev = require "libev"
+
+local ev_loop = ffi.typeof('ev_loop')
+local ev_loop_mt = {
+ __gc = function(self)
+ print("GC: ev_loop_t");
+ libev.ev_loop_destroy(self);
+ end,
+
+ __new = function(ct, flags)
+ flags = flags or ffi.C.EVFLAG_AUTO
+ return libev.ev_loop_new( flags )
+ end,
+
+ __index = {
+ -- loop:run( flags )
+ run = function( self, flags )
+ flags = flags or 0
+ libev.ev_run(self, flags )
+ end,
+
+ -- loop:halt( how )
+ halt = function( ev_loop, how )
+ how = how or libev.EVBREAK_ALL
+ libev.ev_break(ev_loop, how)
+ end,
+
+ -- loop:suspend()
+ suspend = function( ev_loop )
+ libev.ev_suspend(ev_loop)
+ end,
+
+ -- loop:resume()
+ resume = function( ev_loop )
+ libev.ev_resume(ev_loop)
+ end,
+
+ -- bool = loop:is_default()
+ is_default = function( ev_loop )
+ return libev.is_default_loop(ev_loop) ~= 0
+ end,
+
+ -- num = loop:iteration()
+ iteration = function( ev_loop )
+ return libev.ev_iteration(ev_loop)
+ end,
+
+ -- num = loop:depth() [libev >= 3.7]
+ depth = function( ev_loop )
+ return libev.ev_depth(ev_loop)
+ end,
+
+ -- epochs = loop:now()
+ now = function( ev_loop )
+ return libev.ev_now(ev_loop)
+ end,
+
+ -- epochs = loop:update_now()
+ update_now = function( ev_loop )
+ libev.ev_now_update(ev_loop)
+ return libev.ev_now(ev_loop)
+ end,
+
+ -- backend_id = loop:backend()
+ backend = function( ev_loop )
+ return libev.ev_backend( ev_loop )
+ end,
+
+ -- loop:loop()
+ loop = function(ev_loop)
+ ev_loop:run()
+ end,
+
+ -- loop:unloop()
+ unloop = function( ev_loop )
+ ev_loop:halt()
+ end,
+ },
+}
+ffi.metatype( ev_loop, ev_loop_mt);
+
+
+
+local ev_timer = ffi.typeof('ev_timer')
+local ev_timer_mt = {
+ __new = function( ct, on_timeout_fn, after_seconds, repeat_seconds )
+ assert( on_timeout_fn, "on_timeout_fn cannot be nil" )
+ repeat_seconds = repeat_seconds or 0
+ assert( after_seconds > 0, "after_seconds must be > 0" )
+ assert( repeat_seconds >= 0, "repeat_seconds must be >= 0" )
+
+ local obj = ffi.new(ct)
+ obj.active = 0
+ obj.pending = 0
+ obj.priority = 0
+ obj.cb = on_timeout_fn
+ obj.at = after_seconds
+ obj.repeat_ = repeat_seconds
+ return obj
+ end,
+
+ __index = {
+ -- timer:start(loop [, is_daemon])
+ start = function( ev_timer, loop, is_daemon )
+ assert( ffi.istype(ev_loop, loop), "loop is not an ev_loop" )
+ libev.ev_timer_start(loop, ev_timer)
+ --TODO loop_start_watcher(L, 2, 1, is_daemon);
+ end,
+
+ -- timer:stop(loop)
+ stop = function( timer, loop )
+ -- TODO loop_stop_watcher(L, 2, 1);
+ assert( ffi.istype(ev_loop, loop), "loop is not an ev_loop" )
+ libev.ev_timer_stop(loop, timer)
+ end,
+
+ -- timer:again(loop [, seconds])
+ again = function( ev_timer, loop, repeat_seconds )
+ assert( ffi.istype(ev_loop_t, loop), "loop is not an ev_loop" )
+ repeat_seconds = repeat_seconds or 0
+ if repeat_seconds then
+ assert( repeat_seconds >= 0, "repeat_seconds must be >= 0" )
+ timer.repeat_ = repeat_seconds
+ end
+ if timer.repeat_ ~= 0 then
+ libev.ev_timer_again(loop, ev_timer)
+ --TODO loop_start_watcher(L, 2, 1, -1);
+ else
+ -- Just calling stop instead of again in case the symantics change in libev
+ --TODO loop_stop_watcher(L, 2, 1);
+ libev.ev_timer_stop(loop, ev_timer)
+ end
+ end,
+
+ clear_pending = function( ev_timer, loop )
+ assert( ffi.istype(ev_loop_t, loop), "loop is not an ev_loop" )
+ local revents = libev.ev_clear_pending(loop, ev_timer)
+ if timer.repeat_ ~= 0 and band(revents, libev.EV_TIMEOUT) ~= 0 then
+ --TODO loop_stop_watcher(L, 2, 1)
+ end
+ return revents
+ end,
+
+ remaining = function( ev_timer, loop )
+ assert( ffi.istype(ev_loop_t, loop), "loop is not an ev_loop" )
+ return libev.ev_timer_remaining(loop, ev_timer)
+ end,
+ },
+}
+ffi.metatype( ev_timer, ev_timer_mt);
+
+
+
+local ev_signal_t = ffi.typeof('ev_signal')
+ffi.metatype( ev_signal_t, {
+ __index = {
+ -- signal:start(loop [, is_daemon])
+ start = function( ev_signal, ev_loop, is_daemon )
+ assert( ffi.istype(ev_loop_t, ev_loop), "loop is not an ev_loop" )
+ libev.ev_signal_start(ev_loop, ev_signal)
+ --TODO loop_start_watcher(L, 2, 1, is_daemon);
+ end,
+ -- signal:stop(loop)
+ stop = function( ev_signal, ev_loop )
+ -- TODO loop_stop_watcher(L, 2, 1);
+ assert( ffi.istype(ev_loop_t, ev_loop), "loop is not an ev_loop" )
+ libev.ev_signal_stop(ev_loop, ev_signal)
+ end,
+ },
+})
+
+local ev_io = ffi.typeof('ev_io')
+local ev_io_mt = {
+ __new = function(ct, on_io_fn, file_descriptor, revents)
+ assert( on_io_fn, "on_io_fn cannot be nil" )
+ revents = revents or 0
+ local obj = ffi.new(ct);
+ obj.active = 0
+ obj.pending = 0
+ obj.priority = 0
+ obj.cb = on_io_fn
+ obj.fd = file_descriptor
+ obj.events = bor( revents, ffi.C.EV__IOFDSET )
+ return obj
+ end,
+
+ __index = {
+ -- io:start(loop [, is_daemon])
+ start = function( ev_io, loop, is_daemon )
+ assert( ffi.istype(ev_loop, loop), "loop is not an ev_loop" )
+ libev.ev_io_start(loop, ev_io)
+ --TODO loop_start_watcher(L, 2, 1, is_daemon);
+ end,
+ -- io:stop(loop)
+ stop = function( ev_io, loop )
+ -- TODO loop_stop_watcher(L, 2, 1);
+ assert( ffi.istype(ev_loop_t, loop), "loop is not an ev_loop" )
+ libev.ev_io_stop(loop, ev_io)
+ end,
+
+ -- fd = io:getfd()
+ getfd = function( ev_io )
+ return io.fd
+ end,
+ },
+}
+ffi.metatype( ev_io, ev_io_mt);
+
+local ev_idle = ffi.typeof('ev_idle')
+local ev_idle_mt = {
+ __new = function(ct, on_idle_fn)
+ assert( on_idle_fn, "on_idle_fn cannot be nil" )
+ local obj = ffi.new(ct);
+ obj.active = 0;
+ obj.pending = 0;
+ obj.priority = 0;
+ obj.cb = on_idle_fn;
+ return obj;
+ end,
+
+ __index = {
+ -- idle:start(loop [, is_daemon])
+ start = function( idler, loop, is_daemon )
+ assert( ffi.istype(ev_loop, loop), "loop is not an ev_loop" )
+ libev.ev_idle_start(loop, idler)
+ --TODO loop_start_watcher(L, 2, 1, is_daemon);
+ end,
+ -- idle:stop(loop)
+ stop = function( idler, loop )
+ -- TODO loop_stop_watcher(L, 2, 1);
+ assert( ffi.istype(ev_loop, loop), "loop is not an ev_loop" )
+ libev.ev_idle_stop(loop, idler)
+ end,
+ },
+}
+ffi.metatype( ev_idle, ev_idle_mt);
+
+
+
+-- Public API
+-- This is the table we return to the requirer
+local ev = {
+ -- structures
+ ev_loop = ev_loop,
+ ev_idle = ev_idle,
+ ev_io = ev_io,
+ ev_timer = ev_timer,
+
+ -- enums
+ UNDEF = libev.EV_UNDEF,
+ NONE = libev.EV_NONE,
+ READ = libev.EV_READ,
+ WRITE = libev.EV_WRITE,
+ IOFDSET = libev.EV__IOFDSET,
+ wIO = libev.EV_IO,
+ wTIMER = libev.EV_TIMER,
+ wPERIODIC = libev.EV_PERIODIC,
+ wSIGNAL = libev.EV_SIGNAL,
+ wCHILD = libev.EV_CHILD,
+ wSTAT = libev.EV_STAT,
+ wIDLE = libev.EV_IDLE,
+ wPREPARE = libev.EV_PREPARE,
+ wCHECK = libev.EV_CHECK,
+ wEMBED = libev.EV_EMBED,
+ wFORK = libev.EV_FORK,
+ wCLEANUP = libev.EV_CLEANUP,
+ wASYNC = libev.EV_ASYNC,
+ wCUSTOM = libev.EV_CUSTOM,
+ ERROR =libev.EV_ERROR,
+ FLAG_AUTO = libev.EVFLAG_AUTO,
+ FLAG_NOENV = libev.EVFLAG_NOENV,
+ FLAG_FORKCHECK = libev.EVFLAG_FORKCHECK,
+ FLAG_NOINOTIFY = libev.EVFLAG_NOINOTIFY,
+ FLAG_SIGNALFD = libev.EVFLAG_SIGNALFD,
+ FLAG_NOSIGMASK = libev.EVFLAG_NOSIGMASK,
+ BACKEND_SELECT = libev.EVBACKEND_SELECT,
+ BACKEND_POLL = libev.EVBACKEND_POLL,
+ BACKEND_EPOLL = libev.EVBACKEND_EPOLL,
+ BACKEND_KQUEUE = libev.EVBACKEND_KQUEUE,
+ BACKEND_DEVPOLL = libev.EVBACKEND_DEVPOLL,
+ BACKEND_PORT = libev.EVBACKEND_PORT,
+ BACKEND_ALL = libev.EVBACKEND_ALL,
+ BACKEND_MASK = libev.EVBACKEND_MASK,
+}
+
+
+
+---
+function ev.time()
+ return libev.ev_time()
+end
+
+function ev.sleep( interval )
+ libev.ev_sleep( interval )
+end
+
+
+
+
+--sig = ev.Signal.new(on_signal, signal_number)
+function ev.Signal(on_signal_fn, signal_number)
+ assert( on_signal_fn, "on_signal_fn cannot be nil" )
+ local ev_signal = ev_signal_t()
+ ev_signal.active = 0
+ ev_signal.pending = 0
+ ev_signal.priority = 0
+ ev_signal.cb = on_signal_fn
+ ev_signal.signum = signal_number
+ return ev_signal
+end
+
+--- io = ev.IO(on_io, file_descriptor, revents)
+function ev.IO(on_io_fn, file_descriptor, revents)
+ assert( on_io_fn, "on_io_fn cannot be nil" )
+ local ev_io = ev_io_t()
+ ev_io.active = 0
+ ev_io.pending = 0
+ ev_io.priority = 0
+ ev_io.cb = on_io_fn
+ ev_io.fd = file_descriptor
+ revents = revents or 0
+ ev_io.events = bor( revents, ffi.C.EV__IOFDSET )
+ return ev_io
+end
+
+
+
+--TODO Child, Stat Periodic, Prepare, Check, Embed, Async, Clenaup, Fork
+
+-- Allow direct access to library
+ev.Native = libev
+
+-- Return the Public API
+return ev
View
71 include/constants-arm.lua
@@ -0,0 +1,71 @@
+-- arm specific constants
+
+local ffi = require "ffi"
+
+assert(ffi.abi("eabi"), "only support eabi for arm")
+
+local octal = function (s) return tonumber(s, 8) end
+
+local arch = {}
+
+arch.SYS = {
+ mknod = 14,
+ getpid = 20,
+ acct = 51,
+ ustat = 62,
+ stat = 106,
+ fstat = 108,
+ lstat = 107,
+ clone = 120,
+ _llseek = 140,
+ getdents = 141,
+ getcwd = 183,
+ stat64 = 195,
+ lstat64 = 196,
+ fstat64 = 197,
+ getdents64 = 217,
+ readahead = 225,
+ setxattr = 226,
+ lsetxattr = 227,
+ fsetxattr = 228,
+ getxattr = 229,
+ lgetxattr = 230,
+ fgetxattr = 231,
+ listxattr = 232,
+ llistxattr = 233,
+ flistxattr = 234,
+ removexattr = 235,
+ lremovexattr = 236,
+ fremovexattr = 237,
+ io_setup = 243,
+ io_destroy = 244,
+ io_getevents = 245,
+ io_submit = 246,
+ io_cancel = 247,
+ clock_settime = 262,
+ clock_gettime = 263,
+ clock_getres = 264,
+ clock_nanosleep = 265,
+ mknodat = 324,
+ fstatat64 = 327,
+ splice = 340,
+ sync_file_range = 341,
+ tee = 342,
+ vmsplice = 343,
+ timerfd_create = 350,
+ fallocate = 352,
+ timerfd_settime = 353,
+ timerfd_gettime = 354,
+ pipe2 = 359,
+ setns = 375,
+}
+
+-- TODO cleanup to return table
+arch.oflags = function(S)
+ S.O_DIRECTORY = octal('040000')
+ S.O_NOFOLLOW = octal('0100000')
+ S.O_DIRECT = octal('0200000')
+end
+
+return arch
+
View
381 include/constants-mips.lua
@@ -0,0 +1,381 @@
+-- mips specific constants
+
+error("mips support is coming soon")
+
+local arch = {}
+
+arch.SYS = {
+ syscall = 4000,
+ exit = 4001,
+ fork = 4002,
+ read = 4003,
+ write = 4004,
+ open = 4005,
+ close = 4006,
+ waitpid = 4007,
+ creat = 4008,
+ link = 4009,
+ unlink = 4010,
+ execve = 4011,
+ chdir = 4012,
+ time = 4013,
+ mknod = 4014,
+ chmod = 4015,
+ lchown = 4016,
+ break = 4017,
+ unused18 = 4018,
+ lseek = 4019,
+ getpid = 4020,
+ mount = 4021,
+ umount = 4022,
+ setuid = 4023,
+ getuid = 4024,
+ stime = 4025,
+ ptrace = 4026,
+ alarm = 4027,
+ unused28 = 4028,
+ pause = 4029,
+ utime = 4030,
+ stty = 4031,
+ gtty = 4032,
+ access = 4033,
+ nice = 4034,
+ ftime = 4035,
+ sync = 4036,
+ kill = 4037,
+ rename = 4038,
+ mkdir = 4039,
+ rmdir = 4040,
+ dup = 4041,
+ pipe = 4042,
+ times = 4043,
+ prof = 4044,
+ brk = 4045,
+ setgid = 4046,
+ getgid = 4047,
+ signal = 4048,
+ geteuid = 4049,
+ getegid = 4050,
+ acct = 4051,
+ umount2 = 4052,
+ lock = 4053,
+ ioctl = 4054,
+ fcntl = 4055,
+ mpx = 4056,
+ setpgid = 4057,
+ ulimit = 4058,
+ unused59 = 4059,
+ umask = 4060,
+ chroot = 4061,
+ ustat = 4062,
+ dup2 = 4063,
+ getppid = 4064,
+ getpgrp = 4065,
+ setsid = 4066,
+ sigaction = 4067,
+ sgetmask = 4068,
+ ssetmask = 4069,
+ setreuid = 4070,
+ setregid = 4071,
+ sigsuspend = 4072,
+ sigpending = 4073,
+ sethostname = 4074,
+ setrlimit = 4075,
+ getrlimit = 4076,
+ getrusage = 4077,
+ gettimeofday = 4078,
+ settimeofday = 4079,
+ getgroups = 4080,
+ setgroups = 4081,
+ reserved82 = 4082,
+ symlink = 4083,
+ unused84 = 4084,
+ readlink = 4085,
+ uselib = 4086,
+ swapon = 4087,
+ reboot = 4088,
+ readdir = 4089,
+ mmap = 4090,
+ munmap = 4091,
+ truncate = 4092,
+ ftruncate = 4093,
+ fchmod = 4094,
+ fchown = 4095,
+ getpriority = 4096,
+ setpriority = 4097,
+ profil = 4098,
+ statfs = 4099,
+ fstatfs = 4100,
+ ioperm = 4101,
+ socketcall = 4102,
+ syslog = 4103,
+ setitimer = 4104,
+ getitimer = 4105,
+ stat = 4106,
+ lstat = 4107,
+ fstat = 4108,
+ unused109 = 4109,
+ iopl = 4110,
+ vhangup = 4111,
+ idle = 4112,
+ vm86 = 4113,
+ wait4 = 4114,
+ swapoff = 4115,
+ sysinfo = 4116,
+ ipc = 4117,
+ fsync = 4118,
+ sigreturn = 4119,
+ clone = 4120,
+ setdomainname = 4121,
+ uname = 4122,
+ modify_ldt = 4123,
+ adjtimex = 4124,
+ mprotect = 4125,
+ sigprocmask = 4126,
+ create_module = 4127,
+ init_module = 4128,
+ delete_module = 4129,
+ get_kernel_syms = 4130,
+ quotactl = 4131,
+ getpgid = 4132,
+ fchdir = 4133,
+ bdflush = 4134,
+ sysfs = 4135,
+ personality = 4136,
+ afs_syscall = 4137,
+ setfsuid = 4138,
+ setfsgid = 4139,
+ _llseek = 4140,
+ getdents = 4141,
+ select = 4142,
+ flock = 4143,
+ msync = 4144,
+ readv = 4145,
+ writev = 4146,
+ cacheflush = 4147,
+ cachectl = 4148,
+ sysmips = 4149,
+ unused150 = 4150,
+ getsid = 4151,
+ fdatasync = 4152,
+ _sysctl = 4153,
+ mlock = 4154,
+ munlock = 4155,
+ mlockall = 4156,
+ munlockall = 4157,
+ sched_setparam = 4158,
+ sched_getparam = 4159,
+ sched_setscheduler = 4160,
+ sched_getscheduler = 4161,
+ sched_yield = 4162,
+ sched_get_priority_max= 4163,
+ sched_get_priority_min= 4164,
+ sched_rr_get_interval = 4165,
+ nanosleep = 4166,
+ mremap = 4167,
+ accept = 4168,
+ bind = 4169,
+ connect = 4170,
+ getpeername = 4171,
+ getsockname = 4172,
+ getsockopt = 4173,
+ listen = 4174,
+ recv = 4175,
+ recvfrom = 4176,
+ recvmsg = 4177,
+ send = 4178,
+ sendmsg = 4179,
+ sendto = 4180,
+ setsockopt = 4181,
+ shutdown = 4182,
+ socket = 4183,
+ socketpair = 4184,
+ setresuid = 4185,
+ getresuid = 4186,
+ query_module = 4187,
+ poll = 4188,
+ nfsservctl = 4189,
+ setresgid = 4190,
+ getresgid = 4191,
+ prctl = 4192,
+ rt_sigreturn = 4193,
+ rt_sigaction = 4194,
+ rt_sigprocmask = 4195,
+ rt_sigpending = 4196,
+ rt_sigtimedwait = 4197,
+ rt_sigqueueinfo = 4198,
+ rt_sigsuspend = 4199,
+ pread = 4200,
+ pwrite = 4201,
+ chown = 4202,
+ getcwd = 4203,
+ capget = 4204,
+ capset = 4205,
+ sigaltstack = 4206,
+ sendfile = 4207,
+ getpmsg = 4208,
+ putpmsg = 4209,
+ mmap2 = 4210,
+ truncate64 = 4211,
+ ftruncate64 = 4212,
+ stat64 = 4213,
+ lstat64 = 4214,
+ fstat64 = 4215,
+ pivot_root = 4216,
+ mincore = 4217,
+ madvise = 4218,
+ getdents64 = 4219,
+ fcntl64 = 4220,
+ reserved221 = 4221,
+ gettid = 4222,
+ readahead = 4223,
+ setxattr = 4224,
+ lsetxattr = 4225,
+ fsetxattr = 4226,
+ getxattr = 4227,
+ lgetxattr = 4228,
+ fgetxattr = 4229,
+ listxattr = 4230,
+ llistxattr = 4231,
+ flistxattr = 4232,
+ removexattr = 4233,
+ lremovexattr = 4234,
+ fremovexattr = 4235,
+ tkill = 4236,
+ sendfile64 = 4237,
+ futex = 4238,
+ sched_setaffinity = 4239,
+ sched_getaffinity = 4240,
+ io_setup = 4241,
+ io_destroy = 4242,
+ io_getevents = 4243,
+ io_submit = 4244,
+ io_cancel = 4245,
+ exit_group = 4246,
+ lookup_dcookie = 4247,
+ epoll_create = 4248,
+ epoll_ctl = 4249,
+ epoll_wait = 4250,
+ remap_file_pages = 4251,
+ set_tid_address = 4252,
+ restart_syscall = 4253,
+ fadvise = 4254,
+ statfs64 = 4255,
+ fstatfs64 = 4256,
+ timer_create = 4257,
+ timer_settime = 4258,
+ timer_gettime = 4259,
+ timer_getoverrun = 4260,
+ timer_delete = 4261,
+ clock_settime = 4262,
+ clock_gettime = 4263,
+ clock_getres = 4264,
+ clock_nanosleep = 4265,
+ tgkill = 4266,
+ utimes = 4267,
+ mbind = 4268,
+ get_mempolicy = 4269,
+ set_mempolicy = 4270,
+ mq_open = 4271,
+ mq_unlink = 4272,
+ mq_timedsend = 4273,
+ mq_timedreceive = 4274,
+ mq_notify = 4275,
+ mq_getsetattr = 4276,
+ vserver = 4277,
+ waitid = 4278,
+ add_key = 4280,
+ request_key = 4281,
+ keyctl = 4282,
+ set_thread_area = 4283,
+ inotify_init = 4284,
+ inotify_add_watch = 4285,
+ inotify_rm_watch = 4286,
+ migrate_pages = 4287,
+ openat = 4288,
+ mkdirat = 4289,
+ mknodat = 4290,
+ fchownat = 4291,
+ futimesat = 4292,
+ fstatat = 4293,
+ unlinkat = 4294,
+ renameat = 4295,
+ linkat = 4296,
+ symlinkat = 4297,
+ readlinkat = 4298,
+ fchmodat = 4299,
+ faccessat = 4300,
+ pselect6 = 4301,
+ ppoll = 4302,
+ unshare = 4303,
+ splice = 4304,
+ sync_file_range = 4305,
+ tee = 4306,
+ vmsplice = 4307,
+ move_pages = 4308,
+ set_robust_list = 4309,
+ get_robust_list = 4310,
+ kexec_load = 4311,
+ getcpu = 4312,
+ epoll_pwait = 4313,
+ ioprio_set = 4314,
+ ioprio_get = 4315,
+ utimensat = 4316,
+ signalfd = 4317,
+ timerfd = 4318,
+ eventfd = 4319,
+ fallocate = 4320,
+ fallocate = 4320,
+ timerfd_create = 4321,
+ timerfd_gettime = 4322,
+ timerfd_settime = 4323,
+ signalfd4 = 4324,
+ eventfd2 = 4325,
+ epoll_create1 = 4326,
+ dup3 = 4327,
+ pipe2 = 4328,
+ inotify_init1 = 4329,
+ preadv = 4330,
+ pwritev = 4331,
+ rt_tgsigqueueinfo = 4332,
+ perf_event_open = 4333,
+ accept4 = 4334,
+ recvmmsg = 4335,
+ fanotify_init = 4336,
+ fanotify_mark = 4337,
+ prlimit64 = 4338,
+ name_to_handle_at = 4339,
+ open_by_handle_at = 4340,
+ clock_adjtime = 4341,
+ syncfs = 4342,
+ fallocate = 4320,
+ timerfd_create = 4321,
+ timerfd_gettime = 4322,
+ timerfd_settime = 4323,
+ signalfd4 = 4324,
+ eventfd2 = 4325,
+ epoll_create1 = 4326,
+ dup3 = 4327,
+ pipe2 = 4328,
+ inotify_init1 = 4329,
+ preadv = 4330,
+ pwritev = 4331,
+ rt_tgsigqueueinfo = 4332,
+ perf_event_open = 4333,
+ accept4 = 4334,
+ recvmmsg = 4335,
+ fanotify_init = 4336,
+ fanotify_mark = 4337,
+ prlimit64 = 4338,
+ name_to_handle_at = 4339,
+ open_by_handle_at = 4340,
+ clock_adjtime = 4341,
+ syncfs = 4342,
+ sendmmsg = 4343,
+ setns = 4344,
+ process_vm_readv = 4345,
+ process_vm_writev = 4346,
+}
+
+return arch
+
View
12 include/constants-ppc.lua
@@ -0,0 +1,12 @@
+-- ppc specific code
+
+error("ppc support is coming soon")
+
+local arch = {}
+
+arch.socketoptions = function(S)
+ error("ppc socketoptions need to be set")
+end
+
+return arch
+
View
337 include/constants-x64.lua
@@ -0,0 +1,337 @@
+-- x64 specific constants
+
+local arch = {}
+
+arch.SYS = {
+ read = 0,
+ write = 1,
+ open = 2,
+ close = 3,
+ stat = 4,
+ fstat = 5,
+ lstat = 6,
+ poll = 7,
+ lseek = 8,
+ mmap = 9,
+ mprotect = 10,
+ munmap = 11,
+ brk = 12,
+ rt_sigaction = 13,
+ rt_sigprocmask = 14,
+ rt_sigreturn = 15,
+ ioctl = 16,
+ pread64 = 17,
+ pwrite64 = 18,
+ readv = 19,
+ writev = 20,
+ access = 21,
+ pipe = 22,
+ select = 23,
+ sched_yield = 24,
+ mremap = 25,
+ msync = 26,
+ mincore = 27,
+ madvise = 28,
+ shmget = 29,
+ shmat = 30,
+ shmctl = 31,
+ dup = 32,
+ dup2 = 33,
+ pause = 34,
+ nanosleep = 35,
+ getitimer = 36,
+ alarm = 37,
+ setitimer = 38,
+ getpid = 39,
+ sendfile = 40,
+ socket = 41,
+ connect = 42,
+ accept = 43,
+ sendto = 44,
+ recvfrom = 45,
+ sendmsg = 46,
+ recvmsg = 47,
+ shutdown = 48,
+ bind = 49,
+ listen = 50,
+ getsockname = 51,
+ getpeername = 52,
+ socketpair = 53,
+ setsockopt = 54,
+ getsockopt = 55,
+ clone = 56,
+ fork = 57,
+ vfork = 58,
+ execve = 59,
+ exit = 60,
+ wait4 = 61,
+ kill = 62,
+ uname = 63,
+ semget = 64,
+ semop = 65,
+ semctl = 66,
+ shmdt = 67,
+ msgget = 68,
+ msgsnd = 69,
+ msgrcv = 70,
+ msgctl = 71,
+ fcntl = 72,
+ flock = 73,
+ fsync = 74,
+ fdatasync = 75,
+ truncate = 76,
+ ftruncate = 77,
+ getdents = 78,
+ getcwd = 79,
+ chdir = 80,
+ fchdir = 81,
+ rename = 82,
+ mkdir = 83,
+ rmdir = 84,
+ creat = 85,
+ link = 86,
+ unlink = 87,
+ symlink = 88,
+ readlink = 89,
+ chmod = 90,
+ fchmod = 91,
+ chown = 92,
+ fchown = 93,
+ lchown = 94,
+ umask = 95,
+ gettimeofday = 96,
+ getrlimit = 97,
+ getrusage = 98,
+ sysinfo = 99,
+ times = 100,
+ ptrace = 101,
+ getuid = 102,
+ syslog = 103,
+ getgid = 104,
+ setuid = 105,
+ setgid = 106,
+ geteuid = 107,
+ getegid = 108,
+ setpgid = 109,
+ getppid = 110,
+ getpgrp = 111,
+ setsid = 112,
+ setreuid = 113,
+ setregid = 114,
+ getgroups = 115,
+ setgroups = 116,
+ setresuid = 117,
+ getresuid = 118,
+ setresgid = 119,
+ getresgid = 120,
+ getpgid = 121,
+ setfsuid = 122,
+ setfsgid = 123,
+ getsid = 124,
+ capget = 125,
+ capset = 126,
+ rt_sigpending = 127,
+ rt_sigtimedwait = 128,
+ rt_sigqueueinfo = 129,
+ rt_sigsuspend = 130,
+ sigaltstack = 131,
+ utime = 132,
+ mknod = 133,
+ uselib = 134,
+ personality = 135,
+ ustat = 136,
+ statfs = 137,
+ fstatfs = 138,
+ sysfs = 139,
+ getpriority = 140,
+ setpriority = 141,
+ sched_setparam = 142,
+ sched_getparam = 143,
+ sched_setscheduler = 144,
+ sched_getscheduler = 145,
+ sched_get_priority_max = 146,
+ sched_get_priority_min = 147,
+ sched_rr_get_interval = 148,
+ mlock = 149,
+ munlock = 150,
+ mlockall = 151,
+ munlockall = 152,
+ vhangup = 153,
+ modify_ldt = 154,
+ pivot_root = 155,
+ _sysctl = 156,
+ prctl = 157,
+ arch_prctl = 158,
+ adjtimex = 159,
+ setrlimit = 160,
+ chroot = 161,
+ sync = 162,
+ acct = 163,
+ settimeofday = 164,
+ mount = 165,
+ umount2 = 166,
+ swapon = 167,
+ swapoff = 168,
+ reboot = 169,
+ sethostname = 170,
+ setdomainname = 171,
+ iopl = 172,
+ ioperm = 173,
+ create_module = 174,
+ init_module = 175,
+ delete_module = 176,
+ get_kernel_syms = 177,
+ query_module = 178,
+ quotactl = 179,
+ nfsservctl = 180,
+ getpmsg = 181,
+ putpmsg = 182,
+ afs_syscall = 183,
+ tuxcall = 184,
+ security = 185,
+ gettid = 186,
+ readahead = 187,
+ setxattr = 188,
+ lsetxattr = 189,
+ fsetxattr = 190,
+ getxattr = 191,
+ lgetxattr = 192,
+ fgetxattr = 193,
+ listxattr = 194,
+ llistxattr = 195,
+ flistxattr = 196,
+ removexattr = 197,
+ lremovexattr = 198,
+ fremovexattr = 199,
+ tkill = 200,
+ time = 201,
+ futex = 202,
+ sched_setaffinity = 203,
+ sched_getaffinity = 204,
+ set_thread_area = 205,
+ io_setup = 206,
+ io_destroy = 207,
+ io_getevents = 208,
+ io_submit = 209,
+ io_cancel = 210,
+ get_thread_area = 211,
+ lookup_dcookie = 212,
+ epoll_create = 213,
+ epoll_ctl_old = 214,
+ epoll_wait_old = 215,
+ remap_file_pages = 216,
+ getdents64 = 217,
+ set_tid_address = 218,
+ restart_syscall = 219,
+ semtimedop = 220,
+ fadvise64 = 221,
+ timer_create = 222,
+ timer_settime = 223,
+ timer_gettime = 224,
+ timer_getoverrun = 225,
+ timer_delete = 226,
+ clock_settime = 227,
+ clock_gettime = 228,
+ clock_getres = 229,
+ clock_nanosleep = 230,
+ exit_group = 231,
+ epoll_wait = 232,
+ epoll_ctl = 233,
+ tgkill = 234,
+ utimes = 235,
+ vserver = 236,
+ mbind = 237,
+ set_mempolicy = 238,
+ get_mempolicy = 239,
+ mq_open = 240,
+ mq_unlink = 241,
+ mq_timedsend = 242,
+ mq_timedreceive = 243,
+ mq_notify = 244,
+ mq_getsetattr = 245,
+ kexec_load = 246,
+ waitid = 247,
+ add_key = 248,
+ request_key = 249,
+ keyctl = 250,
+ ioprio_set = 251,
+ ioprio_get = 252,
+ inotify_init = 253,
+ inotify_add_watch = 254,
+ inotify_rm_watch = 255,
+ migrate_pages = 256,
+ openat = 257,
+ mkdirat = 258,
+ mknodat = 259,
+ fchownat = 260,
+ futimesat = 261,
+ newfstatat = 262,
+ unlinkat = 263,
+ renameat = 264,
+ linkat = 265,
+ symlinkat = 266,
+ readlinkat = 267,
+ fchmodat = 268,
+ faccessat = 269,
+ pselect6 = 270,
+ ppoll = 271,
+ unshare = 272,
+ set_robust_list = 273,
+ get_robust_list = 274,
+ splice = 275,
+ tee = 276,
+ sync_file_range = 277,
+ vmsplice = 278,
+ move_pages = 279,
+ utimensat = 280,
+ epoll_pwait = 281,
+ signalfd = 282,
+ timerfd_create = 283,
+ eventfd = 284,
+ fallocate = 285,
+ timerfd_settime = 286,
+ timerfd_gettime = 287,
+ accept4 = 288,
+ signalfd4 = 289,
+ eventfd2 = 290,
+ epoll_create1 = 291,
+ dup3 = 292,
+ pipe2 = 293,
+ inotify_init1 = 294,
+ preadv = 295,
+ pwritev = 296,
+ rt_tgsigqueueinfo = 297,
+ perf_event_open = 298,
+ recvmmsg = 299,
+ fanotify_init = 300,
+ fanotify_mark = 301,
+ prlimit64 = 302,
+ name_to_handle_at = 303,
+ open_by_handle_at = 304,
+ clock_adjtime = 305,
+ syncfs = 306,
+ sendmmsg = 307,
+ setns = 308,
+ getcpu = 309,
+ process_vm_readv = 310,
+ process_vm_writev = 311,
+}
+
+-- TODO probably set these here not in main
+--[[ from Musl
+#undef SYS_fstatat
+#undef SYS_pread
+#undef SYS_pwrite
+#undef SYS_getdents
+# define SYS_fstatat SYS_newfstatat
+# define SYS_pread SYS_pread64
+# define SYS_pwrite SYS_pwrite64
+# define SYS_getdents SYS_getdents64
+# define SYS_fadvise SYS_fadvise64
+]]
+
+arch.SYS.fstatat = arch.SYS.newfstatat
+
+return arch
+
+
View
352 include/constants-x86.lua
@@ -0,0 +1,352 @@
+-- x86 specific code
+
+local arch = {}
+
+arch.SYS = {
+ restart_syscall = 0,
+ exit = 1,
+ fork = 2,
+ read = 3,
+ write = 4,
+ open = 5,
+ close = 6,
+ waitpid = 7,
+ creat = 8,
+ link = 9,
+ unlink = 10,
+ execve = 11,
+ chdir = 12,
+ time = 13,
+ mknod = 14,
+ chmod = 15,
+ lchown = 16,
+ --break = 17, -- set below
+ oldstat = 18,
+ lseek = 19,
+ getpid = 20,
+ mount = 21,
+ umount = 22,
+ setuid = 23,
+ getuid = 24,
+ stime = 25,
+ ptrace = 26,
+ alarm = 27,
+ oldfstat = 28,
+ pause = 29,
+ utime = 30,
+ stty = 31,
+ gtty = 32,
+ access = 33,
+ nice = 34,
+ ftime = 35,
+ sync = 36,
+ kill = 37,
+ rename = 38,
+ mkdir = 39,
+ rmdir = 40,
+ dup = 41,
+ pipe = 42,
+ times = 43,
+ prof = 44,
+ brk = 45,
+ setgid = 46,
+ getgid = 47,
+ signal = 48,
+ geteuid = 49,
+ getegid = 50,
+ acct = 51,
+ umount2 = 52,
+ lock = 53,
+ ioctl = 54,
+ fcntl = 55,
+ mpx = 56,
+ setpgid = 57,
+ ulimit = 58,
+ oldolduname = 59,
+ umask = 60,
+ chroot = 61,
+ ustat = 62,
+ dup2 = 63,
+ getppid = 64,
+ getpgrp = 65,
+ setsid = 66,
+ sigaction = 67,
+ sgetmask = 68,
+ ssetmask = 69,
+ setreuid = 70,
+ setregid = 71,
+ sigsuspend = 72,
+ sigpending = 73,
+ sethostname = 74,
+ setrlimit = 75,
+ getrlimit = 76,
+ getrusage = 77,
+ gettimeofday = 78,
+ settimeofday = 79,
+ getgroups = 80,
+ setgroups = 81,
+ select = 82,
+ symlink = 83,
+ oldlstat = 84,
+ readlink = 85,
+ uselib = 86,
+ swapon = 87,
+ reboot = 88,
+ readdir = 89,
+ mmap = 90,
+ munmap = 91,
+ truncate = 92,
+ ftruncate = 93,
+ fchmod = 94,
+ fchown = 95,
+ getpriority = 96,
+ setpriority = 97,
+ profil = 98,
+ statfs = 99,
+ fstatfs = 100,
+ ioperm = 101,
+ socketcall = 102,
+ syslog = 103,
+ setitimer = 104,
+ getitimer = 105,
+ stat = 106,
+ lstat = 107,
+ fstat = 108,
+ olduname = 109,
+ iopl = 110,
+ vhangup = 111,
+ idle = 112,
+ vm86old = 113,
+ wait4 = 114,
+ swapoff = 115,
+ sysinfo = 116,
+ ipc = 117,
+ fsync = 118,
+ sigreturn = 119,
+ clone = 120,
+ setdomainname = 121,
+ uname = 122,
+ modify_ldt = 123,
+ adjtimex = 124,
+ mprotect = 125,
+ sigprocmask = 126,
+ create_module = 127,
+ init_module = 128,
+ delete_module = 129,
+ get_kernel_syms = 130,
+ quotactl = 131,
+ getpgid = 132,
+ fchdir = 133,
+ bdflush = 134,
+ sysfs = 135,
+ personality = 136,
+ afs_syscall = 137,
+ setfsuid = 138,
+ setfsgid = 139,
+ _llseek = 140,
+ getdents = 141,
+ _newselect = 142,
+ flock = 143,
+ msync = 144,
+ readv = 145,
+ writev = 146,
+ getsid = 147,
+ fdatasync = 148,
+ _sysctl = 149,
+ mlock = 150,
+ munlock = 151,
+ mlockall = 152,
+ munlockall = 153,
+ sched_setparam = 154,
+ sched_getparam = 155,
+ sched_setscheduler = 156,
+ sched_getscheduler = 157,
+ sched_yield = 158,
+ sched_get_priority_max = 159,
+ sched_get_priority_min = 160,
+ sched_rr_get_interval = 161,
+ nanosleep = 162,
+ mremap = 163,
+ setresuid = 164,
+ getresuid = 165,
+ vm86 = 166,
+ query_module = 167,
+ poll = 168,
+ nfsservctl = 169,
+ setresgid = 170,
+ getresgid = 171,
+ prctl = 172,
+ rt_sigreturn = 173,
+ rt_sigaction = 174,
+ rt_sigprocmask = 175,
+ rt_sigpending = 176,
+ rt_sigtimedwait = 177,
+ rt_sigqueueinfo = 178,
+ rt_sigsuspend = 179,
+ pread64 = 180,
+ pwrite64 = 181,
+ chown = 182,
+ getcwd = 183,
+ capget = 184,
+ capset = 185,
+ sigaltstack = 186,
+ sendfile = 187,
+ getpmsg = 188,
+ putpmsg = 189,
+ vfork = 190,
+ ugetrlimit = 191,
+ mmap2 = 192,
+ truncate64 = 193,
+ ftruncate64 = 194,
+ stat64 = 195,
+ lstat64 = 196,
+ fstat64 = 197,
+ lchown32 = 198,
+ getuid32 = 199,
+ getgid32 = 200,
+ geteuid32 = 201,
+ getegid32 = 202,
+ setreuid32 = 203,
+ setregid32 = 204,
+ getgroups32 = 205,
+ setgroups32 = 206,
+ fchown32 = 207,
+ setresuid32 = 208,
+ getresuid32 = 209,
+ setresgid32 = 210,
+ getresgid32 = 211,
+ chown32 = 212,
+ setuid32 = 213,
+ setgid32 = 214,
+ setfsuid32 = 215,
+ setfsgid32 = 216,
+ pivot_root = 217,
+ mincore = 218,
+ madvise = 219,
+ madvise1 = 219,
+ getdents64 = 220,
+ fcntl64 = 221,
+ gettid = 224,
+ readahead = 225,
+ setxattr = 226,
+ lsetxattr = 227,
+ fsetxattr = 228,
+ getxattr = 229,
+ lgetxattr = 230,
+ fgetxattr = 231,
+ listxattr = 232,
+ llistxattr = 233,
+ flistxattr = 234,
+ removexattr = 235,
+ lremovexattr = 236,
+ fremovexattr = 237,
+ tkill = 238,
+ sendfile64 = 239,
+ futex = 240,
+ sched_setaffinity = 241,
+ sched_getaffinity = 242,
+ set_thread_area = 243,
+ get_thread_area = 244,
+ io_setup = 245,
+ io_destroy = 246,
+ io_getevents = 247,
+ io_submit = 248,
+ io_cancel = 249,
+ fadvise64 = 250,
+ exit_group = 252,
+ lookup_dcookie = 253,
+ epoll_create = 254,
+ epoll_ctl = 255,
+ epoll_wait = 256,
+ remap_file_pages = 257,
+ set_tid_address = 258,
+ timer_create = 259,
+ timer_settime = 260,
+ timer_gettime = 261,
+ timer_getoverrun = 262,
+ timer_delete = 263,
+ clock_settime = 264,
+ clock_gettime = 265,
+ clock_getres = 266,
+ clock_nanosleep = 267,
+ statfs64 = 268,
+ fstatfs64 = 269,
+ tgkill = 270,
+ utimes = 271,
+ fadvise64_64 = 272,
+ vserver = 273,
+ mbind = 274,
+ get_mempolicy = 275,
+ set_mempolicy = 276,
+ mq_open = 277,
+ mq_unlink = 278,
+ mq_timedsend = 279,
+ mq_timedreceive = 280,
+ mq_notify = 281,
+ mq_getsetattr = 282,
+ kexec_load = 283,
+ waitid = 284,
+ add_key = 286,
+ request_key = 287,
+ keyctl = 288,
+ ioprio_set = 289,
+ ioprio_get = 290,
+ inotify_init = 291,
+ inotify_add_watch = 292,
+ inotify_rm_watch = 293,
+ migrate_pages = 294,
+ openat = 295,
+ mkdirat = 296,
+ mknodat = 297,
+ fchownat = 298,
+ futimesat = 299,
+ fstatat64 = 300,
+ unlinkat = 301,
+ renameat = 302,
+ linkat = 303,
+ symlinkat = 304,
+ readlinkat = 305,
+ fchmodat = 306,
+ faccessat = 307,
+ pselect6 = 308,
+ ppoll = 309,
+ unshare = 310,
+ set_robust_list = 311,
+ get_robust_list = 312,
+ splice = 313,
+ sync_file_range = 314,
+ tee = 315,
+ vmsplice = 316,
+ move_pages = 317,
+ getcpu = 318,
+ epoll_pwait = 319,
+ utimensat = 320,
+ signalfd = 321,
+ timerfd_create = 322,
+ eventfd = 323,
+ fallocate = 324,
+ timerfd_settime = 325,
+ timerfd_gettime = 326,
+ signalfd4 = 327,
+ eventfd2 = 328,
+ epoll_create1 = 329,
+ dup3 = 330,
+ pipe2 = 331,
+ inotify_init1 = 332,
+ preadv = 333,
+ pwritev = 334,
+ prlimit64 = 340,
+ name_to_handle_at = 341,
+ open_by_handle_at = 342,
+ clock_adjtime = 343,
+ syncfs = 344,
+ sendmmsg = 345,
+ setns = 346,
+ process_vm_readv = 347,
+ process_vm_writev = 348,
+}
+
+arch.SYS["break"] = 17 -- reserved word
+
+return arch
+
View
1,931 include/constants.lua
@@ -0,0 +1,1931 @@
+-- tables of constants
+
+-- so far almost all the single flag options have been converted to seperate tables with metamethods but still TODO
+-- are the multi flag ones
+
+local ffi = require "ffi"
+local bit = require "bit"
+
+local arch = require("include/constants-" .. ffi.arch) -- architecture specific code
+
+local function octal(s) return tonumber(s, 8) end
+
+local function split(delimiter, text)
+ if delimiter == "" then return {text} end
+ if #text == 0 then return {} end
+ local list = {}
+ local pos = 1
+ while true do
+ local first, last = text:find(delimiter, pos)
+ if first then
+ list[#list + 1] = text:sub(pos, first - 1)
+ pos = last + 1
+ else
+ list[#list + 1] = text:sub(pos)
+ break
+ end
+ end
+ return list
+end
+
+local function trim(s) -- TODO should replace underscore with space
+ return (s:gsub("^%s*(.-)%s*$", "%1"))
+end
+
+-- for single valued flags only
+local function strflag(t, str)
+ if not str then return 0 end
+ if type(str) ~= "string" then return str end
+ if #str == 0 then return 0 end
+ local val = rawget(t, str)
+ if val then return val end
+ local s = trim(str):upper()
+ if #s == 0 then return 0 end
+ local val = rawget(t, s)
+ if not val then return nil end
+ t[str] = val -- this memoizes for future use
+ return val
+end
+
+local stringflag = {__index = strflag, __call = function(t, a) return t[a] end}
+
+local S = {} -- TODO rename
+
+S.SYS = arch.SYS
+
+S.STD = setmetatable({
+ IN_FILENO = 0,
+ OUT_FILENO = 1,
+ ERR_FILENO = 2,
+ IN = 0,
+ OUT = 1,
+ ERR = 2,
+}, stringflag)
+
+-- sizes
+S.PATH_MAX = 4096
+
+-- open, fcntl
+S.O_ACCMODE = octal('0003')
+S.O_RDONLY = octal('00')
+S.O_WRONLY = octal('01')
+S.O_RDWR = octal('02')
+S.O_CREAT = octal('0100')
+S.O_EXCL = octal('0200')
+S.O_NOCTTY = octal('0400')
+S.O_TRUNC = octal('01000')
+S.O_APPEND = octal('02000')
+S.O_NONBLOCK = octal('04000')
+S.O_NDELAY = S.O_NONBLOCK
+S.O_SYNC = octal('04010000')
+S.O_FSYNC = S.O_SYNC
+S.O_ASYNC = octal('020000')
+S.O_CLOEXEC = octal('02000000')
+S.O_NOATIME = octal('01000000')
+S.O_DSYNC = octal('010000')
+S.O_RSYNC = S.O_SYNC
+
+-- incorporate into metatable for O so set as O>LARGEFILE or 0
+if ffi.abi("32bit") then S.O_LARGEFILE = octal('0100000') else S.O_LARGEFILE = 0 end
+
+-- these are arch dependent!
+if arch.oflags then arch.oflags(S)
+else -- generic values from asm-generic
+ S.O_DIRECTORY = octal('0200000')
+ S.O_NOFOLLOW = octal('0400000')
+ S.O_DIRECT = octal('040000')
+end
+
+-- modes
+S.S_IFMT = octal('0170000')
+S.S_IFSOCK = octal('0140000')
+S.S_IFLNK = octal('0120000')
+S.S_IFREG = octal('0100000')
+S.S_IFBLK = octal('0060000')
+S.S_IFDIR = octal('0040000')
+S.S_IFCHR = octal('0020000')
+S.S_IFIFO = octal('0010000')
+S.S_ISUID = octal('0004000')
+S.S_ISGID = octal('0002000')
+S.S_ISVTX = octal('0001000')
+
+S.S_IRWXU = octal('00700')
+S.S_IRUSR = octal('00400')
+S.S_IWUSR = octal('00200')
+S.S_IXUSR = octal('00100')
+S.S_IRWXG = octal('00070')
+S.S_IRGRP = octal('00040')
+S.S_IWGRP = octal('00020')
+S.S_IXGRP = octal('00010')
+S.S_IRWXO = octal('00007')
+S.S_IROTH = octal('00004')
+S.S_IWOTH = octal('00002')
+S.S_IXOTH = octal('00001')
+
+-- access
+S.R_OK = 4
+S.W_OK = 2
+S.X_OK = 1
+S.F_OK = 0
+
+-- fcntl
+S.F = setmetatable({
+ DUPFD = 0,
+ GETFD = 1,
+ SETFD = 2,
+ GETFL = 3,
+ SETFL = 4,
+ GETLK = 5,
+ SETLK = 6,
+ SETLKW = 7,
+ SETOWN = 8,
+ GETOWN = 9,
+ SETSIG = 10,
+ GETSIG = 11,
+ GETLK64 = 12,
+ SETLK64 = 13,
+ SETLKW64 = 14,
+ SETOWN_EX = 15,
+ GETOWN_EX = 16,
+ SETLEASE = 1024,
+ GETLEASE = 1025,
+ NOTIFY = 1026,
+ SETPIPE_SZ = 1031,
+ GETPIPE_SZ = 1032,
+ DUPFD_CLOEXEC = 1030,
+}, stringflag)
+
+-- messy
+if ffi.abi("64bit") then
+ S.F.GETLK64 = S.F.GETLK
+ S.F.SETLK64 = S.F.SETLK
+ S.F.SETLKW64 = S.F.SETLKW
+else
+ S.F.GETLK = S.F.GETLK64
+ S.F.SETLK = S.F.SETLK64
+ S.F.SETLKW = S.F.SETLKW64
+end
+
+S.FD_CLOEXEC = 1
+
+-- note changed from F_ to FCNTL_LOCK
+S.FCNTL_LOCK = setmetatable({
+ RDLCK = 0,
+ WRLCK = 1,
+ UNLCK = 2,
+}, stringflag)
+
+-- lockf, changed from F_ to LOCKF_
+S.LOCKF = setmetatable({
+ ULOCK = 0,
+ LOCK = 1,
+ TLOCK = 2,
+ TEST = 3,
+}, stringflag)
+
+--mmap
+S.PROT_READ = 0x1
+S.PROT_WRITE = 0x2
+S.PROT_EXEC = 0x4
+S.PROT_NONE = 0x0
+S.PROT_GROWSDOWN = 0x01000000
+S.PROT_GROWSUP = 0x02000000
+
+-- Sharing types
+S.MAP_SHARED = 0x01
+S.MAP_PRIVATE = 0x02
+S.MAP_TYPE = 0x0f
+S.MAP_FIXED = 0x10
+S.MAP_FILE = 0
+S.MAP_ANONYMOUS = 0x20
+S.MAP_ANON = S.MAP_ANONYMOUS
+S.MAP_32BIT = 0x40
+S.MAP_GROWSDOWN = 0x00100
+S.MAP_DENYWRITE = 0x00800
+S.MAP_EXECUTABLE = 0x01000
+S.MAP_LOCKED = 0x02000
+S.MAP_NORESERVE = 0x04000
+S.MAP_POPULATE = 0x08000
+S.MAP_NONBLOCK = 0x10000
+S.MAP_STACK = 0x20000
+S.MAP_HUGETLB = 0x40000
+
+-- flags for `mlockall'.
+S.MCL_CURRENT = 1
+S.MCL_FUTURE = 2
+
+-- flags for `mremap'.
+S.MREMAP_MAYMOVE = 1
+S.MREMAP_FIXED = 2
+
+-- madvise advice parameter
+S.MADV = setmetatable({
+ NORMAL = 0,
+ RANDOM = 1,
+ SEQUENTIAL = 2,
+ WILLNEED = 3,
+ DONTNEED = 4,
+ REMOVE = 9,
+ DONTFORK = 10,
+ DOFORK = 11,
+ MERGEABLE = 12,
+ UNMERGEABLE = 13,
+ HUGEPAGE = 14,
+ NOHUGEPAGE = 15,
+ HWPOISON = 100,
+}, stringflag)
+
+-- posix fadvise
+S.POSIX_FADV = setmetatable({
+ NORMAL = 0,
+ RANDOM = 1,
+ SEQUENTIAL = 2,
+ WILLNEED = 3,
+ DONTNEED = 4,
+ NOREUSE = 5,
+}, stringflag)
+
+-- fallocate
+S.FALLOC_FL = setmetatable({
+ KEEP_SIZE = 0x01,
+ PUNCH_HOLE = 0x02,
+}, stringflag)
+
+-- getpriority, setpriority flags
+S.PRIO = setmetatable({
+ PROCESS = 0,
+ PGRP = 1,
+ USER = 2,
+}, stringflag)
+
+-- lseek
+S.SEEK = setmetatable({
+ SET = 0,
+ CUR = 1,
+ END = 2,
+}, stringflag)
+
+-- exit
+S.EXIT = setmetatable({
+ SUCCESS = 0,
+ FAILURE = 1,
+}, stringflag)
+
+-- sigaction, note renamed SIGACT from SIG
+S.SIGACT = setmetatable({
+ ERR = -1,
+ DFL = 0,
+ IGN = 1,
+ HOLD = 2,
+}, stringflag)
+
+S.SIG = setmetatable({
+ HUP = 1,
+ INT = 2,
+ QUIT = 3,
+ ILL = 4,
+ TRAP = 5,
+ ABRT = 6,
+ BUS = 7,
+ FPE = 8,
+ KILL = 9,
+ USR1 = 10,
+ SEGV = 11,
+ USR2 = 12,
+ PIPE = 13,
+ ALRM = 14,
+ TERM = 15,
+ STKFLT = 16,
+ CHLD = 17,
+ CONT = 18,
+ STOP = 19,
+ TSTP = 20,
+ TTIN = 21,
+ TTOU = 22,
+ URG = 23,
+ XCPU = 24,
+ XFSZ = 25,
+ VTALRM = 26,
+ PROF = 27,
+ WINCH = 28,
+ IO = 29,
+ PWR = 30,
+ SYS = 31,
+}, stringflag)
+
+local signals = {}
+for k, v in pairs(S.SIG) do signals[v] = k end
+
+S.SIG.IOT = 6
+S.SIG.UNUSED = 31
+S.SIG.CLD = S.SIG.CHLD
+S.SIG.POLL = S.SIG.IO
+
+S.NSIG = 65
+
+-- sigprocmask note renaming of SIG to SIGPM
+S.SIGPM = setmetatable({
+ BLOCK = 0,
+ UNBLOCK = 1,
+ SETMASK = 2,
+}, stringflag)
+
+-- signalfd
+S.SFD_CLOEXEC = octal('02000000')
+S.SFD_NONBLOCK = octal('04000')
+
+-- sockets note mix of single and multiple flags
+S.SOCK_STREAM = 1
+S.SOCK_DGRAM = 2
+S.SOCK_RAW = 3
+S.SOCK_RDM = 4
+S.SOCK_SEQPACKET = 5
+S.SOCK_DCCP = 6
+S.SOCK_PACKET = 10
+
+S.SOCK_CLOEXEC = octal('02000000')
+S.SOCK_NONBLOCK = octal('04000')
+
+-- misc socket constants
+S.SCM = setmetatable({
+ RIGHTS = 0x01,
+ CREDENTIALS = 0x02,
+}, stringflag)
+
+-- setsockopt
+S.SOL = setmetatable({
+ SOCKET = 1,
+ RAW = 255,
+ DECNET = 261,
+ X25 = 262,
+ PACKET = 263,
+ ATM = 264,
+ AAL = 265,
+ IRDA = 266,
+}, stringflag)
+
+S.SO = setmetatable({
+ DEBUG = 1,
+ REUSEADDR = 2,
+ TYPE = 3,
+ ERROR = 4,
+ DONTROUTE = 5,
+ BROADCAST = 6,
+ SNDBUF = 7,
+ RCVBUF = 8,
+ KEEPALIVE = 9,
+ OOBINLINE = 10,
+ NO_CHECK = 11,
+ PRIORITY = 12,
+ LINGER = 13,
+ BSDCOMPAT = 14,
+ SNDBUFFORCE = 32,
+ RCVBUFFORCE = 33,
+}, stringflag)
+if arch.socketoptions then arch.socketoptions(S)
+else
+ S.SO.PASSCRED = 16
+ S.SO.PEERCRED = 17
+ S.SO.RCVLOWAT = 18
+ S.SO.SNDLOWAT = 19
+ S.SO.RCVTIMEO = 20
+ S.SO.SNDTIMEO = 21
+end
+
+-- Maximum queue length specifiable by listen.
+S.SOMAXCONN = 128
+
+-- shutdown
+S.SHUT = setmetatable({
+ RD = 0,
+ WR = 1,
+ RDWR = 2,
+}, stringflag)
+
+-- waitpid 3rd arg
+S.WNOHANG = 1
+S.WUNTRACED = 2
+
+-- waitid
+S.P = setmetatable({
+ ALL = 0,
+ PID = 1,
+ PGID = 2,
+}, stringflag)
+
+S.WSTOPPED = 2
+S.WEXITED = 4
+S.WCONTINUED = 8
+S.WNOWAIT = 0x01000000
+
+S.__WNOTHREAD = 0x20000000
+S.__WALL = 0x40000000
+S.__WCLONE = 0x80000000
+S.NOTHREAD, S.WALL, S.WCLONE = S.__WNOTHREAD, S.__WALL, S.__WCLONE
+
+-- struct siginfo, eg waitid
+S.SI = setmetatable({
+ ASYNCNL = -60,
+ TKILL = -6,
+ SIGIO = -5,
+ ASYNCIO = -4,
+ MESGQ = -3,
+ TIMER = -2,
+ QUEUE = -1,
+ USER = 0,
+ KERNEL = 0x80,
+}, stringflag)
+
+S.ILL = setmetatable({
+ ILLOPC = 1,
+ ILLOPN = 2,
+ ILLADR = 3,
+ ILLTRP = 4,
+ PRVOPC = 5,
+ PRVREG = 6,
+ COPROC = 7,
+ BADSTK = 8,
+}, stringflag)
+
+S.FPE = setmetatable({
+ INTDIV = 1,
+ INTOVF = 2,
+ FLTDIV = 3,
+ FLTOVF = 4,
+ FLTUND = 5,
+ FLTRES = 6,
+ FLTINV = 7,
+ FLTSUB = 8,
+}, stringflag)
+
+S.SEGV = setmetatable({
+ MAPERR = 1,
+ ACCERR = 2,
+}, stringflag)
+
+S.BUS = setmetatable({
+ ADRALN = 1,
+ ADRERR = 2,
+ OBJERR = 3,
+}, stringflag)
+
+S.TRAP = setmetatable({
+ BRKPT = 1,
+ TRACE = 2,
+}, stringflag)
+
+S.CLD = setmetatable({
+ EXITED = 1,
+ KILLED = 2,
+ DUMPED = 3,
+ TRAPPED = 4,
+ STOPPED = 5,
+ CONTINUED = 6,
+}, stringflag)
+
+S.POLL = setmetatable({
+ IN = 1,
+ OUT = 2,
+ MSG = 3,
+ ERR = 4,
+ PRI = 5,
+ HUP = 6,
+}, stringflag)
+
+-- sigaction
+S.SA_NOCLDSTOP = 0x00000001
+S.SA_NOCLDWAIT = 0x00000002
+S.SA_SIGINFO = 0x00000004
+S.SA_ONSTACK = 0x08000000
+S.SA_RESTART = 0x10000000
+S.SA_NODEFER = 0x40000000
+S.SA_RESETHAND = 0x80000000
+S.SA_NOMASK = S.SA_NODEFER
+S.SA_ONESHOT = S.SA_RESETHAND
+S.SA_RESTORER = 0x04000000
+
+-- timers
+S.ITIMER = setmetatable({
+ REAL = 0,
+ VIRTUAL = 1,
+ PROF = 2,
+}, stringflag)
+
+-- clocks
+S.CLOCK = setmetatable({
+ REALTIME = 0,
+ MONOTONIC = 1,
+ PROCESS_CPUTIME_ID = 2,
+ THREAD_CPUTIME_ID = 3,
+ MONOTONIC_RAW = 4,
+ REALTIME_COARSE = 5,
+ MONOTONIC_COARSE = 6,
+}, stringflag)
+
+S.TIMER = setmetatable({
+ ABSTIME = 1,
+}, stringflag)
+
+-- adjtimex
+S.ADJ_OFFSET = 0x0001
+S.ADJ_FREQUENCY = 0x0002
+S.ADJ_MAXERROR = 0x0004
+S.ADJ_ESTERROR = 0x0008
+S.ADJ_STATUS = 0x0010
+S.ADJ_TIMECONST = 0x0020
+S.ADJ_TAI = 0x0080
+S.ADJ_MICRO = 0x1000
+S.ADJ_NANO = 0x2000
+S.ADJ_TICK = 0x4000
+S.ADJ_OFFSET_SINGLESHOT = 0x8001
+S.ADJ_OFFSET_SS_READ = 0xa001
+
+S.STA_PLL = 0x0001
+S.STA_PPSFREQ = 0x0002
+S.STA_PPSTIME = 0x0004
+S.STA_FLL = 0x0008
+S.STA_INS = 0x0010
+S.STA_DEL = 0x0020
+S.STA_UNSYNC = 0x0040
+S.STA_FREQHOLD = 0x0080
+S.STA_PPSSIGNAL = 0x0100
+S.STA_PPSJITTER = 0x0200
+S.STA_PPSWANDER = 0x0400
+S.STA_PPSERROR = 0x0800
+S.STA_CLOCKERR = 0x1000
+S.STA_NANO = 0x2000
+S.STA_MODE = 0x4000
+S.STA_CLK = 0x8000
+
+-- return values for adjtimex
+S.TIME = setmetatable({
+ OK = 0,