aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-11-03 01:51:25 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2023-11-03 01:51:25 -0400
commit4e13804bb9e0480bbf2c0753de994482246cada8 (patch)
tree47fecba668630296a9409e3ec02816391550b843
parent59599b0f3e57d1881639d482bf1758c7f93d0dc2 (diff)
patch zero overrun
-rw-r--r--README.md2
-rw-r--r--lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs1
-rw-r--r--lib/Utils/src/Memory/MemoryUtil.cs32
-rw-r--r--lib/Utils/src/Memory/UnsafeMemoryHandle.cs15
4 files changed, 25 insertions, 25 deletions
diff --git a/README.md b/README.md
index 0368302..433fb48 100644
--- a/README.md
+++ b/README.md
@@ -37,7 +37,7 @@ Again, go to my website below, my email address is available, go ahead and send
- [Net.Messaging.FBM](lib/Net.Messaging.FBM/#) - Fixed Buffer Messaging protocol, high performance, request/response architecture, client & server library, built atop http and web-sockets. As implied, relies on fixed sized internal buffers that are negotiated to transfer data with minimal overhead for known messaging architectures.
- [Utils.Memory](lib/Utils.Memory/#) - Utilty libraries for native memory management framework for VNLib, including an x64 CMake build of rpmalloc.
- [Net.Compression](lib/Net.Compression/#) - A cross platform native compression provider and IHttpCompressorManager configured for runtime dynamic loading for high performance native response data compression.
-- [Net.Rest.Client](lib/Net.Rest.Client/#) - A minimal library that provides a RestSharp client resource pool for concurrent usage with async support, along with an OAuth2 client credentials IAuthenticator implementation for use with Oauth2 plugins.
+- [Net.Rest.Client](lib/Net.Rest.Client/#) - A library for defining REST api clients via a fluent api by defining sites and endpoints, OAuth2 authenticator for RestSharp, and a simple RestSharp client pool.
## Builds & Source
Builds contain the individual components listed below packaged per-project, available for download on my website. Build packages will be tgz archives (except for nuget packages). You can obtain debug and release builds, along with per-project source code
diff --git a/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs b/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs
index 7b391a0..ee49f99 100644
--- a/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs
+++ b/lib/Plugins.Essentials.ServiceStack/src/Construction/SsBuilderExtensions.cs
@@ -26,7 +26,6 @@ using System;
using System.IO;
using System.Net;
using System.Linq;
-using System.Threading.Tasks;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
diff --git a/lib/Utils/src/Memory/MemoryUtil.cs b/lib/Utils/src/Memory/MemoryUtil.cs
index a1ad0c1..52a9528 100644
--- a/lib/Utils/src/Memory/MemoryUtil.cs
+++ b/lib/Utils/src/Memory/MemoryUtil.cs
@@ -350,17 +350,25 @@ namespace VNLib.Utils.Memory
/// Zeroes a block of memory pointing to the structure
/// </summary>
/// <typeparam name="T">The structure type</typeparam>
- /// <param name="structPtr">The pointer to the allocated structure</param>
+ /// <param name="structRef">The reference to the allocated structure</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ZeroStruct<T>(void* structPtr) where T: unmanaged => InitializeBlock((T*)structPtr, Unsafe.SizeOf<T>());
+ public static void ZeroStruct<T>(ref T structRef) where T : unmanaged => InitializeBlock(ref structRef, 1);
/// <summary>
/// Zeroes a block of memory pointing to the structure
/// </summary>
/// <typeparam name="T">The structure type</typeparam>
- /// <param name="block">The pointer to the allocated structure</param>
+ /// <param name="structPtr">The pointer to the allocated structure</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ZeroStruct<T>(IntPtr block) where T : unmanaged => ZeroStruct<T>(block.ToPointer());
+ public static void ZeroStruct<T>(T* structPtr) where T : unmanaged
+ {
+ if (structPtr == null)
+ {
+ throw new ArgumentNullException(nameof(structPtr));
+ }
+
+ ZeroStruct(ref *structPtr);
+ }
/// <summary>
/// Zeroes a block of memory pointing to the structure
@@ -368,24 +376,17 @@ namespace VNLib.Utils.Memory
/// <typeparam name="T">The structure type</typeparam>
/// <param name="structPtr">The pointer to the allocated structure</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ZeroStruct<T>(T* structPtr) where T : unmanaged => ZeroStruct<T>((void*)structPtr);
+ public static void ZeroStruct<T>(void* structPtr) where T: unmanaged => ZeroStruct((T*)structPtr);
/// <summary>
/// Zeroes a block of memory pointing to the structure
/// </summary>
/// <typeparam name="T">The structure type</typeparam>
- /// <param name="structRef">The reference to the allocated structure</param>
+ /// <param name="block">The pointer to the allocated structure</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void ZeroStruct<T>(ref T structRef) where T : unmanaged
- {
- if(Unsafe.IsNullRef(ref structRef))
- {
- throw new ArgumentNullException(nameof(structRef));
- }
+ public static void ZeroStruct<T>(IntPtr block) where T : unmanaged => ZeroStruct<T>(block.ToPointer());
+
- Unsafe.InitBlock(ref Unsafe.As<T, byte>(ref structRef), 0, (uint)sizeof(T));
- }
-
#endregion
#region Copy
@@ -526,7 +527,6 @@ namespace VNLib.Utils.Memory
public static void CopyStruct<T>(ReadOnlySpan<byte> sourceData, void* target) where T: unmanaged => CopyStruct(sourceData, (T*)target);
-
/// <summary>
/// Copies the memory of the structure pointed to by the source pointer to the target
/// reference data sequence
diff --git a/lib/Utils/src/Memory/UnsafeMemoryHandle.cs b/lib/Utils/src/Memory/UnsafeMemoryHandle.cs
index e4857d1..6a1fcc8 100644
--- a/lib/Utils/src/Memory/UnsafeMemoryHandle.cs
+++ b/lib/Utils/src/Memory/UnsafeMemoryHandle.cs
@@ -46,19 +46,20 @@ namespace VNLib.Utils.Memory
Pool,
PrivateHeap
}
-
- private readonly T[]? _poolArr;
+
private readonly IntPtr _memoryPtr;
+ private readonly int _length;
+ private readonly HandleType _handleType;
+
+ private readonly T[]? _poolArr;
private readonly ArrayPool<T>? _pool;
private readonly IUnmangedHeap? _heap;
- private readonly HandleType _handleType;
- private readonly int _length;
///<inheritdoc/>
public readonly Span<T> Span
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => _handleType == HandleType.Pool ? _poolArr.AsSpan(0, IntLength) : MemoryUtil.GetSpan<T>(_memoryPtr, IntLength);
+ get => _handleType == HandleType.Pool ? _poolArr.AsSpan(0, _length) : MemoryUtil.GetSpan<T>(_memoryPtr, _length);
}
/// <summary>
/// Gets the integer number of elements of the block of memory pointed to by this handle
@@ -153,7 +154,7 @@ namespace VNLib.Utils.Memory
///<inheritdoc/>
public readonly override int GetHashCode() => _handleType == HandleType.Pool ? _poolArr!.GetHashCode() : _memoryPtr.GetHashCode();
///<inheritdoc/>
- public readonly unsafe MemoryHandle Pin(int elementIndex)
+ public readonly MemoryHandle Pin(int elementIndex)
{
//guard empty handle
if (_handleType == HandleType.None)
@@ -162,7 +163,7 @@ namespace VNLib.Utils.Memory
}
//Guard size
- if (elementIndex < 0 || elementIndex >= IntLength)
+ if (elementIndex < 0 || elementIndex >= _length)
{
throw new ArgumentOutOfRangeException(nameof(elementIndex));
}