[PATCH] Export _NCPUWORDS as variable for access from within the gnat-rts
Hi, This patch will make the define _NCPUWORDS accessible for the ada runtime. It is necessary to model the pthread_attr_t implementation for rtems in Ada. We had a stack corruption because the C an Ada declarations of the type where out of synch. I will send the updated s-osinte-rtems.ads to gcc if this patch is accepted. I put devel@rtems.org CC for input from the rtems developers. Best regards, Jan>From c8df985ac8bc4cd92e4bbbf6588e71b85d059524 Mon Sep 17 00:00:00 2001 From: Jan Sommer Date: Thu, 29 Oct 2015 13:59:14 +0100 Subject: [PATCH] Export _NCPUWORDS as variable for access from within the gnat-rts --- newlib/libc/sys/rtems/cpusetalloc.c| 2 ++ newlib/libc/sys/rtems/include/sys/cpuset.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/newlib/libc/sys/rtems/cpusetalloc.c b/newlib/libc/sys/rtems/cpusetalloc.c index e2b1985..20544b0 100644 --- a/newlib/libc/sys/rtems/cpusetalloc.c +++ b/newlib/libc/sys/rtems/cpusetalloc.c @@ -32,6 +32,8 @@ #include #include +const size_t _ADA_NCPUWORDS = _NCPUWORDS - 1; + cpu_set_t *__cpuset_alloc(int num_cpus) { return (cpu_set_t *)malloc(CPU_ALLOC_SIZE(num_cpus)); diff --git a/newlib/libc/sys/rtems/include/sys/cpuset.h b/newlib/libc/sys/rtems/include/sys/cpuset.h index 8fae475..50a07e7 100644 --- a/newlib/libc/sys/rtems/include/sys/cpuset.h +++ b/newlib/libc/sys/rtems/include/sys/cpuset.h @@ -70,6 +70,9 @@ typedef struct _cpuset { cpu_set_word_t __bits[_NCPUWORDS]; } cpu_set_t; +/* Make _NCPUWORDS accessible for the ada runtime */ +extern const size_t _ADA_NCPUWORDS; + /* determine the mask for a particular cpu within the element */ static __inline cpu_set_word_t __cpuset_mask(int cpu) { -- 2.5.0 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] Export _NCPUWORDS as variable for access from within the gnat-rts
Sorry. I am trying to use j...@rtems.org more and this actually bounced from the rtems devel mailing list. I have a habit to break. :( On 10/29/2015 8:14 AM, Jan Sommer wrote: Hi, This patch will make the define _NCPUWORDS accessible for the ada runtime. It is necessary to model the pthread_attr_t implementation for rtems in Ada. We had a stack corruption because the C an Ada declarations of the type where out of synch. I will send the updated s-osinte-rtems.ads to gcc if this patch is accepted. I put devel@rtems.org CC for input from the rtems developers. Is it possible to define this in the RTEMS Ada glue file? Generally, I like the Ada support to be self-contained and have no impact on anything else. This puts an Ada specific variable in generic code. This is similar to how I had to do the Ada task minimum stack size. It could have gone in more common code but nothing else uses it so should not be impacted. Plus newlib doesn't know anything about our Ada glue layer. Best to keep it that way. Best regards, Jan -- Joel Sherrill, Ph.D. Check out RTEMS at https://www.rtems.org Truly free real-time operating system ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] Export _NCPUWORDS as variable for access from within the gnat-rts
Am Thursday 29 October 2015, 08:45:57 schrieb Joel Sherrill: > > On 10/29/2015 8:14 AM, Jan Sommer wrote: > > Hi, > > > > This patch will make the define _NCPUWORDS accessible for the ada runtime. > > It is necessary to model the pthread_attr_t implementation for rtems in > > Ada. > > We had a stack corruption because the C an Ada declarations of the type > > where out of synch. > > I will send the updated s-osinte-rtems.ads to gcc if this patch is > > accepted. > > > > I put devel@rtems.org CC for input from the rtems developers. > > > > Is it possible to define this in the RTEMS Ada glue file? > What is the rtems Ada glue file? Just to clarify: The problem I had was that pthread_attr_t has a field of typedef struct _cpuset { cpu_set_word_t __bits[_NCPUWORDS]; } cpu_set_t; which's length depends on _NCPUWORDS. In ada I added types like this: NUMCPUWORDS : constant size_t; pragma Import ( Convention=> C, Entity=> NUMCPUWORDS, External_Name => "_ADA_NCPUWORDS" ); type cpu_set_array is array (0 .. NUMCPUWORDS) of aliased cpu_set_word_t; type cpu_set_t is record bits : aliased cpu_set_array; end record; I just put it into newlib, because I thought the export should be close to the original declaration. If you can point to a better fitting location I am happy to put it there. Best regards, Jan > Generally, I like the Ada support to be self-contained and > have no impact on anything else. This puts an Ada specific > variable in generic code. > > This is similar to how I had to do the Ada task minimum > stack size. It could have gone in more common code but > nothing else uses it so should not be impacted. > > Plus newlib doesn't know anything about our Ada glue layer. > Best to keep it that way. > > > Best regards, > > > > Jan > > ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH] Export _NCPUWORDS as variable for access from within the gnat-rts
On 10/29/2015 9:20 AM, Jan Sommer wrote: Am Thursday 29 October 2015, 08:45:57 schrieb Joel Sherrill: On 10/29/2015 8:14 AM, Jan Sommer wrote: Hi, This patch will make the define _NCPUWORDS accessible for the ada runtime. It is necessary to model the pthread_attr_t implementation for rtems in Ada. We had a stack corruption because the C an Ada declarations of the type where out of synch. I will send the updated s-osinte-rtems.ads to gcc if this patch is accepted. I put devel@rtems.org CC for input from the rtems developers. Is it possible to define this in the RTEMS Ada glue file? What is the rtems Ada glue file? There are two support files in cpukit/libgnat. I looked through the git log history of these files and it is quite boring. But there isn't much code here, it is target independent, and might be worth a double check. Better that than debugging something else. There is also some BSP specific code to map exceptions into Ada exceptions. Some is in libbsp/shared. From memory, the sparc BSPs have the exception propagation glue. Just to clarify: The problem I had was that pthread_attr_t has a field of typedef struct _cpuset { cpu_set_word_t __bits[_NCPUWORDS]; } cpu_set_t; which's length depends on _NCPUWORDS. In ada I added types like this: NUMCPUWORDS : constant size_t; pragma Import ( Convention=> C, Entity=> NUMCPUWORDS, External_Name => "_ADA_NCPUWORDS" ); type cpu_set_array is array (0 .. NUMCPUWORDS) of aliased cpu_set_word_t; type cpu_set_t is record bits : aliased cpu_set_array; end record; I just put it into newlib, because I thought the export should be close to the original declaration. If you can point to a better fitting location I am happy to put it there. There are a handful of similar cases handled in libgnat. You have to have real C variables or methods to use macros. Best regards, Jan Generally, I like the Ada support to be self-contained and have no impact on anything else. This puts an Ada specific variable in generic code. This is similar to how I had to do the Ada task minimum stack size. It could have gone in more common code but nothing else uses it so should not be impacted. Plus newlib doesn't know anything about our Ada glue layer. Best to keep it that way. Best regards, Jan ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel -- Joel Sherrill, Ph.D. Check out RTEMS at https://www.rtems.org Truly free real-time operating sysem ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 2/2] Export _NCPUWORDS for Ada
Used in s-osinte-rtems.ads to model pthread_attr_t --- cpukit/libgnat/adasupp.c | 4 1 file changed, 4 insertions(+) diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c index 662b1cc..cde36b6 100644 --- a/cpukit/libgnat/adasupp.c +++ b/cpukit/libgnat/adasupp.c @@ -10,6 +10,10 @@ #include #include + +/* export _NCPUWORDS for Ada */ +const size_t _ada_ncpuwords = _NCPUWORDS - 1; + /* * _ada_pthread_minimum_stack_size * -- 2.5.0 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 1/2] Include stackimpl.h otherwise PTHREAD_MINIMUM_STACK_SIZE cannot be evaluated
--- cpukit/libgnat/adasupp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c index a6e1f38..662b1cc 100644 --- a/cpukit/libgnat/adasupp.c +++ b/cpukit/libgnat/adasupp.c @@ -8,6 +8,7 @@ #include #include #include +#include /* * _ada_pthread_minimum_stack_size -- 2.5.0 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 2/2] Export _NCPUWORDS for Ada
_NCPUWORDS is defined in newlib in newlib/libc/sys/rtems/sys/cpuset.h and used to define the type cpu_set_t there. typedef struct _cpuset { cpu_set_word_t __bits[_NCPUWORDS]; } cpu_set_t; cpu_set_t is used for a field in the struct pthread_attr_t in file newlib/libc/include/types.h The Gnat Ada runtime uses POSIX-threads for tasking, therefore the pthread-types have to be declared in Ada in order to import them. As the fixed size array in cpu_set_t depends on the value of _NCPUWORDS it is exported with the symbol _ada_ncpuwords in order to access it from within the Ada runtime. The Ada declaration of pthread_attr_t is located in gcc/ada/s-osinte-rtems.ads and _ada_ncpuwords is imported there. --- cpukit/libgnat/adasupp.c | 4 1 file changed, 4 insertions(+) diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c index 662b1cc..cde36b6 100644 --- a/cpukit/libgnat/adasupp.c +++ b/cpukit/libgnat/adasupp.c @@ -10,6 +10,10 @@ #include #include + +/* export _NCPUWORDS for Ada */ +const size_t _ada_ncpuwords = _NCPUWORDS - 1; + /* * _ada_pthread_minimum_stack_size * -- 2.5.0 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
[PATCH 1/2] Include stackimpl.h otherwise PTHREAD_MINIMUM_STACK_SIZE cannot be evaluated
--- cpukit/libgnat/adasupp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c index a6e1f38..662b1cc 100644 --- a/cpukit/libgnat/adasupp.c +++ b/cpukit/libgnat/adasupp.c @@ -8,6 +8,7 @@ #include #include #include +#include /* * _ada_pthread_minimum_stack_size -- 2.5.0 ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH 1/2] Include stackimpl.h otherwise PTHREAD_MINIMUM_STACK_SIZE cannot be evaluated
I fixed the commit message and check it in on master and 4.11 branch. On 29/10/15 22:10, Jan Sommer wrote: --- cpukit/libgnat/adasupp.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c index a6e1f38..662b1cc 100644 --- a/cpukit/libgnat/adasupp.c +++ b/cpukit/libgnat/adasupp.c @@ -8,6 +8,7 @@ #include #include #include +#include /* * _ada_pthread_minimum_stack_size -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.hu...@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH 2/2] Export _NCPUWORDS for Ada
How is this tackled in the glibc/Linux support? Is the exact layout of the structures really interesting for Ada? I guess its sufficient to tell Ada the size and alignment of pthread_attr_t for example. On 29/10/15 22:10, Jan Sommer wrote: _NCPUWORDS is defined in newlib in newlib/libc/sys/rtems/sys/cpuset.h and used to define the type cpu_set_t there. typedef struct _cpuset { cpu_set_word_t __bits[_NCPUWORDS]; } cpu_set_t; cpu_set_t is used for a field in the struct pthread_attr_t in file newlib/libc/include/types.h The Gnat Ada runtime uses POSIX-threads for tasking, therefore the pthread-types have to be declared in Ada in order to import them. As the fixed size array in cpu_set_t depends on the value of _NCPUWORDS it is exported with the symbol _ada_ncpuwords in order to access it from within the Ada runtime. The Ada declaration of pthread_attr_t is located in gcc/ada/s-osinte-rtems.ads and _ada_ncpuwords is imported there. --- cpukit/libgnat/adasupp.c | 4 1 file changed, 4 insertions(+) diff --git a/cpukit/libgnat/adasupp.c b/cpukit/libgnat/adasupp.c index 662b1cc..cde36b6 100644 --- a/cpukit/libgnat/adasupp.c +++ b/cpukit/libgnat/adasupp.c @@ -10,6 +10,10 @@ #include #include + +/* export _NCPUWORDS for Ada */ +const size_t _ada_ncpuwords = _NCPUWORDS - 1; + /* * _ada_pthread_minimum_stack_size * -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.hu...@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel
Re: [PATCH 2/2] Export _NCPUWORDS for Ada
On 30/10/15 07:50, Sebastian Huber wrote: How is this tackled in the glibc/Linux support? Is the exact layout of the structures really interesting for Ada? I guess its sufficient to tell Ada the size and alignment of pthread_attr_t for example. It would be good to have test cases that ensure that the Ada and C view of the structures is identical. -- Sebastian Huber, embedded brains GmbH Address : Dornierstr. 4, D-82178 Puchheim, Germany Phone : +49 89 189 47 41-16 Fax : +49 89 189 47 41-09 E-Mail : sebastian.hu...@embedded-brains.de PGP : Public key available on request. Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG. ___ devel mailing list devel@rtems.org http://lists.rtems.org/mailman/listinfo/devel