Stack checking in GNAT (was: ada compiler?)



Samuel Tardieu writes:
You have two ways of doing stack checking:

1- at the GCC level by checking the stack at the entry of every
subprogram and comparing it to a thread/task specific marker; this
is costly

2- at the OS level by mapping a page after the stack which does not
allow either reads or writes to the page (or, when this is not
possible, which doesn't allow writes)

[detailed explanation]

Does that answer your question?

Yes, thank you very much. It seems that I can enable or disable stack
checking, and select from the two methods above, by patching some
flags in System and Targparm. In System:

Stack_Check_Default : constant Boolean := False;
Stack_Check_Probes : constant Boolean := False;

Stack_Check_Default is True only on VMS.

Stack_Check_Probes is True only on VMS, IRIX, MinGW, Solaris and Tru64
Unix (it depends on the OS, not the processor).

And in Targparm.ads:

Stack_Check_Probes_On_Target : Boolean := False;
-- Indicates if stack check probes are used, as opposed to the standard
-- target independent comparison method.

(the "stack check probes" are method 2, the "standard target
independent comparison method" is method 1)

Stack_Check_Default_On_Target : Boolean := False;
-- Indicates if stack checking is on by default

I don't understand the difference between the flags in System and
those in Targparm (i.e. why are there two sets of flags, and what
happens if their values are different?). Also I am curious to know
what would be the effect of changing these flags in Debian. Can you
help?

--
Ludovic Brenta.
.



Relevant Pages

  • Re: [ubuntu-hardened] Re: Collecting NX information
    ... >>everything PaX wants ... define exactly what the flags should do. ... Stack and heap default to +X ... kernel randomizes anything that can be randomized in the address ...
    (Linux-Kernel)
  • Re: Multiple Undo Program / Command Logger
    ... HALT errors if suspending isn't OK, ... it then halts (which creates a brand new "Last Stack") ... you can have a different BetaENTER program ... The following resets flags and modes after any operation, ...
    (comp.sys.hp48)
  • [Patch] no exec: sync x86_64 behaviour with i386
    ... Control non executable mappings for 64bit processes. ... -per executable using ELF header flags ... Stack is non executable, heap/data is. ...
    (Linux-Kernel)
  • Re: [KMDF] Removing FDO and let PDO running
    ... You're right, here's what my stack looks like with!devnode ... CapabilityFlags LockSupported, UniqueID, ... Unknown flags 0xe9740000 ...
    (microsoft.public.development.device.drivers)
  • Re: CPU design
    ... Simpler solution - have the microcode FSM push the flags to the stack. ... re-entrant, so a faster context switch is to re-map the Registers, Flags (and even PC? ...
    (comp.arch.fpga)