Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions BUGS-TO-REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14135,3 +14135,58 @@ Severity: medium. A program that lays out its controls in `Form_Load` gets a bro

<!-- Reproducer: bugs/cef-move-before-ready/ (mode run, exe: exit 10 and the access violation, win32, BETA 1042, 2026-11-15; with both forms unmoved it exits 11). Not run as win64: only the win32 runtime was downloaded (owner's approval was for that one); the reproducer falls back to the package's default runtime folder, and uses %TEMP%\tb-cef when the runtime is there. The later calls' errors come from a scratch probe (Navigate and Unload raise -2147467259 under On Error Resume Next; DocumentTitle raises nothing; the Automation error box still shows). Found 2026-11-15 taking the CEF picture (shoot_docs setup cef): the fixture moved its control in Sub Main. Narrowed with a full-memory dump of the browser process, taken by running the exe under cdb -o on a private desktop. The fixture now places its control in its .tbform. docs/Reference/Built-In/CEF/CefBrowser/index.md (Lifecycle) carries a WARNING labelled BETA 1042 for it; when a fixed build is released, the WARNING goes. -->

---

## A `FastCall` Declare bound in the import table does not pass its arguments in registers, in a 32-bit build

**Describe the bug**
With **Runtime Binding Of DLL Declares** set to **No** (`project.dllRuntimeBinding: false`), a 32-bit build calls a `Declare` marked `FastCall` without its arguments in ECX and EDX, where a `__fastcall` routine reads them. The routine works on other values, and the program then ends with an access violation. The same project with run-time binding passes the arguments as it should. The IDE run of the probe (`[RunAfterBuild]`) is wrong too, and the compiler restarts after it. Observed with `tbrun` and `tbrun --exe`.

**To Reproduce**
Steps to reproduce the behavior:
1. Open `declare-fastcall-static-binding-32bit.twinproj` (attached as `declare-fastcall-static-binding-32bit.zip`). Its Settings set Runtime Binding Of DLL Declares to No, and its one source file, `Startup.twin`, is:
```
Module Startup

' RtlUlongByteSwap is __fastcall in the 32-bit ntdll.dll: it takes its argument in ECX and
' returns its bytes in the opposite order.
Private Declare PtrSafe Function RtlUlongByteSwap FastCall Lib "ntdll" (ByVal Source As Long) As Long

Public Sub Main()
Dim r As Long = RtlUlongByteSwap(&H12345678)
Debug.Print "RtlUlongByteSwap(&H12345678) = &H" & Hex$(r)
Debug.Print "after the call"
End Sub

[RunAfterBuild]
Private Sub Built()
Debug.Cls
Main
End Sub

End Module
```
2. Build it as win32. The DEBUG CONSOLE shows `RtlUlongByteSwap(&H12345678) = &H6000000` (the value changes from run to run), and the compiler restarts.
3. Run the built exe. It ends with an access violation (0xC0000005) after the call.

What decides it, each in a 32-bit build:
- Runtime Binding Of DLL Declares set to Yes, the default: the exe prints `&H78563412` and ends normally.
- A `FastCall` Declare of a routine with two parameters, in a DLL of our own whose `__fastcall` routine records ECX and EDX: with run-time binding both hold the arguments; bound in the import table neither does, and the exe ends with an access violation.
- A `Declare` with the settings of a package: the package's own Settings decide the binding of its Declares, and a package that turns run-time binding off gives the program that uses it the same calls.

A 64-bit build has one calling convention, so `FastCall` changes nothing there.

**Expected behavior**
The call passes its arguments as a `__fastcall` call does, the first two in ECX and EDX, however the Declare is bound: `RtlUlongByteSwap(&H12345678)` returns `&H78563412`, and the program goes on.

**Desktop:**
- OS: Windows 10 Pro 22H2 (build 19045)
- twinBASIC compiler version: BETA 1042

**Additional context**
A kernel-mode driver has to bind its Declares in the import table, since the kernel resolves a driver's imports when it loads it and the run-time binder's `LoadLibrary` and `GetProcAddress` are not there. The 32-bit kernel exports many routines as `__fastcall` (`IofCallDriver`, `ObfDereferenceObject`, `ExAcquireFastMutex`, `KfRaiseIrql`, ...), so a 32-bit driver cannot call any of them through a Declare. Found with the contributed package tbKMode 0.3.0.6, whose Settings turn run-time binding off for that reason: its test exe ends at the first `FastCall` routine it calls. VB6 has no comparison: it has no `FastCall`.

Severity: high for 32-bit drivers: no `__fastcall` routine of the kernel can be called, and the driver corrupts its stack with no diagnostic. Low otherwise: a user-mode program rarely needs both.

<!-- Reproducer: bugs/declare-fastcall-static-binding-32bit/ (mode run, exe; expect is tbrun exit 5, a byte swap other than &H78563412 from the IDE run and the exe's access violation). The two-parameter case and the run-time-binding control were run with tbrun --exe on scratch trees that are not kept, against tbKMode's stand-in for ntoskrnl.exe (test/package-tests/tbKMode/exe/fake-kernel). Found 2026-11-22 moving the tbKMode section to 0.3.0.6. docs/Reference/Contributed/tbKMode/index.md carries a WARNING labelled BETA 1042 under "Building a driver"; when a fixed build is released, the WARNING goes, and tbKMode's 32-bit exe cases run past their FastCall routines again. -->

28 changes: 14 additions & 14 deletions WIP.BugHunt.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,22 @@ Seen on BETA 1042 by the `commonctls` setup (fixture `test/shots/commonctls`).

### tbKMode

tbKMode 0.3.0.5, BETA 1042, met while moving its section to that version. Neither is checked.

- **Are the 16-bit limits a defect at all?** **MAXUINT16**, **MAXUSHORT**, **MAXWORD**,
**USHRT_MAX** and **_UI16_MAX** are `&HFFFF`, an Integer literal, so -1 where C has 65535;
**MINSHORT** is -32768 where C's `&H8000` is the int 32768. modWDM's constants NOTE states
them as wrong, with failing checks in `WDMValueTests.Constants_Values` (the five through
`values` in `wdk/modWDM.json`). But the package declares a USHORT field as an Integer, and -1
equals such a field that holds 65535, so the Integer values may be the right ones for the
package and C's the wrong expectation; MINSHORT's -32768 is the real minimum of a SHORT.
**Page affected** if they are not defects: the NOTE's bullets, the `values` entries and the
generated expectations change.
- **SE_SELF_RELATIVE** (`SECURITY_DESCRIPTOR_CONTROL`, modWDM.twin line 4724) is `&H8000&`, a
Long 32768, which an Integer cannot hold: **SECURITY_DESCRIPTOR.Control** (line 233) and the
tbKMode 0.3.0.6, BETA 1042, met while moving its section to that version. Neither is checked.

- **RtlFailFast** (modWDM.twin line 5837) is a `cdecl naked` Sub whose code is `mov ecx, 7` then
`int 29h`: it loads 7 (`FAST_FAIL_FATAL_APP_EXIT`), not its *code* argument, so
**FatalListEntryError**, which passes `FAST_FAIL_CORRUPT_LIST_ENTRY` (3), raises 7. The WDK's
`RtlFailFast` is `__fastfail(Code)`. Read from the source only: a case would end the process.
**Page affected**: modWDM's sections of **RtlFailFast** and **FatalListEntryError**.
- **SE_SELF_RELATIVE** (`SECURITY_DESCRIPTOR_CONTROL`, modWDM.twin line 4954) is `&H8000&`, a
Long 32768, which an Integer cannot hold: **SECURITY_DESCRIPTOR.Control** (line 236) and the
*Control* of RtlGetControlSecurityDescriptor and RtlSetControlSecurityDescriptor (lines
4949-4950) are Integers, so assigning the flag to one may raise overflow, and comparing one with
5155-5156) are Integers, so assigning the flag to one may raise overflow, and comparing one with
it is never true. Not run.
- **MmCopyMemory** (modWDM.twin line 5354) takes *NumberOfBytes* `ByVal As Long`, where the WDK's
routine takes a `SIZE_T`: 8 bytes in a 64-bit build, passed in a register whose high 32 bits the
call may leave as they were. The verifier's `check` reports it (0.3.0.5 and 0.3.0.6); no case and
no page states it. **Page affected**: modWDM's Declares, if it is a defect.

### User-defined types (from the GdiPlus work)

Expand Down
7 changes: 6 additions & 1 deletion WIP.VBCCR18.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ without a page in bold, with no link; link it when its page exists.

## The package

- 1.8.141.0 compiles on BETA 1042 for win32 and win64, embedded with its own copy of OLEGuids.
- 1.8.142.0 compiles on BETA 1042 for win32 and win64, embedded with its own copy of OLEGuids.
- The controls are the classes marked `[COMControl]`. Each is a VB6 UserControl that makes a
window of Windows' own control inside itself, so `hWnd` (that window) and `hWndUserControl`
differ.
Expand Down Expand Up @@ -132,6 +132,11 @@ without a page in bold, with no link; link it when its page exists.
the setting, a run of 276 cases had one of its last cases (WindowedLabelTests, the last
fixture) "not return" on win32 in some runs, a different one each time. A case that loads
HostForm many times itself counts against the same limit.
- **`HotKeyTests.SetRules_KeyWithAnInvalidCombination_GetsTheDefaultModifiers` can fail once
on win64 with modifiers 4 (`vbAltMask`)**, a modifier the case never sends: the control
reads the keyboard's state, which a key held elsewhere changes. Seen once in three runs of
1.8.142.0, whose HotKey is unchanged from 1.8.141.0; it passed on the run after. Before
`--update` records it, run win64 again.
- **A case does not read `Err.Number` after an assignment that succeeds**: twinBASIC leaves 438
there (WIP.BugHunt.md, *UserControl*). It checks the value the property then has. A case
assigns directly, not through `CallByName`, which reports another error number.
59 changes: 46 additions & 13 deletions WIP.tbKMode.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,31 @@ about the package beyond its pages; the rules for every contributed package are
verifier's page, `Verifier.md`, and the writer's, `Writer.md`, after it. Tables of two columns (Constants three), rows alphabetical, the
name cell `**Name**{: #Name }` or `[**Name**](<checked Microsoft URL>){: #Name }`, one-sentence
descriptions, enum members not listed. modWDM's procedures are `###` sections. An object-type
function (0.3.0.5 returns the object type itself) is plain prose. modWDM has an `## Aliases` table
(CBoolean, KIRQL, KPROCESSOR_MODE); modImage's aliases are commented out in the package.
- **Callouts** are labelled with the package version (`0.3.0.5`) or `timeless`, each backed by
cases or the probe.
function (from 0.3.0.5 it returns the object type itself) is plain prose. modWDM has an `## Aliases`
table (CBoolean, KIRQL, KPROCESSOR_MODE, POOL_FLAGS), and from 0.3.0.6 modImage has one too
(IMAGE_LOAD_CONFIG_DIRECTORY, an Alias of the 32-bit or the 64-bit structure, whose two targets the
writer joins: the snapshot keeps no `#If` of an alias). A name that is a procedure in one build and
a Declare in the other (InterlockedIncrement, KeAcquireSpinLock, KeQuerySystemTime) is a `###`
section in `procedures.md` with a syntax for each build.
- **Callouts** are labelled with the package version (`0.3.0.6`) or `timeless`, each backed by
cases or the probe; the one about twinBASIC itself, under *Building a driver*, is labelled `BETA
1042` and names its reproducer, `bugs/declare-fastcall-static-binding-32bit`.
- The owner reviewed the 0.3.0.5 pages, the verifier's included (2026-11-17).
- **A declaration right for the kit the package was written from is no defect**: modSysInfo follows
the 10.0.22621 SDK (`POLICY_AUDIT_SUBCATEGORY_COUNT` 59, no `FileFsGuidInformation`), and its cases
check that kit's values (`wdk/modSysInfo.json`, `values` and `sizes`).
check that kit's values (`wdk/modSysInfo.json`, `values` and `sizes`). From 0.3.0.6 the load
configuration directories have the fields of the newest kit (`UmaFunctionPointers`), a version the
package chose: `sizes` asserts them, and modImage says so in prose.
- **The package's conventions are no defects** (owner, 2026-11-22, from fafalone on tbKMode#4,
2026-11-19): the 16-bit limits are Integers (or SCHAR_MIN a Byte) holding the bits of C's value,
as the package's USHORT fields are Integers, so `values` asserts -1, -32768 and 128, and modWDM
says so in prose under Constants; and **SOURCE_FILE** holds ANSI bytes that the driver puts there,
since kernel mode has no conversion of a String, so the IoAcquireRemoveLock case fills it with
`StrConv(..., vbFromUnicode)` and the page describes it in prose.
- **IO_DRIVER_CREATE_CONTEXT.SiloContext stays a NOTE** (owner, 2026-11-22): fafalone answered on #4
that it is under `#If NTDDI_VERSION >= NTDDI_WIN10_RS1` as in the SDK, but the package defines no
NTDDI_VERSION and a project's constants do not reach a package, so the field is never compiled;
the NOTE says why.

## How the pages are written

Expand All @@ -46,10 +63,18 @@ package*). Each folder's README says how.
(`wdkcheck.mjs`, configured by `verifier/config/tbKMode.json`), and finds Microsoft Learn's pages
(`learn.mjs`, committed `learn/<Module>.json`). Needs neither Visual Studio nor the WDK. The cases
stay beside the verifier's own check because the compiler is the authority on a Type's layout.
- `exe/`: cases run in a built exe against a stand-in `ntoskrnl.exe` built with MSVC
(`fake-kernel/`). A routine a new exe case calls is added to the stand-in and its `.def`. A
routine called in the wrong convention gets an x86 naked stand-in that pops what the defective
caller pushed; its comment says what to change once fixed.
- `exe/`: cases run in a built exe against stand-ins built with MSVC (`fake-kernel/`):
`ntoskrnl.exe`, and for x86 `hal.dll`, which passes each call to the first so that the cases
read one record. From 0.3.0.6 the package binds its Declares in the exe's import table (its
Settings turn run-time binding off), so `prepare.mjs` returns them as `beside` and
`tbrun --beside` copies them into the exe's folder, where the loader finds them before System32;
a routine the exe imports that a stand-in lacks stops the exe from starting (0xC0000139), so a
routine a new case reaches is added to the stand-in and its `.def`. A routine called in the wrong
convention gets an x86 naked stand-in that pops what the defective caller pushed; its comment
says what to change once fixed (KfAcquireSpinLock, 0.3.0.6). **A 32-bit exe ends at its first
FastCall case** (twinBASIC BETA 1042, `bugs/declare-fastcall-static-binding-32bit`): those cases
are last in the file and record *no result*; the cases that call no FastCall Declare come before
them.
- `probe/`: builds small drivers with `tbbuild --build` and judges their import tables with the
verifier's `checkDriver`; it backs the landing page's warning on the package's own settings.
- `verifier/`: published as `tbKMode-verifier.zip` (its page, `Verifier.md`). `check` checks each
Expand Down Expand Up @@ -80,7 +105,12 @@ compile case's record holds its line number, so new ones go at the end of a file
named like a WDK macro breaks the generated C++ unless guarded (the WDK program hides such macros
with push_macro). Never pin `NTDDI_VERSION`. A layout case compares offsets and sizes only; the
verifier's check also compares field sizes. The source closes one `#If` with `#endif` (no space), so
a reader of `#If` blocks takes `#End\s*If`.
a reader of `#If` blocks takes `#End\s*If`. The compiler's constants are numbers, 1 and 0, not
Booleans: `#If Win64 = 1` holds in a 64-bit build and `(TWINBASIC = 1) Or (Win64 = 1)` in both (BETA
1042), so `conditions.mjs` gives them 1 and 0, and reads the scanner's `Not (x)`, its form of an
`#Else`, as logical; wdkcheck leaves out a field whose `#If` holds in neither build. A constant the
package declares as a LongLong is compared as one (POOL_FLAG_REQUIRED_END, `&H0000000080000000^`):
CLng of it overflows.

From writing the WDK databases: on x86 the headers need `/Gz` (most routines have no convention in
their declaration); `cl /d1PP` loses the name of a `#define` whose comment runs on to the next line,
Expand All @@ -97,11 +127,14 @@ and each file's `#Const` (an undefined constant is Empty).
Issues for fafalone's repository are drafted in the main checkout's `.claude/drafts/`; the owner
posts them. #1 (modFltMgr, modDisk) and #2 (modSysInfo) were answered by 0.3.0.5 (comment for #2:
`tbkmode-issue-2-comment.md`). #3 (the package's Settings) and #4 (the declarations of modWDM and modImage) are filed
(2026-11-17), from `tbkmode-issue-3.md` and `tbkmode-issue-4.md`.
(2026-11-17), from `tbkmode-issue-3.md` and `tbkmode-issue-4.md`. 0.3.0.6 answered #3 (its Settings
set the five) and most of #4; fafalone's replies on #2 and #4 decided the conventions above. The
reply to #4 on 0.3.0.6 is drafted in `tbkmode-issue-4-comment.md`.

## Leads, not on the pages

In [WIP.BugHunt.md](WIP.BugHunt.md#tbkmode): the 16-bit limits (perhaps no defect) and
`SE_SELF_RELATIVE` `&H8000&` against the Integer `Control` field. Omissions, not defects: newer
In [WIP.BugHunt.md](WIP.BugHunt.md#tbkmode): RtlFailFast's fixed reason (on the page as a NOTE
marked `none`), `SE_SELF_RELATIVE` `&H8000&` against the Integer `Control` field, and MmCopyMemory's
4-byte *NumberOfBytes* in a 64-bit build, which the verifier reports and no page states yet. Omissions, not defects: newer
members missing from `IMAGE_DEBUG_EX_CH` and `ImageMachineType`, `SYMBOLIC_LINK_SET`; optional
pointers declared `ByRef` (the `ByVal vbNullPtr` paragraph covers them).
Binary file not shown.
8 changes: 8 additions & 0 deletions bugs/declare-fastcall-static-binding-32bit/repro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mode": "run",
"exe": true,
"expect": {
"exit": 5,
"output": ["^RtlUlongByteSwap\\(&H12345678\\) = &H(?!78563412$)", "^--- exe: exit -1073741819"]
}
}
62 changes: 62 additions & 0 deletions bugs/declare-fastcall-static-binding-32bit/src/Settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"project.dllRuntimeBinding": false,
"configuration.inherits": "Defaults",
"project.appTitle": "DeclareFastcallStaticBinding32bit",
"project.buildPath": "${SourcePath}\\Build\\${ProjectName}_${Architecture}.${FileExtension}",
"project.buildType": "Standard EXE",
"project.description": "Reproduces: A FastCall Declare bound in the import table does not pass its arguments in registers (32-bit)",
"project.exportPathIsV2": true,
"project.id": "{4129C1F6-3062-4449-A9B3-6E2E1284DBFF}",
"project.name": "DeclareFastcallStaticBinding32bit",
"project.optionExplicit": true,
"project.references": [
{
"id": "{00020430-0000-0000-C000-000000000046}",
"lcid": 0,
"name": "OLE Automation",
"path32": "C:\\Windows\\SysWOW64\\stdole2.tlb",
"path64": "C:\\Windows\\System32\\stdole2.tlb",
"symbolId": "stdole",
"versionMajor": 2,
"versionMinor": 0
},
{
"id": "{F50B82D0-DCAB-43FE-9631-11959D4A4728}",
"isCompilerPackage": true,
"licence": "MIT",
"name": "[COMPILER PACKAGE] twinBASIC - VB Compatibility Package (Forms)",
"path32": "",
"path64": "",
"publisher": "TWINBASIC-COMPILER",
"symbolId": "VB",
"versionBuild": 0,
"versionMajor": 0,
"versionMinor": 0,
"versionRevision": 31
},
{
"id": "{C192FB39-64CA-4D9B-B477-A5502F48EFCC}",
"isCompilerPackage": true,
"licence": "MIT",
"name": "[COMPILER PACKAGE] twinBASIC - App global class object",
"path32": "",
"path64": "",
"publisher": "TWINBASIC-COMPILER",
"symbolId": "AppGlobalClassProject",
"versionBuild": 0,
"versionMajor": 1,
"versionMinor": 0,
"versionRevision": 0
}
],
"project.settingsVersion": 1,
"project.startupObject": "Sub Main",
"project.warnings": {
"errors": [],
"hints": [],
"ignored": [],
"info": [],
"warnings": []
},
"runtime.useUnicodeStandardLibrary": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Module Startup

' RtlUlongByteSwap is __fastcall in the 32-bit ntdll.dll: it takes its argument in ECX and
' returns its bytes in the opposite order.
Private Declare PtrSafe Function RtlUlongByteSwap FastCall Lib "ntdll" (ByVal Source As Long) As Long

Public Sub Main()
Dim r As Long = RtlUlongByteSwap(&H12345678)
Debug.Print "RtlUlongByteSwap(&H12345678) = &H" & Hex$(r)
Debug.Print "after the call"
End Sub

[RunAfterBuild]
Private Sub Built()
Debug.Cls
Main
End Sub

End Module
Loading