Skip to content

Commit

Permalink
Minimal changes to zerolib to support more use cases. (#181)
Browse files Browse the repository at this point in the history
* Minimal changes to zerolib to support more use cases.

* Adding .NET method to access command line args.

* Integrating Michal's feedback 2/22/24
  • Loading branch information
lucabol committed Feb 25, 2024
1 parent 2f05968 commit f1e4bcf
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/zerolib/Internal/Startup.Efi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal static unsafe void InitializeCommandLineArgsW(int argc, char** argv)
// argc and argv are garbage because EfiMain didn't pass any
}

private static string[] GetMainMethodArguments()
internal static string[] GetMainMethodArguments()
{
return new string[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/zerolib/Internal/Startup.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static unsafe void InitializeCommandLineArgs(int argc, sbyte** argv)
s_argv = argv;
}

private static string[] GetMainMethodArguments()
internal static string[] GetMainMethodArguments()
{
string[] args = new string[s_argc - 1];
for (int i = 1; i < s_argc; ++i)
Expand Down
2 changes: 1 addition & 1 deletion src/zerolib/Internal/Startup.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal static unsafe void InitializeCommandLineArgsW(int argc, char** argv)
// argc and argv are a lie because CRT didn't start the process on Windows
}

private static string[] GetMainMethodArguments()
internal static string[] GetMainMethodArguments()
{
int argc;
char** argv = CommandLineToArgvW(GetCommandLineW(), &argc);
Expand Down
2 changes: 1 addition & 1 deletion src/zerolib/Internal/Stubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal unsafe struct MethodTable

namespace Internal.Runtime.CompilerHelpers
{
class ThrowHelpers
partial class ThrowHelpers
{
static void ThrowIndexOutOfRangeException() => Environment.FailFast(null);
static void ThrowDivideByZeroException() => Environment.FailFast(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace System.Runtime.CompilerServices
{
// A class responsible for running static constructors. The compiler will call into this
// code to ensure static constructors run and that they only run once.
internal static class ClassConstructorRunner
internal static partial class ClassConstructorRunner
{
private static IntPtr CheckStaticClassConstructionReturnNonGCStaticBase(ref StaticClassConstructionContext context, IntPtr nonGcStaticBase)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ public class CallConvStdcall { }
public class CallConvSuppressGCTransition { }
public class CallConvThiscall { }
public class CallConvMemberFunction { }

public sealed class InlineArrayAttribute : Attribute
{
public InlineArrayAttribute(int size) { }
}

public sealed class ExtensionAttribute : Attribute { }
}
2 changes: 2 additions & 0 deletions src/zerolib/System/Runtime/CompilerServices/Unsafe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ public static unsafe partial class Unsafe
public static extern T As<T>(object o) where T : class;
[Intrinsic]
public static extern void* AsPointer<T>(ref T value);
[Intrinsic]
public static extern ref T AsRef<T>(void* source);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace System.Runtime.InteropServices
{
public enum UnmanagedType { }

public enum CharSet
{
None = 1,
Expand Down
10 changes: 9 additions & 1 deletion src/zerolib/System/Runtime/InteropServices/MemoryMarshal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@

namespace System.Runtime.InteropServices
{
public static class MemoryMarshal
public static partial class MemoryMarshal
{
[Intrinsic]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetArrayDataReference<T>(T[] array) => ref Unsafe.As<byte, T>(ref Unsafe.As<RawArrayData>(array).Data);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static System.Span<T> CreateSpan<T>(ref T reference, int length)
=> new System.Span<T>(Unsafe.AsPointer(ref reference), length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static System.ReadOnlySpan<T> CreateReadOnlySpan<T>(ref T reference, int length)
=> new System.ReadOnlySpan<T>(Unsafe.AsPointer(ref reference), length);
}
}

0 comments on commit f1e4bcf

Please sign in to comment.