diff --git a/src/sys/create.c b/src/sys/create.c index 3b2f807d..eacf7233 100644 --- a/src/sys/create.c +++ b/src/sys/create.c @@ -690,7 +690,7 @@ static NTSTATUS FspFsvolCreateTryOpen(PIRP Irp, const FSP_FSCTL_TRANSACT_RSP *Re FSP_FSCTL_TRANSACT_REQ *Request = FspIrpRequest(Irp); BOOLEAN Success; - Success = FspFileNodeTryAcquireExclusive(FileNode, Both); + Success = DEBUGRANDTEST(90, TRUE) && FspFileNodeTryAcquireExclusive(FileNode, Both); if (!Success) { /* repost the IRP to retry later */ diff --git a/src/sys/debug.c b/src/sys/debug.c index 5dd0a5af..a00514a6 100644 --- a/src/sys/debug.c +++ b/src/sys/debug.c @@ -261,4 +261,22 @@ const char *FsInformationClassSym(FS_INFORMATION_CLASS FsInformationClass) return "FS_INFORMATION_CLASS:Unknown"; } } + +ULONG DebugRandom(VOID) +{ + static KSPIN_LOCK SpinLock = 0; + static ULONG Seed = 1; + KIRQL Irql; + ULONG Result; + + KeAcquireSpinLock(&SpinLock, &Irql); + + /* see ucrt sources */ + Seed = Seed * 214013 + 2531011; + Result = (Seed >> 16) & 0x7fff; + + KeReleaseSpinLock(&SpinLock, Irql); + + return Result; +} #endif diff --git a/src/sys/driver.h b/src/sys/driver.h index 84319e82..3661f04f 100644 --- a/src/sys/driver.h +++ b/src/sys/driver.h @@ -56,7 +56,7 @@ extern __declspec(selectany) int fsp_bp = 1; #define DEBUGBREAK() \ do \ { \ - static int bp = 1; \ + static int bp = 1; \ if (bp && fsp_bp && !KD_DEBUGGER_NOT_PRESENT)\ DbgBreakPoint(); \ } while (0,0) @@ -64,6 +64,13 @@ extern __declspec(selectany) int fsp_bp = 1; #define DEBUGBREAK() do {} while (0,0) #endif +/* DEBUGRANDTEST */ +#if DBG +#define DEBUGRANDTEST(Percent, Default) (DebugRandom() <= (Percent) * 0x7fff / 100 ? (Default) : !(Default)) +#else +#define DEBUGRANDTEST(Percent, Default) (Default) +#endif + /* FSP_ENTER/FSP_LEAVE */ #if DBG #define FSP_DEBUGLOG_(fmt, rfmt, ...) \ @@ -632,6 +639,7 @@ const char *IrpMinorFunctionSym(UCHAR MajorFunction, UCHAR MinorFunction); const char *IoctlCodeSym(ULONG ControlCode); const char *FileInformationClassSym(FILE_INFORMATION_CLASS FileInformationClass); const char *FsInformationClassSym(FS_INFORMATION_CLASS FsInformationClass); +ULONG DebugRandom(VOID); static inline VOID FspDebugLogIrp(const char *func, PIRP Irp, NTSTATUS Result) {