Skip to content

Commit

Permalink
Added fix for waiting for infinite time.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranid committed Feb 4, 2019
1 parent 6a82c53 commit 332cf28
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion NtApiDotNet/NtObjectUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ internal static LargeInteger ToLargeInteger(this long? l)

internal static LargeInteger ToLargeInteger(this NtWaitTimeout timeout)
{
return ToLargeInteger(timeout?.Timeout);
return timeout?.Timeout;
}

internal static int GetLength(this SafeBuffer buffer)
Expand Down
8 changes: 4 additions & 4 deletions NtApiDotNet/NtThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,9 +1045,9 @@ public IContext GetContext(ContextFlags flags)
/// <param name="alertable">Set if the thread should be alertable</param>
/// <param name="delay">The delay, negative values indicate relative times.</param>
/// <returns>True if the thread was alerted before the delay expired.</returns>
public static bool Sleep(bool alertable, long delay)
public static bool Sleep(bool alertable, NtWaitTimeout delay)
{
NtStatus status = NtSystemCalls.NtDelayExecution(alertable, new LargeInteger(delay));
NtStatus status = NtSystemCalls.NtDelayExecution(alertable, delay?.Timeout);
if (!status.IsSuccess())
{
throw new NtException(status);
Expand All @@ -1062,9 +1062,9 @@ public static bool Sleep(bool alertable, long delay)
/// <param name="alertable">Set if the thread should be alertable</param>
/// <param name="delay">The delay, negative values indicate relative times.</param>
/// <returns>True if the thread was alerted before the delay expired.</returns>
public static bool Sleep(bool alertable, NtWaitTimeout delay)
public static bool Sleep(bool alertable, long delay)
{
return Sleep(alertable, delay.Timeout);
return Sleep(alertable, new NtWaitTimeout(delay));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion NtApiDotNet/NtTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ private void SetProperties(int? isolation_level, int? isolation_flags, NtWaitTim
}
if (timeout != null)
{
init_value.Timeout = new LargeIntegerStruct() { QuadPart = timeout.Timeout };
init_value.Timeout = new LargeIntegerStruct() { QuadPart = timeout.Timeout.QuadPart };
}

buffer.Write(0, init_value);
Expand Down
17 changes: 9 additions & 8 deletions NtApiDotNet/NtWait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ internal NtWaitTimeout()

internal NtWaitTimeout(long value)
{
Timeout = value;
Timeout = new LargeInteger(value);
}

/// <summary>
/// Get a timeout which will wait indefinitely.
/// </summary>
public static NtWaitTimeout Infinite { get { return new NtWaitTimeout(); } }
public static NtWaitTimeout Infinite => new NtWaitTimeout();

/// <summary>
/// Get a relative timeout in seconds.
Expand Down Expand Up @@ -108,23 +108,24 @@ public static NtWaitTimeout FromRelative(long relative)
/// <summary>
/// The timeout as a long.
/// </summary>
public long Timeout { get; }
public LargeInteger Timeout { get; }

/// <summary>
/// Overridden ToString method.
/// </summary>
/// <returns>The timeout as a string.</returns>
public override string ToString()
{
if (Timeout < 0)
if (Timeout == null)
{
return $"Relative: {-Timeout}";
return "Infinite";
}
else if (Timeout > 0)

if (Timeout.QuadPart <= 0)
{
return $"Absolute: {Timeout}";
return $"Relative: {-Timeout.QuadPart}";
}
return "Infinite";
return $"Absolute: {Timeout.QuadPart}";
}
}

Expand Down

0 comments on commit 332cf28

Please sign in to comment.