home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / tools / nosecuri / nosecuri.EXE / callback.h next >
Encoding:
C/C++ Source or Header  |  1999-05-24  |  1.3 KB  |  44 lines

  1. #ifdef __GNUC__
  2.  
  3. #ifndef __CALLBACK_H__
  4. #define __CALLBACK_H__
  5.  
  6. /* This is a workaround for a bug in the current version of gcc:
  7.  
  8.    gcc assumes that no one will touch %a4 after it is set up in crt0.o.
  9.    This isn't true if a function is called as a callback by something
  10.    that wasn't compiled by gcc (like FrmCloseAllForms()).  It may also
  11.    not be true if it is used as a callback by something in a different
  12.    shared library.
  13.  
  14.    We really want a function attribute "callback" which will insert this
  15.    progloue and epilogoue automatically.
  16.  
  17.       - Ian */
  18.  
  19. register void *reg_a4 asm("%a4");
  20.  
  21. #define CALLBACK_PROLOGUE \
  22.     void *save_a4 = reg_a4; asm("move.l %%a5,%%a4; sub.l #edata,%%a4" : :);
  23.  
  24. #define CALLBACK_EPILOGUE reg_a4 = save_a4;
  25.  
  26. #endif
  27.  
  28. #endif
  29.  
  30. /* 
  31. In any function in your code that is called _directly from the OS_
  32. (like custom draw routines, event handlers, etc.), insert CALLBACK_PROLOGUE
  33. at the beginning (right after the local var declarations), and
  34. CALLBACK_EPILOGUE at the end (right before the "return").  NOTE: make sure
  35. that it is _impossible_ for your routine to return without executing
  36. the CALLBACK_EPILOGUE.  Also, make sure to #include "callback.h", of course.
  37.  
  38. There is a compiler flag that attempts to do this, but last I checked,
  39. the code it generates was wrong; it forgot to restore the original %a4 value.
  40.  
  41.    - Ian
  42.  
  43. */
  44.