[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ExoSegCSAlias()
 Creates a code descriptor for the given data segment
------------------------------------------------------------------------------
 C Prototype

     void *ExoSegCSAlias(void *pm_ptr)

 Returns

     This function returns a function pointer to the same linear address as
     pm_ptr, or NULL if an error occurred.

 Description

     The new descriptor created by ExoSegCSAlias points to the segment base
     of pm_ptr.  This function enables you to execute code in a data segment.
     To store data in a code segment, use ExoSegDSAlias().  Because
     ExoSegCSAlias() is run with interrupts enabled, realtime applications
     should not call it from an external interrupt handler.

     The offset of the alias will ALWAYS equal the offset of the original
     pointer.

     ExoFreeSelector() MUST be called to free the selector allocated with
     ExoSegCSAlias().  Selectors are a limited resource and repeated calls to
     ExoSegCSAlias() as well as ExoSegDSAlias() and ExoProtectedPtr() could
     use up all the available selectors causing the program to crash.  Once
     you are done with a pointer created with ExoSegCSAlias(), free the
     selector unless you will be using the pointer throughout the program.

 Examples

     This code fragment calls executable machine code written by the program
     to a data buffer.

     char writablecode[100];
     void (*funcptr(void));

     /* during execution the program would write executable machine
        code to the 100 byte writablecode buffer */

     /* create a selector that is a code segment alias to the data
        segment containing the variable writablecode */

     funcptr = ExoSegCSAlias(writablecode);

     /* set the offset of the function pointer to the offset of the
        writablecode buffer */
     FP_OFF(funcptr) = FP_OFF(writablecode);

     /* call the code written to the writablecode buffer */
     *funcptr();

     /* cancel the code segment selector */
     ExoFreeSelector(FP_SEG(funcptr));

 Files   Library is EXOSPACE.LIB, header file is Exospace.api.


See Also: ExoSegDSAlias()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson