Re: A89: Event Handlers......
[Prev][Next][Index][Thread]
Re: A89: Event Handlers......
> I want to install a new event handler (using EV_hook like Doors), but
there
> is a problem. If doors or any compatable kernel that uses SHIFT+ON to
launch
> the program called doors (and what kernel doesn't?) is installed, then my
> handler will overwrite the pointer to the kernel's and SHIFT+ON will no
> longer work! I need a way to find the address/pointer of the allocated
memory
> the kernel stores this handler code in so I can call it at the end of my
> handler (does that make sense?).
As James noted earlier, you can simply get the value presently in EV_hook,
save it in a variable of your own, and call that at the end of your handler
instead of EV_defaultHandler.
Note that EVENT_HANDLER is a pointer to a function, which creates some "odd"
looking C calls for those who aren't experienced in using them. Refer the
K&RC2's sections on pointers to functions (look it up in the index) for more
information on them. Sample code follows (somebody please check and make
sure I make no errors in my haste, especially on the function call in the
handler):
/* includes, defines, prototypes, etc here */
EVENT_HANDLER old_hook;
void _main(void)
{
old_hook = EV_hook;
EV_captureEvents (Handler);
TRY
EV_eventLoop ();
ONERR
EV_captureEvents (NULL);
ENDTRY
/* more code here */
}
void Handler (EVENT *ev)
{
/* handle events here, and end it with */
if (old_hook != NULL)
(*old_hook)(ev);
}
---------------
HOWEVER, as I stated in my previous posts, I do not believe that the *-ON
handlers are best implemented using the event handler, when int 6 is
sufficient and, IMHO, superior, for reasons explained in the lsat message I
sent to this list.
If you'd like to use int 6 instead, it's very simple to add the wrapper -
sample 68k ASM wrapper follows, assuming that the routine to install the
wrapper saved the old int 6 address at the label old_int_6_address:
int_6_wrapper:
;save registers used here
;your code goes here
;restore all registers here
move.l (old_int_6_address),-(sp) ;motorola has stated that using
rts ;parenthesis to indicate indirection
;in 68k is deprecated, but it sure
;makes this more readable
Implementing that in TI-GCC is a bit more difficult; refer to Zeljko's
previous great messages on implementing interrupts in TI-GCC from this past
week.
> Also, as I am doing this in C, is there a
> way I can determine the size of the compiled function so I can copy it to
a
> block of memory (need to copy the handler function to a block of memory
and
> lock it so the function can be called). I need to do something like
> memcpy(*my_hook_function, pointer_to_allocated_memory, num_of_bytes), but
I
> need num_of_bytes
Yup, that's what the sizeof() operator is for. I believe it's valid for
functions, too - but the rest of your call is wrong, so let me just cover
how memcpy is called - TI-GCC lists the prototype as:
void *memcpy (void *dest, const void *src, unsigned long len);
Your example needs to switch the source and destination, and use the
address-of (unary &) operator rather than *:
memcpy (pointer_to_allocated_memory, &my_hook_function, sizeof
(my_hook_function));
I'm afraid that might be split into multiple lines by your email software -
just remove the line break =(
Once again, somebody please check me on that code above - I no longer trust
myself after the 3==4 etc debacle =)
> Hope this makes sense, and thanks for any help anyone can give me.
No problem - that's what this list is for, and your questions were very
reasonable =)\
-Scott
Follow-Ups: