Qué hace
- Módulos del proceso actual y de otro proceso
- Características de la CPU como mapa de bits, condicionadas a XGETBV
- Versión real del SO, memoria libre, detección de contenedores y WSL
- Comparación de la imagen en disco con la imagen en memoria
- Firma del binario como datos, sin acceso a la red
- Detector de depuradores que informa de qué señales se activaron
- Huella compuesta con cada componente consultable
- Cada función o funciona o devuelve <code>eNotSupported</code>
Medido
- Sección <code>.text</code> en disco vs. en memoria: 0 bytes distintos en Linux y Windows. Un solo byte de código parcheado se informa en su offset exacto
- Listas de módulos: dos recorridos independientes, sin código compartido, encontraron 27 y 27 módulos. Recorrer el proceso actual lleva menos de cien microsegundos (presupuesto de 2 ms)
Límites conocidos
- En Linux no se puede suspender un solo hilo (<code>eNotSupported</code>)
- La detección de depuradores no atrapa a un depurador que quiere ocultarse
What spec 05 asks for, what is done, and above all what each number was measured against. A traversal that returns a plausible list proves nothing. What proves something is the comparison with an independent source.
---
What exists
| piece | header | oracle it was checked against |
|---|---|---|
| states and capabilities | platform_common.hpp | the capability probes instead of assuming: it tries and sees |
| loaded modules | modules.hpp | PEB / dl_iterate_phdr vs. what the loader says |
| processes | processes.hpp | NtQuerySystemInformation / /proc, and the process's own PID |
| memory regions | memory_regions.hpp | a round trip through ProtectMemory |
| threads | threads.hpp | the threads the test itself creates |
| remote memory | remote_memory.hpp | writing and reading back in the process itself |
| export resolution | exports.hpp | **dlsym / GetProcAddress**, symbol by symbol |
| image integrity | image_integrity.hpp | one byte changed in the process's own code, the mapped headers, the program headers, and a binary signed by Microsoft |
| privileges and identity | privileges.hpp | a behavioral probe (it tries what only an admin can do), /proc/self/status, ConvertStringSidToSid, and a real attached debugger |
| system facts | os_facts.hpp | the Windows registry, GetPhysicallyInstalledSystemMemory, sysinfo(2), /proc/sys/kernel/osrelease |
| processor facts | cpu_facts.hpp | **/proc/cpuinfo**, IsProcessorFeaturePresent, GetLogicalProcessorInformationEx, and the ladder in resource/cpu_features.h |
| disks and network interfaces | hardware.hpp | the two-pass protocol, which has to converge to the byte, and the loopback interface, which every machine has |
| hardware fingerprint | fingerprint.hpp | itself, across calls and across masks, and the text of each component, which is what makes it debuggable |
| suspending, resuming and reading registers | threads.hpp | a thread the test created: its counter stops advancing, and starts advancing again. The only oracle here that is not self-referential |
| modules of another process | modules.hpp | the loader traversal, which does not share a single line of code with this one and has to find the same number |
Test suites: platform.modules (201 on Windows), platform.hardware (55) and platform.cabi / platform.cabi.c17 (88, built as C11 and C17). The difference comes from the comparisons that exist on only one side. The whole ctest run is 75/75 on Windows x64, Debug and Release.
What this batch added has not been through any compiler on Linux. What was already here was green on Linux Debug/Release in the previous batch. The new paths for
/sys/block,getifaddrs,/etc/machine-idand/proc/<pid>/mapsare written and have not been compiled, because this test machine runs Windows. This is stated here instead of being inherited from the old paragraph.
---
The processor facts
Why a bitmap, if there was already a ladder
Cpu::ESimdLevel is a ladder: scalar → SSE2 → SSSE3 → SSE4.1 → SSE4.2 → AVX2 → NEON. It serves to choose between implementations of the same kernel, where each rung contains the previous one. And it does not serve the question "does it have AES-NI?", because the real world is not a ladder. There are parts with AES-NI and without AVX2. AVX-512 comes in half a dozen variants that do not always go together. The SHA extensions are independent of everything.
The two coexist, and the test suite requires them to agree on the five levels that overlap. They are two independent detectors (cpu_facts.cpp does not include cpu_features.h, on purpose) reading the same silicon. A disagreement is a defect in one of the two.
The system state gate
CPUID answers for the silicon. What answers for the system is XGETBV: if the operating system does not know how to save the wide registers on a context switch, using them corrupts the program, intermittently and depending on load.
Three fields, and the difference between them is the point:
uFeaturesRaw: what the silicon declares. Do not use it to choose a code path.uXcr0: what the system saves.uFeatures: what can be used. It isCpuFeaturesUsableWith( uFeaturesRaw, uXcr0 ).
CpuFeaturesUsableWith is public and pure arithmetic, and it is separate for a concrete reason: a planted defect that erased the gate survived. This machine has a system that saves YMM, so with or without the gate the answer is the same, and the oracle did not reach the path. Separated from the read, the decision became callable with an invented XCR0, and seven checks cover it: it clears AVX/AVX2/FMA/F16C with a zeroed XCR0, clears AVX-512 when the three extra pieces are missing, does not touch what fits in 128 bits, and never adds a bit that was not in the input.
What this does not prove: that CpuFacts calls the gate. That could only be seen on a system that did not save YMM, and there is none here. The sem-chamada mutant survived, and that is stated.
What the same machine answered differently on the two systems
| Linux (WSL2) | Windows | |
|---|---|---|
iInvariantTsc | 0 | 1 |
uXcr0 | 0x7 | 0x1F |
The i7-6700 has had the invariant counter since the part has existed. The Hyper-V underneath WSL hides leaf 0x80000007, and the Linux kernel also stops publishing constant_tsc on the same machine: both sides read the same hidden data. That is why the field is documented as "I was not told", and not as "it does not have it", exactly like the hypervisor field. The 0x1F on Windows is the extra MPX bits, which the gate ignores.
Against the kernel, field by field
On Linux, 28 instructions are compared through the flags line, plus family, model, stepping, vendor, brand name, cache line, last level cache and the threads/core ratio. Two traps the measurement taught:
- **
SSE3is calledpni** in the kernel. Anyone searching for"sse3"finds the substring inside"ssse3", or finds nothing. Both answers are wrong. - **
LZCNTis left out of the comparison on purpose.** The kernel publishes it asabm, which is the name of an AMD set, and there are Intel parts with the instruction that do not get that name. Comparing would produce a divergence that is not a defect on either side.
And the instrument proves it is alive before accusing: if reading /proc/cpuinfo failed, no alias would match and the comparison would accuse the whole map of lying. The diagnosis would be the opposite of the defect. That is why the test requires fpu to be present and an invented flag to be absent.
What this machine cannot prove
The mutant that swaps the L1 data cache for the L1 instruction cache survived. On this i7-6700 both measure 32 KiB, and no oracle on this machine distinguishes them by size. The Windows GetLogicalProcessorInformationEx publishes CacheData separately from CacheInstruction and would catch the defect on a part where the two differ. It is written and wired in, and here it can do nothing. Saying otherwise would be inventing.
The same goes for the mutant that reads leaf 0x40000000 without the hypervisor announcement: this machine runs under Hyper-V on both systems, and the guard is never exercised.
---
The buffer that is not enough
This is the most serious defect spec 05 has produced so far, and it came from load, not from a mutant.
The process traversal failed 1 time in 10 with the machine busy. The failure was correct: the buffer had been sized by a measurement taken moments earlier, processes were born, and the text no longer fit. The function returned eBufferTooSmall, which is correct.
But the entries already written to the output vector were left with a null pName and with uNameLength announcing the length of the name that did not fit. Code that checks the return code discards the vector. Code that does not check it (and that is the half worth protecting) walks the vector and calls strlen on a null pointer, or copies sixty bytes from a one-byte pointer.
There were five places: three copies of SSink::Put (modules, processes, regions) and two wide paths on Windows. All fixed the same way:
- A full buffer returns the empty string, not null.
- The length comes from what was stored, not from what was meant to be stored.
Finding a size that really overflows took three measurements
A finding that reproduces 1 in 10 under load is useless as a test. The condition had to be provoked on purpose, and that was harder than it looks:
- **
uNeeded - 1.** On Windows:code 0, 323 entries, it still fit.NtQuerySystemInformationasks for more than it uses, and the slack swallowed the byte. - A ladder of fractions (0.99 · 0.97 · 0.95 …). On Windows:
0.0%, code 2, 0 entries, it jumped over the window. There the arena is almost all working buffer for the query and the text is about two percent, so the useful window is only a few percent wide. - Bisection to the boundary, one byte below. It worked on both systems, and the defect planted in the Windows wide path survived: one byte from the boundary, what fails is the last allocation of the last entry, which is the one-byte empty path. The name never gets to not fit.
What works is the middle of the window, and for that two boundaries are bisected (the "everything fits" one and the "no longer writes any entry at all" one), and the test asks for what lies between them. Measured: Linux [1, 344), Windows [606592, 611875). In the middle, half of the names fail.
With the mutant restored: 169 of 343 entries flagged on Windows, 7 of 7 in the modules, 58 of 59 in the regions. Without it, zero in any configuration.
And the case refuses to pass without having measured
Each block counts how many entries it looked at and fails when it looked at zero. That is the line that caught Windows coming out with zero processes when the eight-byte crumb did not let the query run. Without it, the case would have passed on Windows without examining a single entry, and I would have written that the fix was proven on both systems.
The two-pass protocol converges, and that is what is required
The test no longer requires eOk on the second pass. Requiring that meant requiring the process list to stand still, which no system promises. What is required now is stronger: asking again with the new size eventually fits, in at most eight rounds, with one eighth of slack.
---
The system facts
On Windows, the version lies if you ask through the front door
GetVersionEx and VerifyVersionInfo answer 6.2 (Windows 8) on any Windows 10 or 11, unless the executable carries a manifest declaring that it was tested on the newer versions. This is deliberate compatibility behavior from Microsoft, not a defect.
For a library this is unacceptable: the manifest belongs to the program that integrates it, and the library has no say over it. The library uses RtlGetVersion, from ntdll, which tells the truth without any manifest. The UBR (the fourth field) exists only in the registry and is read from there.
The test suite is not content to assert this: it measures it. On a Windows 10 build 19045 machine:
registry: 10.x build 19045 | the library: 10.0 build 19045
'GetVersionEx' (the front door) says: 6.2 build 9200 <- it LIES, which is why it is not usedThe registry line is the oracle (it is written by the system installer and does not go through ntdll). The GetVersionEx line is printed as data, not as a failure, because one day this executable may gain a manifest. If someone replaces RtlGetVersion with GetVersionEx "because it is simpler", the first two checks fail immediately.
What changes is not in the facts structure
SOsFacts only holds what does not change while the process lives. Free memory changes between two lines of code, and storing it there would deliver a stale number that looks like a measurement. That is why it lives in AvailablePhysicalMemory(), which measures on the spot.
The test suite checks the difference in both directions: the facts have to be the same object across calls, and free memory has to drop when the test allocates and touches 256 MiB. Measured: a 259 MiB drop on Linux, 257 MiB on Windows. Without that line, an AvailablePhysicalMemory that returned a constant would pass forever, and that was one of the planted defects.
On Linux the value comes from MemAvailable, not from MemFree. The difference is huge: on a healthy machine MemFree is almost zero, because the kernel uses everything left over as disk cache. Anyone who sized a buffer by MemFree would conclude that a machine with 32 GiB free has no memory at all.
An "independent oracle" of mine that was not independent
I wrote, in the code, that the memory total matched sysconf( _SC_PHYS_PAGES ), *"which does not read /proc"*. The measurement gave a 0.00% difference, exactly zero. An exact zero between two supposedly independent sources is a reason for suspicion, and it was: glibc 2.39 implements _SC_PHYS_PAGES by reading /proc/meminfo itself.
It was replaced with sysinfo(2), which is a system call and does not touch text. And the claim was corrected to what is actually proven: there is no truly independent measurement of total memory on Linux. MemTotal and sysinfo::totalram come from the same kernel counter and agree by construction. What the comparison reaches is my parsing of the text (the key, the unit, the multiplier), and that is exactly the part that can be wrong. The mutants confirm it: replacing 1024 with 1000 gives a 2.34% divergence, and replacing MemTotal with MemFree gives 15.20%.
Container: "detected" is not the opposite of "I am not in one"
Every method looks for traces: a file, a cgroup line, a kernel suffix. An environment that leaves no trace is invisible. True is reliable. False means "I found no trace", the same rule as the hypervisor bit.
WSL is on the list by deliberate choice: it is not a container, and it is not plain Linux either, and several measurements in this very library came out different because of it. The iInvariantTsc above is the example.
A guard that guarded nothing
A mutant that erased the "the key starts the line" check in /etc/os-release survived. Investigated: the loop already advances from line break to line break, so the cursor is always at the start of a line and the condition was always true. It was dead code. Worse, the comment next to it pointed at it, so anyone who touched the loop advance, where the protection really lives, would find no warning at all.
With the condition removed and the comment moved to where the guarantee is, the correct mutant (p = pBreak + 1 → p = p + 1) kills immediately: the distribution is read as 24.04 instead of ubuntu, because ID= is a substring of VERSION_ID=.
Two defects of mine that only x86 would reveal, and one of them not even that
The mutant that replaces GetNativeSystemInfo with GetSystemInfo survived on x64, as expected: the two only diverge in a 32-bit process under WOW64.
But the test assertion for x86 accepted "x86_64" or "x86", that is, any answer. The mutant would have survived on x86 as well. An independent 32-bit probe measured what the assertion claimed. The output below is the capture of that measurement, made before 2026-10-05, and originally printed in Portuguese (shown here translated):
under WOW64 ............... yes
GetSystemInfo ............. INTEL (x86)
GetNativeSystemInfo ....... AMD64 (x86_64)With that, the check came to have one correct answer: under WOW64 it requires "x86_64", outside it requires "x86", decided by IsWow64Process.
What does not run on this machine: the x86 configuration
The x86 binary of platform.modules cannot be produced in this environment. It is linked, it sits on disk at 486,912 bytes, and:
- It runs with exit code 0 and zero bytes of output.
cmdsays it "is not recognized as a command".dumpbin /headersreads nothing from it, while it reads a neighboring binary in the same folder.
It is not a valid PE image. The x86 neighbors from the same build (core_alloc_guard, compression_c_abi) run normally, and so does a trivial 32-bit probe. The machine has Kaspersky and Malwarebytes active, and this is the failure mode already known here (the same one that produces LNK1104).
This is not a defect of the library, and it is not resolved by touching the antivirus without the owner deciding. It is recorded as a limit of the test machine, and it stands as a product warning: a module that walks the PEB, enumerates processes, reads remote memory and resolves exports without the loader will attract endpoint protection on the customer's machine.
---
Privileges, identity and debugger
This is not cached, unlike the rest of the module
CpuFacts and OsFacts compute once and always return the same object. QueryToken measures on every call, and the reason is concrete: identity changes. A process can drop privilege, and dropping privilege is exactly what a well-written program does after using what it needed. Returning the old answer would say "I am root" to a process that just stopped being root.
The check I wrote for this checked nothing
The first block compared two consecutive calls and asserted &A != &B, with a comment saying that this proved "it measures, it does not cache". **A mutant that added a static and always returned the cached copy passed both and survived the entire battery**: &A != &B is trivially true for two stack objects. I had written a tautology and called it a check.
What proves it is changing the identity between the two calls, and finding a way to do that without privilege took two attempts:
setegidto a supplementary group. The system refused, and rightly so: an unprivileged process can only set as effective its real, effective or saved group. I had assumed the opposite.- A user namespace. Creating one requires no privilege at all, and inside it the process is user zero with the full capability set. The identity really changes, and it changes twice, because afterwards the capabilities are dropped voluntarily.
in the user namespace: bits 0xF
ok inside the namespace the process is user ZERO and reports itself elevated
ok and the capability mask is not empty
ok and DROPPING the capabilities changes the next answer: this MEASURES, it does not cache
ok and what did not change stays the sameIt is also the only place in the test suite where iElevated == 1 and a non-empty capability mask ever exist. Without it, half of QueryToken was never executed.
On Windows there is no equivalent: the SID, the elevation and the integrity of this process are fixed after it is born, and forging a token would require privilege that the test does not have and should not ask for. The property is verified on Linux and, on Windows, rests only on reading the code. That is stated in the source and here, instead of being disguised with a check that does not reach the path.
Elevation is compared with what the machine lets you do
iElevated is what the system says. The test suite tries what only an administrator can do (opening the service manager with create rights on Windows, reading /etc/shadow on Linux) and compares. It is the same philosophy as Supports in the rest of the module: the capability probes instead of assuming.
IsDebuggerPresent, honest about its own limits
The spec asks for exactly this, and the honesty is written before the code:
None of these probes detects a debugger that does not want to be detected.
All of them read a signal that the system itself publishes, and any of them can be erased. It serves for logging, for diagnostics, and for raising the cost for someone who is not trying to hide. It does not serve to protect anything: anyone who writes if( DebuggerPresent() ) exit() with anti-tampering in mind is building a paper lock.
That is why the function returns which signals lit up: ETL_DBG_SIGNAL_PEB, _REMOTE, _HEAP on Windows, and _TRACER on Linux.
A detector that has never seen a debugger is not tested
Checking that the function returns false in a run without a debugger proves nothing: a function that always returned false would pass. It is the instrument that has to read zero, indistinguishable from a broken one.
The test suite attaches a real debugger to a child process (PTRACE_TRACEME on Linux, DEBUG_ONLY_THIS_PROCESS with event pumping on Windows) and requires the detector to light up in there. And it runs the same child without a debugger to prove that it is not stuck on "yes". Two directions, because one alone measures nothing.
And that found a defect of mine
The first run on Windows came out PEB=1 remote=1 heap=0. I went to check: the offset of NtGlobalFlag in the process block is 0xBC on 64 bits and 0x68 on 32. I had written 0x70 and 0x40. I was reading another field.
Without the line that prints the three signals separately, it would have stayed silent forever. And the risk goes beyond staying silent: a wrong offset can read garbage with the bits set and light up a false signal, which is the most expensive defect in this file. Once corrected, the signal lights up under a debugger (0xB) and does not light up without one.
The test suite never requires that signal to light up: the offset has no public contract and will change one day. It only requires that it does not light up without a debugger, which is the only direction in which a loose signal does damage.
What does not translate, does not translate
EIntegrityLevel is a Windows concept. On POSIX the answer is eNotApplicable, and the test suite requires that explicitly. It would be easy to say "root is high, user is medium", and it would be wrong: the two models answer different questions, and a caller comparing levels across platforms would be comparing things that cannot be compared.
---
The image on disk against the image in memory
This does not compute any digest, and the decision is deliberate
The spec talks about a hash. This module has no SHA, no CRC, and returns no digest. In part by convention: §2 forbids a module from including another module's header to obtain functionality, and SHA-256 lives in the Cryptography module. The main reason, however, is that the value lies in knowing what to digest, not in the digest.
ReadSectionNormalized delivers the bytes already comparable, and the caller digests them with whatever it wants. CompareSection compares the two sides without digesting anything and says where they differ, which, for diagnostics, is worth more than a digest that only says yes or no.
What makes the two sides differ without anyone having tampered with anything
Relocation (the image was linked for one address and loaded at another), the import table (on disk it holds names, in memory addresses) and alignment padding. Comparing without handling this accuses every image of every process of tampering.
The comparison neutralizes (zeroes, on both sides) each range that the loader was allowed to modify, and says how many bytes were neutralized. That number is part of the result: neutralizing too much hides tampering, and a comparison that neutralized everything would always say "equal".
.text | constant pointer section | |
|---|---|---|
| Linux | 263,070 bytes, 0 neutralized, 0 different | .data.rel.ro: 9,408 bytes, 7,768 neutralized, 0 different |
| Windows | 404,210 bytes, 0 neutralized, 0 different | .rdata: 186,801 bytes, 8,408 neutralized, 0 different |
Zero in .text is the normal case and the best case: 64-bit code addresses relative to the instruction pointer, so nothing had to be forgiven.
A comparison that has never seen tampering is not tested
"The two sides are equal" is satisfied by an implementation that always returns "equal". The test suite changes one byte of the process's own code (in a function nobody calls, hand-picked so that changing it does not bring the process down) and requires the comparison to flag it:
with ONE byte changed: 1 different, the first at +36955 (expected +36955) [Linux]
with ONE byte changed: 1 different, the first at +53672 (expected +53672) [Windows]One byte, counted as one, at the exact offset. And restoring the byte makes the comparison report equal again. Without that last line, an implementation that started saying "different" forever after the first tampering would pass.
The defect the measurement found: the copy relocation
The first case that actually exercised neutralization was the Linux .data.rel.ro, and it failed: 7,656 bytes neutralized and 69 still differing.
The 69 bytes were **five R_X86_64_COPY. A copy relocation does not fix up a pointer. It brings the entire object** from inside a shared library into this image. In this case, vtables from libstdc++, 24 to 40 bytes each. I forgave eight bytes at every relocation, without exception, and the rest was left uncovered.
Recognizing a copy without depending on the architecture: the type number changes (5 on x86-64, 1024 on AArch64), but the shape is the same. The target is the symbol's own address, and the symbol has a size. In the others, the target is a table entry and never coincides with the symbol.
Fixed: 7,768 neutralized, 0 different.
Without the .data.rel.ro case, this defect would never have appeared: .text and .rodata have zero relocations, and they would have passed with the relocation code entirely erased.
The build identity, and an oracle the test suite did not have
A planted defect that returned the wrong ELF note survived everything I had written: the identity existed, was stable, was not zero, and even distinguished two different binaries. It returned .note.gnu.property, which is also named "GNU", is also not zero, and comes before the build note in every binary on this machine.
The oracle that kills it is the path the library does not use: the library finds the note through the section table, read from the file. The test suite finds it through the program headers (dl_iterate_phdr + PT_NOTE), read from the loaded image, which is how a debugger finds it without having the file at hand. Two structures maintained by different parts of the linker.
On Windows the equivalent oracle is the mapped headers, and it also caught the mutant that replaced the section size with the raw size (404,480 instead of 404,210).
And not every binary has an identity
The Windows Release build failed, and the library was right: without debug information there is no CodeView record, and without it there is no PDB GUID. What was wrong was the test, which always required an identity.
Accepting "does not exist" with nothing else would be worse: an implementation that answered that for everything would pass. Now the test suite first asks, through the mapped headers, whether there is a CodeView record, and only then decides what to check. The Release build now proves the negative case.
It is a real asymmetry between the two systems: in ELF the linker emits the build note by default, in every build. In PE it only exists when symbols were requested.
The signature, as a fact and not as a verdict
The spec is explicit: report signature status as data, not as a trust decision. This library does not decide whether a binary is trustworthy. It reports what it found (who signed, who issued, what the chain answered), and the caller decides.
This is not pedantry. "Signed" and "trustworthy" are different things: malware signed with a stolen certificate exists, and legitimate unsigned software exists even more. A library that returned a boolean called bTrusted would be making, on behalf of the caller, a decision that depends on the caller's policy.
The oracle: checking only our own binary, which is not signed, would let through an implementation that answered "unsigned" for everything. The test suite compares against a binary signed by Microsoft:
this binary: unsigned
'kernel32.dll': chain is valid | 'Microsoft Windows' issued by 'Microsoft Windows Production PCA 2011'The query does not go to the network to check revocation. That blocks for seconds and fails on its own on a machine without outbound access, and a library cannot decide, on behalf of the program that integrates it, that the program will wait for a server. The result comes out as a fact: "chain is valid" does not promise that the certificate was not revoked.
In ELF the answer is eNotApplicable. There are package signatures and kernel module signatures, and neither is a property of the ELF file that can be read here. Inventing a "valid" from an installed package would be answering another question.
Three defenses the tests do not reach, and they are stated
Of seventeen planted defects, fourteen died. The three survivors are redundant defenses on the tested path, and each one is documented in the code itself:
- The import table. Erasing its neutralization leaves the count exactly the same: 8,408 with and without it. Each entry holds an absolute address, and every absolute address has a relocation. The relocation loop already covered them all. It stays because an image linked with a fixed base has no relocations at all, and there it is the only thing that covers the table. There is no such binary on this machine.
- The four-byte alignment of ELF notes. The build note lives alone in its section, so reaching the "next note" is never needed to find it. The rounding protects against running off the buffer when walking a section with dozens of notes, not against returning the wrong value.
- **The
RSDSsignature.** In these binaries the firstCodeViewrecord is already anRSDS, so the check never breaks a tie. It protects against an older format coming first. Without it, the sixteen bytes read would belong to another structure, looking like an identity without being one.
---
The C layer
The spec requires it for a concrete reason: the module will be consumed from C# and Rust, and neither of them speaks C++. ethereal/c/platform/platform.h.
Half the value is in compiling
A header that claims to be C and carries a C++ type, a keyword, or a double-slash comment under an older standard goes unnoticed while only C++ includes it, and breaks on the integrator's machine, which is the worst place to find out. That is why it is compiled twice, as C11 and as C17, without extensions.
The other half: the sizeof of two different compilers
Each struct that crosses carries iStructSize, and the side that filled it in was C++: it is the sizeof that the C++ compiler computed. The test compares it with the sizeof that the C compiler computes over the mirror:
ETLC_CpuFacts: C says 176, C++ wrote 176
ETLC_OsFacts: C says 256, C++ wrote 256It is the same idea as the static_asserts in the implementation, but it crosses a boundary they do not reach: there, both sides are seen by the same compiler.
The mirrors pass without a copy
ETLC_ModuleInfo and ETLC_ProcessInfo have a field order identical to the C++ side, and that is not aesthetics. With identical layouts the wrapper hands the caller's vector directly to the traversal, without converting anything. On a machine with 350 processes, a conversion pass would be pure overhead.
What makes this safe instead of reckless are the assertions: **a static_assert for the size of each struct and for the offset of each field**. Checking only sizeof would let through two fields swapped in place. The size does not change and the content all goes to the wrong place, which is the most silent defect an ABI boundary produces.
The battery has two natures
Some defects have to break the build, others the test. Requiring the right nature matters: a layout deviation that "fails the test" instead of not compiling would mean that the error got past the compiler and was only caught by luck, at run time.
| planted defect | expected | result |
|---|---|---|
| an extra field in the C struct | does not compile | did not compile |
| two fields swapped in place | does not compile | did not compile |
| a 64-char string shrunk to 48 | does not compile | did not compile |
| a shifted capability number | does not compile | did not compile |
| a state translated to the wrong one | fails | failed |
| a capability without a range check | fails | failed |
| a null pointer accepted instead of refused | fails | failed |
| the XCR0 gate does not cross | fails | failed |
| two states with the same name | fails | failed |
Nine out of nine.
A capability I invented
The first version of the C header made its own list of capabilities and invented a WRITE_REMOTE that does not exist on the C++ side. Writing remote memory has no separate capability: whoever can read can ask to write, and the refusal comes from the call. The compiler refused.
The fix was to delete the table, instead of correcting it. The numbers on the C side became the same as in the enum class, with a static_assert for each, and translating became a range check. One less table to maintain is one less table to get wrong.
---
The audit against spec 05, and what it found
Until this batch, this README said:
The C++ layer and the C layer are complete. What remains requires an environment, not code.
They were not. The line-by-line audit against the spec found eight things, and one of them was a serious defect. Everything is closed, and what it was is described here.
| what the spec asks for | was it there? |
|---|---|
EnumModules( iPid, … ): the modules of another process | did not exist |
SuspendThread, ResumeThread, context capture | did not exist |
LockMemory: pinning pages in physical memory | did not exist |
| enumeration of disks with model, serial, size and type | did not exist |
| enumeration of network interfaces with physical address, index and flags | did not exist |
| a composite fingerprint, with the components queryable one by one | did not exist |
| memory per NUMA node (there was only the node count) | did not exist |
the vector form of EnumThreads and EnumMemoryRegions | did not exist |
And the C layer did not carry threads, memory regions or remote memory across, which the spec requires in so many words: "this module is very likely to be consumed from C# and Rust, so the ABI surface needs to be complete, not partial."
---
The defect: the capability lied, and the test had the lie written as its expectation
Compiled( ECapability::eCodeSignature ) answered false on a Windows build in which QuerySignature is written, works, and this very README says was checked against a binary signed by Microsoft.
This module's policy is explicit about this:
*"every function either works or returns
ENotSupported, and there is a compile-time and runtime capability query so the caller can branch before calling. Silent degradation into an empty result set is forbidden."*
Anyone who branched on the query (which is exactly what this module tells you to do) would never call a function that works. It is worse than an empty list: it is the branch that is never even tried.
And nothing could catch this, because each of the two halves passes its tests on its own and they only disagree with each other. What existed was the opposite of a defense (the code of the time, before 2026-10-05, when the test messages were still in Portuguese, shown here translated):
Check( !Compiled( ECapability::eCodeSignature ),
"and the one that does not exist yet says it does not exist yet" );The test required the capability to lie. It was written when the signature did not exist yet, and it kept passing after it did, pinning the value instead of checking the promise.
Now it checks the promise, which is something else:
const EPlatformError e = QuerySignature( "etl-ficheiro-que-nao-existe.bin", &Sig );
Check( Compiled( ECapability::eCodeSignature ) == ( e != EPlatformError::eNotSupported ),
"the signature capability agrees with what the call does" );The path is, on purpose, one that does not exist. The question here is "does this platform know how to answer this", not "is this file signed". A missing file gives eNotFound, which is an answer about the file. eNotSupported is an answer about the platform. Only the second is the one the capability promises to predict.
---
The fingerprint: the problem is drift, not collision
The spec asks for "a composite stable hardware fingerprint for licensing, with the component list documented and each component individually queryable so the caller can build its own".
Two machines producing the same number is rare and obvious when it happens. What happens every day is the same machine producing a different number (the user swaps a network card, turns on a VPN, starts a container), and licensing accuses of fraud someone who did nothing.
That is why each component declares its stability, and the default mask includes only the stable ones:
| component | stability | what changes it | included by default |
|---|---|---|---|
| CPU identity | high | replacing the processor | yes |
| machine identifier | high | reinstalling the system, cloning an image | yes |
| CPU topology | medium | replacing the processor, a resized VM | yes |
| disk serials | medium | replacing or adding a disk | yes |
| physical memory | medium | adding memory | yes |
| physical addresses | low | a VPN, a container, a cable, a dock | no |
Physical addresses are the classic component and the worst one. They are here because the spec asks for them as a queryable component, and not because they should be part of the composition. The mitigation, for those who want them, is twofold: virtual and loopback interfaces are discarded, and the remaining ones are included sorted.
Sorting is not tidiness. The order in which the system enumerates disks and interfaces is not guaranteed across boots (a USB disk plugged in before boot can appear first), and without sorting the fingerprint changed on its own on the same machine, with the same hardware. It is the same drift defect, through a path nobody looks at.
The text is the source of truth, and the number is derived
Each component first builds its text form, and the digest comes from that form. This is not redundancy: it is what makes the thing debuggable. A user whose license stopped working sends the text, and you can see at a glance which component changed. With only the composite number, the answer to that question is "I don't know".
cpu identity stable 92d31bae7b0db420 cpu:GenuineIntel:6:94:3:Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
cpu topology medium 8f4a4a92deb8965e topo:4/8:64:32768:262144:8388608
machine id stable 9949e9f676c2d91b machine:e22894ad-535d-4c88-8660-4301e1ca7da6
disk serials medium 5cd688a630e5b998 disks:0000_0000_0000_0000_0026_B768_6B26_0885.
mac addresses UNSTABLE cfa10a36285bda99 macs:00e04caa077d
physical memory medium 936de298278b124e mem:95
composite: ab39361757fcadea (missing: 0x00)Physical memory is included at a 256 MiB granularity, and that is deliberate: the total the system publishes varies by a few megabytes between boots, depending on what the integrated graphics reserves. Using the exact number would make the fingerprint change on its own.
What is missing is not ignored, and if everything is missing there is no number
A component that was not collected enters the composition as absence, not as empty. Otherwise, a machine where the disk serial number cannot be read would produce the same number as another where it is read and happens to be empty. And pMissingOut says which ones were missing.
**If everything is missing, the answer is eNotSupported and not a number.** A composite fingerprint made only of absences is identical everywhere, and returning it with eOk would be the silent degradation this module's policy forbids. It would be the most dangerous kind, because the license of one machine would work on every other machine where collection also failed.
And the digest is 64-bit FNV-1a, by choice. It is not cryptographic and does not need to be: this is an identifier, not a secret. Anyone running the code on the machine computes the same number, and no digest changes that. What matters here more than strength is being stable across versions: a license that stopped working because the library changed its digest would be a worse defect than any collision.
---
The serial number is the field most often missing, and the one that lies most
The spec asks for "serial where permitted", and "where permitted" is the important part: a disk's serial number arrives through an IOCTL that the system can refuse, that a USB disk may not answer, and that a virtual machine usually fills with the same text in every instance.
That is why it comes out empty when it could not be obtained, and is never filled with a substitute. A fingerprint built on an invented serial number is the same on two different machines, which is the worst possible defect here, and the most silent one.
And the disk answers without elevation, if the request is made correctly
The trap is the open call. CreateFileW with GENERIC_READ on \\.\PhysicalDrive0 requires elevation and fails with ERROR_ACCESS_DENIED for a regular user, and it is what almost everyone writes.
With zero access, the same open succeeds: a handle without read rights still works for the property IOCTLs, which are the three that matter. Reading the sectors would still require elevation, and this module does not read sectors.
And it is the geometry that gives the size without rights: IOCTL_DISK_GET_LENGTH_INFO gives the same number and requires read access. IOCTL_DISK_GET_DRIVE_GEOMETRY_EX does not, and it brings the sector size as a bonus.
On Linux, /sys/block/<name>/size is always in units of 512, even when the physical sector is something else, and this catches anyone who multiplies by the sector size read alongside it: on a disk with 4 KiB sectors, that gives eight times the real size. The kernel documents this, and almost nobody reads it.
---
Suspending a thread is a fact you collect, and the danger is deadlock
The spec's non-goals section forbids injection, hooks and countermeasures. Suspending a thread is none of those: anyone who reads a thread's register context first has to suspend it, otherwise they read garbage that changes while they read. The spec asks for both, "where the platform permits".
The real danger is deadlock, and it is not hypothetical: if the suspended thread is inside the memory allocator and the thread that suspended it then asks for memory, both stay there forever. That is why SuspendThread refuses to suspend the calling thread (that would be an instant deadlock and is never what was wanted), and resuming lives right next to it, in the same header.
And suspensions accumulate on Windows: suspending twice requires resuming twice. It is the opposite of page locks, where one VirtualUnlock releases what many VirtualLock calls pinned. The two rules are opposite, and both are written down, because nobody guesses them.
On Linux there is no way to suspend a single thread, and that is eNotSupported, not an oversight. SIGSTOP stops the whole process, and the alternative (a real-time signal with a handler that waits on a semaphore) requires the target to cooperate, by having installed that handler beforehand. That is already changing the program, not collecting a fact. Reading the registers requires ptrace, which requires being the process that traces the target, and a process cannot trace itself, which is exactly the case this module serves.
The oracle here is not self-referential
Almost everything in this module has the same testing problem: the oracle is the machine itself. How many disks there are is whatever the machine says.
Suspending a thread does not have that problem. The test creates the thread, knows what it is doing, and observes that it stopped: a counter the thread increments stops advancing, and starts advancing again when the thread is resumed. That does not depend on the module telling the truth about anything else.
And the context that is read has a check of the same kind: the top of the stack has to be aligned to eight. A context read from a misaligned buffer, or from a CONTEXT with the wrong flags, gives garbage, and garbage is almost never aligned.
---
Locking pages: the budget is small, and that is the detail that catches everyone
On Windows the process has a minimum working set, and VirtualLock fails with ERROR_WORKING_SET_QUOTA when more than that is requested. The default value covers a few dozen pages, much less than whoever writes the call usually assumes. On Linux there is RLIMIT_MEMLOCK, which on many distributions is 64 KiB for an unprivileged user.
**Both are eAccessDenied, not eSystemError**: the information exists and another privilege level reaches it. The difference between the two states is whether the caller gives up or requests SeLockMemoryPrivilege and tries again.
---
The modules of another process are not EnumModulesSelf with a PID
The difference is orders of magnitude. The self traversal reads the loader list in this process's memory: no system call, under a hundred microseconds, and it is the one that runs in the scan loop. The other one opens a handle and asks the system, image by image: dozens of calls and a file system read per module. It is not for the scan loop, and the spec puts the 2 ms budget only on the self traversal.
LIST_MODULES_ALL is mandatory, and forgetting it is the classic defect: without it, a 32-bit process seen from a 64-bit one returns only part of the list, **with eOk**, which is exactly the silent degradation the policy forbids.
And this has a truly independent oracle: the two traversals (the loader one and the one that asks the system) do not share a single line of code, and they have to find the same number of modules in the same process. Measured: 27 and 27.
---
How this was verified
tests/platform_hardware.cpp (platform.hardware), 55 checks, and the C ABI target went from 37 to 88.
There is no known correct answer for almost any of this, so the judgment is made by properties that have to hold whatever the machine:
- The two-pass protocol converges: the second pass asks for exactly what the first one promised, and not one byte more. One byte less in the buffer is refused, not truncated.
- The fingerprint is stable within the same run, and changes when a component is removed from the mask.
- A component's digest does not depend on the size of the caller's buffer.
- What is not collected returns
eNotFoundwith a zero digest, and never a substitute. - No physical address goes beyond what fits in the structure.
- And the capability answers the same as what the call does, which is the promise this module almost broke silently.
A defect of mine that only the measurement caught, and it is the same pattern as always: the first version of the disk enumeration only called the visitor once a buffer was present. The effect was that the measuring pass (the one done with an empty buffer, on purpose) delivered no entries at all, and anyone who measured first, as the spec requires, counted zero disks on a machine that has disks. modules.cpp already did the right thing, and the reason was written next to g_pEmpty.
And a second one, in the C-side test: it gave the thread traversal a four-kilobyte buffer and expected the list. On Windows that buffer is not only for text. It is the working buffer of NtQuerySystemInformation, which writes the state of the entire system into it before it can find the target process. That is hundreds of kilobytes. The returned state was eBufferTooSmall, which is the correct answer. It was the test that was reading "it did not fit" as "there are no threads".
---
---
---
The stack limits, and the two defects the test caught
iStackBase and iStackLimit in SThreadInfo: the last missing piece of spec 05 on the C++ side and on the C side.
How to get there without opening a handle per thread
The obvious way is to open each thread, ask for its TEB with NtQueryInformationThread, and read the memory where it lives: one handle and two calls per entry, in a traversal the spec wants to be cheap, and with rights you do not always have.
It is not necessary. The **SystemExtendedProcessInformation (57) class returns exactly the same tree as class 5, which was already in use, with one difference: each thread entry is larger**, and the extra part includes the TEB address. One call, the same buffer, nothing per thread.
The decision of which class to use has to be made before walking the buffer, because it is what gives the stride of the thread vector. Walking with the wrong stride reads garbage, and garbage that looks like addresses, which is the worst kind. When class 57 does not answer, the code falls back to class 5 and the limits stay at zero, which is what this module says when it cannot get them.
The first defect: those were not the limits that mattered
The extended entry also carries fields named StackBase and StackLimit, and the temptation is to use them. That is what was done, and the test failed. The output below is the capture of that failure, from before 2026-10-05, when the tests still printed in Portuguese (shown here translated):
this thread: [ffff8e0e93201000, ffff8e0e93208000), and a local of mine is at aea2aff404
FAIL and a local variable of this function falls INSIDE them**ffff... addresses and a twenty-eight kibibyte range: it is the kernel stack.** Both fields come from the ETHREAD. The stack that matters to someone inspecting a process is the user stack, which is where the return addresses are.
It is in the NT_TIB, in the first two pointers after ExceptionList, and the TEB came in the same entry, for free. The kernel fields stay declared and are not used: they are in the right place so that the vector stride comes out right, and nothing more.
What caught the error, and why that check was written this way
Two numbers in the right order could belong to any thread. What ties them to this one is the address of a local variable:
const int iOnStack = 0;
const ETL_UINT64 uHere = reinterpret_cast< ETL_UINT64 >( &iOnStack );
Check( uHere >= C.uMyLimit && uHere < C.uMyBase, ... );A plausibility check would have passed with the wrong numbers. Base greater than limit, a range of reasonable size, equal across all threads: all true for the kernel stack.
Now: [10b6efb000, 10b6f00000), with the local at 10b6eff1c4. Inside.
And the read uses ReadProcessMemory even though it is this process
A thread can die between the traversal and the read, and its TEB stops being mapped. A direct access would bring down the whole process. The read returns false and the entry keeps the zeros this module uses to say I could not.
One handle for the whole traversal, not one per thread. When the process cannot be opened, the limits come out zeroed and the rest of the entry comes out the same as before. Losing the stack cannot cost the name or the processor time.
On Linux they come out zero, and that is an answer
/proc gives the stack limit only for the main thread. A number that held for one entry and lied for the others is worse than none. The test requires this explicitly: on Linux, no entry carries limits. On Windows, all of them do. And on either system they come in pairs or not at all: a base without a limit would be half an answer about addresses, and half an answer is worse than none because whoever reads it believes it.
Two measurements that measured the machine instead of the module
Running the test suite in Debug with --parallel 8 made this test fail in two places. Neither pointed to a defect in the module, and both were badly designed for the same underlying reason: they assumed a quiet machine.
1. The region traversal used the median
The target is absolute: walking the memory regions has to fit in 1 ms. Twenty samples were taken, and the median was compared with the target.
The median answers "how much does this normally cost on this machine, right now", and when the machine has eight tests competing for the same cores, the answer is about the machine. Under sustained load more than half of the samples come out spoiled, and the median goes with them.
It switched to the minimum, which is the decision this project had already made in event.signal and console.cli: the minimum answers "how much does this cost when nothing gets in the way", which is what an absolute target wants to know. It is only spoiled if all twenty samples hit load.
Both are printed, because the distance between them is what says whether the measurement was reliable.
2. The bisection ran over a moving target
The other case searches, by bisection, for the buffer size at which EnumProcesses overflows and still writes entries: the narrow window between "nothing fits" and "everything fits".
That size depends on how many processes are on the machine and what they are called. That changes from one read to the next, because processes are born and die all the time, and with ctest starting and stopping eight tests, it changes a lot. The window found in one pass was no longer valid at the final read, and the check failed saying it had not found the middle. It was the middle that had moved.
The whole search now repeats up to ten times, and stops as soon as it catches the window at rest. A quiet machine gets it on the first try and pays nothing. The attempt number is printed, so that a machine that needs five says so instead of hiding it.
---
The first run on Linux, and the half fix it found
The signature capability lied again, and on the other side
Compiled( ECapability::eCodeSignature ) answered **false** on Linux. And the QuerySignature there is implemented: it returns eOk with eStatus = eNotApplicable, and its comment explains why. An ELF has no embedded signature, and saying so is answering, not refusing.
What makes this worth recording is the comment that was already in Compiled at the time (today it has been rewritten in English):
*"It was a lie against the module's own policy. The header promises that whoever asks first receives the same information they would receive by calling. Here
QuerySignatureworked and the capability answeredfalse."*
**That fix had been born inside an #if defined( ETL_PLATFORM_WINDOWS ).** The diagnosis was right, it was written down, and the fix covered half of the platforms, leaving on Linux exactly the lie that the text above describes as resolved.
And what caught it was the check that tests neither of the two halves
Check( Compiled( ECapability::eCodeSignature ) == bCallKnows,
"the signature capability agrees with what the call does" );It does not ask whether the capability is right, nor whether the call works: it asks whether the two agree. Each of the two halves passes its own tests on its own, and they only disagree with each other. That is why this check saw what neither saw alone.
**The capability asks whether the code exists, not whether the answer is yes.**
eNotApplicableis an answer. Whoever wants to know whether there is a valid signature looks ateStatus. Whoever wants to know whether they can ask looks at the capability.
And the two-pass protocol does not measure the same thing on both platforms
This was only learned with both running, and it took three versions of the same check: the original had a Windows shape, the first fix ended up with a Linux shape, and only the third states the contract.
| what the first pass returns | |
|---|---|
| Windows | ERR_BUFFER, a large uNeeded, count zeroed |
| Linux | OK, count done, uNeeded zeroed |
On Windows the thread traversal goes through SystemProcessInformation, which returns the entire process tree at once: without a buffer there is nothing, not even the count. On Linux the read is from /proc/<pid>/task/, one entry at a time, and there is no text to store.
What both promise is only this: after the measuring pass, you know what is needed for the second pass to succeed. Which of the two things you learn depends on how the platform collects the data, and neither form is more correct than the other. The test now requires what is common (the first pass taught something) and prints both, which is what keeps the difference visible to whoever reads the report.
And there was a
malloc( 0 )on the path: the standard allows it to returnNULL, and that would have sent the case to the out of memory branch on a platform that simply does not ask for a buffer. It would have stayed green without running, which is worse than failing.
What is still missing from spec 05
- ~~**
iStackBaseandiStackLimitinSThreadInfo.~~ Delivered**, in both layers (see the dedicated section above). And the assumption written here, thatNtQueryInformationThreadwas needed per thread, was wrong: theSystemExtendedProcessInformationclass carries the TEB in the same traversal, without any handle per entry. On Linux they come out zero, and the test requires them to come out zero in all entries. - The batched remote read (
ReadRemoteMemoryBatch) exists in C++ and does not cross to C. The other two do. - The environment, which is what this README already said and is still true: testing as a non-elevated user, cross-platform parity conformance, a 24 h soak at 1 Hz, and TSan.
- And none of this was compiled on Linux. The paths for
/sys/block,getifaddrs,/etc/machine-idand/proc/<pid>/mapsare written and have not been through any compiler, because this test machine runs Windows. This is stated, and not delivered silently.
---