Permalink
Browse files

[Mac] CGDisplayBounds signature now matches Mac ABI

This resolves a crash in CGDisplayBounds when running through monokick.
  • Loading branch information...
1 parent ffb7bd8 commit cf3a30d024cd351ae81e3f1bf9b8d4b06921cd00 @thefiddler thefiddler committed Apr 3, 2014
Showing with 14 additions and 2 deletions.
  1. +14 −2 Source/OpenTK/Platform/MacOS/Carbon/QuartzDisplayServicesAPI.cs
@@ -69,8 +69,20 @@ internal static class CG
[DllImport(appServices,EntryPoint="CGMainDisplayID")]
internal static extern IntPtr MainDisplayID();
- [DllImport(appServices, EntryPoint = "CGDisplayBounds")]
- internal unsafe static extern HIRect DisplayBounds(IntPtr display);
+ // Note: sizeof(HIRect) == 16, which is larger than 8 bytes.
+ // The x86 and x64 Mac ABIs pass such structs as pointers in the
+ // first parameter slot. This is normally handled automatically
+ // by gcc/clang, but here we have to do it ourselves.
+ // See "Listing 4" on https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/LowLevelABI/130-IA-32_Function_Calling_Conventions/IA32.html#//apple_ref/doc/uid/TP40002492-SW3
+ internal unsafe static HIRect DisplayBounds(IntPtr display)
+ {
+ HIRect rect;
+ DisplayBounds(out rect, display);
+ return rect;
+ }
+
+ [DllImport(appServices, EntryPoint = "CGDisplayBounds")]
+ unsafe static extern void DisplayBounds(out HIRect rect, IntPtr display);
[DllImport(appServices,EntryPoint="CGDisplayPixelsWide")]
internal static extern int DisplayPixelsWide(IntPtr display);

0 comments on commit cf3a30d

Please sign in to comment.