public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32
@ 2019-09-18  8:40 Pierre-Marie de Rodat
  2019-09-19 14:41 ` Iain Sandoe
  0 siblings, 1 reply; 10+ messages in thread
From: Pierre-Marie de Rodat @ 2019-09-18  8:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: Olivier Hainque

[-- Attachment #1: Type: text/plain, Size: 733 bytes --]

The dwActiveProcessorMask field in a SYSTEM_INFO structure on Windows
should be DWORD_PTR, an integer the size of a pointer.

In s-win32, it is currently declared as DWORD. This happens to work on
32bit hosts and is wrong on 64bit hosts, causing mishaps in accesses to
this component and all the following ones.

The proposed correction adds a definition for DWORD_PTR and uses it for
dwActiveProcessorMask in System.Win32.SYSTEM_INFO.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-09-18  Olivier Hainque  <hainque@adacore.com>

gcc/ada/

	* libgnat/s-win32.ads (DWORD_PTR): New type, pointer size
	unsigned int.
	(SYSTEM_INFO): Use it for dwActiveProcessorMask.

gcc/testsuite/

	* gnat.dg/system_info1.adb: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 2239 bytes --]

--- gcc/ada/libgnat/s-win32.ads
+++ gcc/ada/libgnat/s-win32.ads
@@ -57,15 +57,16 @@ package System.Win32 is
    INVALID_HANDLE_VALUE : constant HANDLE := -1;
    INVALID_FILE_SIZE    : constant := 16#FFFFFFFF#;
 
-   type ULONG  is new Interfaces.C.unsigned_long;
-   type DWORD  is new Interfaces.C.unsigned_long;
-   type WORD   is new Interfaces.C.unsigned_short;
-   type BYTE   is new Interfaces.C.unsigned_char;
-   type LONG   is new Interfaces.C.long;
-   type CHAR   is new Interfaces.C.char;
-   type SIZE_T is new Interfaces.C.size_t;
-
-   type BOOL   is new Interfaces.C.int;
+   type ULONG     is new Interfaces.C.unsigned_long;
+   type DWORD     is new Interfaces.C.unsigned_long;
+   type WORD      is new Interfaces.C.unsigned_short;
+   type BYTE      is new Interfaces.C.unsigned_char;
+   type LONG      is new Interfaces.C.long;
+   type CHAR      is new Interfaces.C.char;
+   type SIZE_T    is new Interfaces.C.size_t;
+   type DWORD_PTR is mod 2 ** Standard'Address_Size;
+
+   type BOOL      is new Interfaces.C.int;
    for BOOL'Size use Interfaces.C.int'Size;
 
    type Bits1  is range 0 .. 2 ** 1 - 1;
@@ -265,7 +266,7 @@ package System.Win32 is
       dwPageSize                  : DWORD;
       lpMinimumApplicationAddress : PVOID;
       lpMaximumApplicationAddress : PVOID;
-      dwActiveProcessorMask       : DWORD;
+      dwActiveProcessorMask       : DWORD_PTR;
       dwNumberOfProcessors        : DWORD;
       dwProcessorType             : DWORD;
       dwAllocationGranularity     : DWORD;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/system_info1.adb
@@ -0,0 +1,23 @@
+--  { dg-do run }
+
+with System.Multiprocessors;
+with System.Task_Info;
+
+procedure System_Info1 is
+   Ncpus : constant System.Multiprocessors.CPU :=
+     System.Multiprocessors.Number_Of_CPUS;
+   Nprocs : constant Integer :=
+     System.Task_Info.Number_Of_Processors;
+
+   use type System.Multiprocessors.CPU;
+begin
+   if Nprocs <= 0 or else Nprocs > 1024 then
+      raise Program_Error;
+   end if;
+   if Ncpus <= 0 or else Ncpus > 1024 then
+      raise Program_Error;
+   end if;
+   if Nprocs /= Integer (Ncpus) then
+      raise Program_Error;
+   end if;
+end;
\ No newline at end of file


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-09-23 10:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-18  8:40 [Ada] Fix 32/64bit mistake on SYSTEM_INFO component in s-win32 Pierre-Marie de Rodat
2019-09-19 14:41 ` Iain Sandoe
2019-09-19 14:56   ` Rainer Orth
2019-09-19 15:02     ` Iain Sandoe
2019-09-19 16:40       ` Olivier Hainque
2019-09-20 12:21         ` Olivier Hainque
2019-09-20 13:02           ` Rainer Orth
2019-09-20 14:12             ` Arnaud Charlet
2019-09-23 10:12               ` Rainer Orth
2019-09-20 12:57       ` Rainer Orth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).