Windows (experimental)

--os=windows (or its other name --os=nt) writes a Windows x64 console executable (PE32+) from Pascal, C or Nil Python. It is EXPERIMENTAL, like every target except Linux.

./pxx --os=windows hello.pas hello.exe     # run it on Windows, or: wine64 hello.exe

The program imports kernel32.dll and ws2_32.dll (sockets), and only functions that every Windows since XP and Server 2003 exports, so it needs no C runtime (msvcrt or ucrt) and no installer. The few newer functions it uses are looked up when it starts, with a fallback for each one a system lacks (see below), so the same .exe is meant for Windows 8 and later, Windows 7, and ReactOS.

Older Windows and ReactOS

Newer function Missing on Stand-in
GetSystemTimePreciseAsFileTime Windows 7, ReactOS GetSystemTimeAsFileTime (a coarser wall clock)
QueryUnbiasedInterruptTime ReactOS QueryPerformanceCounter (also counts time asleep)
GetTickCount64 ReactOS GetTickCount (wraps after 49.7 days)
WaitOnAddress, WakeByAddress* Windows 7, ReactOS the waiting thread re-reads the word, yielding and then sleeping 1 ms

The translator's own lock is a spinlock, so SRW locks are not needed. The last fallback makes a contended lock or a thread join take up to a millisecond longer. Set PXX_WINABI_PRE8=1 to use every fallback on a newer system; make test-windows runs a few time, socket and thread tests that way under Wine.

Tested on ReactOS

The make test-windows programs were also run inside the ReactOS x64 nightly live CD (kernel "0.4.16-amd64-dev", Build 20260429, under qemu with no network adapter): 78 of 83 give the same output as on Linux. The harness is in tools/vm/reactos/: rossnap.sh boots the live CD once and saves a qemu snapshot, rosbatch.sh test... then runs a batch from it in about ten seconds plus the programs' own time. The translator works around three ReactOS behaviours:

The compiler itself builds for Windows (--os=windows compiler/compiler.pas) and works there: under Wine and inside ReactOS it compiled hello.pas to a Windows .exe that runs. A compiler built this way makes Windows programs by default (pascal26 hello.pas writes hello.exe; --os=linux still gives a Linux ELF), and --version reports host: x86-64 nt (NT, whichever system provides it: Windows, ReactOS or Wine). It finds lib/ and compiler/builtin/ (where winabi lives) the usual way: installed as <root>/compiler/pascal26.exe beside <root>/lib, or through PXX_HOME. It also compiles itself there: on 2026-11-15, under Wine, the Windows build compiled compiler/compiler.pas in 42 s to an .exe byte-identical to the one the Linux compiler makes with --os=windows. The guard that refuses an output naming an input also works there: g/sub/../t.pas and G/T.PAS (Windows names ignore case) both count as g/t.pas.

Known differences there:

How it works

The design is the same as the BSD targets (see FreeBSD and the BSDs). The runtime is written against the Linux system-call interface, and under --os=windows every system call goes to a small translator compiled into the program (compiler/builtin/winabi.pas). The translator answers it with kernel32 calls. Windows has no stable system-call numbers (they change between builds), so kernel32 is the bottom layer rather than the kernel.

Five things differ from the BSD ports:

What works

Each item is checked against the Linux build of the same test by make test-windows (run under Wine through tools/vm/wine.sh):

Windows has no fork, so the runtime's one spawn routine (PalBackendVforkAndExec3) passes the whole request to the translator, which calls CreateProcessW instead of forking and execing. The argument list is quoted so that the child's C runtime splits it back into the same strings. A program named without a path is looked up on PATH (separated by ;, with or without .exe), then by CreateProcessW itself. A child ended by kill reports that signal to wait, as on Linux. A C program's own fork() answers ENOSYS.

select, poll and epoll_wait check each fd, then wait in Winsock's select on the sockets among them, which wakes as soon as one is ready. Windows has no one call that also covers consoles and pipes, so when one of those is in the set the wait is cut to a few milliseconds and the check repeats.

Sockets keep Linux's defaults where Windows differs: an IPv6 socket also takes IPv4 (IPV6_V6ONLY off), a UDP socket ignores the ICMP "port unreachable" that Windows would report on the next receive, and an accepted socket does not inherit the listener's non-blocking mode. SO_REUSEADDR and SO_REUSEPORT are recorded but not passed on: Windows already lets a server rebind a port that is in TIME_WAIT, and its own SO_REUSEADDR would let a second socket take a port that is in use. socketpair is a connected pair of loopback TCP (or UDP) sockets.

Signals:

/proc has six files: /proc/self/environ, /proc/self/exe (the program's own file), /proc/self/fdinfo/N (the volume serial number as mnt_id and the file index as ino, which the compiler's output guard compares), /proc/mounts (one line per local drive, C: / ntfs rw 0 0, with the current drive on / and the others on D:/ and so on) and the aggregate cpu line of /proc/stat (GetSystemTimes), and /proc/net/dev (the interface names, every counter 0). Every other /proc path is ENOENT, also under Wine, whose drive Z: would otherwise show Linux's own /proc.

The runtime's DNS resolver reads /etc/hosts and /etc/resolv.conf. On Windows /etc/hosts is the system's own hosts file (<system directory>\drivers\etc\hosts), and /etc/resolv.conf is made up when it is opened: a nameserver line for each DNS server Windows is set to use, and a search line for its domain, from GetNetworkParams in iphlpapi.dll (loaded only then, so the image still imports kernel32 and ws2_32 alone).

Network interfaces (if_nameindex, if_nametoindex, getifaddrs) come from GetAdaptersAddresses, from the same DLL loaded the same way. They are IPv4 adapters only, as Linux's SIOCGIFCONF lists them. The runtime answers the Linux SIOCGIFCONF, SIOCGIFFLAGS, SIOCGIFADDR, SIOCGIFNETMASK, SIOCGIFBRDADDR, SIOCGIFINDEX and SIOCGIFNAME ioctls itself. A name is Windows' own (loopback_0, ethernet_32768, from ConvertInterfaceLuidToNameA). Where Windows has no such name (ReactOS and XP), a loopback is lo and any other adapter if<index>. ReactOS reports index 0 for its loopback, which would end if_nameindex's list, so such an adapter gets the next free index.

Paths are converted from UTF-8 to UTF-16, and / works as a separator. /dev/null becomes NUL. An absolute Unix path such as /tmp/x is taken on the current drive. Under Wine that is drive Z:, the Unix root, so the path means what it means on Linux.

Not supported yet

A system call the translator does not map returns ENOSYS. Set PXX_WINABI_TRACE=1 in the environment to have each one named on stderr.

The work log is in devdocs/progress/working/feature-port-windows-pe.md.