Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into codesign-simulator-by…
Browse files Browse the repository at this point in the history
…-default
  • Loading branch information
rolfbjarne committed Jun 10, 2024
2 parents b3c66b6 + 1216646 commit 9266820
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<VerifyDependencyInjectionOpenGenericServiceTrimmability Condition="'$(VerifyDependencyInjectionOpenGenericServiceTrimmability)' == '' And '$(_BundlerDebug)' != 'true'">false</VerifyDependencyInjectionOpenGenericServiceTrimmability>
<VerifyDependencyInjectionOpenGenericServiceTrimmability Condition="'$(VerifyDependencyInjectionOpenGenericServiceTrimmability)' == ''">true</VerifyDependencyInjectionOpenGenericServiceTrimmability>
<!-- This should be set by dotnet/sdk instead, once https://github.com/dotnet/sdk/issues/25392 gets resolved. -->
<DynamicCodeSupport Condition="'$(DynamicCodeSupport)' == '' And '$(MtouchInterpreter)' != '' And ('$(_PlatformName)' == 'iOS' Or '$(_PlatformName)' == 'tvOS' Or '$(_PlatformName)' == 'MacCatalyst')">false</DynamicCodeSupport>
<DynamicCodeSupport Condition="'$(DynamicCodeSupport)' == '' And '$(MtouchInterpreter)' == '' And ('$(_PlatformName)' == 'iOS' Or '$(_PlatformName)' == 'tvOS' Or '$(_PlatformName)' == 'MacCatalyst')">false</DynamicCodeSupport>

<!-- We don't need to generate reference assemblies for apps or app extensions -->
<ProduceReferenceAssembly Condition="'$(ProduceReferenceAssembly)' == '' And ('$(OutputType)' == 'Exe' Or '$(IsAppExtension)' == 'true')">false</ProduceReferenceAssembly>
Expand Down
6 changes: 4 additions & 2 deletions runtime/coreclr-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@
// get the symbols for the addresses
char** strs = backtrace_symbols (addresses, frames);

const int max_symbol_length = 512; // this is just to have a maximum value, so that we can use strnlen instead of strlen

// compute the total length of all the symbols, adding 1 for every line (for the newline)
size_t length = 0;
int i;
for (i = 0; i < frames; i++)
length += strlen (strs [i]) + 1;
length += strnlen (strs [i], max_symbol_length) + 1;
length++;

// format the symbols as one long string with newlines
Expand All @@ -67,7 +69,7 @@
size_t left = length;
for (i = 0; i < frames; i++) {
snprintf (buffer, left, "%s\n", strs [i]);
size_t slen = strlen (strs [i]) + 1;
size_t slen = strnlen (strs [i], max_symbol_length) + 1;
left -= slen;
buffer += slen;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
if (xamarin_runtime_libraries == NULL)
return false;

size_t libraryNameLength = strlen (libraryName);
size_t libraryNameLength = strnlen (libraryName, 255 /* max length of file name across all relevant file systems currently in use */);
// The libraries in xamarin_runtime_libraries are extension-less, so we need to
// remove any .dylib extension for the library name we're comparing with too.
if (libraryNameLength > 6 && strcmp (libraryName + libraryNameLength - 6, ".dylib") == 0)
Expand Down
111 changes: 107 additions & 4 deletions src/GameController/GCExtendedGamepadSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,16 @@ public struct GCExtendedGamepadSnapshotData {
[iOS (12, 2)]
[TV (12, 2)]
#endif
#if XAMCORE_5_0
byte supportsClickableThumbsticks;
public bool SupportsClickableThumbsticks {
get => supportsClickableThumbsticks != 0;
set => supportsClickableThumbsticks = value.AsByte ();
}
#else
[MarshalAs (UnmanagedType.I1)]
public bool SupportsClickableThumbsticks;
#endif

#if NET
[SupportedOSPlatform ("tvos12.2")]
Expand All @@ -174,8 +182,7 @@ public struct GCExtendedGamepadSnapshotData {
[TV (12, 2)]
[iOS (12, 2)]
#endif
[MarshalAs (UnmanagedType.I1)]
bool LeftThumbstickButton;
byte LeftThumbstickButton;

#if NET
[SupportedOSPlatform ("tvos12.2")]
Expand All @@ -190,8 +197,7 @@ public struct GCExtendedGamepadSnapshotData {
[TV (12, 2)]
[iOS (12, 2)]
#endif
[MarshalAs (UnmanagedType.I1)]
bool RightThumbstickButton;
byte RightThumbstickButton;

#if NET
[SupportedOSPlatform ("tvos12.2")]
Expand All @@ -208,7 +214,11 @@ public struct GCExtendedGamepadSnapshotData {
#endif
[DllImport (Constants.GameControllerLibrary)]
unsafe static extern /* NSData * __nullable */ IntPtr NSDataFromGCExtendedGamepadSnapshotData (
#if XAMCORE_5_0
/* GCExtendedGamepadSnapshotData * __nullable */ GCExtendedGamepadSnapshotData* snapshotData);
#else
/* GCExtendedGamepadSnapshotData * __nullable */ GCExtendedGamepadSnapshotData_Blittable* snapshotData);
#endif

#if NET
[SupportedOSPlatform ("tvos12.2")]
Expand All @@ -226,13 +236,95 @@ public struct GCExtendedGamepadSnapshotData {
public NSData? ToNSData ()
{
unsafe {
#if !XAMCORE_5_0
var blittable = ToBlittable ();
GCExtendedGamepadSnapshotData_Blittable* self = &blittable;
{
#else
fixed (GCExtendedGamepadSnapshotData* self = &this) {
#endif
var p = NSDataFromGCExtendedGamepadSnapshotData (self);
return p == IntPtr.Zero ? null : new NSData (p);
}
}
}

#if !XAMCORE_5_0
internal GCExtendedGamepadSnapshotData_Blittable ToBlittable ()
{
var blittable = new GCExtendedGamepadSnapshotData_Blittable ();
blittable.Version = Version;
blittable.Size = Size;
blittable.DPadX = DPadX;
blittable.DPadY = DPadY;
blittable.ButtonA = ButtonA;
blittable.ButtonB = ButtonB;
blittable.ButtonX = ButtonX;
blittable.ButtonY = ButtonY;
blittable.LeftShoulder = LeftShoulder;
blittable.RightShoulder = RightShoulder;
blittable.LeftThumbstickX = LeftThumbstickX;
blittable.LeftThumbstickY = LeftThumbstickY;
blittable.RightThumbstickX = RightThumbstickX;
blittable.RightThumbstickY = RightThumbstickY;
blittable.LeftTrigger = LeftTrigger;
blittable.RightTrigger = RightTrigger;
blittable.SupportsClickableThumbsticks = SupportsClickableThumbsticks.AsByte ();
blittable.LeftThumbstickButton = LeftThumbstickButton;
blittable.RightThumbstickButton = RightThumbstickButton;
return blittable;
}

internal GCExtendedGamepadSnapshotData (GCExtendedGamepadSnapshotData_Blittable blittable)
{
Version = blittable.Version;
Size = blittable.Size;
DPadX = blittable.DPadX;
DPadY = blittable.DPadY;
ButtonA = blittable.ButtonA;
ButtonB = blittable.ButtonB;
ButtonX = blittable.ButtonX;
ButtonY = blittable.ButtonY;
LeftShoulder = blittable.LeftShoulder;
RightShoulder = blittable.RightShoulder;
LeftThumbstickX = blittable.LeftThumbstickX;
LeftThumbstickY = blittable.LeftThumbstickY;
RightThumbstickX = blittable.RightThumbstickX;
RightThumbstickY = blittable.RightThumbstickY;
LeftTrigger = blittable.LeftTrigger;
RightTrigger = blittable.RightTrigger;
SupportsClickableThumbsticks = blittable.SupportsClickableThumbsticks != 0;
LeftThumbstickButton = blittable.LeftThumbstickButton;
RightThumbstickButton = blittable.RightThumbstickButton;
}
#endif
}


#if !XAMCORE_5_0
[StructLayout (LayoutKind.Sequential, Pack = 1)]
struct GCExtendedGamepadSnapshotData_Blittable {
public ushort Version;
public ushort Size;
public float DPadX;
public float DPadY;
public float ButtonA;
public float ButtonB;
public float ButtonX;
public float ButtonY;
public float LeftShoulder;
public float RightShoulder;
public float LeftThumbstickX;
public float LeftThumbstickY;
public float RightThumbstickX;
public float RightThumbstickY;
public float LeftTrigger;
public float RightTrigger;
public byte SupportsClickableThumbsticks;
public byte LeftThumbstickButton;
public byte RightThumbstickButton;
}
#endif // !XAMORE_5_0

public partial class GCExtendedGamepadSnapshot {

Expand All @@ -257,7 +349,11 @@ unsafe static extern byte GCExtendedGamepadSnapShotDataV100FromNSData (
#endif
[DllImport (Constants.GameControllerLibrary)]
unsafe static extern byte GCExtendedGamepadSnapshotDataFromNSData (
#if XAMCORE_5_0
/* GCExtendedGamepadSnapshotData * __nullable */ GCExtendedGamepadSnapshotData* snapshotData,
#else
/* GCExtendedGamepadSnapshotData * __nullable */ GCExtendedGamepadSnapshotData_Blittable* snapshotData,
#endif
/* NSData * __nullable */ IntPtr data);

public static bool TryGetSnapShotData (NSData? data, out GCExtendedGamepadSnapShotDataV100 snapshotData)
Expand Down Expand Up @@ -285,7 +381,14 @@ public static bool TryGetExtendedSnapShotData (NSData? data, out GCExtendedGamep
{
snapshotData = default;
unsafe {
#if XAMCORE_5_0
return GCExtendedGamepadSnapshotDataFromNSData ((GCExtendedGamepadSnapshotData*) Unsafe.AsPointer<GCExtendedGamepadSnapshotData> (ref snapshotData), data.GetHandle ()) != 0;
#else
GCExtendedGamepadSnapshotData_Blittable blittableData = snapshotData.ToBlittable ();
var rv = GCExtendedGamepadSnapshotDataFromNSData (&blittableData, data.GetHandle ()) != 0;
snapshotData = new GCExtendedGamepadSnapshotData (blittableData);
return rv;
#endif
}
}
}
Expand Down
Loading

1 comment on commit 9266820

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.