Notice: We have migrated to GitLab launching 2024-05-01 see here: https://gitlab.rtems.org/

Ticket #3256: v2-0001-RTEMS-Ada-Fix-some-POSIX-types.patch

File v2-0001-RTEMS-Ada-Fix-some-POSIX-types.patch, 8.8 KB (added by Sebastian Huber, on 12/04/17 at 08:41:47)
  • gcc/ada/gcc-interface/Makefile.in

    diff --git a/gcc/ada/gcc-interface/Makefile.in b/gcc/ada/gcc-interface/Makefile.in
    index d94fadf508b..7a570196a88 100644
    a b ifeq ($(strip $(filter-out rtems%,$(target_os))),) 
    17261726  s-intman.adb<s-intman-posix.adb \
    17271727  s-osinte.adb<s-osinte-rtems.adb \
    17281728  s-osinte.ads<s-osinte-rtems.ads \
    1729   s-osprim.adb<s-osprim-posix.adb \
     1729  s-osprim.adb<s-osprim-rtems.adb \
    17301730  s-parame.adb<s-parame-rtems.adb \
    17311731  s-taprop.adb<s-taprop-posix.adb \
    17321732  s-taspri.ads<s-taspri-posix.ads \
  • gcc/ada/s-osinte-rtems.ads

    diff --git a/gcc/ada/s-osinte-rtems.ads b/gcc/ada/s-osinte-rtems.ads
    index a658bbe8b0d..d127024cf3b 100644
    a b private 
    620620
    621621   type pid_t is new int;
    622622
    623    type time_t is new long;
     623   type time_t is new Long_Long_Integer;
    624624
    625625   type timespec is record
    626626      tv_sec  : time_t;
    private 
    649649      Data : char_array (1 .. OS_Constants.PTHREAD_MUTEXATTR_SIZE);
    650650   end  record;
    651651   pragma Convention (C, pthread_mutexattr_t);
    652    for pthread_mutexattr_t'Alignment use Interfaces.C.double'Alignment;
     652   for pthread_mutexattr_t'Alignment use Interfaces.C.int'Alignment;
    653653
    654654   type pthread_rwlockattr_t is record
    655655      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCKATTR_SIZE);
    656656   end record;
    657657   pragma Convention (C, pthread_rwlockattr_t);
    658    for pthread_rwlockattr_t'Alignment use Interfaces.C.double'Alignment;
     658   for pthread_rwlockattr_t'Alignment use Interfaces.C.int'Alignment;
    659659
    660660   type pthread_t is new rtems_id;
    661661
    662    type pthread_mutex_t is new rtems_id;
     662   type pthread_mutex_t is record
     663      Data : char_array (1 .. OS_Constants.PTHREAD_MUTEX_SIZE);
     664   end record;
     665   pragma Convention (C, pthread_mutex_t);
     666   for pthread_mutex_t'Alignment use Interfaces.C.double'Alignment;
    663667
    664    type pthread_rwlock_t is new rtems_id;
     668   type pthread_rwlock_t is record
     669      Data : char_array (1 .. OS_Constants.PTHREAD_RWLOCK_SIZE);
     670   end record;
     671   pragma Convention (C, pthread_rwlock_t);
     672   for pthread_rwlock_t'Alignment use Interfaces.C.size_t'Alignment;
    665673
    666    type pthread_cond_t is new rtems_id;
     674   type pthread_cond_t is record
     675      Data : char_array (1 .. OS_Constants.PTHREAD_COND_SIZE);
     676   end record;
     677   pragma Convention (C, pthread_cond_t);
     678   for pthread_cond_t'Alignment use Interfaces.C.size_t'Alignment;
    667679
    668680   type pthread_key_t is new rtems_id;
    669681
  • new file gcc/ada/s-osprim-rtems.adb

    diff --git a/gcc/ada/s-osprim-rtems.adb b/gcc/ada/s-osprim-rtems.adb
    new file mode 100644
    index 00000000000..df8754baa69
    - +  
     1------------------------------------------------------------------------------
     2--                                                                          --
     3--                 GNAT RUN-TIME LIBRARY (GNARL) COMPONENTS                 --
     4--                                                                          --
     5--                  S Y S T E M . O S _ P R I M I T I V E S                 --
     6--                                                                          --
     7--                                  B o d y                                 --
     8--                                                                          --
     9--          Copyright (C) 1998-2015, Free Software Foundation, Inc.         --
     10--                                                                          --
     11-- GNARL is free software; you can  redistribute it  and/or modify it under --
     12-- terms of the  GNU General Public License as published  by the Free Soft- --
     13-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
     14-- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
     15-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
     16-- or FITNESS FOR A PARTICULAR PURPOSE.                                     --
     17--                                                                          --
     18-- As a special exception under Section 7 of GPL version 3, you are granted --
     19-- additional permissions described in the GCC Runtime Library Exception,   --
     20-- version 3.1, as published by the Free Software Foundation.               --
     21--                                                                          --
     22-- You should have received a copy of the GNU General Public License and    --
     23-- a copy of the GCC Runtime Library Exception along with this program;     --
     24-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
     25-- <http://www.gnu.org/licenses/>.                                          --
     26--                                                                          --
     27-- GNARL was developed by the GNARL team at Florida State University.       --
     28-- Extensive contributions were provided by Ada Core Technologies, Inc.     --
     29--                                                                          --
     30------------------------------------------------------------------------------
     31
     32--  This version is for POSIX-like operating systems
     33
     34package body System.OS_Primitives is
     35
     36   --  ??? These definitions are duplicated from System.OS_Interface
     37   --  because we don't want to depend on any package. Consider removing
     38   --  these declarations in System.OS_Interface and move these ones in
     39   --  the spec.
     40
     41   type time_t is new Long_Long_Integer;
     42
     43   type timespec is record
     44      tv_sec  : time_t;
     45      tv_nsec : Long_Integer;
     46   end record;
     47   pragma Convention (C, timespec);
     48
     49   function nanosleep (rqtp, rmtp : not null access timespec) return Integer;
     50   pragma Import (C, nanosleep, "nanosleep");
     51
     52   -----------
     53   -- Clock --
     54   -----------
     55
     56   function Clock return Duration is
     57
     58      type timeval is record
     59         tv_sec  : time_t;
     60         tv_usec : Long_Integer;
     61      end record;
     62      pragma Convention (C, timeval);
     63
     64      procedure timeval_to_duration
     65        (T    : not null access timeval;
     66         sec  : not null access Long_Long_Integer;
     67         usec : not null access Long_Integer);
     68      pragma Import (C, timeval_to_duration, "__gnat_timeval_to_duration");
     69
     70      Micro  : constant := 10**6;
     71      sec    : aliased Long_Long_Integer;
     72      usec   : aliased Long_Integer;
     73      TV     : aliased timeval;
     74      Result : Integer;
     75      pragma Unreferenced (Result);
     76
     77      function gettimeofday
     78        (Tv : access timeval;
     79         Tz : System.Address := System.Null_Address) return Integer;
     80      pragma Import (C, gettimeofday, "gettimeofday");
     81
     82   begin
     83      --  The return codes for gettimeofday are as follows (from man pages):
     84      --    EPERM  settimeofday is called by someone other than the superuser
     85      --    EINVAL Timezone (or something else) is invalid
     86      --    EFAULT One of tv or tz pointed outside accessible address space
     87
     88      --  None of these codes signal a potential clock skew, hence the return
     89      --  value is never checked.
     90
     91      Result := gettimeofday (TV'Access, System.Null_Address);
     92      timeval_to_duration (TV'Access, sec'Access, usec'Access);
     93      return Duration (sec) + Duration (usec) / Micro;
     94   end Clock;
     95
     96   -----------------
     97   -- To_Timespec --
     98   -----------------
     99
     100   function To_Timespec (D : Duration) return timespec;
     101
     102   function To_Timespec (D : Duration) return timespec is
     103      S : time_t;
     104      F : Duration;
     105
     106   begin
     107      S := time_t (Long_Long_Integer (D));
     108      F := D - Duration (S);
     109
     110      --  If F has negative value due to a round-up, adjust for positive F
     111      --  value.
     112
     113      if F < 0.0 then
     114         S := S - 1;
     115         F := F + 1.0;
     116      end if;
     117
     118      return
     119        timespec'(tv_sec  => S,
     120                  tv_nsec => Long_Integer (Long_Long_Integer (F * 10#1#E9)));
     121   end To_Timespec;
     122
     123   -----------------
     124   -- Timed_Delay --
     125   -----------------
     126
     127   procedure Timed_Delay
     128     (Time : Duration;
     129      Mode : Integer)
     130   is
     131      Request    : aliased timespec;
     132      Remaind    : aliased timespec;
     133      Rel_Time   : Duration;
     134      Abs_Time   : Duration;
     135      Base_Time  : constant Duration := Clock;
     136      Check_Time : Duration := Base_Time;
     137
     138      Result : Integer;
     139      pragma Unreferenced (Result);
     140
     141   begin
     142      if Mode = Relative then
     143         Rel_Time := Time;
     144         Abs_Time := Time + Check_Time;
     145      else
     146         Rel_Time := Time - Check_Time;
     147         Abs_Time := Time;
     148      end if;
     149
     150      if Rel_Time > 0.0 then
     151         loop
     152            Request := To_Timespec (Rel_Time);
     153            Result := nanosleep (Request'Access, Remaind'Access);
     154            Check_Time := Clock;
     155
     156            exit when Abs_Time <= Check_Time or else Check_Time < Base_Time;
     157
     158            Rel_Time := Abs_Time - Check_Time;
     159         end loop;
     160      end if;
     161   end Timed_Delay;
     162
     163   ----------------
     164   -- Initialize --
     165   ----------------
     166
     167   procedure Initialize is
     168   begin
     169      null;
     170   end Initialize;
     171
     172end System.OS_Primitives;