Blog Netscape
Running Netscape Navigator 4.08 Natively on FreeBSD 15.1
Netscape Navigator 4.08 for FreeBSD is an i386 QMAGIC a.out executable. Its
first instruction is at virtual address 0x1020, its text mapping begins at
0x1000, and it enters the kernel with the historical lcall $7,0 system-call
gate. Those details describe an executable and kernel interface that predates
ELF and the native amd64 syscall convention.
The objective was to run the unmodified binary on FreeBSD 15.1/amd64 through FreeBSD's native a.out and FreeBSD32 paths. Linuxulator, binary translation, CPU emulation, and nested virtual machines were excluded. All builds and tests ran on a dedicated FreeBSD 15.1-RELEASE-p2 VM.
QMAGIC, 0x1000, and 0x1020
The hexadecimal prefix 0x means that an address is written in base 16.
0x1000 is 4096 in decimal, or one 4 KiB page. 0x1020 is 32 bytes later.
Before ELF became the standard Unix executable format, BSD systems used
a.out. An a.out file starts with a fixed header describing the machine type,
entry address, and sizes of the text, data, and BSS regions:
- text contains executable machine code and read-only data;
- data contains initialized writable variables;
- BSS reserves zero-initialized writable memory that does not need to be stored in the file.
QMAGIC is the compact demand-paged variant of a.out, identified by magic value
0314 in octal. A “magic” value is a fixed signature in a file header that
tells the kernel which format parser to use. “Demand-paged” means the kernel
maps file pages into the process and loads them as they are accessed instead of
copying the complete program into memory at exec time.
For QMAGIC, file offset zero—including the 32-byte a.out header—is mapped at
virtual address 0x1000. Navigator's actual machine code begins immediately
after that header, so the calculation is:
mapping base 0x1000
header size + 0x20
------
entry point 0x1020
The entry point is the address where the kernel starts the CPU after building the new process. The mapping starts one page above address zero, while the first 32 bytes at that mapping still contain the file header rather than code.
Restoring QMAGIC activation
The first failure occurred before userspace. In exec_aout_imgact(), the
kernel called exec_map_stack() while the process still referenced the amd64
ELF system vector. The resulting stack geometry was incompatible with the
a.out address space, and activation failed with ENOMEM.
The process field p_sysent points to a system vector: kernel metadata that
selects the process's syscall table and ABI-specific address-space rules. The
fix sets it to aout_sysvec before constructing the stack. It also saves and
restores the previous system vector if stack construction returns a recoverable
error:
old_sysent = imgp->proc->p_sysent;
imgp->proc->p_sysent = &aout_sysvec;
error = exec_map_stack(imgp);
if (error != 0) {
imgp->proc->p_sysent = old_sysent;
return (error);
}
With that ordering corrected, execution reached Navigator's entry point.
Enabling the native syscall gate
The next apparent blocker was this seven-byte x86 instruction:
lcall $7, $0
lcall means “far call.” Unlike an ordinary call, which changes only the
instruction pointer, a far call also selects a code segment. Here, selector 7
historically referred to an i386 descriptor-table call gate leading from user
mode into the FreeBSD kernel; the offset is zero. It does not mean “call
normal userspace address 7” or “jump to address zero.” The processor also puts
a far return instruction pointer and code-segment selector on the stack.
The calling convention around that gate passes the syscall number in EAX and
the syscall arguments as 32-bit words on the user stack. A simplified call
looks like this:
push argument N ... argument 1
put syscall number in EAX
lcall $7, $0
This differs from a native modern amd64 syscall, where the program executes
syscall, places the syscall number in RAX, and places the first six
arguments in registers RDI, RSI, RDX, R10, R8, and R9.
There is one important compatibility detail: modern FreeBSD's 32-bit
int $0x80 path still reads 32-bit arguments from the user stack. The
historical selector-7 frame has two extra words—the far return address and code
selector—before those arguments. Under COMPAT_43, FreeBSD 15.1 recognizes
that frame, removes the two extra words, and then passes it to the common
FreeBSD32 stack-argument reader. System-call results return in EAX; the carry
flag distinguishes success from an errno result for this ABI.
FreeBSD 15.1 already contains this selector-7 handling in its amd64 FreeBSD32
syscall path, but it is compiled only under COMPAT_43. That option was absent
from the running GENERIC kernel. A small NETSCAPE kernel configuration
therefore included GENERIC and added:
options COMPAT_43
GENERIC already supplied COMPAT_FREEBSD32. After booting the resulting
kernel, selector-7 frame conversion, stack arguments, carry flag, and errno
behavior were handled by the kernel. The diagnostic ntrace supervisor
reported zero gate patches, confirming that it was not providing syscall
translation.
Reproducing a.out memory semantics
Navigator's crt0—the startup code that runs before the browser's main
function—successfully opened /usr/libexec/ld.so and mapped it at a
kernel-selected high address, with text beginning at 0x20625000. An early
trace had treated that placement as invalid. Disassembly and mapping data
showed a different cause: the fault at 0x206340f0 was an instruction fetch
from the linker's readable and writable, but non-executable, data page. The
linker's PLT (Procedure Linkage Table) contains small stubs for dynamic function
calls; its code is position-relative and can run at the high address.
Historical a.out objects expect readable mappings to be executable. The mmap
and mprotect paths were changed to add PROT_EXEC when PROT_READ is present,
but only when the process system vector is marked SV_AOUT. Explicit
PROT_MAX values are adjusted consistently. Ordinary ELF32 behavior and
kern.elf32.read_exec remain unchanged.
One additional mapping issue appeared after the linker began loading libc. An
anonymous mmap—memory not backed by a file—landed at 0x74e000, directly above
Navigator's BSS. The following brk(0x74f000) request to grow the process heap
failed because the mapping occupied that address. For SV_AOUT processes only,
zero-address anonymous mappings now use the existing post-heap placement path.
Linker work mappings moved high, while the low heap remained available.
Staging the historical runtime
The original binaries were not patched. A disposable runtime tree contained:
- the recovered QMAGIC
ld.soandlibc.so.3.1from FreeBSD compat22; - a.out XFree86 3.3.5 libraries;
libg++.so.4.0,libstdc++.so.2.0, andlibm.so.2.0, added only after the linker named each missing soname;- historical X locale data and bitmap fonts.
The library search path was absolute and restricted to the two recovered runtime directories:
LD_LIBRARY_PATH=/var/tmp/netscape-runtime/compat22:\
/var/tmp/netscape-runtime/x11
The browser initially reached its license dialog but faulted during subsequent
GUI construction. Its output identified missing Helvetica and Courier bitmap
fonts. Checksum-verified Xfnts.tgz and Xf100.tgz from the FreeBSD 3.4
XFree86 distribution supplied the required font directories to a dummy X
server.
Verification
The accepted kernel was FreeBSD 15.1-RELEASE-p2 with both COMPAT_43 and
COMPAT_FREEBSD32 present in its embedded configuration. Representative
Navigator mappings were:
0x00001000-0x00625000 r-x navigator-4.08.bin
0x00625000-0x0070e000 rwx navigator-4.08.bin
0x20625000-0x20634000 r-x /usr/libexec/ld.so
0x20634000-0x20636000 rwx /usr/libexec/ld.so
0x207ca000-0x20828000 r-x libc.so.3.1
An ordinary ELF32 negative control mapped a page read/write, changed it to
read-only, and attempted to execute it in a child. The child received
SIGSEGV, proving that read-implies-execute had not leaked into ELF32 policy.
Navigator then ran directly, without ntrace:
- A local
file:page rendered in an X window. - Three consecutive launches rendered a page served on
127.0.0.1:18080; each produced oneGET /acceptance.html HTTP/1.0. - A final run exercised the GUI's File -> Exit action and returned status 0 without adding a kernel warning.
The browser ran as an unprivileged user with a disposable profile. Java and
JavaScript were disabled, no plugin or external-helper runtime was supplied,
X11 TCP listening was disabled, and the VM had no public default route.
security.bsd.map_at_zero remained 0.
The resulting compatibility change consists of three narrowly scoped pieces:
correct a.out stack initialization, the existing COMPAT_43 syscall gate, and
SV_AOUT-specific virtual-memory semantics. The original Navigator, dynamic
linker, libc, and X libraries execute unmodified through FreeBSD's native
a.out/FreeBSD32 path.