selfdb README

The project's README from github.com/fzakaria/selfdb. As one markdown file: README.md.

selfdb

SELF — the Structured Executable & Linkable Format: a program that is a SQLite database instead of an ELF file, and the machinery to actually run it on Linux/NixOS.

sqlelf (arXiv:2405.03883) put a SQL view over ELF. This project inverts it: the rows are the format, a binfmt_misc interpreter executes them, and nixpkgs/NixOS is the vehicle to run a real slice of a system on it.

$ file hello
hello: SQLite 3.x database, application id 0x53454c46, user version 1
$ ./hello
Hello, world!
$ sqlite3 hello 'SELECT soname FROM ldd'          # ldd, as a query
$ sqlite3 hello 'DELETE FROM sections; VACUUM'    # strip, as a transaction
$ ./hello                                         # still runs
Hello, world!

What's here

Read DESIGN.md; §13 tracks implementation status.

Try it

$ nix develop                        # dev shell (converter + loader + tools)
$ nix develop -c bash tests/all.sh   # run M0..M3b end to end
$ nix develop -c bash tests/showcase.sh
$ nix run .#self-vm                  # a NixOS VM where ./hello.self just runs
                                     # (login: root, empty password)

$ bash examples/server/build.sh ./server   # a website, inserted into a program
$ loader/self-exec ./server 8080           # http://localhost:8080

selfdb (fzakaria/selfdb)

Searching Database…

572 ·GitHub
这是什么?selfdb(SELF,Structured Executable & Linkable Format)让程序本身就是一个货真价实的 SQLite 数据库而不是 ELF 二进制,还附带在 Linux/NixOS 上真正执行这个数据库的加载器机制。
这是一个库,还是一个带自己工具链的文件格式?它是一种自定义可执行文件格式(用 SQLite 数据库中的行取代 ELF 节),配有转换器、运行它的内核 binfmt_misc 解释器,以及部署它的 Nix 打包。
我怎样尝试转换并运行一个 .self 文件?用 converter/ 里的 self CLI(或直接用 elf2self/self2elf)把 ELF 二进制转换成 .self SQLite 文件,然后依靠 loader/ 中的 self-exec binfmt_misc 解释器(通过 Nix 包/NixOS 模块安装)来执行它。
运行它需要 Nix 或 NixOS 吗?需要——这个项目围绕 nixpkgs/NixOS 构建:它提供 Nix 包、selfify 钩子和一个 NixOS 模块(programs.self),用于注册 binfmt 解释器并把真实的系统组件作为 .self 文件运行。
每种执行模式(memfd、native、selfld)都能完全正常工作吗?实现状态在设计文档中单独跟踪,这暗示三种加载器模式中有些比其他的完成度更高。
除了 Linux/NixOS 它还能在别处运行吗?不能,它依赖 Linux 的 binfmt_misc 机制以及用于打包和 NixOS 模块的 Nix 生态,因此只能在那些环境上运行。
self-httpd 是什么?examples/server/ 里的一个示例服务器,它的页面、程序和访问日志都放在同一个 .self 文件里:它把 argv[0] 当作数据库打开,从自己的路由表提供响应,因此编辑线上站点就是一个 SQL UPDATE。
为什么要把 ELF 反转成数据库,而不直接用 ELF?它的灵感来自 sqlelf(arXiv:2405.03883),后者在 ELF 之上套了一层 SQL 视图;selfdb 把这个想法反过来,让 SQL 行本身就是格式,再通过 binfmt_misc 解释器执行。
libself-audit.so 是做什么的?它是一个 LDAUDIT 库,让原版 glibc 能够加载 .self 共享库——通过 SQL 查询来解析符号,而不是普通的 ELF 动态链接。
格式本身定义在哪里?.self SQLite 模式的 DDL 在 schema/self.sql,由 selfconv/schema.py 生成。
What are similar projects?wcdb-key-tool, h2o, XRAG, PS2Recomp, ANE, Tinyhttpd, pwndbg, wikiskill
Creator
fzakaria
Size
0.1 MB
Stars
572
Updated
CommitSep 24
Age
1mo
Commits · 90 Days