This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] fix bug in handling of foreign threads


Tested under i686-linux, commited on mainline.

In case of foreign threads, the field Self.Common.Task_Image_Len was kept
uninitialized, leading to potential bad memory access when using
Ada.Task_Identification.Name on a foreign thread.
Test program, build with gprmake -Pprj bug1
Should run with no output:
--
with P;
procedure Bug1 is
   procedure C_Func; pragma Import (C, C_Func);
begin C_Func; end Bug1;
with Ada.Task_Identification; use Ada.Task_Identification;
with Ada.Text_IO; use Ada.Text_IO;
package body P is
   Base : constant String := "foreign thread";
   procedure Ada_Routine is
      Img : constant String := Image (Current_Task);
   begin
      if Img'Length < Base'Length or else Img (1 .. Base'Length) /= Base then
         Put_Line ("failed");
      end if;
   end Ada_Routine;
end P;
package P is
   procedure Ada_Routine; pragma Export (C, Ada_Routine);
end P;
--
project Prj is
   for Languages use ("ada", "c");
   package Compiler is
      for Default_Switches ("c") use ("-D_REENTRANT");
   end Compiler;
end Prj;
--
#include <pthread.h>
extern void ada_routine (void);
void *thread_body (void *param)
{
  ada_routine ();
  return NULL;
}
void c_func (void)
{
  pthread_t t;
  pthread_create(&t, NULL, thread_body, NULL);
  pthread_join (t, NULL);
}
--

2005-02-09  Arnaud Charlet  <charlet@adacore.com>

	* s-tporft.adb (Register_Foreign_Thread): Initialize Task_Image[_Len]
	fields for foreign threads.

Attachment: difs.18
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]