Explorar el Código

Add a Linux SDL3 host harness for the browser

The browser only needs the small SYS_* ABI, so host/ now implements it
for Linux: the same ucmd_lib.h wrappers dispatch to host files, BSD
sockets behind uhttp/TLS, fork/exec plus a pipe tty for the curl __serve
helpers, and an SDL3 window (native Wayland here).  The ring-3 allocator
is reused over an mmap arena, keeping heap_reset() behaviour.

make browser-host builds browser-host and host-curl without touching the
target images.  --headless --wait N --shot out.ppm writes the RGB565
canvas as a PPM for the compatibility ladder.  Host sockets replace the
NebOS TCP stack, so the WM and kernel drivers are not exercised.
Johannes Zellner hace 6 días
padre
commit
e762867916
Se han modificado 22 ficheros con 2191 adiciones y 0 borrados
  1. 3 0
      .gitignore
  2. 10 0
      AGENTS.md
  3. 78 0
      Makefile
  4. 3 0
      docs/development.html
  5. 22 0
      host/curl_main.c
  6. 239 0
      host/fs.c
  7. 18 0
      host/fs.h
  8. 46 0
      host/heap.c
  9. 79 0
      host/host.c
  10. 25 0
      host/host.h
  11. 9 0
      host/include/ucmd_heap.h
  12. 92 0
      host/main.c
  13. 237 0
      host/net.c
  14. 15 0
      host/net.h
  15. 149 0
      host/proc.c
  16. 10 0
      host/proc.h
  17. 343 0
      host/syscall.c
  18. 137 0
      host/window.c
  19. 54 0
      host/window.h
  20. 152 0
      host/window_headless.c
  21. 461 0
      host/window_sdl3.c
  22. 9 0
      ucmd_lib.h

+ 3 - 0
.gitignore

@@ -34,4 +34,7 @@ chat_login_test
 chat-test-out/
 wpa_test
 wifi_store_test
+host/build/
+browser-host
+host-curl
 firmware/

+ 10 - 0
AGENTS.md

@@ -68,6 +68,7 @@ make run-uefi   # boot usb-efi.img under OVMF (x86-64 UEFI; serial log in /tmp/o
 make test-uefi  # headless OVMF boot test (greps the serial log for the boot line)
 make test-install # installer test: clone, reinstall, install self, /data, BIOS/UEFI boot
 make rootfs     # build cmds.img (the 8 MB rootfs partition image)
+make browser-host # Linux SDL3 host harness (browser-host + host-curl); dev-only
 make nowm       # diagnostic kernel with no WM; the boot console stays visible
 make dev        # serial kernel + rootfs reload (KXE2)
 make kernel-dev # serial kernel-only reload (keeps the running rootfs)
@@ -94,6 +95,15 @@ make clean
 
 - Build flags (in `Makefile`): `-m32 -march=i586 -ffreestanding -fno-pie -nostdlib
   -fno-stack-protector -mno-sse -mno-sse2 -mno-mmx -O2`.
+- `make browser-host` is a development-only harness, not part of the images: it
+  builds `browser.c`, ngui, the image/TLS stack and QuickJS as a 32-bit Linux
+  program against the same `SYS_*` ABI (`host/syscall.c`, an SDL3 window,
+  host files/sockets and `fork/exec` for `curl __serve`).  Run
+  `./browser-host [--size WxH] [--root DIR] URL|FILE`, or
+  `./browser-host --headless --wait 3000 --shot out.ppm URL` to render the
+  compat ladder without a display.  It needs the multilib `lib32-sdl3`,
+  `lib32-wayland` and `lib32-libxkbcommon`; host sockets replace the NebOS TCP
+  stack and the kernel/WM paths are not exercised.
 - QEMU guests default to 512 MB (`QEMU_MEM`, e.g. `make run QEMU_MEM=1G`),
   matching `MM_MAX_PHYS` in `phys.h`; all run and UEFI targets pass `-m`.
 - The command pack is the system rootfs: `cmds.pack` (NBPAK1), gzip-compressed

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 78 - 0
Makefile


+ 3 - 0
docs/development.html

@@ -191,6 +191,7 @@
 					<tr><td><code>make test-chat</code></td><td>Host tests (ASan/UBSan) for the chat client's JSON parser, cookie jar and the OIDC login page/reply/config parsers.</td></tr>
 					<tr><td><code>make test-chat-e2e</code></td><td>Boots QEMU with an NE2000 on slirp, starts <code>tools/mock_chat.py</code> and drives <code>chat</code> through QMP: native login, send, live poll, read marker, older paging, browse/join, new DM, saved-session resume and sign-out.  <code>CHAT_E2E=--totp|--consent|--passkey|--wrong</code> runs a login variant.</td></tr>
 					<tr><td><code>make compat-serve</code></td><td>Serve the browser compatibility ladder from <code>testdata/browser/compat/</code> on port 8000 for the board or QEMU guest.</td></tr>
+					<tr><td><code>make browser-host</code></td><td>Build the Linux SDL3 development harness (<code>browser-host</code> and its <code>host-curl</code> helper). It implements the ring-3 <code>SYS_*</code> ABI with host files, BSD sockets, <code>fork/exec</code> and an SDL3 window, so pages render and accept input without QEMU. Run <code>./browser-host [--size WxH] [--root DIR] URL|FILE</code>; <code>--headless --wait 3000 --shot out.ppm</code> writes the canvas without a display. Needs the 32-bit SDL3/Wayland libraries (<code>lib32-sdl3</code>, <code>lib32-wayland</code>, <code>lib32-libxkbcommon</code>).</td></tr>
 					<tr><td><code>make fonts</code></td><td>Regenerate the checked-in Arimo/Liberation Mono subsets with <code>pyftsubset</code>.</td></tr>
 				</tbody>
 			</table>
@@ -297,6 +298,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 			<li><strong>Touchpad gestures.</strong> <code>make test-touchpad</code> feeds synthetic contact frames to <span class="file">touchpad_gesture.c</span> and checks one/two-finger taps, the corner and physical-button mapping, scroll start/direction, pointer freeze and re-anchoring, and the option switches.</li>
 			<li><strong>Chat client.</strong> <code>make test-chat</code> covers the pure modules on the host.  <code>tools/mock_chat.py</code> is a two-origin mock of Cloudron Chat (port 18080) and the Cloudron OIDC login (18081) with <code>test</code>, <code>totp</code> (code 123456), <code>passkey</code> and <code>consent</code> accounts (password <code>test</code>) and <code>/debug/state</code>, <code>/debug/inject</code> endpoints; run it alone and enter <code>http://10.0.2.2:18080</code> in a QEMU guest's chat, or let <code>make test-chat-e2e</code> drive it.  Screenshots land in <code>chat-test-out/</code>.</li>
 			<li><strong>Browser compatibility.</strong> <code>make compat-serve</code> serves the numbered A/B ladder in <code>testdata/browser/compat/</code>. Open the index on the board (or at <code>http://10.0.2.2:8000/</code> from a QEMU guest with user networking) and compare each pair; the index table records the current status.</li>
+			<li><strong>Host browser harness.</strong> <code>make browser-host</code> builds the real browser, ngui, image/TLS code and QuickJS as a 32-bit Linux program against the same <code>SYS_*</code> ABI. <code>./browser-host testdata/browser/compat/010-block-width.html</code> opens an SDL3 window (native Wayland on this desktop); the address bar, wheel, links and keys use the normal browser paths. <code>./browser-host --headless --wait 3000 --shot /tmp/opencode/page.ppm URL</code> renders without a display for scripts and screenshots. The harness uses host sockets rather than the NebOS TCP stack, and an <code>mmap</code> arena with the ring-3 allocator, so it tests browser/HTML/CSS/JS/image/font/TLS logic rather than drivers.</li>
 			<li><strong>UEFI.</strong> <code>make test-uefi</code> boots the dual image under OVMF headless and greps the serial log for the boot line.</li>
 			<li><strong>Compositor stats.</strong> The ring-3 WM overwrites <code>/share/wmstats</code> every two seconds with <code>frames</code>, total and worst compositing time in milliseconds, and the pixels drawn in the interval. Read it in a terminal or fetch it over WebDAV to measure a target.</li>
 		</ul>
@@ -369,6 +371,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 			<li><code>Makefile</code> — targets and image rules</li>
 			<li><code>libc/</code>, <code>libc.a</code> — optional ring-3 libc and its host test</li>
 			<li><code>third_party/quickjs/</code> (see its <code>VENDOR</code>), <code>js_mu.c/h</code>, <code>js_browser.c/h</code> — vendored JavaScript engine, its MuJS-style stack API and the browser bindings; <code>js_test.c</code> host tests</li>
+			<li><code>host/</code> — Linux SDL3 browser harness: <code>syscall.c</code> implements the <code>SYS_*</code> ABI, <code>window_sdl3.c</code> the Wayland window/input, <code>fs.c</code>/<code>net.c</code>/<code>proc.c</code> the host file, socket and <code>curl __serve</code> services, and <code>window_headless.c</code> the screenshot mode; <span class="file">ucmd_lib.h</span> selects the host prototypes with <code>UCMD_HOST</code></li>
 			<li><code>ufont.c</code>, <code>ufont_ttf.c</code>, <code>fonts/</code> — UI font engine and subsets; <code>ufont_test.c</code> host test</li>
 			<li><code>kexec.c</code>, <code>kexec_send.c</code> — serial reload</li>
 			<li><code>netkexec.c</code>, <code>netkexec_send.c</code> — network reload</li>

+ 22 - 0
host/curl_main.c

@@ -0,0 +1,22 @@
+/* host-curl: the browser's __serve helper, built for Linux. */
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "host.h"
+
+extern void curl_start(const char *arg);
+
+int main(int argc, char **argv)
+{
+	const char *root = getenv("NEBOS_HOST_ROOT");
+
+	memset(&host_opts, 0, sizeof(host_opts));
+	host_opts.headless = 1;
+	if (host_runtime_init(argv[0], root) != 0)
+		return 1;
+	signal(SIGPIPE, SIG_IGN);
+	curl_start(argc > 1 && argv[1] ? argv[1] : "");
+	return 0;
+}

+ 239 - 0
host/fs.c

@@ -0,0 +1,239 @@
+/* Guest path mapping and the small file service behind SYS_*_FILE. */
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "host.h"
+#include "fs.h"
+#include "syscall.h"
+
+static int mkdir_p(const char *path)
+{
+	char tmp[HOST_PATH_MAX];
+	size_t n;
+	size_t i;
+
+	n = strlen(path);
+	if (n == 0 || n >= sizeof(tmp))
+		return -1;
+	memcpy(tmp, path, n + 1);
+	if (tmp[n - 1] == '/')
+		tmp[n - 1] = '\0';
+	for (i = 1; tmp[i]; i++) {
+		if (tmp[i] != '/')
+			continue;
+		tmp[i] = '\0';
+		if (mkdir(tmp, 0755) != 0 && errno != EEXIST)
+			return -1;
+		tmp[i] = '/';
+	}
+	if (mkdir(tmp, 0755) != 0 && errno != EEXIST)
+		return -1;
+	return 0;
+}
+
+static int prefix(const char *path, const char *p)
+{
+	size_t n = strlen(p);
+
+	return strncmp(path, p, n) == 0 &&
+	       (path[n] == '\0' || path[n] == '/');
+}
+
+int host_guest_to_host(const char *guest, char *out, size_t cap)
+{
+	if (!guest || !guest[0])
+		return -1;
+	if (guest[0] != '/') {
+		/* Relative paths resolve against the harness cwd, like a
+		 * normal Linux program. */
+		snprintf(out, cap, "%s", guest);
+		return 0;
+	}
+	if (prefix(guest, "/ramfs") || prefix(guest, "/share") ||
+	    prefix(guest, "/data")) {
+		int n = snprintf(out, cap, "%s%s", host_root, guest);
+
+		return (n > 0 && (size_t)n < cap) ? 0 : -1;
+	}
+	/* Any other absolute path is a real host path (testdata pages,
+	 * /tmp files) and is passed through unchanged. */
+	snprintf(out, cap, "%s", guest);
+	return 0;
+}
+
+int host_fs_init(const char *root)
+{
+	char path[HOST_PATH_MAX];
+	char fonts[HOST_PATH_MAX];
+	char link[HOST_PATH_MAX];
+
+	if (mkdir_p(root) != 0)
+		return -1;
+	snprintf(path, sizeof(path), "%s/share", root);
+	if (mkdir_p(path) != 0)
+		return -1;
+	snprintf(path, sizeof(path), "%s/data", root);
+	if (mkdir_p(path) != 0)
+		return -1;
+	snprintf(path, sizeof(path), "%s/ramfs", root);
+	if (mkdir_p(path) != 0)
+		return -1;
+
+	snprintf(fonts, sizeof(fonts), "%s/fonts", host_repo);
+	if (access(fonts, R_OK) != 0) {
+		char cwd[HOST_PATH_MAX];
+
+		if (getcwd(cwd, sizeof(cwd)))
+			snprintf(fonts, sizeof(fonts), "%s/fonts", cwd);
+	}
+	snprintf(link, sizeof(link), "%s/ramfs/fonts", root);
+	if (access(fonts, R_OK) == 0) {
+		struct stat st;
+
+		if (lstat(link, &st) != 0)
+			symlink(fonts, link);
+	}
+	return 0;
+}
+
+int host_fs_stat(const char *path, unsigned int *size, unsigned int *is_dir)
+{
+	char host[HOST_PATH_MAX];
+	struct stat st;
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	if (stat(host, &st) != 0)
+		return -1;
+	if (size)
+		*size = (unsigned int)st.st_size;
+	if (is_dir)
+		*is_dir = S_ISDIR(st.st_mode) ? 1u : 0u;
+	return 0;
+}
+
+int host_fs_read(const char *path, void *buf, unsigned int max)
+{
+	char host[HOST_PATH_MAX];
+	unsigned char *p = (unsigned char *)buf;
+	unsigned int done = 0;
+	int fd;
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	fd = open(host, O_RDONLY);
+	if (fd < 0)
+		return -1;
+	while (done < max) {
+		ssize_t n = read(fd, p + done, max - done);
+
+		if (n < 0) {
+			if (errno == EINTR)
+				continue;
+			close(fd);
+			return -1;
+		}
+		if (n == 0)
+			break;
+		done += (unsigned int)n;
+	}
+	close(fd);
+	return (int)done;
+}
+
+int host_fs_write(const char *path, const void *buf, unsigned int len)
+{
+	char host[HOST_PATH_MAX];
+	const unsigned char *p = (const unsigned char *)buf;
+	unsigned int done = 0;
+	int fd;
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	fd = open(host, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+	if (fd < 0)
+		return -1;
+	while (done < len) {
+		ssize_t n = write(fd, p + done, len - done);
+
+		if (n < 0) {
+			if (errno == EINTR)
+				continue;
+			close(fd);
+			return -1;
+		}
+		if (n == 0)
+			break;
+		done += (unsigned int)n;
+	}
+	close(fd);
+	return done == len ? 0 : -1;
+}
+
+int host_fs_unlink(const char *path)
+{
+	char host[HOST_PATH_MAX];
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	return unlink(host) == 0 ? 0 : -1;
+}
+
+int host_fs_mkdir(const char *path)
+{
+	char host[HOST_PATH_MAX];
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	return mkdir(host, 0755) == 0 ? 0 : -1;
+}
+
+int host_fs_rmdir(const char *path)
+{
+	char host[HOST_PATH_MAX];
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	return rmdir(host) == 0 ? 0 : -1;
+}
+
+int host_fs_list(const char *path, unsigned int index, void *out)
+{
+	char host[HOST_PATH_MAX];
+	struct sys_dirent *de = (struct sys_dirent *)out;
+	struct dirent *d;
+	DIR *dir;
+	unsigned int n = 0;
+
+	if (host_guest_to_host(path, host, sizeof(host)) != 0)
+		return -1;
+	dir = opendir(host);
+	if (!dir)
+		return -1;
+	while ((d = readdir(dir)) != 0) {
+		char full[HOST_PATH_MAX];
+		struct stat st;
+
+		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
+			continue;
+		if (n++ != index)
+			continue;
+		memset(de, 0, sizeof(*de));
+		snprintf(de->name, sizeof(de->name), "%s", d->d_name);
+		snprintf(full, sizeof(full), "%s/%s", host, d->d_name);
+		if (stat(full, &st) == 0) {
+			de->size = (unsigned int)st.st_size;
+			de->is_dir = S_ISDIR(st.st_mode) ? 1u : 0u;
+		}
+		closedir(dir);
+		return 1;
+	}
+	closedir(dir);
+	return 0;
+}

+ 18 - 0
host/fs.h

@@ -0,0 +1,18 @@
+#ifndef HOST_FS_H
+#define HOST_FS_H
+
+#include <stddef.h>
+
+#define HOST_PATH_MAX 1024
+
+int host_fs_init(const char *root);
+int host_guest_to_host(const char *guest, char *out, size_t cap);
+int host_fs_stat(const char *path, unsigned int *size, unsigned int *is_dir);
+int host_fs_read(const char *path, void *buf, unsigned int max);
+int host_fs_write(const char *path, const void *buf, unsigned int len);
+int host_fs_unlink(const char *path);
+int host_fs_mkdir(const char *path);
+int host_fs_rmdir(const char *path);
+int host_fs_list(const char *path, unsigned int index, void *dirent);
+
+#endif

+ 46 - 0
host/heap.c

@@ -0,0 +1,46 @@
+/* mmap backing for the ring-3 allocator reused by the host browser.
+ *
+ * libc/malloc.c reserves a 64 MB arena (its HEAP_MAX_BYTES) and grows it in
+ * place; reserve the whole range PROT_NONE up front so the grow is a
+ * mprotect and the arena can never move. */
+#include <stddef.h>
+#include <sys/mman.h>
+
+#define HOST_ARENA_BYTES (64u * 1024u * 1024u)
+
+static unsigned char *base;
+
+void *__heap_map(unsigned int bytes)
+{
+	if (base || bytes == 0 || bytes > HOST_ARENA_BYTES)
+		return 0;
+	base = (unsigned char *)mmap(0, HOST_ARENA_BYTES, PROT_NONE,
+				     MAP_PRIVATE | MAP_ANONYMOUS |
+				     MAP_NORESERVE, -1, 0);
+	if (base == MAP_FAILED) {
+		base = 0;
+		return 0;
+	}
+	if (mprotect(base, bytes, PROT_READ | PROT_WRITE) != 0) {
+		munmap(base, HOST_ARENA_BYTES);
+		base = 0;
+		return 0;
+	}
+	return base;
+}
+
+int __heap_grow(unsigned int total_bytes)
+{
+	if (!base || total_bytes > HOST_ARENA_BYTES)
+		return -1;
+	return mprotect(base, total_bytes, PROT_READ | PROT_WRITE) == 0 ?
+	       0 : -1;
+}
+
+void __heap_unmap(void)
+{
+	if (base) {
+		munmap(base, HOST_ARENA_BYTES);
+		base = 0;
+	}
+}

+ 79 - 0
host/host.c

@@ -0,0 +1,79 @@
+/* Shared runtime setup for browser-host and host-curl. */
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "host.h"
+#include "fs.h"
+
+struct host_options host_opts;
+char host_root[1024];
+char host_repo[1024];
+char host_curl_bin[1024];
+
+static void dirname_in_place(char *p)
+{
+	char *slash = strrchr(p, '/');
+
+	if (!slash) {
+		strcpy(p, ".");
+		return;
+	}
+	if (slash == p)
+		slash[1] = '\0';
+	else
+		*slash = '\0';
+}
+
+static void exe_dir(char *out, size_t cap, const char *argv0)
+{
+	ssize_t n = readlink("/proc/self/exe", out, cap - 1);
+
+	if (n > 0) {
+		out[n] = '\0';
+		dirname_in_place(out);
+		return;
+	}
+	if (argv0 && argv0[0]) {
+		snprintf(out, cap, "%s", argv0);
+		dirname_in_place(out);
+		return;
+	}
+	out[0] = '\0';
+}
+
+int host_runtime_init(const char *argv0, const char *root)
+{
+	const char *env_root = getenv("NEBOS_HOST_ROOT");
+	const char *env_curl = getenv("NEBOS_HOST_CURL");
+	char exe[1024];
+
+	if (!root || !root[0])
+		root = env_root && env_root[0] ? env_root :
+			"/tmp/opencode/nebos-browser-root";
+	snprintf(host_root, sizeof(host_root), "%s", root);
+	/* Drop a trailing slash except for "/". */
+	if (strlen(host_root) > 1 && host_root[strlen(host_root) - 1] == '/')
+		host_root[strlen(host_root) - 1] = '\0';
+
+	exe_dir(exe, sizeof(exe), argv0);
+	snprintf(host_repo, sizeof(host_repo), "%s", exe);
+
+	if (env_curl && env_curl[0])
+		snprintf(host_curl_bin, sizeof(host_curl_bin), "%s", env_curl);
+	else
+		snprintf(host_curl_bin, sizeof(host_curl_bin), "%s/host-curl",
+			 exe);
+
+	setenv("NEBOS_HOST_ROOT", host_root, 1);
+	setenv("NEBOS_HOST_CURL", host_curl_bin, 1);
+
+	if (host_fs_init(host_root) != 0) {
+		fprintf(stderr, "browser-host: cannot create profile root %s\n",
+			host_root);
+		return -1;
+	}
+	return 0;
+}

+ 25 - 0
host/host.h

@@ -0,0 +1,25 @@
+/* Shared state for the Linux browser harness. */
+#ifndef HOST_HOST_H
+#define HOST_HOST_H
+
+#include <stddef.h>
+
+struct host_options {
+	const char *root;
+	const char *shot;
+	unsigned int wait_ms;
+	int headless;
+	int width;
+	int height;
+};
+
+extern struct host_options host_opts;
+extern char host_root[1024];
+extern char host_repo[1024];
+extern char host_curl_bin[1024];
+
+/* Resolve the repo directory from /proc/self/exe, publish the profile root
+ * and create its /share, /data and /ramfs/fonts layout. */
+int host_runtime_init(const char *argv0, const char *root);
+
+#endif

+ 9 - 0
host/include/ucmd_heap.h

@@ -0,0 +1,9 @@
+/* Host copy of the ring-3 heap extension header.  The real one lives in
+ * libc/include/; the host build uses the system headers, so this keeps the
+ * single declaration available without shadowing libc. */
+#ifndef LIBC_UCMD_HEAP_H
+#define LIBC_UCMD_HEAP_H
+
+void heap_reset(void);
+
+#endif

+ 92 - 0
host/main.c

@@ -0,0 +1,92 @@
+/* browser-host: run the NebOS browser as a Linux/Wayland program.
+ *
+ * Usage: browser-host [--size WxH] [--root DIR] [--headless]
+ *                     [--wait MS] [--shot FILE] [URL|FILE]
+ */
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "host.h"
+
+extern void browser_start(const char *arg);
+
+static void usage(void)
+{
+	fprintf(stderr,
+		"usage: browser-host [--size WxH] [--root DIR] [--headless]\n"
+		"                    [--wait MS] [--shot|--screenshot FILE]\n"
+		"                    [URL|FILE]\n");
+}
+
+static int parse_size(const char *s, int *w, int *h)
+{
+	char *end;
+
+	*w = (int)strtol(s, &end, 10);
+	if (end == s || (*end != 'x' && *end != 'X'))
+		return -1;
+	s = end + 1;
+	*h = (int)strtol(s, &end, 10);
+	if (end == s || *end)
+		return -1;
+	return (*w > 0 && *h > 0) ? 0 : -1;
+}
+
+int main(int argc, char **argv)
+{
+	char argbuf[4096];
+	unsigned int arglen = 0;
+	const char *root = 0;
+	int i;
+
+	memset(&host_opts, 0, sizeof(host_opts));
+	host_opts.wait_ms = 4000;
+	argbuf[0] = '\0';
+
+	for (i = 1; i < argc; i++) {
+		const char *a = argv[i];
+
+		if (!strcmp(a, "--size") && i + 1 < argc) {
+			if (parse_size(argv[++i], &host_opts.width,
+				       &host_opts.height) != 0) {
+				usage();
+				return 1;
+			}
+		} else if (!strcmp(a, "--root") && i + 1 < argc) {
+			root = argv[++i];
+		} else if (!strcmp(a, "--headless")) {
+			host_opts.headless = 1;
+		} else if (!strcmp(a, "--wait") && i + 1 < argc) {
+			host_opts.wait_ms = (unsigned int)strtoul(argv[++i],
+								 0, 10);
+		} else if (!strcmp(a, "--shot") && i + 1 < argc) {
+			host_opts.shot = argv[++i];
+		} else if (!strcmp(a, "--screenshot") && i + 1 < argc) {
+			host_opts.shot = argv[++i];
+		} else if (!strcmp(a, "--help") || !strcmp(a, "-h")) {
+			usage();
+			return 0;
+		} else {
+			size_t n = strlen(a);
+
+			if (arglen && arglen + 1 < sizeof(argbuf))
+				argbuf[arglen++] = ' ';
+			if (arglen + n >= sizeof(argbuf))
+				n = sizeof(argbuf) - arglen - 1;
+			memcpy(argbuf + arglen, a, n);
+			arglen += (unsigned int)n;
+			argbuf[arglen] = '\0';
+		}
+	}
+	if (host_opts.headless && !host_opts.shot)
+		host_opts.shot = "/tmp/opencode/browser.ppm";
+
+	if (host_runtime_init(argv[0], root) != 0)
+		return 1;
+	signal(SIGPIPE, SIG_IGN);
+
+	browser_start(argbuf[0] ? argbuf : 0);
+	return 0;
+}

+ 237 - 0
host/net.c

@@ -0,0 +1,237 @@
+/* Host BSD-socket backend for the shared uhttp/TLS client. */
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <poll.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "net.h"
+
+static int tcp_fd = -1;
+
+static int ms_left(unsigned long long deadline)
+{
+	unsigned long long now = 0;
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	now = (unsigned long long)ts.tv_sec * 1000ull +
+	      (unsigned long long)ts.tv_nsec / 1000000ull;
+	if (now >= deadline)
+		return 0;
+	return (int)(deadline - now);
+}
+
+static unsigned long long deadline_ms(unsigned int timeout_ms)
+{
+	struct timespec ts;
+	unsigned long long now;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	now = (unsigned long long)ts.tv_sec * 1000ull +
+	      (unsigned long long)ts.tv_nsec / 1000000ull;
+	return now + timeout_ms;
+}
+
+int host_net_dns(const char *name, unsigned char ip[4])
+{
+	struct addrinfo hints;
+	struct addrinfo *res = 0;
+	int rv;
+
+	if (!name || !name[0])
+		return -1;
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_INET;
+	hints.ai_socktype = SOCK_STREAM;
+	rv = getaddrinfo(name, 0, &hints, &res);
+	if (rv != 0 || !res)
+		return -1;
+	memcpy(ip, &((struct sockaddr_in *)res->ai_addr)->sin_addr, 4);
+	freeaddrinfo(res);
+	return 0;
+}
+
+int host_net_connect(const unsigned char mac[6], const unsigned char ip[4],
+		     unsigned int port)
+{
+	struct sockaddr_in sa;
+	int fd;
+	int flags;
+	int rv;
+	int err = 0;
+	socklen_t elen = sizeof(err);
+
+	(void)mac;
+	host_net_close();
+	fd = socket(AF_INET, SOCK_STREAM, 0);
+	if (fd < 0)
+		return -3;
+	memset(&sa, 0, sizeof(sa));
+	sa.sin_family = AF_INET;
+	memcpy(&sa.sin_addr, ip, 4);
+	sa.sin_port = htons((unsigned short)port);
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags >= 0)
+		fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+
+	rv = connect(fd, (struct sockaddr *)&sa, sizeof(sa));
+	if (rv != 0 && errno != EINPROGRESS) {
+		int e = errno;
+
+		close(fd);
+		return e == ECONNREFUSED ? -2 : -3;
+	}
+	if (rv != 0) {
+		struct pollfd pfd;
+
+		pfd.fd = fd;
+		pfd.events = POLLOUT;
+		pfd.revents = 0;
+		do {
+			rv = poll(&pfd, 1, 5000);
+		} while (rv < 0 && errno == EINTR);
+		if (rv == 0) {
+			close(fd);
+			return -1;
+		}
+		if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &err, &elen) != 0)
+			err = errno;
+		if (err != 0) {
+			close(fd);
+			if (err == ECONNREFUSED)
+				return -2;
+			if (err == ETIMEDOUT)
+				return -1;
+			return -3;
+		}
+	}
+	{
+		int one = 1;
+		setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
+	}
+	tcp_fd = fd;
+	return 0;
+}
+
+int host_net_send(const void *buf, unsigned int len)
+{
+	const unsigned char *p = (const unsigned char *)buf;
+	unsigned int done = 0;
+
+	if (tcp_fd < 0)
+		return -3;
+	while (done < len) {
+		ssize_t n = send(tcp_fd, p + done, len - done, MSG_NOSIGNAL);
+
+		if (n < 0) {
+			if (errno == EINTR)
+				continue;
+			if (errno == EAGAIN || errno == EWOULDBLOCK) {
+				struct pollfd pfd;
+				int rv;
+
+				pfd.fd = tcp_fd;
+				pfd.events = POLLOUT;
+				pfd.revents = 0;
+				do {
+					rv = poll(&pfd, 1, 5000);
+				} while (rv < 0 && errno == EINTR);
+				if (rv <= 0)
+					return -1;
+				continue;
+			}
+			return (errno == EPIPE || errno == ECONNRESET) ? -2 : -3;
+		}
+		if (n == 0)
+			return -3;
+		done += (unsigned int)n;
+	}
+	return 0;
+}
+
+int host_net_recv(void *buf, unsigned int max, unsigned int timeout_ms)
+{
+	unsigned long long deadline = deadline_ms(timeout_ms);
+
+	if (tcp_fd < 0)
+		return -2;
+	if (max == 0)
+		return 0;
+	for (;;) {
+		struct pollfd pfd;
+		int left = ms_left(deadline);
+		int rv;
+
+		pfd.fd = tcp_fd;
+		pfd.events = POLLIN;
+		pfd.revents = 0;
+		rv = poll(&pfd, 1, left);
+		if (rv < 0) {
+			if (errno == EINTR)
+				continue;
+			return -2;
+		}
+		if (rv == 0)
+			return -1;
+		{
+			ssize_t n = recv(tcp_fd, buf, max, 0);
+
+			if (n > 0)
+				return (int)n;
+			if (n == 0)
+				return 0;
+			if (errno == EINTR)
+				continue;
+			if (errno == EAGAIN || errno == EWOULDBLOCK)
+				continue;
+			return -2;
+		}
+	}
+}
+
+void host_net_close(void)
+{
+	if (tcp_fd >= 0) {
+		close(tcp_fd);
+		tcp_fd = -1;
+	}
+}
+
+int host_net_peer_mss(void)
+{
+	int mss = 0;
+	socklen_t len = sizeof(mss);
+
+	if (tcp_fd >= 0 &&
+	    getsockopt(tcp_fd, IPPROTO_TCP, TCP_MAXSEG, &mss, &len) == 0 &&
+	    mss > 0)
+		return mss;
+	return 1460;
+}
+
+void host_net_info(struct sys_netinfo *out)
+{
+	memset(out, 0, sizeof(*out));
+	out->present = 1;
+	out->link = 1;
+	out->mac[0] = 0x02;
+	out->mac[5] = 0x01;
+	out->ip[0] = 127;
+	out->ip[3] = 1;
+	out->mask[0] = 255;
+	out->mask[1] = 255;
+	out->mask[2] = 255;
+	out->mask[3] = 255;
+	out->dns[0] = 127;
+	out->dns[3] = 1;
+	snprintf(out->name, sizeof(out->name), "host");
+	snprintf(out->chip, sizeof(out->chip), "linux");
+}

+ 15 - 0
host/net.h

@@ -0,0 +1,15 @@
+#ifndef HOST_NET_H
+#define HOST_NET_H
+
+#include "syscall.h"
+
+int host_net_dns(const char *name, unsigned char ip[4]);
+int host_net_connect(const unsigned char mac[6], const unsigned char ip[4],
+		     unsigned int port);
+int host_net_send(const void *buf, unsigned int len);
+int host_net_recv(void *buf, unsigned int max, unsigned int timeout_ms);
+void host_net_close(void);
+int host_net_peer_mss(void);
+void host_net_info(struct sys_netinfo *out);
+
+#endif

+ 149 - 0
host/proc.c

@@ -0,0 +1,149 @@
+/* Tiny process service: fake ttys for the browser's curl helpers. */
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/prctl.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
+#include "host.h"
+#include "fs.h"
+#include "proc.h"
+
+#define HOST_TTY_MAX 8
+
+struct host_tty {
+	int used;
+	int rfd;
+	int wfd;
+};
+
+static struct host_tty ttys[HOST_TTY_MAX];
+
+int host_tty_create(void)
+{
+	int i;
+	int fds[2];
+
+	for (i = 0; i < HOST_TTY_MAX; i++) {
+		if (ttys[i].used)
+			continue;
+		if (pipe2(fds, O_NONBLOCK | O_CLOEXEC) != 0)
+			return -1;
+		ttys[i].used = 1;
+		ttys[i].rfd = fds[0];
+		ttys[i].wfd = fds[1];
+		return i + 1;
+	}
+	return -1;
+}
+
+int host_tty_read(int id, char *buf, unsigned int max)
+{
+	ssize_t n;
+
+	if (id <= 0 || id > HOST_TTY_MAX)
+		return -1;
+	id--;
+	if (!ttys[id].used)
+		return -1;
+	n = read(ttys[id].rfd, buf, max);
+	if (n < 0)
+		return (errno == EAGAIN || errno == EWOULDBLOCK) ? 0 : -1;
+	return (int)n;
+}
+
+static const char *exec_path(const char *path, char *buf, size_t cap)
+{
+	if (!path || !path[0])
+		return 0;
+	if (!strcmp(path, "/ramfs/bin/curl") && host_curl_bin[0])
+		return host_curl_bin;
+	if (path[0] == '/') {
+		if (host_guest_to_host(path, buf, cap) != 0)
+			return 0;
+		if (access(buf, X_OK) == 0)
+			return buf;
+	}
+	if (access(path, X_OK) == 0)
+		return path;
+	return 0;
+}
+
+int host_spawn(const char *path, const char *arg, int tty, const char *cwd)
+{
+	char exe_buf[HOST_PATH_MAX];
+	char cwd_buf[HOST_PATH_MAX];
+	const char *exe;
+	const char *cwd_host = 0;
+	pid_t pid;
+
+	exe = exec_path(path, exe_buf, sizeof(exe_buf));
+	if (!exe) {
+		fprintf(stderr, "browser-host: cannot find helper %s\n", path);
+		return -1;
+	}
+	if (cwd && cwd[0] &&
+	    host_guest_to_host(cwd, cwd_buf, sizeof(cwd_buf)) == 0)
+		cwd_host = cwd_buf;
+
+	pid = fork();
+	if (pid < 0)
+		return -1;
+	if (pid == 0) {
+		prctl(PR_SET_PDEATHSIG, SIGKILL);
+		if (tty > 0 && tty <= HOST_TTY_MAX &&
+		    ttys[tty - 1].used) {
+			int wfd = ttys[tty - 1].wfd;
+
+			dup2(wfd, STDOUT_FILENO);
+			dup2(wfd, STDERR_FILENO);
+			close(ttys[tty - 1].rfd);
+			if (wfd > STDERR_FILENO)
+				close(wfd);
+		}
+		if (cwd_host)
+			chdir(cwd_host);
+		if (arg && arg[0]) {
+			char *const argv[] = { (char *)exe, (char *)arg, 0 };
+
+			execv(exe, argv);
+		} else {
+			char *const argv[] = { (char *)exe, 0 };
+
+			execv(exe, argv);
+		}
+		_exit(127);
+	}
+	return (int)pid;
+}
+
+int host_alive(unsigned int pid)
+{
+	int status;
+
+	if (pid == 0)
+		return 0;
+	for (;;) {
+		pid_t r = waitpid((pid_t)pid, &status, WNOHANG);
+
+		if (r == 0)
+			return 1;
+		if (r == (pid_t)pid)
+			return 0;
+		if (errno == EINTR)
+			continue;
+		return 0;
+	}
+}
+
+int host_kill(unsigned int pid)
+{
+	if (pid == 0)
+		return -1;
+	return kill((pid_t)pid, SIGKILL) == 0 ? 0 : -1;
+}

+ 10 - 0
host/proc.h

@@ -0,0 +1,10 @@
+#ifndef HOST_PROC_H
+#define HOST_PROC_H
+
+int host_tty_create(void);
+int host_tty_read(int id, char *buf, unsigned int max);
+int host_spawn(const char *path, const char *arg, int tty, const char *cwd);
+int host_alive(unsigned int pid);
+int host_kill(unsigned int pid);
+
+#endif

+ 343 - 0
host/syscall.c

@@ -0,0 +1,343 @@
+/* Host implementation of the tiny ring-3 syscall ABI.
+ *
+ * This is the whole "platform abstraction layer": the browser, ngui, uhttp
+ * and the image/font code keep calling u_syscall*(), but here they land in
+ * normal Linux calls instead of int 0x80. */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "host.h"
+#include "fs.h"
+#include "net.h"
+#include "proc.h"
+#include "syscall.h"
+#include "window.h"
+
+static void *argp(int a)
+{
+	return (void *)(uintptr_t)(unsigned int)a;
+}
+
+static unsigned int host_ticks(void)
+{
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	return (unsigned int)((unsigned long long)ts.tv_sec * 1000ull +
+			      (unsigned long long)ts.tv_nsec / 1000000ull);
+}
+
+static int rtc_now(struct sys_datetime *dt)
+{
+	time_t t = time(0);
+	struct tm tm;
+
+	if (!gmtime_r(&t, &tm))
+		return -1;
+	dt->year = (unsigned int)(tm.tm_year + 1900);
+	dt->month = (unsigned int)(tm.tm_mon + 1);
+	dt->day = (unsigned int)tm.tm_mday;
+	dt->hour = (unsigned int)tm.tm_hour;
+	dt->minute = (unsigned int)tm.tm_min;
+	dt->second = (unsigned int)tm.tm_sec;
+	dt->wday = (unsigned int)tm.tm_wday;
+	return 0;
+}
+
+static int unsupported(int num)
+{
+	fprintf(stderr, "browser-host: unsupported syscall %d\n", num);
+	return -1;
+}
+
+int u_syscall1(int num, int a1);
+int u_syscall3(int num, int a1, int a2, int a3);
+
+int u_syscall0(int num)
+{
+	return u_syscall1(num, 0);
+}
+
+int u_syscall1(int num, int a1)
+{
+	return u_syscall3(num, a1, 0, 0);
+}
+
+int u_syscall2(int num, int a1, int a2)
+{
+	return u_syscall3(num, a1, a2, 0);
+}
+
+int u_syscall3(int num, int a1, int a2, int a3)
+{
+	switch (num) {
+	case SYS_PUTSTR: {
+		const char *s = (const char *)argp(a1);
+
+		if (s)
+			fputs(s, stdout);
+		return 0;
+	}
+	case SYS_GET_TICKS_MS:
+		return (int)host_ticks();
+	case SYS_SLEEP_MS:
+		host_window_pump((unsigned int)a1);
+		return 0;
+	case SYS_EXIT:
+		fflush(stdout);
+		fflush(stderr);
+		exit(a1);
+		return 0;
+
+	case SYS_READ_FILE:
+		return host_fs_read((const char *)argp(a1), argp(a2),
+				    (unsigned int)a3);
+	case SYS_WRITE_FILE:
+		return host_fs_write((const char *)argp(a1), argp(a2),
+				     (unsigned int)a3);
+	case SYS_LIST_DIR:
+		return host_fs_list((const char *)argp(a1), (unsigned int)a2,
+				    argp(a3));
+	case SYS_UNLINK:
+		return host_fs_unlink((const char *)argp(a1));
+	case SYS_MKDIR:
+		return host_fs_mkdir((const char *)argp(a1));
+	case SYS_RMDIR:
+		return host_fs_rmdir((const char *)argp(a1));
+
+	case SYS_GETCWD: {
+		char *buf = (char *)argp(a1);
+
+		if (!buf || !a2)
+			return -1;
+		return getcwd(buf, (size_t)a2) ? 0 : -1;
+	}
+	case SYS_CHDIR: {
+		char host[HOST_PATH_MAX];
+
+		if (host_guest_to_host((const char *)argp(a1), host,
+				       sizeof(host)) != 0)
+			return -1;
+		return chdir(host) == 0 ? 0 : -1;
+	}
+	case SYS_FS_STAT: {
+		struct sys_stat *st = (struct sys_stat *)argp(a2);
+
+		if (!st)
+			return -1;
+		memset(st, 0, sizeof(*st));
+		if (host_fs_stat((const char *)argp(a1), &st->size,
+				 &st->is_dir) != 0)
+			return -1;
+		return 0;
+	}
+
+	case SYS_RTC_HMS: {
+		struct sys_time *out = (struct sys_time *)argp(a1);
+		struct sys_datetime dt;
+
+		if (!out || rtc_now(&dt) != 0)
+			return -1;
+		out->hour = dt.hour;
+		out->minute = dt.minute;
+		out->second = dt.second;
+		return 0;
+	}
+	case SYS_RTC_GET: {
+		struct sys_datetime *out = (struct sys_datetime *)argp(a1);
+
+		if (!out)
+			return -1;
+		return rtc_now(out);
+	}
+	case SYS_RTC_SET:
+		return -1;
+
+	case SYS_KEY_POLL:
+		return host_window_key();
+	case SYS_WIN_KEY_WAIT:
+		return host_window_key_wait((unsigned int)a1);
+
+	case SYS_WIN_CREATE: {
+		const struct win_create *in =
+			(const struct win_create *)argp(a1);
+		struct win_info *out = (struct win_info *)argp(a2);
+		int w, h;
+
+		if (!in || !out)
+			return -1;
+		w = host_opts.width ? host_opts.width : (int)in->w;
+		h = host_opts.height ? host_opts.height : (int)in->h;
+		if (w <= 0 || h <= 0)
+			return -1;
+		if (host_window_open((unsigned int)w, (unsigned int)h,
+				     in->title) != 0)
+			return -1;
+		out->fb = host_window_fb();
+		out->width = host_window_width();
+		out->height = host_window_height();
+		out->id = 1;
+		return 0;
+	}
+	case SYS_WIN_PRESENT:
+		host_window_present(0, 0, host_window_width(),
+				    host_window_height());
+		return 0;
+	case SYS_WIN_CLOSE:
+		host_window_close();
+		return 0;
+	case SYS_WIN_INFO: {
+		struct win_info *out = (struct win_info *)argp(a1);
+
+		if (!out || !host_window_fb())
+			return -1;
+		out->fb = host_window_fb();
+		out->width = host_window_width();
+		out->height = host_window_height();
+		out->id = 1;
+		return 0;
+	}
+	case SYS_WIN_ACK_RESIZE:
+		return 0;
+	case SYS_WIN_POINTER:
+		return host_window_pointer((struct win_pointer *)argp(a1));
+	case SYS_WIN_EVENT:
+		return host_window_event((struct win_event *)argp(a1));
+	case SYS_WIN_SCROLL:
+		return host_window_scroll((struct win_scroll *)argp(a1));
+	case SYS_WIN_RESIZE_SELF:
+		return -1;
+	case SYS_SCREEN_INFO: {
+		struct sys_screen *out = (struct sys_screen *)argp(a1);
+
+		if (!out)
+			return -1;
+		return host_window_screen(&out->width, &out->height);
+	}
+
+	case SYS_TTY_CREATE:
+		return host_tty_create();
+	case SYS_TTY_READ:
+		return host_tty_read(a1, (char *)argp(a2),
+				     (unsigned int)a3);
+	case SYS_SPAWN: {
+		const struct sys_spawn *sp =
+			(const struct sys_spawn *)argp(a1);
+
+		if (!sp)
+			return -1;
+		return host_spawn(sp->path, sp->arg, (int)sp->tty, sp->cwd);
+	}
+	case SYS_ALIVE:
+		return host_alive((unsigned int)a1);
+	case SYS_KILL:
+		return host_kill((unsigned int)a1);
+	case SYS_GETPID:
+		return (int)getpid();
+
+	case SYS_NET_INFO: {
+		struct sys_netinfo *out = (struct sys_netinfo *)argp(a1);
+
+		if (!out)
+			return 0;
+		host_net_info(out);
+		return 1;
+	}
+	case SYS_NET_CONFIGURED:
+		return 1;
+	case SYS_NET_ACQUIRE:
+	case SYS_NET_RELEASE:
+		return 0;
+	case SYS_NET_NEXT_HOP: {
+		const unsigned char *dst = (const unsigned char *)argp(a1);
+		unsigned char *hop = (unsigned char *)argp(a2);
+
+		if (dst && hop)
+			memcpy(hop, dst, 4);
+		return 0;
+	}
+	case SYS_NET_ARP: {
+		unsigned char *mac = (unsigned char *)argp(a2);
+
+		if (mac) {
+			mac[0] = 0x02;
+			mac[1] = mac[2] = mac[3] = mac[4] = 0;
+			mac[5] = 0x01;
+		}
+		return 0;
+	}
+	case SYS_DNS_RESOLVE:
+		return host_net_dns((const char *)argp(a1),
+				    (unsigned char *)argp(a2));
+	case SYS_TCP_CONNECT:
+		return host_net_connect((const unsigned char *)argp(a1),
+					(const unsigned char *)argp(a2),
+					(unsigned int)a3);
+	case SYS_TCP_PEER_MSS:
+		return host_net_peer_mss();
+	case SYS_TCP_SEND:
+		return host_net_send(argp(a1), (unsigned int)a2);
+	case SYS_TCP_RECV:
+		return host_net_recv(argp(a1), (unsigned int)a2,
+				     (unsigned int)a3);
+	case SYS_TCP_CLOSE:
+		host_net_close();
+		return 0;
+	case SYS_NET_GET_IP: {
+		unsigned char *ip = (unsigned char *)argp(a1);
+
+		if (ip) {
+			ip[0] = 127;
+			ip[1] = ip[2] = 0;
+			ip[3] = 1;
+		}
+		return 0;
+	}
+	case SYS_NET_GET_MASK: {
+		unsigned char *ip = (unsigned char *)argp(a1);
+
+		if (ip)
+			memset(ip, 0xFF, 4);
+		return 0;
+	}
+	case SYS_NET_GET_GW:
+	case SYS_NET_GET_DNS: {
+		unsigned char *ip = (unsigned char *)argp(a1);
+
+		if (ip) {
+			ip[0] = 127;
+			ip[1] = ip[2] = 0;
+			ip[3] = 1;
+		}
+		return 0;
+	}
+	case SYS_NET_MAC: {
+		unsigned char *mac = (unsigned char *)argp(a1);
+
+		if (mac) {
+			mac[0] = 0x02;
+			mac[1] = mac[2] = mac[3] = mac[4] = 0;
+			mac[5] = 0x01;
+		}
+		return 0;
+	}
+	case SYS_NET_PRINT_INFO:
+		fprintf(stderr, "browser-host: netdev host (linux)\n");
+		return 0;
+	case SYS_NETLOG: {
+		const char *s = (const char *)argp(a1);
+
+		if (s)
+			fprintf(stderr, "%s\n", s);
+		return 0;
+	}
+
+	default:
+		return unsupported(num);
+	}
+}

+ 137 - 0
host/window.c

@@ -0,0 +1,137 @@
+/* Backend selection for the host window. */
+#include <unistd.h>
+
+#include "host.h"
+#include "window.h"
+
+static int open;
+static int headless;
+
+int host_window_open(unsigned int w, unsigned int h, const char *title)
+{
+	int rv;
+
+	if (open) {
+		if ((unsigned int)host_window_width() == w &&
+		    (unsigned int)host_window_height() == h)
+			return 0;
+		return -1;
+	}
+	headless = host_opts.headless ? 1 : 0;
+	rv = headless ? host_headless_open(w, h, title) :
+			host_sdl_open(w, h, title);
+	if (rv == 0)
+		open = 1;
+	return rv;
+}
+
+void host_window_close(void)
+{
+	if (!open)
+		return;
+	if (headless)
+		host_headless_close();
+	else
+		host_sdl_close();
+	open = 0;
+}
+
+void *host_window_fb(void)
+{
+	if (!open)
+		return 0;
+	return headless ? host_headless_fb() : host_sdl_fb();
+}
+
+unsigned int host_window_width(void)
+{
+	if (!open)
+		return 0;
+	return headless ? host_headless_width() : host_sdl_width();
+}
+
+unsigned int host_window_height(void)
+{
+	if (!open)
+		return 0;
+	return headless ? host_headless_height() : host_sdl_height();
+}
+
+void host_window_present(int x, int y, unsigned int w, unsigned int h)
+{
+	(void)x;
+	(void)y;
+	(void)w;
+	(void)h;
+	if (!open)
+		return;
+	if (headless)
+		host_headless_present();
+	else
+		host_sdl_present();
+}
+
+void host_window_pump(unsigned int timeout_ms)
+{
+	if (!open) {
+		if (timeout_ms)
+			usleep(timeout_ms * 1000u);
+		return;
+	}
+	if (headless)
+		host_headless_pump(timeout_ms);
+	else
+		host_sdl_pump(timeout_ms);
+}
+
+int host_window_pointer(struct win_pointer *out)
+{
+	if (!open)
+		return -1;
+	return headless ? host_headless_pointer(out) : host_sdl_pointer(out);
+}
+
+int host_window_event(struct win_event *out)
+{
+	if (!open)
+		return 0;
+	return headless ? host_headless_event(out) : host_sdl_event(out);
+}
+
+int host_window_scroll(struct win_scroll *out)
+{
+	if (!open)
+		return 0;
+	return headless ? host_headless_scroll(out) : host_sdl_scroll(out);
+}
+
+int host_window_key(void)
+{
+	if (!open)
+		return 0;
+	return headless ? host_headless_key() : host_sdl_key();
+}
+
+int host_window_screen(unsigned int *w, unsigned int *h)
+{
+	if (!open)
+		return -1;
+	return headless ? host_headless_screen(w, h) : host_sdl_screen(w, h);
+}
+
+int host_window_key_wait(unsigned int timeout_ms)
+{
+	if (!open) {
+		host_window_pump(timeout_ms);
+		return 0;
+	}
+	return headless ? host_headless_key_wait(timeout_ms) :
+			 host_sdl_key_wait(timeout_ms);
+}
+
+const char *host_window_backend(void)
+{
+	if (!open)
+		return "none";
+	return headless ? host_headless_backend() : host_sdl_backend();
+}

+ 54 - 0
host/window.h

@@ -0,0 +1,54 @@
+/* Platform window backend for the host browser harness. */
+#ifndef HOST_WINDOW_H
+#define HOST_WINDOW_H
+
+#include "syscall.h"
+#include "wm_abi.h"
+
+int host_window_open(unsigned int w, unsigned int h, const char *title);
+void host_window_close(void);
+void *host_window_fb(void);
+unsigned int host_window_width(void);
+unsigned int host_window_height(void);
+void host_window_present(int x, int y, unsigned int w, unsigned int h);
+void host_window_pump(unsigned int timeout_ms);
+int host_window_pointer(struct win_pointer *out);
+int host_window_event(struct win_event *out);
+int host_window_scroll(struct win_scroll *out);
+int host_window_key(void);
+int host_window_screen(unsigned int *w, unsigned int *h);
+int host_window_key_wait(unsigned int timeout_ms);
+const char *host_window_backend(void);
+
+/* Active backend (window.c selects by host_opts.headless). */
+void host_sdl_close(void);
+int host_sdl_open(unsigned int w, unsigned int h, const char *title);
+void *host_sdl_fb(void);
+unsigned int host_sdl_width(void);
+unsigned int host_sdl_height(void);
+void host_sdl_present(void);
+void host_sdl_pump(unsigned int timeout_ms);
+int host_sdl_pointer(struct win_pointer *out);
+int host_sdl_event(struct win_event *out);
+int host_sdl_scroll(struct win_scroll *out);
+int host_sdl_key(void);
+int host_sdl_screen(unsigned int *w, unsigned int *h);
+int host_sdl_key_wait(unsigned int timeout_ms);
+const char *host_sdl_backend(void);
+
+void host_headless_close(void);
+int host_headless_open(unsigned int w, unsigned int h, const char *title);
+void *host_headless_fb(void);
+unsigned int host_headless_width(void);
+unsigned int host_headless_height(void);
+void host_headless_present(void);
+void host_headless_pump(unsigned int timeout_ms);
+int host_headless_pointer(struct win_pointer *out);
+int host_headless_event(struct win_event *out);
+int host_headless_scroll(struct win_scroll *out);
+int host_headless_key(void);
+int host_headless_screen(unsigned int *w, unsigned int *h);
+int host_headless_key_wait(unsigned int timeout_ms);
+const char *host_headless_backend(void);
+
+#endif

+ 152 - 0
host/window_headless.c

@@ -0,0 +1,152 @@
+/* Headless window backend: renders into the same RGB565 canvas and writes a
+ * PPM after the first present plus host_opts.wait_ms. */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "host.h"
+#include "window.h"
+
+static unsigned short *fb;
+static int win_w, win_h;
+static int presented;
+static unsigned long long first_present;
+
+static unsigned long long now_ms(void)
+{
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	return (unsigned long long)ts.tv_sec * 1000ull +
+	       (unsigned long long)ts.tv_nsec / 1000000ull;
+}
+
+static int write_ppm(const char *path)
+{
+	FILE *f;
+	int x, y;
+
+	if (!path || !path[0])
+		return -1;
+	f = fopen(path, "wb");
+	if (!f)
+		return -1;
+	fprintf(f, "P6\n%d %d\n255\n", win_w, win_h);
+	for (y = 0; y < win_h; y++) {
+		for (x = 0; x < win_w; x++) {
+			unsigned int v = fb[y * win_w + x];
+			unsigned char rgb[3];
+
+			rgb[0] = (unsigned char)(((v >> 11) & 31) * 255 / 31);
+			rgb[1] = (unsigned char)(((v >> 5) & 63) * 255 / 63);
+			rgb[2] = (unsigned char)((v & 31) * 255 / 31);
+			fwrite(rgb, 1, 3, f);
+		}
+	}
+	fclose(f);
+	fprintf(stderr, "browser-host: wrote %s (%dx%d)\n", path, win_w,
+		win_h);
+	return 0;
+}
+
+int host_headless_open(unsigned int w, unsigned int h, const char *title)
+{
+	(void)title;
+	fb = (unsigned short *)calloc((size_t)w * h, sizeof(unsigned short));
+	if (!fb)
+		return -1;
+	win_w = (int)w;
+	win_h = (int)h;
+	presented = 0;
+	first_present = 0;
+	return 0;
+}
+
+void host_headless_close(void)
+{
+	free(fb);
+	fb = 0;
+}
+
+void *host_headless_fb(void)
+{
+	return fb;
+}
+
+unsigned int host_headless_width(void)
+{
+	return (unsigned int)win_w;
+}
+
+unsigned int host_headless_height(void)
+{
+	return (unsigned int)win_h;
+}
+
+void host_headless_present(void)
+{
+	if (!presented) {
+		presented = 1;
+		first_present = now_ms();
+	}
+}
+
+void host_headless_pump(unsigned int timeout_ms)
+{
+	if (presented && host_opts.wait_ms) {
+		unsigned long long now = now_ms();
+
+		if (now - first_present >= host_opts.wait_ms) {
+			write_ppm(host_opts.shot);
+			fflush(stdout);
+			_exit(0);
+		}
+	}
+	if (timeout_ms)
+		usleep(timeout_ms * 1000u);
+}
+
+int host_headless_pointer(struct win_pointer *out)
+{
+	memset(out, 0, sizeof(*out));
+	out->focused = 1;
+	out->inside = 1;
+	return 0;
+}
+
+int host_headless_event(struct win_event *out)
+{
+	(void)out;
+	return 0;
+}
+
+int host_headless_scroll(struct win_scroll *out)
+{
+	(void)out;
+	return 0;
+}
+
+int host_headless_key(void)
+{
+	return 0;
+}
+
+int host_headless_screen(unsigned int *w, unsigned int *h)
+{
+	*w = (unsigned int)win_w;
+	*h = (unsigned int)win_h;
+	return 0;
+}
+
+int host_headless_key_wait(unsigned int timeout_ms)
+{
+	host_headless_pump(timeout_ms);
+	return 0;
+}
+
+const char *host_headless_backend(void)
+{
+	return "headless";
+}

+ 461 - 0
host/window_sdl3.c

@@ -0,0 +1,461 @@
+/* SDL3 window backend for the host browser harness.
+ *
+ * SDL3 selects the Wayland driver on this desktop (and falls back to X11 if
+ * it cannot connect); the browser still owns a plain RGB565 canvas and only
+ * sees the generic win_* ABI through host/syscall.c. */
+#include <SDL3/SDL.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "window.h"
+
+#define KEYQ_MAX 256
+#define EVQ_MAX  64
+
+static SDL_Window *win;
+static SDL_Renderer *ren;
+static SDL_Texture *tex;
+static unsigned short *fb;
+static int win_w, win_h;
+static int inited;
+static int focused;
+static int inside;
+static int close_sent;
+static int mouse_x, mouse_y;
+static unsigned mouse_buttons;
+static int scroll_x, scroll_y;
+static char backend[32] = "none";
+
+static int keyq[KEYQ_MAX];
+static unsigned int key_head, key_tail;
+static struct win_event evq[EVQ_MAX];
+static unsigned int ev_head, ev_tail;
+
+static void push_key(int k)
+{
+	unsigned int next = (key_head + 1) % KEYQ_MAX;
+
+	if (next == key_tail)
+		return;
+	keyq[key_head] = k;
+	key_head = next;
+}
+
+static int pop_key(void)
+{
+	int k;
+
+	if (key_tail == key_head)
+		return 0;
+	k = keyq[key_tail];
+	key_tail = (key_tail + 1) % KEYQ_MAX;
+	return k;
+}
+
+static void push_event(unsigned int type, int x, int y)
+{
+	unsigned int next = (ev_head + 1) % EVQ_MAX;
+	struct win_event *ev;
+
+	if (next == ev_tail)
+		return;
+	ev = &evq[ev_head];
+	ev->type = type;
+	ev->x = x;
+	ev->y = y;
+	ev->buttons = mouse_buttons;
+	ev_head = next;
+}
+
+static unsigned int neb_buttons(Uint32 state)
+{
+	unsigned int b = 0;
+
+	if (state & SDL_BUTTON_LMASK)
+		b |= 1;
+	if (state & SDL_BUTTON_RMASK)
+		b |= 2;
+	if (state & SDL_BUTTON_MMASK)
+		b |= 4;
+	return b;
+}
+
+static void set_mouse(float x, float y, Uint32 state)
+{
+	mouse_x = (int)x;
+	mouse_y = (int)y;
+	mouse_buttons = neb_buttons(state);
+	inside = mouse_x >= 0 && mouse_y >= 0 &&
+		 mouse_x < win_w && mouse_y < win_h;
+}
+
+static void key_down(const SDL_KeyboardEvent *e)
+{
+	SDL_Keycode k = e->key;
+	SDL_Keymod mod = e->mod;
+	int ctrl = (mod & SDL_KMOD_CTRL) != 0;
+
+	/* Ctrl+letter -> ASCII control code (Ctrl+L = 0x0C, Ctrl+R = 0x12). */
+	if (ctrl && k >= SDLK_A && k <= SDLK_Z) {
+		push_key((int)(k - SDLK_A + 1));
+		return;
+	}
+
+	switch (k) {
+	case SDLK_ESCAPE:
+		push_key(0x1B);
+		return;
+	case SDLK_BACKSPACE:
+		push_key(ctrl ? 0x10C : 0x08);
+		return;
+	case SDLK_TAB:
+		push_key(0x09);
+		return;
+	case SDLK_RETURN:
+	case SDLK_KP_ENTER:
+		push_key('\n');
+		return;
+	case SDLK_DELETE:
+		push_key(ctrl ? 0x10B : 0x108);
+		return;
+	case SDLK_LEFT:
+		push_key(ctrl ? 0x109 : 0x100);
+		return;
+	case SDLK_RIGHT:
+		push_key(ctrl ? 0x10A : 0x101);
+		return;
+	case SDLK_UP:
+		push_key(0x102);
+		return;
+	case SDLK_DOWN:
+		push_key(0x103);
+		return;
+	case SDLK_PAGEUP:
+		push_key(0x104);
+		return;
+	case SDLK_PAGEDOWN:
+		push_key(0x105);
+		return;
+	case SDLK_HOME:
+		push_key(0x106);
+		return;
+	case SDLK_END:
+		push_key(0x107);
+		return;
+	default:
+		break;
+	}
+	/* Printable characters arrive through SDL_EVENT_TEXT_INPUT, which
+	 * honours the keyboard layout and key repeat. */
+}
+
+static void text_utf8(const char *s)
+{
+	const unsigned char *p = (const unsigned char *)s;
+
+	while (p && *p) {
+		unsigned int cp;
+		int n;
+
+		if (*p < 0x80) {
+			cp = *p++;
+			n = 0;
+		} else if ((*p & 0xE0) == 0xC0) {
+			cp = *p++ & 0x1F;
+			n = 1;
+		} else if ((*p & 0xF0) == 0xE0) {
+			cp = *p++ & 0x0F;
+			n = 2;
+		} else if ((*p & 0xF8) == 0xF0) {
+			cp = *p++ & 0x07;
+			n = 3;
+		} else {
+			p++;
+			continue;
+		}
+		while (n-- > 0) {
+			if ((*p & 0xC0) != 0x80) {
+				cp = 0xFFFD;
+				break;
+			}
+			cp = (cp << 6) | (*p++ & 0x3F);
+		}
+		if (cp == '\r' || cp == '\n')
+			push_key('\n');
+		else if (cp >= 0x20 && cp <= 0xFF)
+			push_key((int)cp);
+		else if (cp > 0xFF)
+			push_key('?');
+	}
+}
+
+static void handle_event(SDL_Event *e)
+{
+	switch (e->type) {
+	case SDL_EVENT_QUIT:
+	case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
+		if (!close_sent) {
+			close_sent = 1;
+			push_key(0x1B);
+		}
+		break;
+	case SDL_EVENT_WINDOW_FOCUS_GAINED:
+		focused = 1;
+		break;
+	case SDL_EVENT_WINDOW_FOCUS_LOST:
+		focused = 0;
+		break;
+	case SDL_EVENT_WINDOW_MOUSE_ENTER:
+		inside = 1;
+		break;
+	case SDL_EVENT_WINDOW_MOUSE_LEAVE:
+		inside = 0;
+		break;
+	case SDL_EVENT_MOUSE_MOTION:
+		set_mouse(e->motion.x, e->motion.y, e->motion.state);
+		break;
+	case SDL_EVENT_MOUSE_BUTTON_DOWN:
+	case SDL_EVENT_MOUSE_BUTTON_UP: {
+		unsigned int bit = 0;
+
+		if (e->button.button == SDL_BUTTON_LEFT)
+			bit = 1;
+		else if (e->button.button == SDL_BUTTON_RIGHT)
+			bit = 2;
+		else if (e->button.button == SDL_BUTTON_MIDDLE)
+			bit = 4;
+		mouse_x = (int)e->button.x;
+		mouse_y = (int)e->button.y;
+		inside = mouse_x >= 0 && mouse_y >= 0 &&
+			 mouse_x < win_w && mouse_y < win_h;
+		if (bit) {
+			if (e->type == SDL_EVENT_MOUSE_BUTTON_DOWN)
+				mouse_buttons |= bit;
+			else
+				mouse_buttons &= ~bit;
+			push_event(e->type == SDL_EVENT_MOUSE_BUTTON_DOWN ?
+				   WIN_EV_POINTER_DOWN : WIN_EV_POINTER_UP,
+				   mouse_x, mouse_y);
+		}
+		break;
+	}
+	case SDL_EVENT_MOUSE_WHEEL:
+		/* SDL's y is positive away from the user; the browser wants
+		 * +dy = later content. */
+		scroll_x += (int)(-e->wheel.x * 48.0f);
+		scroll_y += (int)(-e->wheel.y * 48.0f);
+		break;
+	case SDL_EVENT_KEY_DOWN:
+		key_down(&e->key);
+		break;
+	case SDL_EVENT_TEXT_INPUT:
+		text_utf8(e->text.text);
+		break;
+	default:
+		break;
+	}
+}
+
+int host_sdl_open(unsigned int w, unsigned int h, const char *title)
+{
+	const char *drv;
+
+	if (inited)
+		return (win_w == (int)w && win_h == (int)h) ? 0 : -1;
+	if (!SDL_Init(SDL_INIT_VIDEO)) {
+		fprintf(stderr, "browser-host: SDL_Init: %s\n", SDL_GetError());
+		return -1;
+	}
+	drv = SDL_GetCurrentVideoDriver();
+	snprintf(backend, sizeof(backend), "%s", drv ? drv : "?");
+	win = SDL_CreateWindow(title ? title : "Browser", (int)w, (int)h, 0);
+	if (!win) {
+		fprintf(stderr, "browser-host: SDL_CreateWindow: %s\n",
+			SDL_GetError());
+		SDL_Quit();
+		return -1;
+	}
+	ren = SDL_CreateRenderer(win, 0);
+	if (!ren)
+		ren = SDL_CreateRenderer(win, "software");
+	if (!ren) {
+		fprintf(stderr, "browser-host: SDL_CreateRenderer: %s\n",
+			SDL_GetError());
+		SDL_DestroyWindow(win);
+		win = 0;
+		SDL_Quit();
+		return -1;
+	}
+	SDL_SetRenderVSync(ren, 0);
+	tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_RGB565,
+				SDL_TEXTUREACCESS_STREAMING, (int)w, (int)h);
+	if (!tex) {
+		fprintf(stderr, "browser-host: SDL_CreateTexture: %s\n",
+			SDL_GetError());
+		SDL_DestroyRenderer(ren);
+		ren = 0;
+		SDL_DestroyWindow(win);
+		win = 0;
+		SDL_Quit();
+		return -1;
+	}
+	SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST);
+	SDL_SetWindowResizable(win, false);
+	SDL_SetWindowMinimumSize(win, (int)w, (int)h);
+	SDL_SetWindowMaximumSize(win, (int)w, (int)h);
+	SDL_StartTextInput(win);
+
+	fb = (unsigned short *)calloc((size_t)w * h, sizeof(unsigned short));
+	if (!fb) {
+		SDL_DestroyTexture(tex);
+		tex = 0;
+		SDL_DestroyRenderer(ren);
+		ren = 0;
+		SDL_DestroyWindow(win);
+		win = 0;
+		SDL_Quit();
+		return -1;
+	}
+	win_w = (int)w;
+	win_h = (int)h;
+	focused = 1;
+	inside = 1;
+	inited = 1;
+	fprintf(stderr, "browser-host: video driver=%s window=%ux%u\n",
+		backend, w, h);
+	return 0;
+}
+
+void host_sdl_close(void)
+{
+	if (!inited)
+		return;
+	SDL_StopTextInput(win);
+	free(fb);
+	fb = 0;
+	SDL_DestroyTexture(tex);
+	tex = 0;
+	SDL_DestroyRenderer(ren);
+	ren = 0;
+	SDL_DestroyWindow(win);
+	win = 0;
+	SDL_Quit();
+	inited = 0;
+}
+
+void *host_sdl_fb(void)
+{
+	return fb;
+}
+
+unsigned int host_sdl_width(void)
+{
+	return (unsigned int)win_w;
+}
+
+unsigned int host_sdl_height(void)
+{
+	return (unsigned int)win_h;
+}
+
+void host_sdl_present(void)
+{
+	if (!inited || !tex)
+		return;
+	if (!SDL_UpdateTexture(tex, 0, fb, win_w * (int)sizeof(unsigned short)))
+		return;
+	SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
+	SDL_RenderClear(ren);
+	SDL_RenderTexture(ren, tex, 0, 0);
+	SDL_RenderPresent(ren);
+}
+
+void host_sdl_pump(unsigned int timeout_ms)
+{
+	SDL_Event e;
+
+	if (!inited) {
+		if (timeout_ms)
+			usleep(timeout_ms * 1000u);
+		return;
+	}
+	if (timeout_ms) {
+		if (SDL_WaitEventTimeout(&e, (Sint32)timeout_ms))
+			handle_event(&e);
+	} else {
+		SDL_PumpEvents();
+	}
+	while (SDL_PollEvent(&e))
+		handle_event(&e);
+}
+
+int host_sdl_pointer(struct win_pointer *out)
+{
+	SDL_WindowFlags flags;
+
+	if (!inited)
+		return -1;
+	flags = SDL_GetWindowFlags(win);
+	focused = (flags & SDL_WINDOW_INPUT_FOCUS) ? 1 : 0;
+	out->x = mouse_x;
+	out->y = mouse_y;
+	out->buttons = mouse_buttons;
+	out->inside = inside ? 1u : 0u;
+	out->focused = focused ? 1u : 0u;
+	return 0;
+}
+
+int host_sdl_event(struct win_event *out)
+{
+	if (ev_tail == ev_head)
+		return 0;
+	*out = evq[ev_tail];
+	ev_tail = (ev_tail + 1) % EVQ_MAX;
+	return 1;
+}
+
+int host_sdl_scroll(struct win_scroll *out)
+{
+	if (!scroll_x && !scroll_y)
+		return 0;
+	out->dx = scroll_x;
+	out->dy = scroll_y;
+	scroll_x = scroll_y = 0;
+	return 1;
+}
+
+int host_sdl_key(void)
+{
+	return pop_key();
+}
+
+int host_sdl_screen(unsigned int *w, unsigned int *h)
+{
+	SDL_Rect r;
+
+	if (SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &r)) {
+		*w = (unsigned int)r.w;
+		*h = (unsigned int)r.h;
+	} else {
+		*w = (unsigned int)win_w;
+		*h = (unsigned int)win_h;
+	}
+	return 0;
+}
+
+int host_sdl_key_wait(unsigned int timeout_ms)
+{
+	int k = pop_key();
+
+	if (k)
+		return k;
+	host_sdl_pump(timeout_ms);
+	return pop_key();
+}
+
+const char *host_sdl_backend(void)
+{
+	return backend;
+}

+ 9 - 0
ucmd_lib.h

@@ -6,6 +6,14 @@
 #include "syscall.h"
 #include "wm_abi.h"
 
+#ifdef UCMD_HOST
+/* The Linux host harness implements the same little syscall ABI in
+ * host/syscall.c; no ring transition is involved. */
+int u_syscall0(int num);
+int u_syscall1(int num, int a1);
+int u_syscall2(int num, int a1, int a2);
+int u_syscall3(int num, int a1, int a2, int a3);
+#else
 static inline int u_syscall1(int num, int a1)
 {
 	int ret;
@@ -45,6 +53,7 @@ static inline int u_syscall3(int num, int a1, int a2, int a3)
 			  : "memory");
 	return ret;
 }
+#endif /* !UCMD_HOST */
 
 static inline void u_putc(char c)
 {

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio