Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-06

FPC_CHECKPOINTER

5 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sergey Korshunoff

Hi!

In which cases FPC generates a call to SUBJ? Can I assume that FPC_CHECKPOINTER would get as parameter only an allocated by GetMem pointer (in normal cases) ?

This question is because I get a SYSSEGV when use
OPT='-gc -gh" make all
under Linux.

I want to add some additional check (under Linux) before dereferencing a given poiner.

Regards,
Sergey Korshunoff

Reply by email

Marco van de Voort
to Sergey Korshunoff
In which cases FPC generates a call to SUBJ? Can I assume that FPC_CHECKPOINTER would get as parameter only an allocated by GetMem pointer (in normal cases) ?

From the internal docs:
Procedure CheckPointer(p : Pointer);
\Description
Called by the code generator when a pointer is referenced in heap debug mode. Verifies that the pointer actually points in the heap area. \Parameters
p = pointer to check
\Notes
This routine should save /restore all used registers.

(note, the sources of these are in public CVS, and are work in progress. Dir fpc/docs/internal)

Reply by email

Jonas Maebe
to Sergey Korshunoff: Hi! In which cases FPC generates a call to SUBJ? Can I assume that FPC_CHECKPOINTER would…
Sergey Korshunoff wrote
In which cases FPC generates a call to SUBJ? Can I assume that

For all pointer dereferences.

FPC_CHECKPOINTER would get as parameter only an allocated by GetMem pointer (in normal cases) ?

No, it can get any address. The reason is that the compiler cannot know what kind of address you put in a pointer variable or parameter.

This question is because I get a SYSSEGV when use OPT='-gc -gh" make all under Linux.

The reason is that it only works under go32v2 currently, afaik. It has to do with the ordering of the data and code in memory, which is different between go32v2 and linux.

Jonas

Reply by email

Pierre Muller
to Sergey Korshunoff: Hi! In which cases FPC generates a call to SUBJ? Can I assume that FPC_CHECKPOINTER would…
Sergey Korshunoff wrote 9 lines
Hi! In which cases FPC generates a call to SUBJ? Can I assume that FPC_CHECKPOINTER would get as parameter only an allocated by GetMem pointer (in normal cases) ? This question is because I get a SYSSEGV when use OPT='-gc -gh" make all under Linux.

I tested this out, and I got a
Run Time Error 216
generated by heaptrc.pp unit
because the linux version of the FPC_CHECKPOINTER function is wrong, in the sense that it does not accept pointers that point inside the valid stack range ...

Show quoted text 5 lines
I want to add some additional check (under Linux) before dereferencing a given poiner. Regards, Sergey Korshunoff

I added some code to fix the problem,
and it now seems that it does not generate errors anymore, but getting the cycle to an end seems a pretty lengthy topic, as the FPC_CHECKPOINTER function is not optimized at all and does a linear search through all allocated blocks to test if the dereferenced pointer is valid...
This takes ages...
The compilation of the linux system unit with a compiler calling FPC_CHECKPOINTER on each deref
it finished after 4 hours of computation,
when a normal compilation only takes a few seconds in normal conditions.

Reply by email