initial commit

Signed-off-by: Aleksey Selihov <faumaray@gmail.com>
This commit is contained in:
faumaray committed 2026-05-22 02:40:32 +03:00
commit bba5c8a39a
109 files changed
+14085

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
# VoidLibC executable format (.vle)
# Registered with systemd-binfmt.service (reads /etc/binfmt.d/*.conf on boot).
#
# File extensions used by VoidLibC:
# .vle executable (run via voidloader, triggered by this binfmt rule)
# .vls shared library (loaded via voidlib_load / dlopen, not executed directly)
# .vla static archive (linked at build time via voidlink, not executed directly)
#
# Format: :name:type:offset:magic:mask:interpreter:flags
# M = magic-based detection (not extension-based)
# offset 0, magic = "VLC\0" (4 bytes: 0x56 0x4C 0x43 0x00)
# voidloader verifies the Executable flag in the container header;
# shared libraries and static archives are rejected.
:vlc:M:0:VLC\x00::/usr/local/bin/voidloader:
+101
View File
@@ -0,0 +1,101 @@
#!/usr/bin/env bash
# VoidLibC Linux installer.
# Installs voidlink + voidloader, then registers the .vle binfmt_misc entry.
# Must be run as root (or with sudo).
set -euo pipefail
INSTALL_BIN="${INSTALL_BIN:-/usr/local/bin}"
BINFMT_CONF_DIR="${BINFMT_CONF_DIR:-/etc/binfmt.d}"
MAGIC_DIR="${MAGIC_DIR:-/usr/share/file/magic}"
BINFMT_PROC="/proc/sys/fs/binfmt_misc"
BINFMT_ENTRY_NAME="vlc"
# --- Resolve build artifacts ---
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${BUILD_DIR:-${SCRIPT_DIR}/../../build}"
VOIDLOADER="${BUILD_DIR}/voidloader/voidloader"
VOIDLINK="${BUILD_DIR}/voidlink/voidlink"
if [[ ! -f "$VOIDLOADER" ]]; then
echo "error: voidloader not found at $VOIDLOADER" >&2
echo " Set BUILD_DIR to your cmake build directory." >&2
exit 1
fi
if [[ ! -f "$VOIDLINK" ]]; then
echo "error: voidlink not found at $VOIDLINK" >&2
echo " Set BUILD_DIR to your cmake build directory." >&2
exit 1
fi
# --- Install binaries ---
echo "Installing voidlink → ${INSTALL_BIN}/voidlink"
install -Dm755 "$VOIDLINK" "${INSTALL_BIN}/voidlink"
echo "Installing voidloader → ${INSTALL_BIN}/voidloader"
install -Dm755 "$VOIDLOADER" "${INSTALL_BIN}/voidloader"
# --- Register binfmt_misc ---
# 1. Persistent (systemd-binfmt.service reads /etc/binfmt.d on boot).
if [[ -d "$BINFMT_CONF_DIR" ]]; then
echo "Installing binfmt.d config → ${BINFMT_CONF_DIR}/vlc.conf"
install -Dm644 "${SCRIPT_DIR}/binfmt.d/vlc.conf" \
"${BINFMT_CONF_DIR}/vlc.conf"
# Substitute actual interpreter path in case it differs from the default.
sed -i "s|/usr/local/bin/voidloader|${INSTALL_BIN}/voidloader|g" \
"${BINFMT_CONF_DIR}/vlc.conf"
fi
# 2. Immediate (without needing a reboot or systemctl restart).
if [[ -d "$BINFMT_PROC" ]]; then
# Remove stale entry if present (ignore errors if not registered yet).
if [[ -f "${BINFMT_PROC}/${BINFMT_ENTRY_NAME}" ]]; then
echo "Removing stale binfmt_misc entry '${BINFMT_ENTRY_NAME}'"
echo -1 > "${BINFMT_PROC}/${BINFMT_ENTRY_NAME}" 2>/dev/null || true
fi
echo "Registering binfmt_misc entry '${BINFMT_ENTRY_NAME}'"
# Magic: V=0x56 L=0x4C C=0x43 \0=0x00 — null escaped as \x00.
printf ':vlc:M:0:VLC\x00::%s:\n' "${INSTALL_BIN}/voidloader" \
> "${BINFMT_PROC}/register"
echo " binfmt_misc: .vlc files will now execute via voidloader"
else
echo "warning: ${BINFMT_PROC} not mounted; binfmt_misc not active." >&2
echo " Run: mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc" >&2
echo " Then re-run this installer, or reboot after installing the binfmt.d config." >&2
fi
# --- Install file(1) magic database entry ---
if [[ -d "$MAGIC_DIR" ]]; then
echo "Installing file(1) magic definition → ${MAGIC_DIR}/vlc"
install -Dm644 "${SCRIPT_DIR}/magic/vlc.magic" "${MAGIC_DIR}/vlc"
# Recompile the system magic database so `file` picks it up.
# file -C -m DIR reads all magic sources from DIR and writes magic.mgc
# into the current working directory. We need to cd to the parent so
# the compiled database lands next to the magic/ directory where file(1)
# expects it.
if command -v file &>/dev/null; then
MAGIC_PARENT="$(dirname "$MAGIC_DIR")"
MAGIC_BASE="$(basename "$MAGIC_DIR")"
echo "Recompiling magic database in ${MAGIC_PARENT}..."
if ( cd "$MAGIC_PARENT" && file -C -m "$MAGIC_BASE" ) 2>/dev/null; then
echo " file(1) now recognizes VoidLibC files"
else
echo " warning: magic database recompile failed" >&2
echo " Try manually: cd ${MAGIC_PARENT} && sudo file -C -m ${MAGIC_BASE}" >&2
fi
fi
else
echo "warning: ${MAGIC_DIR} not found; file(1) magic not installed." >&2
echo " Install file(1) and re-run, or copy tools/vlc.magic manually." >&2
echo " System-wide: sudo cp tools/vlc.magic ${MAGIC_DIR}/vlc" >&2
echo " cd $(dirname '${MAGIC_DIR}') && sudo file -C -m $(basename '${MAGIC_DIR}')" >&2
fi
echo ""
echo "VoidLibC installed successfully."
echo " voidlink: ${INSTALL_BIN}/voidlink"
echo " voidloader: ${INSTALL_BIN}/voidloader"
echo ""
echo "Test: chmod +x hello.vle && ./hello.vle"
echo " voidlink dump hello.vls"
+29
View File
@@ -0,0 +1,29 @@
# magic(5) entry for VoidLibC container files.
#
# File extensions:
# .vle executable (bit 2 = Executable)
# .vls shared library (default when neither executable nor static)
# .vla static archive (bit 4 = StaticLibrary)
#
# Offset layout (FileHeader, packed, LE):
# 0 u32 magic = 0x00434C56
# 4 u16 version_major
# 6 u16 version_minor
# 8 u32 flags (bit 0=HasDebug, bit 1=HasCppExports, bit 2=Executable,
# bit 3=HasDynamicImports, bit 4=StaticLibrary)
# 12 u16 arch (1 = x86_64)
#
# Quick test: file -m vlc.magic <file>
# System-wide: sudo cp vlc.magic /usr/share/file/magic/vlc
# cd /usr/share/file && sudo file -C -m magic
0 lelong 0x00434C56 VoidLibC container
>4 leshort x \b v%d
>6 leshort x \b.%d
>12 leshort 1 \b, x86_64
>8 lelong &0x04 \b, executable
>8 lelong ^0x04 \b, shared library
>8 lelong &0x10 \b, static archive
>8 lelong &0x08 \b, dynamically linked
>8 lelong ^0x08 \b, statically linked
>8 lelong &0x01 \b, with debug
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Register the .vlc binfmt_misc entry for an already-installed voidloader.
# Use this after a source build instead of running the full installer.
# Requires root (or write access to /proc/sys/fs/binfmt_misc/register).
#
# Usage: sudo ./register_binfmt.sh [/path/to/voidloader]
set -euo pipefail
VOIDLOADER="${1:-/usr/local/bin/voidloader}"
BINFMT_PROC="/proc/sys/fs/binfmt_misc"
BINFMT_ENTRY_NAME="vlc"
if [[ ! -x "$VOIDLOADER" ]]; then
echo "error: voidloader not found or not executable: $VOIDLOADER" >&2
echo " Build it first (cmake --build build) or pass its path as an argument." >&2
exit 1
fi
if [[ ! -d "$BINFMT_PROC" ]]; then
echo "error: ${BINFMT_PROC} not found — is binfmt_misc mounted?" >&2
echo " Try: sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc" >&2
exit 1
fi
# Remove stale entry (ignore if not registered).
if [[ -f "${BINFMT_PROC}/${BINFMT_ENTRY_NAME}" ]]; then
echo "Removing stale binfmt_misc entry '${BINFMT_ENTRY_NAME}'"
echo -1 > "${BINFMT_PROC}/${BINFMT_ENTRY_NAME}"
fi
# Register: magic is V=0x56 L=0x4C C=0x43 \0=0x00.
printf ':vlc:M:0:VLC\x00::%s:\n' "$VOIDLOADER" > "${BINFMT_PROC}/register"
echo "Registered: .vlc files → ${VOIDLOADER}"
echo " Note: this registration is lost on reboot."
echo " For persistence: copy installer/linux/binfmt.d/vlc.conf to /etc/binfmt.d/"
echo " and run: sudo systemctl restart systemd-binfmt"
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# VoidLibC Linux uninstaller.
# Reverses install.sh: removes binaries and deregisters binfmt_misc.
# Must be run as root (or with sudo).
set -euo pipefail
INSTALL_BIN="${INSTALL_BIN:-/usr/local/bin}"
BINFMT_CONF_DIR="${BINFMT_CONF_DIR:-/etc/binfmt.d}"
MAGIC_DIR="${MAGIC_DIR:-/usr/share/file/magic}"
BINFMT_PROC="/proc/sys/fs/binfmt_misc"
BINFMT_ENTRY_NAME="vlc"
# --- Deregister binfmt_misc ---
if [[ -f "${BINFMT_PROC}/${BINFMT_ENTRY_NAME}" ]]; then
echo "Deregistering binfmt_misc entry '${BINFMT_ENTRY_NAME}'"
echo -1 > "${BINFMT_PROC}/${BINFMT_ENTRY_NAME}"
else
echo "(binfmt_misc entry '${BINFMT_ENTRY_NAME}' not active — skipping)"
fi
# --- Remove binfmt.d config ---
if [[ -f "${BINFMT_CONF_DIR}/vlc.conf" ]]; then
echo "Removing ${BINFMT_CONF_DIR}/vlc.conf"
rm -f "${BINFMT_CONF_DIR}/vlc.conf"
fi
# --- Remove binaries ---
for f in "${INSTALL_BIN}/voidlink" "${INSTALL_BIN}/voidloader"; do
if [[ -f "$f" ]]; then
echo "Removing $f"
rm -f "$f"
fi
done
# --- Remove file(1) magic entry ---
if [[ -f "${MAGIC_DIR}/vlc" ]]; then
echo "Removing ${MAGIC_DIR}/vlc"
rm -f "${MAGIC_DIR}/vlc"
if command -v file &>/dev/null; then
echo "Recompiling magic database..."
file -C -m "$MAGIC_DIR" 2>/dev/null || true
fi
fi
echo ""
echo "VoidLibC uninstalled."