alexande@unc.cs.unc.edu (Geoffrey D. Alexander) (12/02/88)
I would to dynamically load and call a function from C. The name of the function would be specified by the user. I am running under SUN BSD Unix. Can this be done? The function I am looking for is similiar to the function offered by the LOAD macro of IBM's MVS operating system. Thanks, Geoff Alexander
crossgl@ingr.UUCP (Gordon Cross) (12/05/88)
In article <5635@thorin.cs.unc.edu>, alexande@unc.cs.unc.edu (Geoffrey D. Alexander) writes: > I would to dynamically load and call a function from C. The name of the > function would be specified by the user. I am running under SUN BSD Unix. > Can this be done? The function I am looking for is similiar to the function > offered by the LOAD macro of IBM's MVS operating system. I wrote a dynamic loader that we use here at this company as a debugging tool since the load time is MUCH MUCH less than the time to re-link a very large application. If you do not have some sort of kernel support that allows one to modify program text (which was the case for us), dynamic loading has certain restrictions. First and most importantly, it must be possible to execute instructions in the data section. Secondly if the function you are loading is already bound into your process, any direct (ie not through pointers) calls cannot be made to reference the new version. The /proc file system (coming soon to System V) should solve this problem elegantly. It may be possible to use the existing "ptrace" system call as well but this requires a parent/child relationship in which the child has agreed to be traced. Since our applications are based on an object-oriented system in which the majority of function calls get translated into indirection through pointers, this restriction did not pose serious problems. We only needed to load the new function address into the corresponding pointer. However there should be no problem with loading new functions. If you find that dynamic loading as I've just described should work for you, let me know. Perhaps we could port it to your system... Gordon Cross Intergraph Corp. Huntsville, AL ...uunet!ingr!crossgl