@@ -52,20 +52,26 @@ private static void Main(string[] args) {
5252 // SELinux can cause weird game corruption-like symptoms when we lack the execheap permission
5353 // So probe for it before continuing to boot on Linux
5454 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) ) {
55+ [ DllImport ( "libc" , SetLastError = true ) ]
56+ static extern nuint getpagesize ( ) ;
57+
5558 [ DllImport ( "libc" , SetLastError = true ) ]
5659 static extern int mprotect ( IntPtr ptr , nuint len , int prot ) ;
5760 const int PROT_READ = 1 , PROT_WRITE = 2 , PROT_EXEC = 4 ;
5861
62+ //Figure out page size
63+ nuint pageSize = getpagesize ( ) ;
64+
5965 //Allocate a bit of memory on the heap
6066 IntPtr heapAlloc = Marshal . AllocHGlobal ( 123 ) ;
61- IntPtr heapPage = heapAlloc & ~ 0xfff ;
67+ IntPtr heapPage = heapAlloc & ~ ( ( nint ) ( pageSize - 1 ) ) ;
6268
6369 //Try to make it executable
64- if ( mprotect ( heapPage , 0x1000 , PROT_READ | PROT_WRITE | PROT_EXEC ) < 0 )
70+ if ( mprotect ( heapPage , pageSize , PROT_READ | PROT_WRITE | PROT_EXEC ) < 0 )
6571 throw new Win32Exception ( Marshal . GetLastPInvokeError ( ) , "SELinux execheap probe failed! Please ensure Everest has this permission, then try again" ) ;
6672
6773 //Cleanup
68- if ( mprotect ( heapPage , 0x1000 , PROT_READ | PROT_WRITE ) < 0 )
74+ if ( mprotect ( heapPage , pageSize , PROT_READ | PROT_WRITE ) < 0 )
6975 throw new Win32Exception ( Marshal . GetLastPInvokeError ( ) , "Failed to revert memory permissions after SELinux execheap probe" ) ;
7076
7177 Marshal . FreeHGlobal ( heapAlloc ) ;
0 commit comments