This is the mail archive of the 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] avoid big stack usage in gnat.os_lib

Tested on i686-linux, committed on mainline.

We used to allocate a big buffer in GNAT.OS_Lib.Copy on the stack was causing
stack overflows
when called from a task with the default stack size. Furthermore,
since this unit is part of the runtime the overflow was not detected by
standard Ada checks and was potentially causing all usual nasty effects.

Following test case should not display any message:
gnatmake -f -u -a -fstack-check g-os_lib.adb
gnatmake -Pdefault
with Ada.Directories; use Ada.Directories;
with Ada.Text_IO; use Ada.Text_IO;
procedure Foo is
   task T is pragma Storage_Size (40_000); end T;
   Big : String (1..2048);
   subtype Times is Integer range 1..1000;
   Name : constant String := "tmp_file";
   task Body T is
      D : Search_Type; F : Directory_Entry_Type; Fi : File_Type;
      Big (Big'Last) := 'a';
      Create (Fi, Name => Name);
      for I in Times loop Put (Fi, Big); end loop;
      Close (Fi);
      Copy_File (Name,Name & ".old");
      when others =>
         Put_Line ("we have a problem with Copy_File");
   end T;
begin null; end Foo;
project Default is
   for Main use ("foo.adb");
   package Compiler is
      for Default_Switches ("ada") use ("-gnatQ", "-gnat05");
   end Compiler;
end Default;

2005-06-14  Vincent Celier  <>
	    Cyrille Comar  <>

	*, g-os_lib.adb (Non_Blocking_Spawn): Two new versions
	with output file descriptor and with output file name.
	(Dup, Dup2): Now global procedures as they are used by two subprograms
	(Copy): Allocate the 200K buffer on the heap rather than on the stack.

Attachment: difs.31
Description: Text document

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