zertovitch / gwindows

GWindows: GUI framework for MS Windows
https://sf.net/projects/gnavi/
21 stars 5 forks source link

Access check issue with a Global_Alloc_Ptr in Get_Clipboard_Text_* in GWindows.Clipboard #26

Open zertovitch opened 8 months ago

zertovitch commented 8 months ago

Built with GNAT version after GNAT CE 2021:

.\gwindows\test\test_clipboard.exe

raised CONSTRAINT_ERROR : gwindows-clipboard.adb:386 access check failed [C:\Ada\gnavi\gwindows\test\test_clipboard.exe] 0x7ff7679437ac Adainit at gwindows-clipboard.adb:386 0x7ff767921ba9 Test_Clipboard at test_clipboard.adb:34

zertovitch commented 8 months ago

Some attempts to solve the issue:

  1. Data : Global_Alloc_Ptr; pragma Suppress (Access_Check, Data); is ineffective.
  2. type Global_Alloc_Ptr is access all Global_Alloc_Type; pragma Suppress (Access_Check, Global_Alloc_Ptr); does suppress the check, but cause a worse issue: PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
  3. Same for using an address:
   subtype Global_Alloc_Ptr is System.Address;

   procedure Poke
     (Data : Global_Alloc_Ptr; Offset : Natural; Byte : Memory_Byte)
   is
      Dest : Memory_Byte_Arr (0 .. Offset)
        with Address => Data;
      pragma Import (Ada, Dest);
   begin
      Dest (Offset) := Byte;
   end Poke;

   function Peek
     (Data : Global_Alloc_Ptr; Offset : Natural) return Memory_Byte
   is
      Source : Memory_Byte_Arr (0 .. Offset)
        with Address => Data;
      pragma Import (Ada, Source);
   begin
      return Source (Offset);
   end Peek;