Sign in Join

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

Mailing lists / fpc-pascal / 2009-03

modifying system.pp's InstallSignals

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

Seth Grover

I'm working on a project in Linux where I've got some special signal handling requirements. I need to modify system.pp's InstallSignals to dynamically load an .so, look up a function by name, and make some calls into that library instead of doing what it normally does.

The dynlibs unit has the code I need to call SafeLoadLibrary and GetProcedureAddress, but my problem is that obviously I can't just put "uses dynlibs" in system since, well, it's system, and there would be circular dependencies since system is pretty much first on the dependency list.

My thought is that basically I'll just have to pull the code from dynlibs.pas, dynlibs.inc, and dl.pp into my own .inc file and include it rather than trying to have anything in a uses section. I'm aware that doing this will decrease the portability of my code and make me dependent on libc, but these changes I'm making to the rtl are for a very specific purpose, and I won't be using them to compile anything else. :)

Does that seem like the right way for me to get the functionality of those calls available to me in InstallSignals? Or is there something easier I'm missing?

Thanks,

SG

This email is fiction. Any resemblance to actual events or persons living or dead is purely coincidental. Seth Grover sethdgrover[at]gmail[dot]com
Marco van de Voort
to Seth Grover

In our previous episode, Seth Grover said:

Does that seem like the right way for me to get the functionality of those calls available to me in InstallSignals? Or is there something easier I'm missing?

It is roughly ok. Optionally you can also -dFPC_USE_LIBC to force the system unit to use libc instead of syscalls, and save a few kb. Note that this is less frequently tested though.

Vincent Snijders
to Seth Grover: I'm working on a project in Linux where I've got some special signal handling…
Seth Grover wrote 5 lines
Does that seem like the right way for me to get the functionality of those calls available to me in InstallSignals? Or is there something easier I'm missing?

I don't think it can be done without editing the system unit. If you are willing to do that, I would add a procvar called CustomSignalHandler: TProcedure in the interface section of the system unit (or in an include file included in the interface section of the system unit).

In the signal handler of the system unit, test assigned(CustomSignalHandler) and call it, if it is assigned, else do the current thing.

Create a new unit MySignalHandlerUnit that contains your signal handler and that has procedure MySignalHandler in its interface.
In the initialization section do

   System.CustomSignalHandler := @MySignalHandler;

Add MySignalHandlerUnit to the uses section of your main program.

Vincent

P.S. I am sure you can find better names.

Jonas Maebe
to Vincent Snijders
Vincent Snijders wrote 14 lines
Seth Grover schreef: > Does that seem like the right way for me to get the functionality of > those calls available to me in InstallSignals? Or is there something > easier I'm missing? I don't think it can be done without editing the system unit. If you are willing to do that, I would add a procvar called CustomSignalHandler: TProcedure in the interface section of the system unit (or in an include file included in the interface section of the system unit). In the signal handler of the system unit, test assigned(CustomSignalHandler) and call it, if it is assigned, else do the current thing.

In general this works well, but not in this case, since InstallSignals is called from the system unit's initialization code, and that's the first code that is executed when a program starts up.

Jonas