Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(windows): retain unpublished runtimes after cleanup failure

morlutof78d137b4274
diff --git a/native/windows/src/addon.cc b/native/windows/src/addon.cc
index bffd4cbd4..ba4b5c0b5 100644
--- a/native/windows/src/addon.cc
+++ b/native/windows/src/addon.cc
@@ -60,6 +60,15 @@ napi_value wrap(napi_env env, std::unique_ptr<Resource> value) {
value.release();
return result;
}
+void publishRuntimeHandle(napi_env env, napi_value observation, std::unique_ptr<Runtime>& value) {
+ auto handle = object(env);
+ check(napi_type_tag_object(env, handle, &RESOURCE_TAG));
+ // Complete the result before transferring cleanup ownership. Any earlier
+ // N-API failure leaves the unpublished runtime in its environment owner.
+ set(env, observation, "handle", handle);
+ check(napi_wrap(env, handle, value.get(), finalize, nullptr, nullptr));
+ value.release();
+}
Resource& resource(napi_env env, napi_value value, Kind kind) {
bool tagged = false;
check(napi_check_object_type_tag(env, value, &RESOURCE_TAG, &tagged));
@@ -77,8 +86,15 @@ napi_value failureValue(napi_env env, const Failure& failure) {
std::wstring detail = message == nullptr ? L"" : message;
if (message != nullptr) LocalFree(message);
const std::wstring constraint(failure.constraint.begin(), failure.constraint.end());
- auto text = string(env, constraint + (failure.path.empty() ? L"" : L" [" + failure.path + L"]") +
- L" (Win32 " + std::to_wstring(failure.win32) + L"): " + detail);
+ std::wstring renderedMessage = constraint + (failure.path.empty() ? L"" : L" [" + failure.path + L"]") +
+ L" (Win32 " + std::to_wstring(failure.win32) + L"): " + detail;
+ if (!failure.cleanupConstraint.empty()) {
+ const std::wstring cleanup(failure.cleanupConstraint.begin(), failure.cleanupConstraint.end());
+ renderedMessage += L"; cleanup also failed: " + cleanup +
+ (failure.cleanupPath.empty() ? L"" : L" [" + failure.cleanupPath + L"]") +
+ L" (Win32 " + std::to_wstring(failure.cleanupWin32) + L")";
+ }
+ auto text = string(env, renderedMessage);
napi_value error; napi_create_error(env, nullptr, text, &error);
const char* code = failure.win32 == ERROR_FILE_NOT_FOUND || failure.win32 == ERROR_PATH_NOT_FOUND ? "ENOENT"
: failure.win32 == ERROR_ACCESS_DENIED ? "EACCES" : "ERR_REA_WINDOWS_NATIVE";
@@ -87,21 +103,24 @@ napi_value failureValue(napi_env env, const Failure& failure) {
set(env, error, "requestedPath", string(env, failure.path));
set(env, error, "win32Code", number(env, failure.win32));
set(env, error, "win32Message", string(env, detail));
+ if (!failure.cleanupConstraint.empty()) {
+ set(env, error, "cleanupConstraint", string(env, failure.cleanupConstraint));
+ set(env, error, "cleanupRequestedPath", string(env, failure.cleanupPath));
+ set(env, error, "cleanupWin32Code", number(env, failure.cleanupWin32));
+ }
if (failure.runtimeDirectoryUnallocated)
set(env, error, "runtimeAllocation", string(env, std::string("not-started")));
return error;
}
-struct InspectionContext { std::unique_ptr<Runtime> probe; };
-
-static void cleanupInspection(void* data) noexcept {
- std::unique_ptr<InspectionContext> context(static_cast<InspectionContext*>(data));
- if (!context->probe) return;
- try { closeRuntime(*context->probe); }
+static void cleanupRuntimeContext(void* data) noexcept {
+ std::unique_ptr<RuntimeContext> context(static_cast<RuntimeContext*>(data));
+ if (!context->pending) return;
+ try { closeRuntime(*context->pending); }
catch (const Failure& failure) {
// Environment teardown cannot retain an owner or return an error. Report
// terminal cleanup failure instead of claiming the directory was removed.
- std::fprintf(stderr, "REA Windows probe cleanup failed (Win32 %lu) path=\"",
+ std::fprintf(stderr, "REA Windows runtime cleanup failed (Win32 %lu) path=\"",
static_cast<unsigned long>(failure.win32));
// Emit reversible UTF-16 escapes without allocation or CRT locale conversion.
for (wchar_t unit : failure.path) {
@@ -112,10 +131,10 @@ static void cleanupInspection(void* data) noexcept {
std::fprintf(stderr, "\"\n");
}
catch (const std::exception& failure) {
- std::fprintf(stderr, "REA Windows probe cleanup failed: %s\n", failure.what());
+ std::fprintf(stderr, "REA Windows runtime cleanup failed: %s\n", failure.what());
}
catch (...) {
- std::fprintf(stderr, "REA Windows probe cleanup failed: unknown native exception\n");
+ std::fprintf(stderr, "REA Windows runtime cleanup failed: unknown native exception\n");
}
}
@@ -128,12 +147,13 @@ static napi_value call(napi_env env, napi_callback_info info) {
require(count == 2, "Native call requires operation and arguments", L"", ERROR_INVALID_PARAMETER);
const auto operation = wide(env, args[0]);
const auto values = array(env, args[1]);
+ auto& context = *static_cast<RuntimeContext*>(data);
if (operation == L"inspect") {
require(values.empty(), "Inspect takes no arguments", L"", ERROR_INVALID_PARAMETER);
- return inspect(env, static_cast<InspectionContext*>(data)->probe);
+ return inspect(env, context.pending);
}
if (operation.rfind(L"process_", 0) == 0) return processCall(env, operation, values);
- return filesystemCall(env, operation, values);
+ return filesystemCall(env, operation, values, context);
} catch (const Failure& failure) {
auto error = failureValue(env, failure);
napi_throw(env, error);
@@ -145,8 +165,8 @@ static napi_value call(napi_env env, napi_callback_info info) {
}
static napi_value initialize(napi_env env, napi_value exports) {
- auto context = std::make_unique<InspectionContext>();
- if (napi_add_env_cleanup_hook(env, cleanupInspection, context.get()) != napi_ok) return nullptr;
+ auto context = std::make_unique<RuntimeContext>();
+ if (napi_add_env_cleanup_hook(env, cleanupRuntimeContext, context.get()) != napi_ok) return nullptr;
// The environment owns callback data before a function can expose it. Failed
// initialization still leaves a valid context for the registered cleanup hook.
auto* data = context.release();
diff --git a/native/windows/src/authority.hpp b/native/windows/src/authority.hpp
index c8bed30dc..0c10dd113 100644
--- a/native/windows/src/authority.hpp
+++ b/native/windows/src/authority.hpp
@@ -33,6 +33,9 @@ struct Failure : std::runtime_error {
DWORD win32;
std::wstring path;
std::string constraint;
+ std::string cleanupConstraint;
+ DWORD cleanupWin32 = ERROR_SUCCESS;
+ std::wstring cleanupPath;
// Affirmative proof for a failed runtime-parent admission; omission is unknown.
bool runtimeDirectoryUnallocated = false;
Failure(std::string constraint, std::wstring path = L"", DWORD code = GetLastError())
@@ -96,6 +99,9 @@ struct Runtime : Resource {
std::atomic_bool snapshotCancelled{false};
Runtime() : Resource(Kind::Runtime) {}
};
+// A failed, not-yet-published runtime remains owned by its N-API environment
+// until a later admission or environment teardown can retry cleanup by handle.
+struct RuntimeContext { std::unique_ptr<Runtime> pending; };
struct Process : Resource {
Handle job, process, stdoutRead, stderrRead, stdinWrite;
// Present only for a job with a commit limit; receives the job's notifications.
@@ -120,21 +126,24 @@ std::wstring wide(napi_env env, napi_value value);
double numeric(napi_env env, napi_value value);
std::vector<napi_value> array(napi_env env, napi_value value);
napi_value wrap(napi_env env, std::unique_ptr<Resource> resource);
+void publishRuntimeHandle(napi_env env, napi_value observation, std::unique_ptr<Runtime>& runtime);
Resource& resource(napi_env env, napi_value value, Kind kind);
std::unique_ptr<File> openFile(const std::wstring& path, DWORD access = GENERIC_READ,
bool directory = false,
DWORD finalSharing = FILE_SHARE_READ);
napi_value identity(napi_env env, HANDLE handle, const std::wstring& path);
-std::unique_ptr<Runtime> createRuntime(const std::wstring& parent, const std::wstring& prefix);
+void createRuntime(const std::wstring& parent, const std::wstring& prefix,
+ std::unique_ptr<Runtime>& owner);
+void cleanupFailedRuntime(std::unique_ptr<Runtime>& owner, Failure& primary);
void closeRuntime(Runtime& runtime);
napi_value filesystemCall(napi_env env, const std::wstring& operation,
- const std::vector<napi_value>& args);
+ const std::vector<napi_value>& args, RuntimeContext& context);
std::unique_ptr<Process> spawnProcess(const std::wstring& command, const std::wstring& commandLine,
const std::wstring& cwd, const std::vector<std::wstring>& environment,
bool protocolStdin = false, ULONGLONG memoryLimit = 0);
napi_value processCall(napi_env env, const std::wstring& operation,
const std::vector<napi_value>& args);
-napi_value inspect(napi_env env, std::unique_ptr<Runtime>& probe);
+napi_value inspect(napi_env env, std::unique_ptr<Runtime>& pending);
} // namespace rea
diff --git a/native/windows/src/filesystem.cc b/native/windows/src/filesystem.cc
index 0544286e2..d4b5d0c4a 100644
--- a/native/windows/src/filesystem.cc
+++ b/native/windows/src/filesystem.cc
@@ -184,6 +184,29 @@ static Handle createRelative(HANDLE parent, const std::wstring& name, DWORD acce
return result;
}
+void cleanupFailedRuntime(std::unique_ptr<Runtime>& owner, Failure& primary) {
+ if (!owner || !owner->directory.valid()) {
+ owner.reset();
+ return;
+ }
+ try {
+ closeRuntime(*owner);
+ owner.reset();
+ } catch (const Failure& cleanup) {
+ primary.cleanupConstraint = cleanup.constraint;
+ primary.cleanupWin32 = cleanup.win32;
+ primary.cleanupPath = cleanup.path;
+ } catch (const std::exception& cleanup) {
+ primary.cleanupConstraint = cleanup.what();
+ primary.cleanupWin32 = ERROR_GEN_FAILURE;
+ primary.cleanupPath = owner->path;
+ } catch (...) {
+ primary.cleanupConstraint = "Unknown runtime cleanup failure";
+ primary.cleanupWin32 = ERROR_GEN_FAILURE;
+ primary.cleanupPath = owner->path;
+ }
+}
+
// Lookup relative to an already-owned directory; path is diagnostic only.
static Handle openRelative(HANDLE parent, const std::wstring& name, DWORD access,
DWORD sharing, ULONG kind, const std::wstring& path) {
@@ -337,7 +360,11 @@ static napi_value readCutterBridgeDescriptor(napi_env env, const std::vector<nap
return result;
}
-std::unique_ptr<Runtime> createRuntime(const std::wstring& parentPath, const std::wstring& prefix) {
+void createRuntime(const std::wstring& parentPath, const std::wstring& prefix,
+ std::unique_ptr<Runtime>& owner) {
+ // A previous failed admission retains the original root handle. Retry that
+ // owner before allowing this environment to allocate another runtime.
+ if (owner) { closeRuntime(*owner); owner.reset(); }
std::unique_ptr<File> parent;
try { parent = openFile(parentPath, 0, true); }
catch (Failure& failure) {
@@ -349,24 +376,27 @@ std::unique_ptr<Runtime> createRuntime(const std::wstring& parentPath, const std
std::array<unsigned char, 16> random;
require(BCryptGenRandom(nullptr, random.data(), random.size(), BCRYPT_USE_SYSTEM_PREFERRED_RNG) == 0,
"Generate runtime identity failed", parentPath, ERROR_GEN_FAILURE);
+ Security security;
auto result = std::make_unique<Runtime>();
const auto name = prefix + hex(random.data(), random.size());
result->path = parent->path + (parent->path.back() == L'\\' ? L"" : L"\\") + name;
- Security security;
- result->directory = createRelative(parent->get(), name,
- DELETE | FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES | READ_CONTROL,
- true, security, result->path);
+ result->parents = std::move(parent->handles);
+ owner = std::move(result);
try {
- verifyPrivate(result->directory.get(), result->path, true);
+ owner->directory = createRelative(owner->parents.back().get(), name,
+ DELETE | FILE_LIST_DIRECTORY | FILE_READ_ATTRIBUTES | READ_CONTROL,
+ true, security, owner->path);
+ verifyPrivate(owner->directory.get(), owner->path, true);
// The owned child pins the parent nonempty before write sharing is relaxed.
- parent->handles.back() = openComponent(parent->path, 0, true, FILE_SHARE_READ | FILE_SHARE_WRITE);
- result->parents = std::move(parent->handles);
- } catch (...) {
- FILE_DISPOSITION_INFO deletion{TRUE};
- SetFileInformationByHandle(result->directory.get(), FileDispositionInfo, &deletion, sizeof(deletion));
+ owner->parents.back() = openComponent(parent->path, 0, true, FILE_SHARE_READ | FILE_SHARE_WRITE);
+ } catch (Failure& primary) {
+ cleanupFailedRuntime(owner, primary);
throw;
+ } catch (const std::exception& error) {
+ Failure primary(error.what(), owner->path, ERROR_GEN_FAILURE);
+ cleanupFailedRuntime(owner, primary);
+ throw primary;
}
- return result;
}
static std::wstring relativePath(Runtime& root, const std::wstring& relative) {
@@ -660,7 +690,8 @@ static napi_value snapshot(napi_env env, napi_value rootValue, Runtime& root,
return promise;
}
-napi_value filesystemCall(napi_env env, const std::wstring& operation, const std::vector<napi_value>& args) {
+napi_value filesystemCall(napi_env env, const std::wstring& operation,
+ const std::vector<napi_value>& args, RuntimeContext& context) {
if (operation == L"cutter_bridge_verify_directory") return verifyCutterBridgeDirectory(env, args);
if (operation == L"cutter_bridge_read_descriptor") return readCutterBridgeDescriptor(env, args);
const auto expected = operation == L"open" || operation == L"close" || operation == L"runtime_close" || operation == L"runtime_snapshot_cancel" ? 1
@@ -694,12 +725,21 @@ napi_value filesystemCall(napi_env env, const std::wstring& operation, const std
return result;
}
if (operation == L"runtime_create") {
- auto root = createRuntime(wide(env, args[0]), wide(env, args[1]));
- auto result = identity(env, root->directory.get(), root->path);
- set(env, result, "path", string(env, root->path));
- set(env, result, "privateDacl", boolean(env, true));
- set(env, result, "handle", wrap(env, std::move(root)));
- return result;
+ createRuntime(wide(env, args[0]), wide(env, args[1]), context.pending);
+ try {
+ auto result = identity(env, context.pending->directory.get(), context.pending->path);
+ set(env, result, "path", string(env, context.pending->path));
+ set(env, result, "privateDacl", boolean(env, true));
+ publishRuntimeHandle(env, result, context.pending);
+ return result;
+ } catch (Failure& primary) {
+ cleanupFailedRuntime(context.pending, primary);
+ throw;
+ } catch (const std::exception& error) {
+ Failure primary(error.what(), context.pending ? context.pending->path : L"", ERROR_GEN_FAILURE);
+ cleanupFailedRuntime(context.pending, primary);
+ throw primary;
+ }
}
auto& root = static_cast<Runtime&>(resource(env, args[0], Kind::Runtime));
require(!root.closing || operation == L"runtime_close", "Runtime cleanup is pending", root.path, ERROR_BUSY);
diff --git a/native/windows/src/process.cc b/native/windows/src/process.cc
index 55e415345..bfdbbcdb6 100644
--- a/native/windows/src/process.cc
+++ b/native/windows/src/process.cc
@@ -454,17 +454,27 @@ napi_value processCall(napi_env env, const std::wstring& operation, const std::v
throw Failure("Unknown native process operation", L"", ERROR_INVALID_PARAMETER);
}
-napi_value inspect(napi_env env, std::unique_ptr<Runtime>& probe) {
+napi_value inspect(napi_env env, std::unique_ptr<Runtime>& pending) {
// Settle the previous owner before admitting another probe. Failed cleanup
// retains its handles, including when identity construction itself failed.
- if (probe) { closeRuntime(*probe); probe.reset(); }
+ if (pending) { closeRuntime(*pending); pending.reset(); }
wchar_t temp[32768];
const auto length = GetTempPathW(32768, temp);
require(length > 0 && length < 32768, "Read temporary directory coordinate failed");
- probe = createRuntime(std::wstring(temp, length), L"rea-native-probe-");
- auto filesystem = identity(env, probe->directory.get(), probe->path);
- closeRuntime(*probe);
- probe.reset();
+ createRuntime(std::wstring(temp, length), L"rea-native-probe-", pending);
+ napi_value filesystem;
+ try {
+ filesystem = identity(env, pending->directory.get(), pending->path);
+ } catch (Failure& primary) {
+ cleanupFailedRuntime(pending, primary);
+ throw;
+ } catch (const std::exception& error) {
+ Failure primary(error.what(), pending ? pending->path : L"", ERROR_GEN_FAILURE);
+ cleanupFailedRuntime(pending, primary);
+ throw primary;
+ }
+ closeRuntime(*pending);
+ pending.reset();
auto job = createJob();
Attributes attributes(1);
HANDLE raw = job.get();
diff --git a/scripts/verify-windows-native-inspection.mjs b/scripts/verify-windows-native-inspection.mjs
index 8480589a4..9c5375cdf 100644
--- a/scripts/verify-windows-native-inspection.mjs
+++ b/scripts/verify-windows-native-inspection.mjs
@@ -55,14 +55,29 @@ try {
join(workspace, "dist", "windows", "WindowsNativeLoader.js"),
).href;
const source = `import assert from 'node:assert/strict';
+import {createRequire} from 'node:module';
import {existsSync,mkdirSync,readFileSync,readdirSync,renameSync,statSync,writeFileSync} from 'node:fs';
import {join} from 'node:path';
import {systemWindowsNativeAuthority} from ${JSON.stringify(loader)};
const temp=process.env.TEMP;
-const first=systemWindowsNativeAuthority();
-assert.equal(first.available,false);
-assert.equal(first.retryable,true);
-assert.match(first.reason,/Delete owned object by handle failed.*Win32 5/s);
+const mode=process.argv[2];
+const creation=mode.startsWith('create-');
+const native=creation?createRequire(import.meta.url)(${JSON.stringify(join(workspace, "native", "windows", "build", "rea-windows-x64.node"))}):null;
+if(creation){
+ let failure;
+ try{native.call('runtime_create',[temp,'rea-native-created-'])}catch(error){failure=error}
+ assert.ok(failure instanceof Error,'runtime_create unexpectedly passed injected post-create validation failure');
+ assert.equal(failure.constraint,'Read private DACL by handle failed');
+ assert.equal(failure.win32Code,5);
+ assert.equal(failure.cleanupConstraint,'Delete owned object by handle failed');
+ assert.equal(failure.cleanupWin32Code,5);
+ assert.notEqual(failure.runtimeAllocation,'not-started');
+} else {
+ const first=systemWindowsNativeAuthority();
+ assert.equal(first.available,false);
+ assert.equal(first.retryable,true);
+ assert.match(first.reason,/Delete owned object by handle failed.*Win32 5/s);
+}
const [name,...extra]=readdirSync(temp);assert.ok(name);assert.equal(extra.length,0);
const path=join(temp,name);const identity=statSync(path,{bigint:true});
// Delete sharing permits rename; ownership follows the retained NTFS handle.
@@ -73,26 +88,40 @@ assert.equal(moved.dev,identity.dev);assert.equal(moved.ino,identity.ino);
mkdirSync(path);const replacement=statSync(path,{bigint:true});
assert.notEqual(replacement.ino,identity.ino);
const sentinel=join(path,'unrelated.txt');writeFileSync(sentinel,'unrelated replacement');
-if(process.argv[2]!=='teardown'){
+if(mode==='retry'){
const second=systemWindowsNativeAuthority();assert.equal(second.available,true);
assert.equal(existsSync(renamed),false);
assert.deepEqual(readdirSync(temp),[name]);
assert.equal(readFileSync(sentinel,'utf8'),'unrelated replacement');
assert.equal(statSync(path,{bigint:true}).ino,replacement.ino);
assert.equal(systemWindowsNativeAuthority(),second);
+} else if(mode==='create-retry') {
+ const second=native.call('runtime_create',[temp,'rea-native-created-retry-']);
+ assert.equal(existsSync(renamed),false);
+ assert.equal(readFileSync(sentinel,'utf8'),'unrelated replacement');
+ native.call('runtime_close',[second.handle]);
+ assert.equal(existsSync(second.path),false);
+ assert.equal(statSync(path,{bigint:true}).ino,replacement.ino);
}
-console.log(JSON.stringify({mode:process.argv[2],firstFailed:true,retainedOwner:true,name,renamed,device:identity.dev.toString(),inode:identity.ino.toString(),replacementInode:replacement.ino.toString()}));
+console.log(JSON.stringify({mode,firstFailed:true,retainedOwner:true,name,renamed,device:identity.dev.toString(),inode:identity.ino.toString(),replacementInode:replacement.ino.toString()}));
`;
const fixture = join(workspace, "probe.mjs");
await writeFile(fixture, source);
- for (const mode of ["retry", "teardown"]) {
+ for (const mode of ["retry", "teardown", "create-retry", "create-teardown"]) {
const temp = join(workspace, mode);
await mkdir(temp);
const child = spawnSync(process.execPath, [fixture, mode], {
encoding: "utf8",
timeout: 20_000,
windowsHide: true,
- env: { ...process.env, TEMP: temp, TMP: temp },
+ env: {
+ ...process.env,
+ TEMP: temp,
+ TMP: temp,
+ ...(mode.startsWith("create-")
+ ? { REA_NATIVE_CREATION_FAILURE: "1" }
+ : {}),
+ },
});
if (child.error !== undefined) throw child.error;
assert.equal(child.status, 0, child.stderr);
@@ -119,7 +148,7 @@ console.log(JSON.stringify({mode:process.argv[2],firstFailed:true,retainedOwner:
);
}
process.stdout.write(
- `${JSON.stringify({ ok: true, controlledDispositionFailure: true, retainedOwner: true, renamedOwnerCleansChildren: true, unrelatedReplacementPreserved: true, retryRecovers: true, successfulAdmissionCached: true, environmentTeardownCleansProbe: true, issue1701HostCauseReproduced: false })}\n`,
+ `${JSON.stringify({ ok: true, inspectionPostCreateValidationFailure: true, runtimeCreatePostCreateValidationFailure: true, controlledRollbackDispositionFailure: true, retainedOwner: true, renamedOwnerCleansChildren: true, unrelatedReplacementPreserved: true, retryRecoversByInspectionAndCreation: true, successfulAdmissionCached: true, environmentTeardownCleansProbeAndCreation: true, issue1701HostCauseReproduced: false })}\n`,
);
} finally {
await rm(workspace, { recursive: true, force: true });
diff --git a/tests/fixtures/windows-native-inspection-failure.cc b/tests/fixtures/windows-native-inspection-failure.cc
index df93e4853..a2285dbba 100644
--- a/tests/fixtures/windows-native-inspection-failure.cc
+++ b/tests/fixtures/windows-native-inspection-failure.cc
@@ -3,11 +3,11 @@
#include "../../native/windows/src/authority.hpp"
#include <atomic>
-static BOOL inspectionDisposition(HANDLE handle, FILE_INFO_BY_HANDLE_CLASS kind,
- LPVOID value, DWORD size) {
- // A real NTFS probe is created normally. Fail its first disposition call so
- // the verifier can observe ownership after failure, independently of host
- // filter drivers or the intermittent error reported in issue #1701.
+static BOOL fixtureDisposition(HANDLE handle, FILE_INFO_BY_HANDLE_CLASS kind,
+ LPVOID value, DWORD size) {
+ // A real NTFS runtime is created normally. Fail its first rollback
+ // disposition so the verifier can observe the owner after post-create
+ // validation fails, independent of host filesystem behavior.
static std::atomic_flag failed = ATOMIC_FLAG_INIT;
if (kind == FileDispositionInfo && !failed.test_and_set()) {
SetLastError(ERROR_ACCESS_DENIED);
@@ -16,5 +16,18 @@ static BOOL inspectionDisposition(HANDLE handle, FILE_INFO_BY_HANDLE_CLASS kind,
return SetFileInformationByHandle(handle, kind, value, size);
}
-#define SetFileInformationByHandle inspectionDisposition
+static DWORD inspectionSecurityInfo(HANDLE handle, SE_OBJECT_TYPE kind,
+ SECURITY_INFORMATION information,
+ PSID* owner, PSID* group, PACL* dacl, PACL* sacl,
+ PSECURITY_DESCRIPTOR* descriptor) {
+ // Force validation to fail only after FILE_CREATE has allocated the root.
+ static std::atomic_flag failed = ATOMIC_FLAG_INIT;
+ wchar_t enabled[2];
+ if (GetEnvironmentVariableW(L"REA_NATIVE_CREATION_FAILURE", enabled, 2) > 0 &&
+ !failed.test_and_set()) return ERROR_ACCESS_DENIED;
+ return GetSecurityInfo(handle, kind, information, owner, group, dacl, sacl, descriptor);
+}
+
+#define SetFileInformationByHandle fixtureDisposition
+#define GetSecurityInfo inspectionSecurityInfo
#include "../../native/windows/src/filesystem.cc"