Unix Plug-ins?

Unix Plug-ins?

Post by Dave Nebing » Tue, 04 Feb 1997 04:00:00



Is it possible to create external code files in Unix?

No, I'm not thinking of libraries (static or shared),
nor am I referring to full applications called after
a fork()/exec() pair.

I'm interested in opening some kind of file, read it into
memory, and jump to it.  Is this possible in Unix?

Thanks,

  Dave.

==========================================================

             The Alt.Sources.Mac Archivist
     <http://www.AmbrosiaSW.com/alt.sources.mac/>
    <ftp://ftp.AmbrosiaSW.com/pub/alt.sources.mac/>

 
 
 

Unix Plug-ins?

Post by Andrew E. Miles » Tue, 04 Feb 1997 04:00:00


: Is it possible to create external code files in Unix?
:
: No, I'm not thinking of libraries (static or shared),
: nor am I referring to full applications called after
: a fork()/exec() pair.
:
: I'm interested in opening some kind of file, read it into
: memory, and jump to it.  Is this possible in Unix?

Sounds like a module to me. See the ELF docs for details.

--

Linux Plug-and-Play Kernel Project http://www.redhat.com/linux-info/pnp/
XFree86 Matrox Team http://www.bf.rmit.edu.au/~ajv/xf86-matrox.html

 
 
 

Unix Plug-ins?

Post by Ken L » Tue, 04 Feb 1997 04:00:00



Quote:Nebinger) writes:

|> Is it possible to create external code files in Unix?
|>
|> No, I'm not thinking of libraries (static or shared),
|> nor am I referring to full applications called after
|> a fork()/exec() pair.
|>
|> I'm interested in opening some kind of file, read it into
|> memory, and jump to it.  Is this possible in Unix?

Sounds like you do want a library, but you want to specify it
and load it at run time.  Many versions of UNIX support a
dlopen() function that does just this.  Netscape plugins,
for example, use this feature.

--

 
 
 

Unix Plug-ins?

Post by Eric Levene » Tue, 04 Feb 1997 04:00:00



>I'm interested in opening some kind of file, read it into
>memory, and jump to it.  Is this possible in Unix?

This is simply a process : exec() read a file into memory and execute it.

What else do you want to do ?

--

--------------------------------------------------------------------
ric Lvnez              "Felix qui potuit rerum cognoscere causas"

(NeXTMail, MIME)                                   Georgica, II-489
--------------------------------------------------------------------

 
 
 

Unix Plug-ins?

Post by Andrew Gabri » Tue, 04 Feb 1997 04:00:00




Quote:>Is it possible to create external code files in Unix?

>No, I'm not thinking of libraries (static or shared),
>nor am I referring to full applications called after
>a fork()/exec() pair.

>I'm interested in opening some kind of file, read it into
>memory, and jump to it.  Is this possible in Unix?

That's basically what a shared library is.
Try man dlopen, man dlsym.

--


 
 
 

Unix Plug-ins?

Post by Mike Campbel » Thu, 06 Feb 1997 04:00:00



> Is it possible to create external code files in Unix?

> No, I'm not thinking of libraries (static or shared), nor am I
> referring to full applications called after a fork()/exec() pair.

> I'm interested in opening some kind of file, read it into memory,
> and jump to it.  Is this possible in Unix?

That's essentially what a shared lib is.
 
 
 

Unix Plug-ins?

Post by Don Re » Fri, 07 Feb 1997 04:00:00


In the beginning, or at least on Mon, 03 Feb 1997 11:01:26 -0600,  Dave

Quote:

>Is it possible to create external code files in Unix?

>No, I'm not thinking of libraries (static or shared),
>nor am I referring to full applications called after
>a fork()/exec() pair.

>I'm interested in opening some kind of file, read it into
>memory, and jump to it.  Is this possible in Unix?

likely to fault but try:

void (*func)();

membuff=malloc(10000);
fread(membuff,1,10000,pFile);
func=membuff;
func();

--


 Calcasieu Lumber Co.                    Austin TX
  ---- "Ya jus' mash that butt'n, righ' jere"  ---

 
 
 

Unix Plug-ins?

Post by Elias Martens » Fri, 07 Feb 1997 04:00:00




>> Is it possible to create external code files in Unix?

>> No, I'm not thinking of libraries (static or shared), nor am I
>> referring to full applications called after a fork()/exec() pair.

>> I'm interested in opening some kind of file, read it into memory,
>> and jump to it.  Is this possible in Unix?

>That's essentially what a shared lib is.

Not, really... It's essentially what a "dynamic" lib is.

--
Elias Martenson

 
 
 

Unix Plug-ins?

Post by Dave Nebing » Fri, 07 Feb 1997 04:00:00



//
// > Is it possible to create external code files in Unix?
// >
// > No, I'm not thinking of libraries (static or shared), nor am I
// > referring to full applications called after a fork()/exec() pair.
// >
// > I'm interested in opening some kind of file, read it into memory,
// > and jump to it.  Is this possible in Unix?
//
// That's essentially what a shared lib is.

But using a shared library means that you have to have it around
at compile time.  I'm looking for a means of using external routines
that are available at runtime, but might not be around at compile
time.

Specifically, I'm interested in creating some number of externally
callable routines that generate reports.  At install time the
customer may choose to add all or some of the routines, and as
time goes on I'd like to add new routines without requiring a new
executable as well.

Dave.

==========================================================

             The Alt.Sources.Mac Archivist
     <http://www.AmbrosiaSW.com/alt.sources.mac/>
    <ftp://ftp.AmbrosiaSW.com/pub/alt.sources.mac/>

 
 
 

Unix Plug-ins?

Post by Guy Harr » Fri, 07 Feb 1997 04:00:00



>likely to fault but try:

>void (*func)();

>membuff=malloc(10000);
>fread(membuff,1,10000,pFile);
>func=membuff;
>func();

*Quite* likely to fault if that function isn't position-independent
code, as it's not being relocated to think it lives at the address
"membuff".

As others have indicated, many UNIXes have calls to load code at run
time, usually "dlopen()" (and "dlsym()" to find a symbol, by name, in
the chunk of code loaded with "dlopen()").  There's also a GNU package
"dld" that can, I think, do the same thing if your UNIX *doesn't* have
calls to do it.

 
 
 

Unix Plug-ins?

Post by Jan C. Zawadzk » Fri, 07 Feb 1997 04:00:00



> But using a shared library means that you have to have it around
> at compile time.  I'm looking for a means of using external routines
> that are available at runtime, but might not be around at compile
> time.

man dlopen

Quote:> Specifically, I'm interested in creating some number of externally
> callable routines that generate reports.  At install time the
> customer may choose to add all or some of the routines, and as
> time goes on I'd like to add new routines without requiring a new
> executable as well.

Look at what netscape does with NSAPI - you can write your own functions
that will be called by the server.  Download their Enterprise server,
look in the /nsapi directory.

Jan

 
 
 

Unix Plug-ins?

Post by Andrew Giert » Sat, 08 Feb 1997 04:00:00


 Dave> But using a shared library means that you have to have it
 Dave> around at compile time.

No it doesn't.

Most Unixes that provide shared libraries also provide a means of
attaching a library to an already-running process; the most common
interface uses the dlopen() and dlsym() functions.

 Dave> Specifically, I'm interested in creating some number of
 Dave> externally callable routines that generate reports.  At install
 Dave> time the customer may choose to add all or some of the
 Dave> routines, and as time goes on I'd like to add new routines
 Dave> without requiring a new executable as well.

Think *hard* about whether this belongs in the same executable - this
sounds like something that should be handled by invoking external
programs (using system(), popen(), or fork() & exec()).

If that isn't the right solution, then look at using dlopen() et al.

--
Andrew.

 
 
 

Unix Plug-ins?

Post by Don Re » Sun, 09 Feb 1997 04:00:00


In the beginning, or at least on 6 Feb 1997 22:30:36 -0800,  Guy Harris


>>likely to fault but try:

>>void (*func)();

>>membuff=malloc(10000);
>>fread(membuff,1,10000,pFile);
>>func=membuff;
>>func();

>*Quite* likely to fault if that function isn't position-independent
>code, as it's not being relocated to think it lives at the address
>"membuff".

I was refering to platforms that enforce seperate execute/data space and
the fault of executing in the the _BSS.

Since Dave explictly stated that he did not want to use shared libs, I assumed
that he is aware of the dl* functions and how they work ('tho I may be wrong
on this).

Ditto on the knowledge of image vs relocatable code.

Quote:

>> I'm interested in opening some kind of file, read it into memory,
>> and jump to it.  Is this possible in Unix?

depending on the platform, yes it is possible.

--


 Calcasieu Lumber Co.                    Austin TX
  ---- "Ya jus' mash that butt'n, righ' jere"  ---

 
 
 

Unix Plug-ins?

Post by Don Re » Sun, 09 Feb 1997 04:00:00


In the beginning, or at least on Thu, 06 Feb 1997 12:46:20 -0600,  Dave

Quote:

>But using a shared library means that you have to have it around
>at compile time.  I'm looking for a means of using external routines
>that are available at runtime, but might not be around at compile
>time.

>Specifically, I'm interested in creating some number of externally
>callable routines that generate reports.  At install time the
>customer may choose to add all or some of the routines, and as
>time goes on I'd like to add new routines without requiring a new
>executable as well.

As a design issue, shared/dynamic libs is probably where you are going.

Say your app has several sales reports. You create a shared lib (libSL.so)
that has all the possible reports in it: rep1 rep2 ... rep9

Now your customer could pick which reports they want by adding them to
a resource file.
Reports 1-4 & 7 are wanted, then the resource file contains:

SLREP=rep1,rep2,rep3,rep4,rep7

Next you write some kind of menu:

char *SLReportMenu() {

/* This parses the resource file and presents just the allowed choices;
returning a pointer to the report name selected (NULL for no report).

coding omitted for the moment ...

*/

Quote:}

Finally the top level function that does the work.

int DoSalesReport() {
void *hdl;
void (*fptr)();
char *str;

        /* get desired report name */

        if ( NULL == (str=SLReportMenu())) {
                /* exit quietly */
                return(0);
        }

        /* open the sales report lib */

        if (NULL == (hdl = dlopen("libSL.so", RTLD_LAZY))) {
                error("missing shared lib ...");      
                return(-1);
        }

         /* point to the report function */

        if (NULL == (fptr = dlsym(hdl, str))) {
                error("invalid report name ...");    
                return(-1);
        }

        (*fptr)();      /* generate the report */

        dlclose(hdl);   /* close the lib */
        return(0);      

Quote:}

Later, as additional reports are written, your customer would install the new
libSL.so, add/edit the rc file to enable the new reports and fire it up ...

--


 Calcasieu Lumber Co.                    Austin TX
  ---- "Ya jus' mash that butt'n, righ' jere"  ---

 
 
 

Unix Plug-ins?

Post by Patrick Steran » Sat, 15 Feb 1997 04:00:00




> >likely to fault but try:

> >void (*func)();

> >membuff=malloc(10000);
> >fread(membuff,1,10000,pFile);
> >func=membuff;
> >func();

> *Quite* likely to fault if that function isn't position-independent
> code, as it's not being relocated to think it lives at the address
> "membuff".

> As others have indicated, many UNIXes have calls to load code at run
> time, usually "dlopen()" (and "dlsym()" to find a symbol, by name, in
> the chunk of code loaded with "dlopen()").  There's also a GNU package
> "dld" that can, I think, do the same thing if your UNIX *doesn't* have
> calls to do it.

Guy, and others,

I am curious how portable code is that opens a shared library and
maps that file into the currently executing programs shared memory
space and executes the code in that area.
and executes it.
As Guy points out, the code must be PIC (position independent), and
I have been burned by trying such niave approaches in the past.
On HP-UX, while I don't know of all of the details, I know that
the OS's use "STUB functions" that somehow work with the
"dynamic link loader" program to map the DLL into the current processes
address space.

I am in a project now that needs this kind of capability, and I am
interested in keeping things as portable as is possible.

I can provide more details if necessary.

--
Patrick Steranka

wk: 301-680-3343

 
 
 

1. Netscape plug-ins on AIX 4

Does anyone know if Netscape supports plug-ins on AIX?  I've a feeling
last time I asked the question they didn't and now they might.

RSVP if you are in the know,

alan
-----------------------------------------------------------------------
 Alan Donovan, FORE Audio & Video, 14 Regent Street, Cambridge CB2 1DB

-----------------------------------------------------------------------

2. removing a user

3. plug-ins netscape

4. Find library path when LD_LIBRARY_PATH not present

5. Reward for NExS Spreadsheet Plug-Ins

6. No permission to Shutdown or su to root??

7. Netscape helpers and plug-ins, also java help

8. getty rates > 19200

9. List of plug-ins for linux/netscape please!

10. Browser Question (Plug-ins) m-w.com

11. Netscape and Plug-ins

12. Netscape plug-ins

13. Acrobat Reader 4.0 MIME Type for Netscape plug-ins