Page MenuHomeFreeBSD

D21775.id62518.diff
No OneTemporary

D21775.id62518.diff

Index: Makefile.inc1
===================================================================
--- Makefile.inc1
+++ Makefile.inc1
@@ -1460,6 +1460,11 @@
. endif
.endfor
+.if make(sysent)
+.include <src.lua.mk>
+.endif
+
+_sysent_PATH= ${WORLDTMP}/legacy/usr/libexec:/usr/libexec:${PATH}
_sysent_dirs= sys/kern
_sysent_dirs+= sys/compat/freebsd32
_sysent_dirs+= sys/amd64/linux \
@@ -1468,7 +1473,9 @@
sys/i386/linux
sysent: .PHONY
.for _dir in ${_sysent_dirs}
- ${_+_}${MAKE} -C ${.CURDIR}/${_dir} sysent
+ @echo "${MAKE} -C ${.CURDIR}/${_dir} sysent"
+ ${_+_}@env PATH=${_sysent_PATH} LUA=${LUA_CMD} \
+ ${MAKE} -C ${.CURDIR}/${_dir} sysent
.endfor
#
@@ -2114,6 +2121,13 @@
${_bt}-lib/libdwarf: ${_bt_m4_depend}
.endif
+# flua is required to regenerate syscall files. It first appeared during the
+# 13.0-CURRENT cycle, thus needs to be built on -older releases and stable
+# branches.
+.if ${BOOTSTRAPPING} < 1300048
+_flua= libexec/flua
+.endif
+
# r245440 mtree -N support added
# r313404 requires sha384.h for libnetbsd, added to libmd in r292782
.if ${BOOTSTRAPPING} < 1100093
@@ -2334,6 +2348,7 @@
usr.bin/xinstall \
${_gensnmptree} \
usr.sbin/config \
+ ${_flua} \
${_crunchide} \
${_crunchgen} \
${_nmtree} \
Index: libexec/Makefile
===================================================================
--- libexec/Makefile
+++ libexec/Makefile
@@ -8,6 +8,7 @@
${_blacklistd-helper} \
${_comsat} \
${_dma} \
+ flua \
getty \
${_mail.local} \
${_makewhatis.local} \
Index: libexec/flua/Makefile
===================================================================
--- /dev/null
+++ libexec/flua/Makefile
@@ -0,0 +1,33 @@
+#! $FreeBSD$
+
+.include <src.lua.mk>
+
+LUASRC?= ${SRCTOP}/contrib/lua/src
+.PATH: ${LUASRC}
+
+PROG= flua
+WARNS?= 2
+MAN= # No manpage; this is internal.
+
+LIBADD= m
+
+# Core functions
+SRCS= lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c \
+ lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c \
+ ltm.c lundump.c lvm.c lzio.c
+
+# Library functions; any change to these likely needs an accompanying change
+# in our custom linit_flua.c. We use our custom linit.c to make it easier to
+# support bootstrap flua that may not have supporting local libraries.
+SRCS+= lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c \
+ lmathlib.c loslib.c lstrlib.c ltablib.c lutf8lib.c loadlib.c
+
+# Entry point
+SRCS+= lua.c
+
+# FreeBSD Extensions
+SRCS+= linit_flua.c lfs.c lposix.c
+
+CFLAGS+= -I${.CURDIR} -I${LUASRC} -DLUA_PROGNAME="\"${PROG}\""
+
+.include <bsd.prog.mk>
Index: libexec/flua/lfs.c
===================================================================
--- libexec/flua/lfs.c
+++ libexec/flua/lfs.c
@@ -52,12 +52,25 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#ifndef _STANDALONE
+#include <sys/stat.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#endif
+
#include <lua.h>
#include "lauxlib.h"
#include "lfs.h"
+
+#ifdef _STANDALONE
#include "lstd.h"
#include "lutils.h"
#include "bootstrap.h"
+#endif
#ifndef nitems
#define nitems(x) (sizeof((x)) / sizeof((x)[0]))
@@ -120,7 +133,11 @@
dp = *dpp;
luaL_argcheck(L, dp != NULL, 1, "closed directory");
+#ifdef _STANDALONE
entry = readdirfd(dp->fd);
+#else
+ entry = readdir(dp);
+#endif
if (entry == NULL) {
closedir(dp);
*dpp = NULL;
@@ -325,10 +342,76 @@
return 1;
}
+#ifndef _STANDALONE
+#define lfs_mkdir_impl(path) (mkdir((path), \
+ S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | \
+ S_IXOTH))
+
+static int
+lua_mkdir(lua_State *L)
+{
+ const char *path;
+ int error, serrno;
+
+ path = luaL_checkstring(L, 1);
+ if (path == NULL) {
+ lua_pushnil(L);
+ lua_pushfstring(L, "cannot convert first argument to string");
+ lua_pushinteger(L, EINVAL);
+ return 3;
+ }
+
+ error = lfs_mkdir_impl(path);
+ if (error == -1) {
+ /* Save it; unclear what other libc functions may be invoked */
+ serrno = errno;
+ lua_pushnil(L);
+ lua_pushfstring(L, strerror(serrno));
+ lua_pushinteger(L, serrno);
+ return 3;
+ }
+
+ lua_pushboolean(L, 1);
+ return 1;
+}
+
+static int
+lua_rmdir(lua_State *L)
+{
+ const char *path;
+ int error, serrno;
+
+ path = luaL_checkstring(L, 1);
+ if (path == NULL) {
+ lua_pushnil(L);
+ lua_pushfstring(L, "cannot convert first argument to string");
+ lua_pushinteger(L, EINVAL);
+ return 3;
+ }
+
+ error = rmdir(path);
+ if (error == -1) {
+ /* Save it; unclear what other libc functions may be invoked */
+ serrno = errno;
+ lua_pushnil(L);
+ lua_pushfstring(L, strerror(serrno));
+ lua_pushinteger(L, serrno);
+ return 3;
+ }
+
+ lua_pushboolean(L, 1);
+ return 1;
+}
+#endif
+
#define REG_SIMPLE(n) { #n, lua_ ## n }
static const struct luaL_Reg fslib[] = {
REG_SIMPLE(attributes),
REG_SIMPLE(dir),
+#ifndef _STANDALONE
+ REG_SIMPLE(mkdir),
+ REG_SIMPLE(rmdir),
+#endif
{ NULL, NULL },
};
#undef REG_SIMPLE
Index: libexec/flua/linit_flua.c
===================================================================
--- /dev/null
+++ libexec/flua/linit_flua.c
@@ -0,0 +1,72 @@
+/*
+** $Id: linit.c,v 1.39.1.1 2017/04/19 17:20:42 roberto Exp $
+** Initialization of libraries for lua.c and other clients
+** See Copyright Notice in lua.h
+*/
+
+
+#define linit_c
+#define LUA_LIB
+
+/*
+** If you embed Lua in your program and need to open the standard
+** libraries, call luaL_openlibs in your program. If you need a
+** different set of libraries, copy this file to your project and edit
+** it to suit your needs.
+**
+** You can also *preload* libraries, so that a later 'require' can
+** open the library, which is already linked to the application.
+** For that, do the following code:
+**
+** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
+** lua_pushcfunction(L, luaopen_modname);
+** lua_setfield(L, -2, modname);
+** lua_pop(L, 1); // remove PRELOAD table
+*/
+
+#include "lprefix.h"
+
+
+#include <stddef.h>
+
+#include "lua.h"
+
+#include "lualib.h"
+#include "lauxlib.h"
+#include "lfs.h"
+#include "lposix.h"
+
+/*
+** these libs are loaded by lua.c and are readily available to any Lua
+** program
+*/
+static const luaL_Reg loadedlibs[] = {
+ {"_G", luaopen_base},
+ {LUA_LOADLIBNAME, luaopen_package},
+ {LUA_COLIBNAME, luaopen_coroutine},
+ {LUA_TABLIBNAME, luaopen_table},
+ {LUA_IOLIBNAME, luaopen_io},
+ {LUA_OSLIBNAME, luaopen_os},
+ {LUA_STRLIBNAME, luaopen_string},
+ {LUA_MATHLIBNAME, luaopen_math},
+ {LUA_UTF8LIBNAME, luaopen_utf8},
+ {LUA_DBLIBNAME, luaopen_debug},
+#if defined(LUA_COMPAT_BITLIB)
+ {LUA_BITLIBNAME, luaopen_bit32},
+#endif
+ /* FreeBSD Extensions */
+ {"lfs", luaopen_lfs},
+ {"posix.unistd", luaopen_posix_unistd},
+ {NULL, NULL}
+};
+
+
+LUALIB_API void luaL_openlibs (lua_State *L) {
+ const luaL_Reg *lib;
+ /* "require" functions from 'loadedlibs' and set results to global table */
+ for (lib = loadedlibs; lib->func; lib++) {
+ luaL_requiref(L, lib->name, lib->func, 1);
+ lua_pop(L, 1); /* remove lib */
+ }
+}
+
Index: libexec/flua/lposix.h
===================================================================
--- /dev/null
+++ libexec/flua/lposix.h
@@ -0,0 +1,11 @@
+/*-
+ *
+ * This file is in the public domain.
+ */
+/* $FreeBSD$ */
+
+#pragma once
+
+#include <lua.h>
+
+int luaopen_posix_unistd(lua_State *L);
Index: libexec/flua/lposix.c
===================================================================
--- /dev/null
+++ libexec/flua/lposix.c
@@ -0,0 +1,64 @@
+/*-
+ * Copyright (c) 2019 Kyle Evans <kevans@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <unistd.h>
+
+#include <lua.h>
+#include "lauxlib.h"
+#include "lposix.h"
+
+/*
+ * Minimal implementation of luaposix needed for internal FreeBSD bits.
+ */
+
+static int
+lua_getpid(lua_State *L)
+{
+ int n;
+
+ n = lua_gettop(L);
+ luaL_argcheck(L, n == 0, 1, "too many arguments");
+ lua_pushinteger(L, getpid());
+ return 1;
+}
+
+#define REG_SIMPLE(n) { #n, lua_ ## n }
+static const struct luaL_Reg unistdlib[] = {
+ REG_SIMPLE(getpid),
+ { NULL, NULL },
+};
+#undef REG_SIMPLE
+
+int
+luaopen_posix_unistd(lua_State *L)
+{
+ luaL_newlib(L, unistdlib);
+ return 1;
+}
Index: libexec/flua/luaconf.h
===================================================================
--- /dev/null
+++ libexec/flua/luaconf.h
@@ -0,0 +1,790 @@
+/*
+** $Id: luaconf.h,v 1.259.1.1 2017/04/19 17:29:57 roberto Exp $
+** Configuration file for Lua
+** See Copyright Notice in lua.h
+*/
+
+
+#ifndef luaconf_h
+#define luaconf_h
+
+#include <limits.h>
+#include <stddef.h>
+
+
+/*
+** ===================================================================
+** Search for "@@" to find all configurable definitions.
+** ===================================================================
+*/
+
+
+/*
+** {====================================================================
+** System Configuration: macros to adapt (if needed) Lua to some
+** particular platform, for instance compiling it with 32-bit numbers or
+** restricting it to C89.
+** =====================================================================
+*/
+
+/*
+@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats. You
+** can also define LUA_32BITS in the make file, but changing here you
+** ensure that all software connected to Lua will be compiled with the
+** same configuration.
+*/
+/* #define LUA_32BITS */
+
+
+/*
+@@ LUA_USE_C89 controls the use of non-ISO-C89 features.
+** Define it if you want Lua to avoid the use of a few C99 features
+** or Windows-specific features on Windows.
+*/
+/* #define LUA_USE_C89 */
+
+
+/*
+** By default, Lua on Windows use (some) specific Windows features
+*/
+#if !defined(LUA_USE_C89) && defined(_WIN32) && !defined(_WIN32_WCE)
+#define LUA_USE_WINDOWS /* enable goodies for regular Windows */
+#endif
+
+
+#if defined(LUA_USE_WINDOWS)
+#define LUA_DL_DLL /* enable support for DLL */
+#define LUA_USE_C89 /* broadly, Windows is C89 */
+#endif
+
+
+#if defined(LUA_USE_LINUX)
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN /* needs an extra library: -ldl */
+#define LUA_USE_READLINE /* needs some extra libraries */
+#endif
+
+
+#if defined(LUA_USE_MACOSX)
+#define LUA_USE_POSIX
+#define LUA_USE_DLOPEN /* MacOS does not need -ldl */
+#define LUA_USE_READLINE /* needs an extra library: -lreadline */
+#endif
+
+
+/*
+@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
+** C89 ('long' and 'double'); Windows always has '__int64', so it does
+** not need to use this case.
+*/
+#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
+#define LUA_C89_NUMBERS
+#endif
+
+
+
+/*
+@@ LUAI_BITSINT defines the (minimum) number of bits in an 'int'.
+*/
+/* avoid undefined shifts */
+#if ((INT_MAX >> 15) >> 15) >= 1
+#define LUAI_BITSINT 32
+#else
+/* 'int' always must have at least 16 bits */
+#define LUAI_BITSINT 16
+#endif
+
+
+/*
+@@ LUA_INT_TYPE defines the type for Lua integers.
+@@ LUA_FLOAT_TYPE defines the type for Lua floats.
+** Lua should work fine with any mix of these options (if supported
+** by your C compiler). The usual configurations are 64-bit integers
+** and 'double' (the default), 32-bit integers and 'float' (for
+** restricted platforms), and 'long'/'double' (for C compilers not
+** compliant with C99, which may not have support for 'long long').
+*/
+
+/* predefined options for LUA_INT_TYPE */
+#define LUA_INT_INT 1
+#define LUA_INT_LONG 2
+#define LUA_INT_LONGLONG 3
+
+/* predefined options for LUA_FLOAT_TYPE */
+#define LUA_FLOAT_FLOAT 1
+#define LUA_FLOAT_DOUBLE 2
+#define LUA_FLOAT_LONGDOUBLE 3
+
+#if defined(LUA_32BITS) /* { */
+/*
+** 32-bit integers and 'float'
+*/
+#if LUAI_BITSINT >= 32 /* use 'int' if big enough */
+#define LUA_INT_TYPE LUA_INT_INT
+#else /* otherwise use 'long' */
+#define LUA_INT_TYPE LUA_INT_LONG
+#endif
+#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
+
+#elif defined(LUA_C89_NUMBERS) /* }{ */
+/*
+** largest types available for C89 ('long' and 'double')
+*/
+#define LUA_INT_TYPE LUA_INT_LONG
+#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
+
+#endif /* } */
+
+
+/*
+** default configuration for 64-bit Lua ('long long' and 'double')
+*/
+#if !defined(LUA_INT_TYPE)
+#define LUA_INT_TYPE LUA_INT_LONGLONG
+#endif
+
+#if !defined(LUA_FLOAT_TYPE)
+#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
+#endif
+
+/* }================================================================== */
+
+
+
+
+/*
+** {==================================================================
+** Configuration for Paths.
+** ===================================================================
+*/
+
+/*
+** LUA_PATH_SEP is the character that separates templates in a path.
+** LUA_PATH_MARK is the string that marks the substitution points in a
+** template.
+** LUA_EXEC_DIR in a Windows path is replaced by the executable's
+** directory.
+*/
+#define LUA_PATH_SEP ";"
+#define LUA_PATH_MARK "?"
+#define LUA_EXEC_DIR "!"
+
+
+/*
+@@ LUA_PATH_DEFAULT is the default path that Lua uses to look for
+** Lua libraries.
+@@ LUA_CPATH_DEFAULT is the default path that Lua uses to look for
+** C libraries.
+** CHANGE them if your machine has a non-conventional directory
+** hierarchy or if you want to install your libraries in
+** non-conventional directories.
+*/
+#define LUA_VDIR LUA_VERSION_MAJOR "." LUA_VERSION_MINOR
+#if defined(_WIN32) /* { */
+/*
+** In Windows, any exclamation mark ('!') in the path is replaced by the
+** path of the directory of the executable file of the current process.
+*/
+#define LUA_LDIR "!\\lua\\"
+#define LUA_CDIR "!\\"
+#define LUA_SHRDIR "!\\..\\share\\lua\\" LUA_VDIR "\\"
+#define LUA_PATH_DEFAULT \
+ LUA_LDIR"?.lua;" LUA_LDIR"?\\init.lua;" \
+ LUA_CDIR"?.lua;" LUA_CDIR"?\\init.lua;" \
+ LUA_SHRDIR"?.lua;" LUA_SHRDIR"?\\init.lua;" \
+ ".\\?.lua;" ".\\?\\init.lua"
+#define LUA_CPATH_DEFAULT \
+ LUA_CDIR"?.dll;" \
+ LUA_CDIR"..\\lib\\lua\\" LUA_VDIR "\\?.dll;" \
+ LUA_CDIR"loadall.dll;" ".\\?.dll"
+
+#else /* }{ */
+
+#define LUA_ROOT "/usr/local/"
+#define LUA_LDIR LUA_ROOT "share/lua/" LUA_VDIR "/"
+#define LUA_CDIR LUA_ROOT "lib/lua/" LUA_VDIR "/"
+#define LUA_PATH_DEFAULT \
+ LUA_LDIR"?.lua;" LUA_LDIR"?/init.lua;" \
+ LUA_CDIR"?.lua;" LUA_CDIR"?/init.lua;" \
+ "./?.lua;" "./?/init.lua"
+#define LUA_CPATH_DEFAULT \
+ LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
+#endif /* } */
+
+
+/*
+@@ LUA_DIRSEP is the directory separator (for submodules).
+** CHANGE it if your machine does not use "/" as the directory separator
+** and is not Windows. (On Windows Lua automatically uses "\".)
+*/
+#if defined(_WIN32)
+#define LUA_DIRSEP "\\"
+#else
+#define LUA_DIRSEP "/"
+#endif
+
+/* }================================================================== */
+
+
+/*
+** {==================================================================
+** Marks for exported symbols in the C code
+** ===================================================================
+*/
+
+/*
+@@ LUA_API is a mark for all core API functions.
+@@ LUALIB_API is a mark for all auxiliary library functions.
+@@ LUAMOD_API is a mark for all standard library opening functions.
+** CHANGE them if you need to define those functions in some special way.
+** For instance, if you want to create one Windows DLL with the core and
+** the libraries, you may want to use the following definition (define
+** LUA_BUILD_AS_DLL to get it).
+*/
+#if defined(LUA_BUILD_AS_DLL) /* { */
+
+#if defined(LUA_CORE) || defined(LUA_LIB) /* { */
+#define LUA_API __declspec(dllexport)
+#else /* }{ */
+#define LUA_API __declspec(dllimport)
+#endif /* } */
+
+#else /* }{ */
+
+#define LUA_API extern
+
+#endif /* } */
+
+
+/* more often than not the libs go together with the core */
+#define LUALIB_API LUA_API
+#define LUAMOD_API LUALIB_API
+
+
+/*
+@@ LUAI_FUNC is a mark for all extern functions that are not to be
+** exported to outside modules.
+@@ LUAI_DDEF and LUAI_DDEC are marks for all extern (const) variables
+** that are not to be exported to outside modules (LUAI_DDEF for
+** definitions and LUAI_DDEC for declarations).
+** CHANGE them if you need to mark them in some special way. Elf/gcc
+** (versions 3.2 and later) mark them as "hidden" to optimize access
+** when Lua is compiled as a shared library. Not all elf targets support
+** this attribute. Unfortunately, gcc does not offer a way to check
+** whether the target offers that support, and those without support
+** give a warning about it. To avoid these warnings, change to the
+** default definition.
+*/
+#if defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \
+ defined(__ELF__) /* { */
+#define LUAI_FUNC __attribute__((visibility("hidden"))) extern
+#else /* }{ */
+#define LUAI_FUNC extern
+#endif /* } */
+
+#define LUAI_DDEC LUAI_FUNC
+#define LUAI_DDEF /* empty */
+
+/* }================================================================== */
+
+
+/*
+** {==================================================================
+** Compatibility with previous versions
+** ===================================================================
+*/
+
+/*
+@@ LUA_COMPAT_5_2 controls other macros for compatibility with Lua 5.2.
+@@ LUA_COMPAT_5_1 controls other macros for compatibility with Lua 5.1.
+** You can define it to get all options, or change specific options
+** to fit your specific needs.
+*/
+#if defined(LUA_COMPAT_5_2) /* { */
+
+/*
+@@ LUA_COMPAT_MATHLIB controls the presence of several deprecated
+** functions in the mathematical library.
+*/
+#define LUA_COMPAT_MATHLIB
+
+/*
+@@ LUA_COMPAT_BITLIB controls the presence of library 'bit32'.
+*/
+#define LUA_COMPAT_BITLIB
+
+/*
+@@ LUA_COMPAT_IPAIRS controls the effectiveness of the __ipairs metamethod.
+*/
+#define LUA_COMPAT_IPAIRS
+
+/*
+@@ LUA_COMPAT_APIINTCASTS controls the presence of macros for
+** manipulating other integer types (lua_pushunsigned, lua_tounsigned,
+** luaL_checkint, luaL_checklong, etc.)
+*/
+#define LUA_COMPAT_APIINTCASTS
+
+#endif /* } */
+
+
+#if defined(LUA_COMPAT_5_1) /* { */
+
+/* Incompatibilities from 5.2 -> 5.3 */
+#define LUA_COMPAT_MATHLIB
+#define LUA_COMPAT_APIINTCASTS
+
+/*
+@@ LUA_COMPAT_UNPACK controls the presence of global 'unpack'.
+** You can replace it with 'table.unpack'.
+*/
+#define LUA_COMPAT_UNPACK
+
+/*
+@@ LUA_COMPAT_LOADERS controls the presence of table 'package.loaders'.
+** You can replace it with 'package.searchers'.
+*/
+#define LUA_COMPAT_LOADERS
+
+/*
+@@ macro 'lua_cpcall' emulates deprecated function lua_cpcall.
+** You can call your C function directly (with light C functions).
+*/
+#define lua_cpcall(L,f,u) \
+ (lua_pushcfunction(L, (f)), \
+ lua_pushlightuserdata(L,(u)), \
+ lua_pcall(L,1,0,0))
+
+
+/*
+@@ LUA_COMPAT_LOG10 defines the function 'log10' in the math library.
+** You can rewrite 'log10(x)' as 'log(x, 10)'.
+*/
+#define LUA_COMPAT_LOG10
+
+/*
+@@ LUA_COMPAT_LOADSTRING defines the function 'loadstring' in the base
+** library. You can rewrite 'loadstring(s)' as 'load(s)'.
+*/
+#define LUA_COMPAT_LOADSTRING
+
+/*
+@@ LUA_COMPAT_MAXN defines the function 'maxn' in the table library.
+*/
+#define LUA_COMPAT_MAXN
+
+/*
+@@ The following macros supply trivial compatibility for some
+** changes in the API. The macros themselves document how to
+** change your code to avoid using them.
+*/
+#define lua_strlen(L,i) lua_rawlen(L, (i))
+
+#define lua_objlen(L,i) lua_rawlen(L, (i))
+
+#define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ)
+#define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT)
+
+/*
+@@ LUA_COMPAT_MODULE controls compatibility with previous
+** module functions 'module' (Lua) and 'luaL_register' (C).
+*/
+#define LUA_COMPAT_MODULE
+
+#endif /* } */
+
+
+/*
+@@ LUA_COMPAT_FLOATSTRING makes Lua format integral floats without a
+@@ a float mark ('.0').
+** This macro is not on by default even in compatibility mode,
+** because this is not really an incompatibility.
+*/
+/* #define LUA_COMPAT_FLOATSTRING */
+
+/* }================================================================== */
+
+
+
+/*
+** {==================================================================
+** Configuration for Numbers.
+** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
+** satisfy your needs.
+** ===================================================================
+*/
+
+/*
+@@ LUA_NUMBER is the floating-point type used by Lua.
+@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
+@@ over a floating number.
+@@ l_mathlim(x) corrects limit name 'x' to the proper float type
+** by prefixing it with one of FLT/DBL/LDBL.
+@@ LUA_NUMBER_FRMLEN is the length modifier for writing floats.
+@@ LUA_NUMBER_FMT is the format for writing floats.
+@@ lua_number2str converts a float to a string.
+@@ l_mathop allows the addition of an 'l' or 'f' to all math operations.
+@@ l_floor takes the floor of a float.
+@@ lua_str2number converts a decimal numeric string to a number.
+*/
+
+
+/* The following definitions are good for most cases here */
+
+#define l_floor(x) (l_mathop(floor)(x))
+
+#define lua_number2str(s,sz,n) \
+ l_sprintf((s), sz, LUA_NUMBER_FMT, (LUAI_UACNUMBER)(n))
+
+/*
+@@ lua_numbertointeger converts a float number to an integer, or
+** returns 0 if float is not within the range of a lua_Integer.
+** (The range comparisons are tricky because of rounding. The tests
+** here assume a two-complement representation, where MININTEGER always
+** has an exact representation as a float; MAXINTEGER may not have one,
+** and therefore its conversion to float may have an ill-defined value.)
+*/
+#define lua_numbertointeger(n,p) \
+ ((n) >= (LUA_NUMBER)(LUA_MININTEGER) && \
+ (n) < -(LUA_NUMBER)(LUA_MININTEGER) && \
+ (*(p) = (LUA_INTEGER)(n), 1))
+
+
+/* now the variable definitions */
+
+#if LUA_FLOAT_TYPE == LUA_FLOAT_FLOAT /* { single float */
+
+#define LUA_NUMBER float
+
+#define l_mathlim(n) (FLT_##n)
+
+#define LUAI_UACNUMBER double
+
+#define LUA_NUMBER_FRMLEN ""
+#define LUA_NUMBER_FMT "%.7g"
+
+#define l_mathop(op) op##f
+
+#define lua_str2number(s,p) strtof((s), (p))
+
+
+#elif LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE /* }{ long double */
+
+#define LUA_NUMBER long double
+
+#define l_mathlim(n) (LDBL_##n)
+
+#define LUAI_UACNUMBER long double
+
+#define LUA_NUMBER_FRMLEN "L"
+#define LUA_NUMBER_FMT "%.19Lg"
+
+#define l_mathop(op) op##l
+
+#define lua_str2number(s,p) strtold((s), (p))
+
+#elif LUA_FLOAT_TYPE == LUA_FLOAT_DOUBLE /* }{ double */
+
+#define LUA_NUMBER double
+
+#define l_mathlim(n) (DBL_##n)
+
+#define LUAI_UACNUMBER double
+
+#define LUA_NUMBER_FRMLEN ""
+#define LUA_NUMBER_FMT "%.14g"
+
+#define l_mathop(op) op
+
+#define lua_str2number(s,p) strtod((s), (p))
+
+#else /* }{ */
+
+#error "numeric float type not defined"
+
+#endif /* } */
+
+
+
+/*
+@@ LUA_INTEGER is the integer type used by Lua.
+**
+@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
+**
+@@ LUAI_UACINT is the result of a 'default argument promotion'
+@@ over a lUA_INTEGER.
+@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.
+@@ LUA_INTEGER_FMT is the format for writing integers.
+@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
+@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
+@@ lua_integer2str converts an integer to a string.
+*/
+
+
+/* The following definitions are good for most cases here */
+
+#define LUA_INTEGER_FMT "%" LUA_INTEGER_FRMLEN "d"
+
+#define LUAI_UACINT LUA_INTEGER
+
+#define lua_integer2str(s,sz,n) \
+ l_sprintf((s), sz, LUA_INTEGER_FMT, (LUAI_UACINT)(n))
+
+/*
+** use LUAI_UACINT here to avoid problems with promotions (which
+** can turn a comparison between unsigneds into a signed comparison)
+*/
+#define LUA_UNSIGNED unsigned LUAI_UACINT
+
+
+/* now the variable definitions */
+
+#if LUA_INT_TYPE == LUA_INT_INT /* { int */
+
+#define LUA_INTEGER int
+#define LUA_INTEGER_FRMLEN ""
+
+#define LUA_MAXINTEGER INT_MAX
+#define LUA_MININTEGER INT_MIN
+
+#elif LUA_INT_TYPE == LUA_INT_LONG /* }{ long */
+
+#define LUA_INTEGER long
+#define LUA_INTEGER_FRMLEN "l"
+
+#define LUA_MAXINTEGER LONG_MAX
+#define LUA_MININTEGER LONG_MIN
+
+#elif LUA_INT_TYPE == LUA_INT_LONGLONG /* }{ long long */
+
+/* use presence of macro LLONG_MAX as proxy for C99 compliance */
+#if defined(LLONG_MAX) /* { */
+/* use ISO C99 stuff */
+
+#define LUA_INTEGER long long
+#define LUA_INTEGER_FRMLEN "ll"
+
+#define LUA_MAXINTEGER LLONG_MAX
+#define LUA_MININTEGER LLONG_MIN
+
+#elif defined(LUA_USE_WINDOWS) /* }{ */
+/* in Windows, can use specific Windows types */
+
+#define LUA_INTEGER __int64
+#define LUA_INTEGER_FRMLEN "I64"
+
+#define LUA_MAXINTEGER _I64_MAX
+#define LUA_MININTEGER _I64_MIN
+
+#else /* }{ */
+
+#error "Compiler does not support 'long long'. Use option '-DLUA_32BITS' \
+ or '-DLUA_C89_NUMBERS' (see file 'luaconf.h' for details)"
+
+#endif /* } */
+
+#else /* }{ */
+
+#error "numeric integer type not defined"
+
+#endif /* } */
+
+/* }================================================================== */
+
+
+/*
+** {==================================================================
+** Dependencies with C99 and other C details
+** ===================================================================
+*/
+
+/*
+@@ l_sprintf is equivalent to 'snprintf' or 'sprintf' in C89.
+** (All uses in Lua have only one format item.)
+*/
+#if !defined(LUA_USE_C89)
+#define l_sprintf(s,sz,f,i) snprintf(s,sz,f,i)
+#else
+#define l_sprintf(s,sz,f,i) ((void)(sz), sprintf(s,f,i))
+#endif
+
+
+/*
+@@ lua_strx2number converts an hexadecimal numeric string to a number.
+** In C99, 'strtod' does that conversion. Otherwise, you can
+** leave 'lua_strx2number' undefined and Lua will provide its own
+** implementation.
+*/
+#if !defined(LUA_USE_C89)
+#define lua_strx2number(s,p) lua_str2number(s,p)
+#endif
+
+
+/*
+@@ lua_pointer2str converts a pointer to a readable string in a
+** non-specified way.
+*/
+#define lua_pointer2str(buff,sz,p) l_sprintf(buff,sz,"%p",p)
+
+
+/*
+@@ lua_number2strx converts a float to an hexadecimal numeric string.
+** In C99, 'sprintf' (with format specifiers '%a'/'%A') does that.
+** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
+** provide its own implementation.
+*/
+#if !defined(LUA_USE_C89)
+#define lua_number2strx(L,b,sz,f,n) \
+ ((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
+#endif
+
+
+/*
+** 'strtof' and 'opf' variants for math functions are not valid in
+** C89. Otherwise, the macro 'HUGE_VALF' is a good proxy for testing the
+** availability of these variants. ('math.h' is already included in
+** all files that use these macros.)
+*/
+#if defined(LUA_USE_C89) || (defined(HUGE_VAL) && !defined(HUGE_VALF))
+#undef l_mathop /* variants not available */
+#undef lua_str2number
+#define l_mathop(op) (lua_Number)op /* no variant */
+#define lua_str2number(s,p) ((lua_Number)strtod((s), (p)))
+#endif
+
+
+/*
+@@ LUA_KCONTEXT is the type of the context ('ctx') for continuation
+** functions. It must be a numerical type; Lua will use 'intptr_t' if
+** available, otherwise it will use 'ptrdiff_t' (the nearest thing to
+** 'intptr_t' in C89)
+*/
+#define LUA_KCONTEXT ptrdiff_t
+
+#if !defined(LUA_USE_C89) && defined(__STDC_VERSION__) && \
+ __STDC_VERSION__ >= 199901L
+#include <stdint.h>
+#if defined(INTPTR_MAX) /* even in C99 this type is optional */
+#undef LUA_KCONTEXT
+#define LUA_KCONTEXT intptr_t
+#endif
+#endif
+
+
+/*
+@@ lua_getlocaledecpoint gets the locale "radix character" (decimal point).
+** Change that if you do not want to use C locales. (Code using this
+** macro must include header 'locale.h'.)
+*/
+#if !defined(lua_getlocaledecpoint)
+#define lua_getlocaledecpoint() (localeconv()->decimal_point[0])
+#endif
+
+/* }================================================================== */
+
+
+/*
+** {==================================================================
+** Language Variations
+** =====================================================================
+*/
+
+/*
+@@ LUA_NOCVTN2S/LUA_NOCVTS2N control how Lua performs some
+** coercions. Define LUA_NOCVTN2S to turn off automatic coercion from
+** numbers to strings. Define LUA_NOCVTS2N to turn off automatic
+** coercion from strings to numbers.
+*/
+/* #define LUA_NOCVTN2S */
+/* #define LUA_NOCVTS2N */
+
+
+/*
+@@ LUA_USE_APICHECK turns on several consistency checks on the C API.
+** Define it as a help when debugging C code.
+*/
+#if defined(LUA_USE_APICHECK)
+#include <assert.h>
+#define luai_apicheck(l,e) assert(e)
+#endif
+
+/* }================================================================== */
+
+
+/*
+** {==================================================================
+** Macros that affect the API and must be stable (that is, must be the
+** same when you compile Lua and when you compile code that links to
+** Lua). You probably do not want/need to change them.
+** =====================================================================
+*/
+
+/*
+@@ LUAI_MAXSTACK limits the size of the Lua stack.
+** CHANGE it if you need a different limit. This limit is arbitrary;
+** its only purpose is to stop Lua from consuming unlimited stack
+** space (and to reserve some numbers for pseudo-indices).
+*/
+#if LUAI_BITSINT >= 32
+#define LUAI_MAXSTACK 1000000
+#else
+#define LUAI_MAXSTACK 15000
+#endif
+
+
+/*
+@@ LUA_EXTRASPACE defines the size of a raw memory area associated with
+** a Lua state with very fast access.
+** CHANGE it if you need a different size.
+*/
+#define LUA_EXTRASPACE (sizeof(void *))
+
+
+/*
+@@ LUA_IDSIZE gives the maximum size for the description of the source
+@@ of a function in debug information.
+** CHANGE it if you want a different size.
+*/
+#define LUA_IDSIZE 60
+
+
+/*
+@@ LUAL_BUFFERSIZE is the buffer size used by the lauxlib buffer system.
+** CHANGE it if it uses too much C-stack space. (For long double,
+** 'string.format("%.99f", -1e4932)' needs 5034 bytes, so a
+** smaller buffer would force a memory allocation for each call to
+** 'string.format'.)
+*/
+#if LUA_FLOAT_TYPE == LUA_FLOAT_LONGDOUBLE
+#define LUAL_BUFFERSIZE 8192
+#else
+#define LUAL_BUFFERSIZE ((int)(0x80 * sizeof(void*) * sizeof(lua_Integer)))
+#endif
+
+/* }================================================================== */
+
+
+/*
+@@ LUA_QL describes how error messages quote program elements.
+** Lua does not use these macros anymore; they are here for
+** compatibility only.
+*/
+#define LUA_QL(x) "'" x "'"
+#define LUA_QS LUA_QL("%s")
+
+
+
+
+/* =================================================================== */
+
+/*
+** Local configuration. You can use this space to add your redefinitions
+** without modifying the main part of the file.
+*/
+
+
+
+
+
+#endif
+
Index: share/mk/src.lua.mk
===================================================================
--- /dev/null
+++ share/mk/src.lua.mk
@@ -0,0 +1,45 @@
+# $FreeBSD$
+#
+# Lua helper file for FreeBSD /usr/src builds.
+#
+# This file provides any necessary assistance for consumers of Lua in the base
+# system.
+
+.if !target(__<src.lua.mk>__)
+__<src.lua.mk>__:
+
+.include <bsd.own.mk>
+
+#
+# LUA_INSTALL_PATH and LUA_CMD describe where the internal lua has been
+# installed to, along with the name of the internal command. The default
+# name is flua.
+#
+# LUA_CMD can be overwritten to point to a Lua that isn't flua. This is fine,
+# but parts of the src build that use it may have certain expectations that
+# may only be fulfilled by the in-tree Lua. The user overwriting it is expected
+# to understand these and provide the expectations.
+#
+# flua is currently equivalent to Lua 5.3, with the following modules:
+# - luafilesystem
+# - lua-posix
+#
+LUA_INSTALL_PATH?= ${LIBEXECDIR}
+LUA_CMD?= flua
+
+#
+# Some standalone usage may want a variable that tries to find the lua command,
+# and cannot necessarily embed the logic for trying to find it amongst bootstrap
+# tools. For these, we provide the LUA variable.
+#
+# The LUA variable should point to LUA_CMD on the system, if it exists.
+# Otherwise, consumers will have to settle for a PATH search and PATH being
+# appropriately set.
+#
+.if !defined(LUA) && exists(${LUA_INSTALL_PATH}/${LUA_CMD})
+LUA= ${LUA_INSTALL_PATH}/${LUA_CMD}
+.else
+LUA?= ${LUA_CMD}
+.endif
+
+.endif # !target(__<src.lua.mk>__)
Index: stand/common/interp_lua.c
===================================================================
--- stand/common/interp_lua.c
+++ stand/common/interp_lua.c
@@ -41,9 +41,11 @@
#include <lualib.h>
#include <lerrno.h>
-#include <lfs.h>
#include <lutils.h>
+/* Source for this lives with flua in ^/libexec/flua */
+int luaopen_lfs(lua_State *L);
+
struct interp_lua_softc {
lua_State *luap;
};
Index: stand/liblua/Makefile
===================================================================
--- stand/liblua/Makefile
+++ stand/liblua/Makefile
@@ -2,8 +2,11 @@
.include <bsd.init.mk>
+FLUASRC= ${SRCTOP}/libexec/flua
+
.PATH: ${LUASRC}
.PATH: ${LIBLUASRC}
+.PATH: ${FLUASRC}
.include "${BOOTSRC}/lua.mk"
@@ -23,7 +26,10 @@
#SRCS+= lbitlib.c liolib.c lmathlib.c loslib.c ltablib.c
# Our utilities.
-SRCS+= lerrno.c lfs.c lstd.c lutils.c
+SRCS+= lerrno.c lstd.c lutils.c
+
+.PATH: ${FLUASRC}
+SRCS+= lfs.c
WARNS= 3
Index: sys/amd64/linux/Makefile
===================================================================
--- sys/amd64/linux/Makefile
+++ sys/amd64/linux/Makefile
@@ -5,11 +5,13 @@
# Don't use an OBJDIR
.OBJDIR: ${.CURDIR}
+.include <src.lua.mk>
+
all:
@echo "make sysent only"
sysent: linux_sysent.c linux_syscall.h linux_proto.h linux_syscalls.c linux_systrace_args.c
linux_sysent.c linux_syscall.h linux_proto.h linux_syscalls.c linux_systrace_args.c: \
- ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
- sh ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
+ ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
+ ${LUA} ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
Index: sys/amd64/linux32/Makefile
===================================================================
--- sys/amd64/linux32/Makefile
+++ sys/amd64/linux32/Makefile
@@ -5,11 +5,13 @@
# Don't use an OBJDIR
.OBJDIR: ${.CURDIR}
+.include <src.lua.mk>
+
all:
@echo "make sysent only"
sysent: linux32_sysent.c linux32_syscall.h linux32_proto.h linux32_syscalls.c linux32_systrace_args.c
-linux32_sysent.c linux32_syscall.h linux32_proto.h linux32_syscalls.c linux32_systrace_args.c: ../../kern/makesyscalls.sh \
+linux32_sysent.c linux32_syscall.h linux32_proto.h linux32_syscalls.c linux32_systrace_args.c: ../../tools/makesyscalls.lua \
syscalls.master ${.CURDIR}/syscalls.conf
- sh ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
+ ${LUA} ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
Index: sys/arm64/linux/Makefile
===================================================================
--- sys/arm64/linux/Makefile
+++ sys/arm64/linux/Makefile
@@ -5,11 +5,13 @@
# Don't use an OBJDIR
.OBJDIR: ${.CURDIR}
+.include <src.lua.mk>
+
all:
@echo "make sysent only"
sysent: linux_sysent.c linux_syscall.h linux_proto.h linux_syscalls.c linux_systrace_args.c
linux_sysent.c linux_syscall.h linux_proto.h linux_syscalls.c linux_systrace_args.c: \
- ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
- sh ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
+ ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
+ ${LUA} ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
Index: sys/compat/freebsd32/Makefile
===================================================================
--- sys/compat/freebsd32/Makefile
+++ sys/compat/freebsd32/Makefile
@@ -5,14 +5,16 @@
# Don't use an OBJDIR
.OBJDIR: ${.CURDIR}
+.include <src.lua.mk>
+
all:
@echo "make sysent only"
sysent: freebsd32_sysent.c freebsd32_syscall.h freebsd32_proto.h freebsd32_systrace_args.c
freebsd32_sysent.c freebsd32_syscalls.c freebsd32_syscall.h freebsd32_proto.h freebsd32_systrace_args.c : \
- ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf ../../kern/capabilities.conf
- sh ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
+ ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf ../../kern/capabilities.conf
+ ${LUA} ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
clean:
rm -f freebsd32_sysent.c freebsd32_syscalls.c freebsd32_syscall.h freebsd32_proto.h
Index: sys/compat/freebsd32/freebsd32_proto.h
===================================================================
--- sys/compat/freebsd32/freebsd32_proto.h
+++ sys/compat/freebsd32/freebsd32_proto.h
@@ -238,7 +238,7 @@
};
struct freebsd32_lio_listio_args {
char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
- char acb_list_l_[PADL_(struct aiocb32 *const *)]; struct aiocb32 *const * acb_list; char acb_list_r_[PADR_(struct aiocb32 *const *)];
+ char acb_list_l_[PADL_(struct aiocb32 * const *)]; struct aiocb32 * const * acb_list; char acb_list_r_[PADR_(struct aiocb32 * const *)];
char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)];
char sig_l_[PADL_(struct sigevent32 *)]; struct sigevent32 * sig; char sig_r_[PADR_(struct sigevent32 *)];
};
@@ -262,17 +262,17 @@
};
struct freebsd32_modstat_args {
char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)];
- char stat_l_[PADL_(struct module_stat32 *)]; struct module_stat32 * stat; char stat_r_[PADR_(struct module_stat32 *)];
+ char stat_l_[PADL_(struct module_stat32*)]; struct module_stat32* stat; char stat_r_[PADR_(struct module_stat32*)];
};
struct freebsd32_kldstat_args {
char fileid_l_[PADL_(int)]; int fileid; char fileid_r_[PADR_(int)];
- char stat_l_[PADL_(struct kld32_file_stat *)]; struct kld32_file_stat * stat; char stat_r_[PADR_(struct kld32_file_stat *)];
+ char stat_l_[PADL_(struct kld32_file_stat*)]; struct kld32_file_stat* stat; char stat_r_[PADR_(struct kld32_file_stat*)];
};
struct freebsd32_aio_return_args {
char aiocbp_l_[PADL_(struct aiocb32 *)]; struct aiocb32 * aiocbp; char aiocbp_r_[PADR_(struct aiocb32 *)];
};
struct freebsd32_aio_suspend_args {
- char aiocbp_l_[PADL_(struct aiocb32 *const *)]; struct aiocb32 *const * aiocbp; char aiocbp_r_[PADR_(struct aiocb32 *const *)];
+ char aiocbp_l_[PADL_(struct aiocb32 * const *)]; struct aiocb32 * const * aiocbp; char aiocbp_r_[PADR_(struct aiocb32 * const *)];
char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)];
char timeout_l_[PADL_(const struct timespec32 *)]; const struct timespec32 * timeout; char timeout_r_[PADR_(const struct timespec32 *)];
};
@@ -1094,7 +1094,7 @@
};
struct freebsd6_freebsd32_lio_listio_args {
char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
- char acb_list_l_[PADL_(struct oaiocb32 *const *)]; struct oaiocb32 *const * acb_list; char acb_list_r_[PADR_(struct oaiocb32 *const *)];
+ char acb_list_l_[PADL_(struct oaiocb32 * const *)]; struct oaiocb32 * const * acb_list; char acb_list_r_[PADR_(struct oaiocb32 * const *)];
char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)];
char sig_l_[PADL_(struct osigevent32 *)]; struct osigevent32 * sig; char sig_r_[PADR_(struct osigevent32 *)];
};
Index: sys/compat/freebsd32/freebsd32_systrace_args.c
===================================================================
--- sys/compat/freebsd32/freebsd32_systrace_args.c
+++ sys/compat/freebsd32/freebsd32_systrace_args.c
@@ -1278,7 +1278,7 @@
case 257: {
struct freebsd32_lio_listio_args *p = params;
iarg[0] = p->mode; /* int */
- uarg[1] = (intptr_t) p->acb_list; /* struct aiocb32 *const * */
+ uarg[1] = (intptr_t) p->acb_list; /* struct aiocb32 * const * */
iarg[2] = p->nent; /* int */
uarg[3] = (intptr_t) p->sig; /* struct sigevent32 * */
*n_args = 4;
@@ -1341,7 +1341,7 @@
case 301: {
struct freebsd32_modstat_args *p = params;
iarg[0] = p->modid; /* int */
- uarg[1] = (intptr_t) p->stat; /* struct module_stat32 * */
+ uarg[1] = (intptr_t) p->stat; /* struct module_stat32* */
*n_args = 2;
break;
}
@@ -1391,7 +1391,7 @@
case 308: {
struct freebsd32_kldstat_args *p = params;
iarg[0] = p->fileid; /* int */
- uarg[1] = (intptr_t) p->stat; /* struct kld32_file_stat * */
+ uarg[1] = (intptr_t) p->stat; /* struct kld32_file_stat* */
*n_args = 2;
break;
}
@@ -1437,7 +1437,7 @@
/* freebsd32_aio_suspend */
case 315: {
struct freebsd32_aio_suspend_args *p = params;
- uarg[0] = (intptr_t) p->aiocbp; /* struct aiocb32 *const * */
+ uarg[0] = (intptr_t) p->aiocbp; /* struct aiocb32 * const * */
iarg[1] = p->nent; /* int */
uarg[2] = (intptr_t) p->timeout; /* const struct timespec32 * */
*n_args = 3;
@@ -5359,7 +5359,7 @@
p = "int";
break;
case 1:
- p = "userland struct aiocb32 *const *";
+ p = "userland struct aiocb32 * const *";
break;
case 2:
p = "int";
@@ -5471,7 +5471,7 @@
p = "int";
break;
case 1:
- p = "userland struct module_stat32 *";
+ p = "userland struct module_stat32*";
break;
default:
break;
@@ -5544,7 +5544,7 @@
p = "int";
break;
case 1:
- p = "userland struct kld32_file_stat *";
+ p = "userland struct kld32_file_stat*";
break;
default:
break;
@@ -5616,7 +5616,7 @@
case 315:
switch(ndx) {
case 0:
- p = "userland struct aiocb32 *const *";
+ p = "userland struct aiocb32 * const *";
break;
case 1:
p = "int";
Index: sys/i386/linux/Makefile
===================================================================
--- sys/i386/linux/Makefile
+++ sys/i386/linux/Makefile
@@ -5,11 +5,13 @@
# Don't use an OBJDIR
.OBJDIR: ${.CURDIR}
+.include <src.lua.mk>
+
all:
@echo "make sysent only"
sysent: linux_sysent.c linux_syscall.h linux_proto.h linux_syscalls.c linux_systrace_args.c
linux_sysent.c linux_syscall.h linux_proto.h linux_syscalls.c linux_systrace_args.c: \
- ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
- sh ../../kern/makesyscalls.sh syscalls.master ${.CURDIR}/syscalls.conf
+ ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
+ ${LUA} ../../tools/makesyscalls.lua syscalls.master ${.CURDIR}/syscalls.conf
Index: sys/i386/linux/linux_systrace_args.c
===================================================================
--- sys/i386/linux/linux_systrace_args.c
+++ sys/i386/linux/linux_systrace_args.c
@@ -1175,7 +1175,7 @@
/* poll */
case 168: {
struct poll_args *p = params;
- uarg[0] = (intptr_t) p->fds; /* struct pollfd * */
+ uarg[0] = (intptr_t) p->fds; /* struct pollfd* */
uarg[1] = p->nfds; /* unsigned int */
iarg[2] = p->timeout; /* long */
*n_args = 3;
@@ -4815,7 +4815,7 @@
case 168:
switch(ndx) {
case 0:
- p = "userland struct pollfd *";
+ p = "userland struct pollfd*";
break;
case 1:
p = "unsigned int";
Index: sys/kern/Makefile
===================================================================
--- sys/kern/Makefile
+++ sys/kern/Makefile
@@ -1,4 +1,4 @@
-# @(#)Makefile 8.2 (Berkeley) 3/21/94
+# @(#)Makefile 8.2 (Berkeley) 3/21/94
# $FreeBSD$
#
# Makefile for init_sysent
@@ -6,6 +6,8 @@
# Don't use an OBJDIR
.OBJDIR: ${.CURDIR}
+.include <src.lua.mk>
+
all:
@echo "make sysent only"
@@ -13,6 +15,6 @@
../sys/sysproto.h
init_sysent.c syscalls.c systrace_args.c ../sys/syscall.h \
-../sys/syscall.mk ../sys/sysproto.h: makesyscalls.sh syscalls.master \
+../sys/syscall.mk ../sys/sysproto.h: ../tools/makesyscalls.lua syscalls.master \
capabilities.conf
- sh makesyscalls.sh syscalls.master
+ ${LUA} ../tools/makesyscalls.lua syscalls.master
Index: sys/kern/systrace_args.c
===================================================================
--- sys/kern/systrace_args.c
+++ sys/kern/systrace_args.c
@@ -1314,7 +1314,7 @@
case 257: {
struct lio_listio_args *p = params;
iarg[0] = p->mode; /* int */
- uarg[1] = (intptr_t) p->acb_list; /* struct aiocb *const * */
+ uarg[1] = (intptr_t) p->acb_list; /* struct aiocb* const * */
iarg[2] = p->nent; /* int */
uarg[3] = (intptr_t) p->sig; /* struct sigevent * */
*n_args = 4;
@@ -1375,7 +1375,7 @@
case 301: {
struct modstat_args *p = params;
iarg[0] = p->modid; /* int */
- uarg[1] = (intptr_t) p->stat; /* struct module_stat * */
+ uarg[1] = (intptr_t) p->stat; /* struct module_stat* */
*n_args = 2;
break;
}
@@ -1471,7 +1471,7 @@
/* aio_suspend */
case 315: {
struct aio_suspend_args *p = params;
- uarg[0] = (intptr_t) p->aiocbp; /* struct aiocb *const * */
+ uarg[0] = (intptr_t) p->aiocbp; /* struct aiocb * const * */
iarg[1] = p->nent; /* int */
uarg[2] = (intptr_t) p->timeout; /* const struct timespec * */
*n_args = 3;
@@ -5410,7 +5410,7 @@
p = "int";
break;
case 1:
- p = "userland struct aiocb *const *";
+ p = "userland struct aiocb* const *";
break;
case 2:
p = "int";
@@ -5516,7 +5516,7 @@
p = "int";
break;
case 1:
- p = "userland struct module_stat *";
+ p = "userland struct module_stat*";
break;
default:
break;
@@ -5661,7 +5661,7 @@
case 315:
switch(ndx) {
case 0:
- p = "userland struct aiocb *const *";
+ p = "userland struct aiocb * const *";
break;
case 1:
p = "int";
Index: sys/sys/sysproto.h
===================================================================
--- sys/sys/sysproto.h
+++ sys/sys/sysproto.h
@@ -710,7 +710,7 @@
};
struct lio_listio_args {
char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
- char acb_list_l_[PADL_(struct aiocb *const *)]; struct aiocb *const * acb_list; char acb_list_r_[PADR_(struct aiocb *const *)];
+ char acb_list_l_[PADL_(struct aiocb* const *)]; struct aiocb* const * acb_list; char acb_list_r_[PADR_(struct aiocb* const *)];
char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)];
char sig_l_[PADL_(struct sigevent *)]; struct sigevent * sig; char sig_r_[PADR_(struct sigevent *)];
};
@@ -743,7 +743,7 @@
};
struct modstat_args {
char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)];
- char stat_l_[PADL_(struct module_stat *)]; struct module_stat * stat; char stat_r_[PADR_(struct module_stat *)];
+ char stat_l_[PADL_(struct module_stat*)]; struct module_stat* stat; char stat_r_[PADR_(struct module_stat*)];
};
struct modfnext_args {
char modid_l_[PADL_(int)]; int modid; char modid_r_[PADR_(int)];
@@ -787,7 +787,7 @@
char aiocbp_l_[PADL_(struct aiocb *)]; struct aiocb * aiocbp; char aiocbp_r_[PADR_(struct aiocb *)];
};
struct aio_suspend_args {
- char aiocbp_l_[PADL_(struct aiocb *const *)]; struct aiocb *const * aiocbp; char aiocbp_r_[PADR_(struct aiocb *const *)];
+ char aiocbp_l_[PADL_(struct aiocb * const *)]; struct aiocb * const * aiocbp; char aiocbp_r_[PADR_(struct aiocb * const *)];
char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)];
char timeout_l_[PADL_(const struct timespec *)]; const struct timespec * timeout; char timeout_r_[PADR_(const struct timespec *)];
};
@@ -2487,7 +2487,7 @@
};
struct freebsd6_lio_listio_args {
char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)];
- char acb_list_l_[PADL_(struct oaiocb *const *)]; struct oaiocb *const * acb_list; char acb_list_r_[PADR_(struct oaiocb *const *)];
+ char acb_list_l_[PADL_(struct oaiocb * const *)]; struct oaiocb * const * acb_list; char acb_list_r_[PADR_(struct oaiocb * const *)];
char nent_l_[PADL_(int)]; int nent; char nent_r_[PADR_(int)];
char sig_l_[PADL_(struct osigevent *)]; struct osigevent * sig; char sig_r_[PADR_(struct osigevent *)];
};
Index: sys/tools/makesyscalls.lua
===================================================================
--- /dev/null
+++ sys/tools/makesyscalls.lua
@@ -0,0 +1,1182 @@
+-- We generally assume that this script will be run by flua, however we've
+-- carefully crafted modules for it that mimic interfaces provided by modules
+-- available in ports. Currently, this script is compatible with lua from ports
+-- along with the compatible luafilesystem and lua-posix modules.
+local lfs = require("lfs")
+local unistd = require("posix.unistd")
+
+local maxsyscall = 0
+local generated_tag = "@" .. "generated"
+
+-- Default configuration; any of these may get replaced by a configuration file
+-- optionally specified.
+local config = {
+ os_id_keyword = "FreeBSD",
+ abi_func_prefix = "",
+ sysnames = "syscalls.c",
+ sysproto = "../sys/sysproto.h",
+ sysproto_h = "_SYS_SYSPROTO_H_",
+ syshdr = "../sys/syscall.h",
+ sysmk = "../sys/syscall.mk",
+ syssw = "init_sysent.c",
+ syscallprefix = "SYS_",
+ switchname = "sysent",
+ namesname = "syscallnames",
+ systrace = "systrace_args.c",
+ capabilities_conf = "capabilities.conf",
+ capenabled = {},
+ mincompat = 0,
+ abi_type_suffix = "",
+ abi_flags = "",
+ abi_flags_mask = 0,
+ ptr_intptr_t_cast = "intptr_t",
+}
+
+local config_modified = {}
+local cleantmp = true
+local tmpspace = "/tmp/sysent." .. unistd.getpid() .. "/"
+
+-- These ones we'll open in place
+local config_files_needed = {
+ "sysnames",
+ "syshdr",
+ "sysmk",
+ "syssw",
+ "systrace",
+}
+
+-- These ones we'll create temporary files for; generation purposes.
+local temp_files = {
+ "sysaue",
+ "sysdcl",
+ "syscompat",
+ "syscompatdcl",
+ "sysent",
+ "sysinc",
+ "sysarg",
+ "sysprotoend",
+ "systracetmp",
+ "systraceret",
+}
+
+-- Opened files
+local files = {}
+
+local function cleanup()
+ for _, v in pairs(files) do
+ v:close()
+ end
+ if cleantmp then
+ for fname in lfs.dir(tmpspace) do
+ os.remove(tmpspace .. "/" .. fname)
+ end
+
+ if not lfs.rmdir(tmpspace) then
+ io.stderr:write("Failed to clean up tmpdir: " ..
+ tmpspace .. "\n")
+ end
+ else
+ io.stderr:write("Temp files left in " .. tmpspace .. "\n")
+ end
+end
+
+local function abort(status, msg)
+ io.stderr:write(msg .. "\n")
+ cleanup()
+ os.exit(status)
+end
+
+-- Each entry should have a value so we can represent abi flags as a bitmask
+-- for convenience. One may also optionally provide an expr; this gets applied
+-- to each argument type to indicate whether this argument is subject to ABI
+-- change given the configured flags.
+local known_abi_flags = {
+ long_size = {
+ value = 0x00000001,
+ expr = "_Contains[a-z_]*_long_",
+ },
+ time_t_size = {
+ value = 0x00000002,
+ expr = "_Contains[a-z_]*_timet_/",
+ },
+ pointer_args = {
+ value = 0x00000004,
+ },
+ pointer_size = {
+ value = 0x00000008,
+ expr = "_Contains[a-z_]*_ptr_",
+ },
+}
+
+local known_flags = {
+ STD = 0x00000001,
+ OBSOL = 0x00000002,
+ UNIMPL = 0x00000004,
+ NODEF = 0x00000008,
+ NOARGS = 0x00000010,
+ NOPROTO = 0x00000020,
+ NOSTD = 0x00000040,
+ NOTSTATIC = 0x00000080,
+
+ -- Compat flags start from here. We have plenty of space.
+}
+
+-- All compat_options entries should have five entries:
+-- definition: The preprocessor macro that will be set for this
+-- compatlevel: The level this compatibility should be included at. This
+-- generally represents the version of FreeBSD that it is compatible
+-- with, but ultimately it's just the level of mincompat in which it's
+-- included.
+-- flag: The name of the flag in syscalls.master.
+-- prefix: The prefix to use for _args and syscall prototype. This will be
+-- used as-is, without "_" or any other character appended.
+-- descr: The description of this compat option in init_sysent.c comments.
+-- The special "stdcompat" entry will cause the other five to be autogenerated.
+local compat_options = {
+ {
+ definition = "COMPAT_43",
+ compatlevel = 3,
+ flag = "COMPAT",
+ prefix = "o",
+ descr = "old",
+ },
+ { stdcompat = "FREEBSD4" },
+ { stdcompat = "FREEBSD6" },
+ { stdcompat = "FREEBSD7" },
+ { stdcompat = "FREEBSD10" },
+ { stdcompat = "FREEBSD11" },
+}
+
+-- config looks like a shell script; in fact, the previous makesyscalls.sh
+-- script actually sourced it in. It had a pretty common format, so we should
+-- be fine to make various assumptions
+local function process_config(file)
+ local cfg = {}
+ local commentExpr = "#.*"
+ local lineExpr = "([%w%p]+)%s*=%s*\"?([^\"]+)\"?"
+
+ if file == nil then
+ return nil, "No file given"
+ end
+
+ local fh = io.open(file)
+ if fh == nil then
+ return nil, "Could not open file"
+ end
+
+ for nextline in fh:lines() do
+ -- Strip any comments
+ nextline = nextline:gsub(commentExpr, "")
+ -- Parse it into key, value pairs
+ local key, value = nextline:match(lineExpr)
+ if key ~= nil and value ~= nil then
+ cfg[key] = value
+ end
+ end
+
+ io.close(fh)
+ return cfg
+end
+
+local function grab_capenabled(file, open_fail_ok)
+ local capentries = {}
+ local commentExpr = "#.*"
+
+ if file == nil then
+ print "No file"
+ return {}
+ end
+
+ local fh = io.open(file)
+ if fh == nil then
+ if not open_fail_ok then
+ abort(1, "Failed to open " .. file)
+ end
+ return {}
+ end
+
+ for nextline in fh:lines() do
+ -- Strip any comments
+ nextline = nextline:gsub(commentExpr, "")
+ if nextline ~= "" then
+ capentries[nextline] = true
+ end
+ end
+
+ io.close(fh)
+ return capentries
+end
+
+local function process_compat()
+ local nval = 0
+ for _, v in pairs(known_flags) do
+ if v > nval then
+ nval = v
+ end
+ end
+
+ nval = nval << 1
+ for _, v in pairs(compat_options) do
+ if v["stdcompat"] ~= nil then
+ local stdcompat = v["stdcompat"]
+ v["definition"] = "COMPAT_" .. stdcompat:upper()
+ v["compatlevel"] = tonumber(stdcompat:match("([0-9]+)$"))
+ v["flag"] = stdcompat:gsub("FREEBSD", "COMPAT")
+ v["prefix"] = stdcompat:lower() .. "_"
+ v["descr"] = stdcompat:lower()
+ end
+
+ local tmpname = "sys" .. v["flag"]:lower()
+ local dcltmpname = tmpname .. "dcl"
+ files[tmpname] = io.tmpfile()
+ files[dcltmpname] = io.tmpfile()
+ v["tmp"] = tmpname
+ v["dcltmp"] = dcltmpname
+
+ known_flags[v["flag"]] = nval
+ v["mask"] = nval
+ nval = nval << 1
+
+ v["count"] = 0
+ end
+end
+
+local function process_abi_flags()
+ local flags, mask = config["abi_flags"], 0
+ for txtflag in flags:gmatch("([^|]+)") do
+ if known_abi_flags[txtflag] == nil then
+ abort(1, "Unknown abi_flag: " .. txtflag)
+ end
+
+ mask = mask | known_abi_flags[txtflag]["value"]
+ end
+
+ config["abi_flags_mask"] = mask
+end
+
+local function abi_changes(name)
+ if known_abi_flags[name] == nil then
+ abort(1, "abi_changes: unknown flag: " .. name)
+ end
+
+ return config["abi_flags_mask"] & known_abi_flags[name]["value"] ~= 0
+end
+
+local function strip_abi_prefix(funcname)
+ local abiprefix = config["abi_func_prefix"]
+ local stripped_name
+ if abiprefix ~= "" and funcname:find("^" .. abiprefix) then
+ stripped_name = funcname:gsub("^" .. abiprefix, "")
+ else
+ stripped_name = funcname
+ end
+
+ return stripped_name
+end
+
+local function read_file(tmpfile)
+ if files[tmpfile] == nil then
+ print("Not found: " .. tmpfile)
+ return
+ end
+
+ local fh = files[tmpfile]
+ fh:seek("set")
+ return fh:read("a")
+end
+
+local function write_line(tmpfile, line)
+ if files[tmpfile] == nil then
+ print("Not found: " .. tmpfile)
+ return
+ end
+ files[tmpfile]:write(line)
+end
+
+local function write_line_pfile(tmppat, line)
+ for k in pairs(files) do
+ if k:match(tmppat) ~= nil then
+ files[k]:write(line)
+ end
+ end
+end
+
+local function trim(s)
+ if s == nil then
+ return nil
+ end
+ return s:gsub("^%s*([^%s]?)", "%1"):gsub("([^%s]?)%s+$", "%1")
+end
+
+local function isptrtype(type)
+ return type:find("*") or type:find("caddr_t")
+ -- XXX NOTYET: or type:find("intptr_t")
+end
+
+local process_syscall_def
+
+-- These patterns are processed in order on any line that isn't empty.
+local pattern_table = {
+ {
+ pattern = "%s*$" .. config['os_id_keyword'],
+ process = function(_, _)
+ -- Ignore... ID tag
+ end,
+ },
+ {
+ dump_prevline = true,
+ pattern = "^#%s*include",
+ process = function(line)
+ line = line .. "\n"
+ write_line('sysinc', line)
+ end,
+ },
+ {
+ dump_prevline = true,
+ pattern = "^#",
+ process = function(line)
+ line = line .. "\n"
+ write_line('sysent', line)
+ write_line('sysdcl', line)
+ write_line('sysarg', line)
+ write_line_pfile('syscompat[0-9]*$', line)
+ write_line('sysnames', line)
+ write_line_pfile('systrace.*', line)
+ end,
+ },
+ {
+ -- Buffer anything else
+ pattern = ".+",
+ process = function(line, prevline)
+ local incomplete = line:find("\\$") ~= nil
+ -- Lines that end in \ get the \ stripped
+ -- Lines that start with a syscall number, prepend \n
+ line = trim(line):gsub("\\$", "")
+ if line:find("^[0-9]") and prevline then
+ process_syscall_def(prevline)
+ prevline = nil
+ end
+
+ prevline = (prevline or '') .. line
+ incomplete = incomplete or prevline:find(",$") ~= nil
+ incomplete = incomplete or prevline:find("{") ~= nil and
+ prevline:find("}") == nil
+ if prevline:find("^[0-9]") and not incomplete then
+ process_syscall_def(prevline)
+ prevline = nil
+ end
+
+ return prevline
+ end,
+ },
+}
+
+local function process_sysfile(file)
+ local capentries = {}
+ local commentExpr = "^%s*;.*"
+
+ if file == nil then
+ print "No file"
+ return {}
+ end
+
+ local fh = io.open(file)
+ if fh == nil then
+ print("Failed to open " .. file)
+ return {}
+ end
+
+ local function do_match(nextline, prevline)
+ local pattern, handler, dump
+ for _, v in pairs(pattern_table) do
+ pattern = v['pattern']
+ handler = v['process']
+ dump = v['dump_prevline']
+ if nextline:match(pattern) then
+ if dump and prevline then
+ process_syscall_def(prevline)
+ prevline = nil
+ end
+
+ return handler(nextline, prevline)
+ end
+ end
+
+ abort(1, "Failed to handle: " .. nextline)
+ end
+
+ local prevline
+ for nextline in fh:lines() do
+ -- Strip any comments
+ nextline = nextline:gsub(commentExpr, "")
+ if nextline ~= "" then
+ prevline = do_match(nextline, prevline)
+ end
+ end
+
+ -- Dump any remainder
+ if prevline ~= nil and prevline:find("^[0-9]") then
+ process_syscall_def(prevline)
+ end
+
+ io.close(fh)
+ return capentries
+end
+
+local function get_mask(flags)
+ local mask = 0
+ for _, v in ipairs(flags) do
+ if known_flags[v] == nil then
+ abort(1, "Checking for unknown flag " .. v)
+ end
+
+ mask = mask | known_flags[v]
+ end
+
+ return mask
+end
+
+local function get_mask_pat(pflags)
+ local mask = 0
+ for k, v in pairs(known_flags) do
+ if k:find(pflags) then
+ mask = mask | v
+ end
+ end
+
+ return mask
+end
+
+local function align_sysent_comment(col)
+ write_line("sysent", "\t")
+ col = col + 8 - col % 8
+ while col < 56 do
+ write_line("sysent", "\t")
+ col = col + 8
+ end
+end
+
+local function strip_arg_annotations(arg)
+ arg = arg:gsub("_In[^ ]*[_)] ?", "")
+ arg = arg:gsub("_Out[^ ]*[_)] ?", "")
+ return trim(arg)
+end
+
+local function check_abi_changes(arg)
+ for k, v in pairs(known_abi_flags) do
+ local expr = v["expr"]
+ if abi_changes(k) and expr ~= nil and arg:find(expr) then
+ return true
+ end
+ end
+
+ return false
+end
+
+local function process_args(args)
+ local funcargs = {}
+
+ for arg in args:gmatch("([^,]+)") do
+ local abi_change = not isptrtype(arg) or check_abi_changes(arg)
+
+ arg = strip_arg_annotations(arg)
+
+ local argname = arg:match("([^* ]+)$")
+
+ -- argtype is... everything else.
+ local argtype = trim(arg:gsub(argname .. "$", ""))
+
+ if argtype == "" and argname == "void" then
+ goto out
+ end
+
+ -- XX TODO: Forward declarations? See: sysstubfwd in CheriBSD
+ if abi_change then
+ local abi_type_suffix = config["abi_type_suffix"]
+ argtype = argtype:gsub("_native ", "")
+ argtype = argtype:gsub("(struct [^ ]*)", "%1" ..
+ abi_type_suffix)
+ argtype = argtype:gsub("(union [^ ]*)", "%1" ..
+ abi_type_suffix)
+ end
+
+ funcargs[#funcargs + 1] = {
+ type = argtype,
+ name = argname,
+ }
+ end
+
+ ::out::
+ return funcargs
+end
+
+local function handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
+ auditev, syscallret, funcname, funcalias, funcargs, argalias)
+ local argssize
+
+ if #funcargs > 0 or flags & known_flags["NODEF"] ~= 0 then
+ argssize = "AS(" .. argalias .. ")"
+ else
+ argssize = "0"
+ end
+ write_line("systrace", string.format("\t/* %s */\n\tcase %d: {\n",
+ funcname, sysnum))
+ write_line("systracetmp", string.format("\t/* %s */\n\tcase %d:\n",
+ funcname, sysnum))
+ write_line("systraceret", string.format("\t/* %s */\n\tcase %d:\n",
+ funcname, sysnum))
+
+ if #funcargs > 0 then
+ write_line("systracetmp", "\t\tswitch(ndx) {\n")
+ write_line("systrace", string.format(
+ "\t\tstruct %s *p = params;\n", argalias))
+
+ local argtype, argname
+ for idx, arg in ipairs(funcargs) do
+ argtype = arg["type"]
+ argname = arg["name"]
+
+ argtype = argtype:gsub("__restrict$", "")
+ -- Pointer arg?
+ if argtype:find("*") then
+ write_line("systracetmp", string.format(
+ "\t\tcase %d:\n\t\t\tp = \"userland %s\";\n\t\t\tbreak;\n",
+ idx - 1, argtype))
+ else
+ write_line("systracetmp", string.format(
+ "\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n",
+ idx - 1, argtype))
+ end
+
+ if isptrtype(argtype) then
+ write_line("systrace", string.format(
+ "\t\tuarg[%d] = (%s) p->%s; /* %s */\n",
+ idx - 1, config["ptr_intptr_t_cast"],
+ argname, argtype))
+ elseif argtype == "union l_semun" then
+ write_line("systrace", string.format(
+ "\t\tuarg[%d] = p->%s.buf; /* %s */\n",
+ idx - 1, argname, argtype))
+ elseif argtype:sub(1,1) == "u" or argtype == "size_t" then
+ write_line("systrace", string.format(
+ "\t\tuarg[%d] = p->%s; /* %s */\n",
+ idx - 1, argname, argtype))
+ else
+ write_line("systrace", string.format(
+ "\t\tiarg[%d] = p->%s; /* %s */\n",
+ idx - 1, argname, argtype))
+ end
+ end
+
+ write_line("systracetmp",
+ "\t\tdefault:\n\t\t\tbreak;\n\t\t};\n")
+
+ write_line("systraceret", "\t\tif (ndx == 0 || ndx == 1)\n")
+ write_line("systraceret", string.format("\t\t\tp = \"%s\";\n",
+ syscallret))
+ write_line("systraceret", "\t\tbreak;\n")
+ end
+ write_line("systrace", string.format(
+ "\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", #funcargs))
+ write_line("systracetmp", "\t\tbreak;\n")
+
+ local nargflags = get_mask({"NOARGS", "NOPROTO", "NODEF"})
+ if flags & nargflags == 0 then
+ if #funcargs > 0 then
+ write_line("sysarg", string.format("struct %s {\n",
+ argalias))
+ for _, v in ipairs(funcargs) do
+ local argname, argtype = v["name"], v["type"]
+ write_line("sysarg", string.format(
+ "\tchar %s_l_[PADL_(%s)]; %s %s; char %s_r_[PADR_(%s)];\n",
+ argname, argtype,
+ argtype, argname,
+ argname, argtype))
+ end
+ write_line("sysarg", "};\n")
+ else
+ write_line("sysarg", string.format(
+ "struct %s {\n\tregister_t dummy;\n};\n", argalias))
+ end
+ end
+
+ local protoflags = get_mask({"NOPROTO", "NODEF"})
+ if flags & protoflags == 0 then
+ if funcname == "nosys" or funcname == "lkmnosys" or
+ funcname == "sysarch" or funcname:find("^freebsd") or
+ funcname:find("^linux") or
+ funcname:find("^cloudabi") then
+ write_line("sysdcl", string.format(
+ "%s\t%s(struct thread *, struct %s *)",
+ rettype, funcname, argalias))
+ else
+ write_line("sysdcl", string.format(
+ "%s\tsys_%s(struct thread *, struct %s *)",
+ rettype, funcname, argalias))
+ end
+ write_line("sysdcl", ";\n")
+ write_line("sysaue", string.format("#define\t%sAUE_%s\t%s\n",
+ config['syscallprefix'], funcalias, auditev))
+ end
+
+ write_line("sysent", string.format("\t{ %s, (sy_call_t *)", argssize))
+ local column = 8 + 2 + #argssize + 15
+
+ if flags & known_flags["NOSTD"] ~= 0 then
+ write_line("sysent", string.format(
+ "lkmressys, AUE_NULL, NULL, 0, 0, %s, SY_THR_ABSENT },",
+ sysflags))
+ column = column + #"lkmressys" + #"AUE_NULL" + 3
+ else
+ if funcname == "nosys" or funcname == "lkmnosys" or
+ funcname == "sysarch" or funcname:find("^freebsd") or
+ funcname:find("^linux") or
+ funcname:find("^cloudabi") then
+ write_line("sysent", string.format(
+ "%s, %s, NULL, 0, 0, %s, %s },",
+ funcname, auditev, sysflags, thr_flag))
+ column = column + #funcname + #auditev + #sysflags + 3
+ else
+ write_line("sysent", string.format(
+ "sys_%s, %s, NULL, 0, 0, %s, %s },",
+ funcname, auditev, sysflags, thr_flag))
+ column = column + #funcname + #auditev + #sysflags + 7
+ end
+ end
+
+ align_sysent_comment(column)
+ write_line("sysent", string.format("/* %d = %s */\n",
+ sysnum, funcalias))
+ write_line("sysnames", string.format("\t\"%s\",\t\t\t/* %d = %s */\n",
+ funcalias, sysnum, funcalias))
+
+ if flags & known_flags["NODEF"] == 0 then
+ write_line("syshdr", string.format("#define\t%s%s\t%d\n",
+ config['syscallprefix'], funcalias, sysnum))
+ write_line("sysmk", string.format(" \\\n\t%s.o",
+ funcalias))
+ end
+end
+
+local function handle_obsol(sysnum, funcname, comment)
+ write_line("sysent",
+ "\t{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },")
+ align_sysent_comment(34)
+
+ write_line("sysent", string.format("/* %d = obsolete %s */\n",
+ sysnum, comment))
+ write_line("sysnames", string.format(
+ "\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
+ funcname, sysnum, comment))
+ write_line("syshdr", string.format("\t\t\t\t/* %d is obsolete %s */\n",
+ sysnum, comment))
+end
+
+local function handle_compat(sysnum, thr_flag, flags, sysflags, rettype,
+ auditev, funcname, funcalias, funcargs, argalias)
+ local argssize, out, outdcl, wrap, prefix, descr
+
+ if #funcargs > 0 or flags & known_flags["NODEF"] ~= 0 then
+ argssize = "AS(" .. argalias .. ")"
+ else
+ argssize = "0"
+ end
+
+ for _, v in pairs(compat_options) do
+ if flags & v["mask"] ~= 0 then
+ if config["mincompat"] > v["compatlevel"] then
+ funcname = strip_abi_prefix(funcname)
+ funcname = v["prefix"] .. funcname
+ return handle_obsol(sysnum, funcname, funcname)
+ end
+ v["count"] = v["count"] + 1
+ out = v["tmp"]
+ outdcl = v["dcltmp"]
+ wrap = v["flag"]:lower()
+ prefix = v["prefix"]
+ descr = v["descr"]
+ goto compatdone
+ end
+ end
+
+ ::compatdone::
+ local dprotoflags = get_mask({"NOPROTO", "NODEF"})
+ local nargflags = dprotoflags | known_flags["NOARGS"]
+ if #funcargs > 0 and flags & nargflags == 0 then
+ write_line(out, string.format("struct %s {\n", argalias))
+ for _, v in ipairs(funcargs) do
+ local argname, argtype = v["name"], v["type"]
+ write_line(out, string.format(
+ "\tchar %s_l_[PADL_(%s)]; %s %s; char %s_r_[PADR_(%s)];\n",
+ argname, argtype,
+ argtype, argname,
+ argname, argtype))
+ end
+ write_line(out, "};\n")
+ elseif flags & nargflags == 0 then
+ write_line("sysarg", string.format(
+ "struct %s {\n\tregister_t dummy;\n};\n", argalias))
+ end
+ if flags & dprotoflags == 0 then
+ write_line(outdcl, string.format(
+ "%s\t%s%s(struct thread *, struct %s *);\n",
+ rettype, prefix, funcname, argalias))
+ write_line("sysaue", string.format(
+ "#define\t%sAUE_%s%s\t%s\n", config['syscallprefix'],
+ prefix, funcname, auditev))
+ end
+
+ if flags & known_flags['NOSTD'] ~= 0 then
+ write_line("sysent", string.format(
+ "\t{ %s, (sy_call_t *)%s, %s, NULL, 0, 0, 0, SY_THR_ABSENT },",
+ "0", "lkmressys", "AUE_NULL"))
+ align_sysent_comment(8 + 2 + #"0" + 15 + #"lkmressys" +
+ #"AUE_NULL" + 3)
+ else
+ write_line("sysent", string.format(
+ "\t{ %s(%s,%s), %s, NULL, 0, 0, %s, %s },",
+ wrap, argssize, funcname, auditev, sysflags, thr_flag))
+ align_sysent_comment(8 + 9 + #argssize + 1 + #funcname +
+ #auditev + #sysflags + 4)
+ end
+
+ write_line("sysent", string.format("/* %d = %s %s */\n",
+ sysnum, descr, funcalias))
+ write_line("sysnames", string.format(
+ "\t\"%s.%s\",\t\t/* %d = %s %s */\n",
+ wrap, funcalias, sysnum, descr, funcalias))
+ -- Do not provide freebsdN_* symbols in libc for < FreeBSD 7
+ local nosymflags = get_mask({"COMPAT", "COMPAT4", "COMPAT6"})
+ if flags & nosymflags ~= 0 then
+ write_line("syshdr", string.format(
+ "\t\t\t\t/* %d is %s %s */\n",
+ sysnum, descr, funcalias))
+ elseif flags & known_flags["NODEF"] == 0 then
+ write_line("syshdr", string.format("#define\t%s%s%s\t%d\n",
+ config['syscallprefix'], prefix, funcalias, sysnum))
+ write_line("sysmk", string.format(" \\\n\t%s%s.o",
+ prefix, funcalias))
+ end
+end
+
+local function handle_unimpl(sysnum, sysstart, sysend, comment)
+ if sysstart == nil and sysend == nil then
+ sysstart = tonumber(sysnum)
+ sysend = tonumber(sysnum)
+ end
+
+ sysnum = sysstart
+ while sysnum <= sysend do
+ write_line("sysent", string.format(
+ "\t{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0, 0, SY_THR_ABSENT },\t\t\t/* %d = %s */\n",
+ sysnum, comment))
+ write_line("sysnames", string.format(
+ "\t\"#%d\",\t\t\t/* %d = %s */\n",
+ sysnum, sysnum, comment))
+ sysnum = sysnum + 1
+ end
+end
+
+process_syscall_def = function(line)
+ local sysstart, sysend, flags, funcname, sysflags
+ local thr_flag, syscallret
+ local orig = line
+ flags = 0
+ thr_flag = "SY_THR_STATIC"
+
+ -- Parse out the interesting information first
+ local initialExpr = "^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s*"
+ local sysnum, auditev, allflags = line:match(initialExpr)
+
+ if sysnum == nil or auditev == nil or allflags == nil then
+ -- XXX TODO: Better?
+ abort(1, "Completely malformed: " .. line)
+ end
+
+ if sysnum:find("-") then
+ sysstart, sysend = sysnum:match("^([%d]+)-([%d]+)$")
+ if sysstart == nil or sysend == nil then
+ abort(1, "Malformed range: " .. sysnum)
+ end
+ sysnum = nil
+ sysstart = tonumber(sysstart)
+ sysend = tonumber(sysend)
+ end
+
+ -- Split flags
+ for flag in allflags:gmatch("([^|]+)") do
+ flags = flags | known_flags[flag]
+ end
+
+ if (flags & known_flags["UNIMPL"]) == 0 and sysnum == nil then
+ abort(1, "Range only allowed with UNIMPL: " .. line)
+ end
+
+ if (flags & known_flags["NOTSTATIC"]) ~= 0 then
+ thr_flag = "SY_THR_ABSENT"
+ end
+
+ -- Strip earlier bits out, leave declaration + alt
+ line = line:gsub("^.+" .. allflags .. "%s*", "")
+
+ local decl_fnd = line:find("^{") ~= nil
+ if decl_fnd and line:find("}") == nil then
+ abort(1, "Malformed, no closing brace: " .. line)
+ end
+
+ local decl, alt
+ if decl_fnd then
+ line = line:gsub("^{", "")
+ decl, alt = line:match("([^}]*)}[%s]*(.*)$")
+ else
+ alt = line
+ end
+
+ if decl == nil and alt == nil then
+ abort(1, "Malformed bits: " .. line)
+ end
+
+ local funcalias, funcomment, argalias, rettype, args
+ if not decl_fnd and alt ~= nil and alt ~= "" then
+ -- Peel off one entry for name
+ funcname = trim(alt:match("^([^%s]+)"))
+ alt = alt:gsub("^([^%s]+)[%s]*", "")
+ end
+ -- Do we even need it?
+ if flags & get_mask({"OBSOL", "UNIMPL"}) ~= 0 then
+ local NF = 0
+ for _ in orig:gmatch("[^%s]+") do
+ NF = NF + 1
+ end
+
+ funcomment = funcname or ''
+ if NF < 6 then
+ funcomment = funcomment .. " " .. alt
+ end
+
+ funcomment = trim(funcomment)
+
+-- if funcname ~= nil then
+-- else
+-- funcomment = trim(alt)
+-- end
+ goto skipalt
+ end
+
+ if alt ~= nil and alt ~= "" then
+ local altExpr = "^([^%s]+)%s+([^%s]+)%s+([^%s]+)"
+ funcalias, argalias, rettype = alt:match(altExpr)
+ funcalias = trim(funcalias)
+ if funcalias == nil or argalias == nil or rettype == nil then
+ abort(1, "Malformed alt: " .. line)
+ end
+ end
+ if decl_fnd then
+ -- Don't clobber rettype set in the alt information
+ if rettype == nil then
+ rettype = "int"
+ end
+ -- Peel off the return type
+ syscallret = line:match("([^%s]+)%s")
+ line = line:match("[^%s]+%s(.+)")
+ -- Pointer incoming
+ if line:sub(1,1) == "*" then
+ syscallret = syscallret .. " "
+ end
+ while line:sub(1,1) == "*" do
+ line = line:sub(2)
+ syscallret = syscallret .. "*"
+ end
+ funcname = line:match("^([^(]+)%(")
+ if funcname == nil then
+ abort(1, "Not a signature? " .. line)
+ end
+ args = line:match("^[^(]+%((.+)%)[^)]*$")
+ end
+
+ ::skipalt::
+
+ if funcname == nil then
+ funcname = funcalias
+ end
+
+ funcname = trim(funcname)
+
+ sysflags = "0"
+
+ -- NODEF events do not get audited
+ if flags & known_flags['NODEF'] ~= 0 then
+ auditev = 'AUE_NULL'
+ end
+
+ -- If applicable; strip the ABI prefix from the name
+ local stripped_name = strip_abi_prefix(funcname)
+
+ if config["capenabled"][funcname] ~= nil or
+ config["capenabled"][stripped_name] ~= nil then
+ sysflags = "SYF_CAPENABLED"
+ end
+
+ local funcargs = {}
+ if args ~= nil then
+ funcargs = process_args(args)
+ end
+
+ local argprefix = ''
+ if abi_changes("pointer_args") then
+ for _, v in ipairs(funcargs) do
+ if isptrtype(v["type"]) then
+ -- argalias should be:
+ -- COMPAT_PREFIX + ABI Prefix + funcname
+ argprefix = config['abi_func_prefix']
+ funcalias = config['abi_func_prefix'] ..
+ funcname
+ goto ptrfound
+ end
+ end
+ ::ptrfound::
+ end
+ if funcalias == nil or funcalias == "" then
+ funcalias = funcname
+ end
+
+ if argalias == nil and funcname ~= nil then
+ argalias = argprefix .. funcname .. "_args"
+ for _, v in pairs(compat_options) do
+ local mask = v["mask"]
+ if (flags & mask) ~= 0 then
+ -- Multiple aliases doesn't seem to make
+ -- sense.
+ argalias = v["prefix"] .. argalias
+ goto out
+ end
+ end
+ ::out::
+ elseif argalias ~= nil then
+ argalias = argprefix .. argalias
+ end
+
+ local ncompatflags = get_mask({"STD", "NODEF", "NOARGS", "NOPROTO",
+ "NOSTD"})
+ local compatflags = get_mask_pat("COMPAT.*")
+ -- Now try compat...
+ if flags & compatflags ~= 0 then
+ if flags & known_flags['STD'] ~= 0 then
+ abort(1, "Incompatible COMPAT/STD: " .. line)
+ end
+ handle_compat(sysnum, thr_flag, flags, sysflags, rettype,
+ auditev, funcname, funcalias, funcargs, argalias)
+ elseif flags & ncompatflags ~= 0 then
+ handle_noncompat(sysnum, thr_flag, flags, sysflags, rettype,
+ auditev, syscallret, funcname, funcalias, funcargs,
+ argalias)
+ elseif flags & known_flags["OBSOL"] ~= 0 then
+ handle_obsol(sysnum, funcname, funcomment)
+ elseif flags & known_flags["UNIMPL"] ~= 0 then
+ handle_unimpl(sysnum, sysstart, sysend, funcomment)
+ if sysend ~= nil and sysend > maxsyscall then
+ maxsyscall = sysend
+ end
+ else
+ abort(1, "Bad flags? " .. line)
+ end
+
+ if sysnum ~= nil and tonumber(sysnum) > maxsyscall then
+ maxsyscall = tonumber(sysnum)
+ end
+end
+
+-- Entry point
+
+if #arg < 1 or #arg > 2 then
+ abort(1, "usage: " .. arg[0] .. " input-file <config-file>")
+end
+
+local sysfile, configfile = arg[1], arg[2]
+
+-- process_config either returns nil and a message, or a
+-- table that we should merge into the global config
+if configfile ~= nil then
+ local res, msg = process_config(configfile)
+
+ if res == nil then
+ -- Error... handle?
+ print(msg)
+ os.exit(1)
+ end
+
+ for k, v in pairs(res) do
+ if v ~= config[k] then
+ config[k] = v
+ config_modified[k] = true
+ end
+ end
+end
+
+-- We ignore errors here if we're relying on the default configuration.
+config["capenabled"] = grab_capenabled(config['capabilities_conf'],
+ config_modified["capabilities_conf"] == nil)
+process_compat()
+process_abi_flags()
+
+if not lfs.mkdir(tmpspace) then
+ abort(1, "Failed to create tempdir " .. tmpspace)
+end
+
+for _, v in ipairs(temp_files) do
+ local tmpname = tmpspace .. v
+ files[v] = io.open(tmpname, "w+")
+end
+
+
+for _, v in ipairs(config_files_needed) do
+ files[v] = io.open(config[v], "w+")
+end
+
+-- Write out all of the preamble bits
+write_line("sysent", "\n/* The casts are bogus but will do for now. */\n")
+write_line("sysent", string.format("struct sysent %s[] = {\n",
+ config['switchname']))
+
+write_line("syssw", "/*\n * System call switch table.\n *\n")
+write_line("syssw", " * DO NOT EDIT-- this file is automatically " ..
+ generated_tag .. ".\n")
+write_line("syssw", string.format(" * $%s$\n", config['os_id_keyword']))
+write_line("syssw", " */\n\n")
+
+write_line("sysarg", "/*\n * System call prototypes.\n *\n")
+write_line("sysarg", " * DO NOT EDIT-- this file is automatically " ..
+ generated_tag .. ".\n")
+write_line("sysarg", string.format(" * $%s$\n", config['os_id_keyword']))
+write_line("sysarg", " */\n\n")
+write_line("sysarg", string.format("#ifndef %s\n", config['sysproto_h']))
+write_line("sysarg", string.format("#define\t%s\n\n", config['sysproto_h']))
+write_line("sysarg", "#include <sys/signal.h>\n")
+write_line("sysarg", "#include <sys/acl.h>\n")
+write_line("sysarg", "#include <sys/cpuset.h>\n")
+write_line("sysarg", "#include <sys/domainset.h>\n")
+write_line("sysarg", "#include <sys/_ffcounter.h>\n")
+write_line("sysarg", "#include <sys/_semaphore.h>\n")
+write_line("sysarg", "#include <sys/ucontext.h>\n")
+write_line("sysarg", "#include <sys/wait.h>\n\n")
+write_line("sysarg", "#include <bsm/audit_kevents.h>\n\n")
+write_line("sysarg", "struct proc;\n\n")
+write_line("sysarg", "struct thread;\n\n")
+write_line("sysarg",
+ "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n")
+write_line("sysarg", "\t\t0 : sizeof(register_t) - sizeof(t))\n\n")
+write_line("sysarg", "#if BYTE_ORDER == LITTLE_ENDIAN\n")
+write_line("sysarg", "#define\tPADL_(t)\t0\n")
+write_line("sysarg", "#define\tPADR_(t)\tPAD_(t)\n")
+write_line("sysarg", "#else\n")
+write_line("sysarg", "#define\tPADL_(t)\tPAD_(t)\n")
+write_line("sysarg", "#define\tPADR_(t)\t0\n")
+write_line("sysarg", "#endif\n\n")
+
+for _, v in pairs(compat_options) do
+ write_line(v["tmp"], string.format("\n#ifdef %s\n\n", v["definition"]))
+end
+
+write_line("sysnames", "/*\n * System call names.\n *\n")
+write_line("sysnames", " * DO NOT EDIT-- this file is automatically " ..
+ generated_tag .. ".\n")
+write_line("sysnames", string.format(" * $%s$\n", config['os_id_keyword']))
+write_line("sysnames", " */\n\n")
+write_line("sysnames", string.format ("const char *%s[] = {\n",
+ config['namesname']))
+
+write_line("syshdr", "/*\n * System call numbers.\n *\n")
+write_line("syshdr", " * DO NOT EDIT-- this file is automatically " ..
+ generated_tag .. ".\n")
+write_line("syshdr", string.format(" * $%s$\n", config['os_id_keyword']))
+write_line("syshdr", " */\n\n")
+
+write_line("sysmk", "# FreeBSD system call object files.\n")
+write_line("sysmk", "# DO NOT EDIT-- this file is automatically " ..
+ generated_tag .. ".\n")
+write_line("sysmk", string.format("# $%s$\n", config['os_id_keyword']))
+write_line("sysmk", "MIASM = ")
+
+write_line("systrace",
+ "/*\n * System call argument to DTrace register array converstion.\n *\n")
+write_line("systrace", " * DO NOT EDIT-- this file is automatically " ..
+ generated_tag .. ".\n")
+write_line("systrace", string.format(" * $%s$\n", config['os_id_keyword']))
+write_line("systrace",
+ " * This file is part of the DTrace syscall provider.\n */\n\n")
+write_line("systrace",
+ "static void\nsystrace_args(int sysnum, void *params, uint64_t *uarg, int *n_args)\n{\n")
+write_line("systrace", "\tint64_t *iarg = (int64_t *) uarg;\n")
+write_line("systrace", "\tswitch (sysnum) {\n")
+
+write_line("systracetmp",
+ "static void\nsystrace_entry_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n")
+write_line("systracetmp", "\tswitch (sysnum) {\n")
+
+write_line("systraceret",
+ "static void\nsystrace_return_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n")
+write_line("systraceret", "\tswitch (sysnum) {\n")
+
+-- Processing the sysfile will parse out the preprocessor bits and put them into
+-- the appropriate place. Any syscall-looking lines get thrown into the sysfile
+-- buffer, one per line, for later processing once they're all glued together.
+process_sysfile(sysfile)
+
+write_line("sysinc",
+ "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n")
+
+for _, v in pairs(compat_options) do
+ if v["count"] > 0 then
+ write_line("sysinc", string.format("\n#ifdef %s\n",
+ v["definition"]))
+ write_line("sysinc", string.format(
+ "#define %s(n, name) n, (sy_call_t *)__CONCAT(%s,name)\n",
+ v["flag"]:lower(), v["prefix"]))
+ write_line("sysinc", "#else\n")
+ write_line("sysinc", string.format(
+ "#define %s(n, name) 0, (sy_call_t *)nosys\n",
+ v["flag"]:lower()))
+ write_line("sysinc", "#endif\n")
+ end
+
+ write_line(v["dcltmp"], string.format("\n#endif /* %s */\n\n",
+ v["definition"]))
+end
+
+write_line("sysprotoend", "\n#undef PAD_\n")
+write_line("sysprotoend", "#undef PADL_\n")
+write_line("sysprotoend", "#undef PADR_\n")
+write_line("sysprotoend", string.format("\n#endif /* !%s */\n",
+ config["sysproto_h"]))
+
+write_line("sysmk", "\n")
+write_line("sysent", "};\n")
+write_line("sysnames", "};\n")
+-- maxsyscall is the highest seen; MAXSYSCALL should be one higher
+write_line("syshdr", string.format("#define\t%sMAXSYSCALL\t%d\n",
+ config["syscallprefix"], maxsyscall + 1))
+write_line("systrace","\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n")
+write_line("systracetmp",
+ "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n")
+write_line("systraceret",
+ "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n")
+
+-- Finish up; output
+write_line("syssw", read_file("sysinc"))
+write_line("syssw", read_file("sysent"))
+
+local fh = io.open(config["sysproto"], "w+")
+fh:write(read_file("sysarg"))
+fh:write(read_file("sysdcl"))
+for _, v in pairs(compat_options) do
+ fh:write(read_file(v["tmp"]))
+ fh:write(read_file(v["dcltmp"]))
+end
+fh:write(read_file("sysaue"))
+fh:write(read_file("sysprotoend"))
+fh:close()
+
+write_line("systrace", read_file("systracetmp"))
+write_line("systrace", read_file("systraceret"))
+
+cleanup()
Index: tools/build/Makefile
===================================================================
--- tools/build/Makefile
+++ tools/build/Makefile
@@ -121,7 +121,8 @@
# and cross-tools stages. We do this here using mkdir since mtree may not exist
# yet (this happens if we are crossbuilding from Linux/Mac).
installdirs:
-.for _dir in bin usr/lib usr/include usr/include/casper lib/geom lib/casper
+.for _dir in bin usr/lib usr/libexec usr/include usr/include/casper lib/geom \
+ lib/casper
mkdir -p "${DESTDIR}/${_dir}"
.endfor
# Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 21, 11:45 PM (17 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27125026
Default Alt Text
D21775.id62518.diff (82 KB)

Event Timeline