> From: Greg Winton [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 05, 2000 2:10 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Shared libraries and reference numbers
>
> At 07:10 PM 1/5/00 +0200, you wrote:
> >Anyway, is it possible to have shared library functions without
> >reference number and if so, could anyone send me some
> working piece of
> >code that implements shared library and program that calls it?
>
> I don't believe its possible to have shared library functions
> that don't
> start with the reference number. The reference number is not
> only used to
> access "globals" in the shared library. It is also used to
> multiplex among
> shared library calls. For example, every shared library's
> "open" function
> has a trap id of sysLibTrapOpen. What distinguishes library A's open
> function from library B's is the reference number.
You should -never- write a shared library function that does not use a
reference number. You might get lucky a few times, but Greg hit the nail on
the head with that last sentence there. Bottom line, w/o a reference
number, the OS will probably jump to the right function offset in the wrong
dispatch table.
When the OS ends up inside of the trap dispatch function, it knows two
things:
1) The address of the lib function it needs to jump to in the appropriate
lib's dispatch table (this is what you use sysLibTrapCustom for). Let's
assume we are calling sysLibTrapMyFunction, which translates to 0xA805.
2) The reference number, which the trap dispatch function expects to be
sitting at the stack, -2(A6). The dispatch function will pop -2(A6) off the
stack, and use that UInt value as its index into the OS's array of
installed-library-dispatch-tables. It will then just jump to the offset
0xA805, into that particular dispatch table, and start executing code it
finds there.
If you supply an invalid refnum, or your function doesn't include that
argument, you are going to jump into an unknown library's dispatch table and
start running somebody else's code. Or you'll just start running garbage.
If you want to see -exactly- what goes on when the OS makes a call to a
shared library, I dispelled the voodoo in an article in the Palm
knowledgebase. I basically did a disassembly and described what happens
step by step. It will bore you to death, but it's great trivia for Palm
cocktail parties!
http://oasis.palm.com/devzone/knowledgebasearticle.cfm?article_id=1670
Later!
-Jeff Ishaq
Vanteon
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html