Commit Graph
18 Commits
Author SHA1 Message Date
atharvranjan a1744a2754 Integrate PR #282 file streams with the combined runtime registry
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 22:05:58 -06:00
atharvranjan c18f9ffa7f Integrate PR #281 with existing startup and argument services
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 22:04:16 -06:00
atharvranjan f9d5838091 Integrate PR #277 with the combined typed runtime services
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 21:59:43 -06:00
atharvranjan 4173a781af Integrate PR #273 and regenerate the combined runtime registry
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 21:58:48 -06:00
zachdoxsee 52e7e3808d Merge task/400-standard-output (with upstream main) into task/402-crt-files
Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:57:12 +01:00
zachdoxsee 464393e02a Merge upstream main into task/400-standard-output
Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:56:59 +01:00
zachdoxsee aae04a2956 Merge upstream main into task/392-program-arguments
Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:56:51 +01:00
zachdoxsee 721073169c Merge upstream main into task/388-must-exist-stubs
Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:56:51 +01:00
zachdoxsee e81382de37 Merge upstream main into task/382-crt-startup
Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:56:51 +01:00
zachdoxsee 1c8d7a40de loader: add files for a hosted C program: fopen, fclose, fgets and perror (#402)
A program built with the mingw-w64 runtime imports fopen, fclose, fgets
and perror, and writes to the stream fopen returns with fprintf, fwrite
and fputs. The four did not resolve, and the output functions accepted
only stdout and stderr.

Adds the four services and file streams for the output functions. The
files are the ones on the in-memory C: drive behind CreateFileW, so a
file written through a C stream is the file ReadFile reads. Text mode,
the default, translates line ends as the fopen documentation describes.

Built on the standard streams from #400. Part of Gate A2.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:49:52 +01:00
zachdoxsee afe8d16d9e loader: add standard output and printf formatting for a hosted C program (#400)
A program built with the mingw-w64 runtime prints through
__stdio_common_vfprintf on the stream __acrt_iob_func(1) returns, and
through fwrite, fputs, fflush and setvbuf. None resolved, and there was
nowhere for standard output to go that a host or a test could read.

Adds a formatting engine for the narrow printf family (d, i, u, o, x, X,
c, s, p and %% with their flags, width, precision and size prefixes), the
three standard streams, those six services, and capture of stdout and
stderr through ServicesState. Floating-point and wide conversions, a
locale, files and input are not modelled and stop the guest.

The engine is compared with the host C library's snprintf on 2,600
generated cases whose result ISO C defines.

Part of Gate A2.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 01:25:20 +01:00
zachdoxsee 32251af4c8 loader: add program arguments for a hosted C program (#392)
A program built with the mingw-w64 runtime gets argc, argv and envp for
main from __p___argc, __p___argv, __p__environ, _configure_narrow_argv
and _initialize_narrow_environment. None resolved, so the loader refused
the program before its entry point, and a host could not say what the
program's arguments are.

The five services are added to the typed registry, and
ServicesState::set_program_arguments lets a host supply argv. The
environment table is empty.

Part of Gate A2.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 23:40:27 +01:00
zachdoxsee 007ad360e9 loader: add VirtualProtect, VirtualQuery and __C_specific_handler as stubs (#388)
A program built with the mingw-w64 runtime imports all three and does not
call them on a normal run. Without them the loader refused the program
before its entry point.

They are declared stub in the typed registry. A call stops the guest with
the runtime-limit fault and writes nothing, so a program that needs one
stops there and cannot run on with a made-up result.

Part of Gate A2.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 23:30:09 +01:00
zachdoxsee 64a0cb1596 loader: add nine C runtime startup services a hosted C program imports (#382)
A program built with the mingw-w64 runtime imports _set_app_type,
_set_new_mode, _configthreadlocale, __setusermatherr,
_set_invalid_parameter_handler, __p__fmode, __p__commode, signal and
SetUnhandledExceptionFilter, and memcpy through
api-ms-win-crt-private-l1-1-0.dll. None resolved, so the loader refused
the program before its entry point.

Each service records what it is given and returns what its public
documentation says. Nothing acts on a recorded value yet, so all nine
are declared partial in the typed registry.

Part of Gate A2.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 23:14:10 +01:00
jelly013 c1ca4ea140 runtime: fix timed waits, continued runs and budget accounting
Let a wait whose deadline has passed time out instead of taking a later
signal. Keep the main thread's pending wait, with its objects and deadline,
when a run that stopped on its budget continues from the same context. Count
every call that ends a turn, and neither sleep nor report a deadlock with a
spent budget.

Retry blocked threads again when one of them ends in the pass, so that a
thread waiting for it is not reported as deadlocked or timed out. Refuse to
open an ended main thread by its ID. Test that a second scheduler cannot
attach while one runs.

Addresses review of #339.
Refs #323

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
2026-11-24 19:34:59 +01:00
jelly013 84866956b9 runtime: add a deterministic guest thread scheduler
Run guest threads on one host thread with independent CPU contexts, guarded
stacks and TEBs, in first-in, first-out order with bounded turns that end at
translated-block boundaries. Add CreateThread, ExitThread, TerminateThread,
GetExitCodeThread, SuspendThread, ResumeThread and SwitchToThread, and let
waits on threads, events, semaphores and mutexes block only the caller.
Report deadlocks, abandoned mutexes and per-thread faults.

Reclaim per-thread state at thread end without passing held locks to a thread
that reuses the TEB address, and bound pending one-time initializations.
Guest threads never run concurrently. Critical sections, SRW locks,
condition variables and Sleep do not block per thread yet.

Verify with C programs compiled for x86-64 Windows and run as translated
guest code at several quanta.

Refs #323

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
2026-11-24 17:47:01 +01:00
Adeeb Rahman 1d0b0d1547 Generate documented ordinal aliases for typed runtime services
Signed-off-by: Adeeb Rahman <therealabeeb@icloud.com>
2026-11-24 08:18:16 -05:00
jelly013 280cd492fe runtime: one import resolver and typed service adapters
Parse import directories with one bounded parser shared by the static probe
and the binder, and resolve imports through one registry lookup. Refuse
conflicting registrations, keep ordinals apart from names, match API sets
exactly, and bind only when every import resolves.

Generate typed Win64 adapters, metadata and a coverage report from a
declarative service registry. Pass floating-point arguments and results in
XMM registers, and stop the guest if a service changes a nonvolatile
register. Make unimplemented generated wrappers fail explicitly.

Verify 20 services by calling them from translated guest code through bound
import slots, and the parser on damaged tables.

Refs #201, #270

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
2026-11-24 13:29:40 +01:00