home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / library / src / setfunction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.1 KB  |  92 lines

  1. /*
  2.     (C) 1995, 96 AROS - The Amiga Replacement OS
  3.     $Id$
  4.     $Log$
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include "exec_intern.h"
  9. #include <aros/lvo.h>
  10.  
  11. /*****************************************************************************
  12.  
  13.     NAME */
  14.     #include <clib/exec_protos.h>
  15.  
  16.     __AROS_LH3(APTR, SetFunction,
  17.  
  18. /*  SYNOPSIS */
  19.     __AROS_LA(struct Library *, library,     A1),
  20.     __AROS_LA(LONG,             funcOffset,  A0),
  21.     __AROS_LA(APTR,             newFunction, D0),
  22.  
  23. /*  LOCATION */
  24.     struct ExecBase *, SysBase, 70, Exec)
  25.  
  26. /*  FUNCTION
  27.     Replaces a certain jumptable entry with another one. This function only
  28.     Forbid()s taskswitching but doesn't Disable() interrupts. You have
  29.     to do your own arbitration for functions which are callable from
  30.     interrupts.
  31.  
  32.     INPUTS
  33.     library     - Pointer to library structure.
  34.     funcOffset  - Offset of the jumpvector from the library base address in
  35.               bytes.
  36.     newFunction - New jumptable entry (pointer to the new function).
  37.  
  38.     RESULT
  39.     Old jumptable entry (pointer to the old function).
  40.  
  41.     NOTES
  42.     While it's more or less safe to patch a library vector with
  43.     SetFunction() it's not possible to safely remove the patch later.
  44.     So don't use this function if it can be avoided.
  45.  
  46.     EXAMPLE
  47.  
  48.     BUGS
  49.  
  50.     SEE ALSO
  51.     MakeLibrary(), MakeFunctions(), SumLibrary().
  52.  
  53.     INTERNALS
  54.  
  55.     HISTORY
  56.  
  57. ******************************************************************************/
  58. {
  59.     __AROS_FUNC_INIT
  60.  
  61.     APTR ret;
  62.  
  63.     /*
  64.     Arbitrate for the jumptable. This isn't enough for interrupt callable
  65.     functions - but it need not be.
  66.     */
  67.     Forbid();
  68.  
  69.     /* Mark the library as changed. */
  70.     library->lib_Flags|=LIBF_CHANGED;
  71.  
  72.     /* Get old vector. */
  73.     ret=__AROS_LVO_GET_FUNC (library, -funcOffset);
  74.  
  75.     /* Write new one. */
  76.     __AROS_LVO_GET (library, -funcOffset)->lve_FuncPtr = newFunction;
  77.  
  78.     /* And clear the instructiuon cache. */
  79.     CacheClearE((char *)library+funcOffset,LIB_VECTSIZE,CACRF_ClearI);
  80.  
  81.     /* Arbitration is no longer needed */
  82.     Permit();
  83.  
  84.     /* Sum the library up again */
  85.     SumLibrary(library);
  86.  
  87.     /* All done. */
  88.     return ret;
  89.     __AROS_FUNC_EXIT
  90. } /* SetFunction */
  91.  
  92.