Chapter Contents

Previous

Next
buildm

buildm



Create a Function Pointer from an Address

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
ERRORS
CAUTIONS
EXAMPLE


SYNOPSIS

#include <dynam.h>

void buildm(const char *name, __remote /* type */ (**fpp)(), 
            const char *ep);


DESCRIPTION

buildm converts the entry point address in ep to a __remote function pointer. The created function pointer can then be used to transfer control to a function or module located at this address. buildm is normally used to generate a function pointer for a C load module that has been loaded without the assistance of the SAS/C Library (for instance, by issuing the OS/390 LOAD SVC), but it can also be used with a non-C load module or with code generated by the program. buildm also assigns a load module name to the entry point address, and use of this name in subsequent calls to loadm or unloadm is recognized as referring to the address in ep . Note that a load module processed with buildm should always include a _dynamn function.

buildm stores the function pointer in the area addressed by fpp . Note that fpp may reference a function returning any valid type of data. If the function pointer cannot be created, a NULL value is stored.

name points to a name to be assigned to the built load module. If name is "" , then a unique name is assigned by buildm . If the name is prefixed with an asterisk, then buildm does not check to see if the name is the name of a previously loaded module (see the buildm section, ERRORS).


RETURN VALUE

buildm stores the function pointer in the area addressed by fpp . If an error occurs, buildm stores NULL in this area.


ERRORS

If the string addressed by name does not start with an asterisk and is the same as a previously built or dynamically loaded module, the request is rejected unless the value of ep is the same as the entry point of the existing load module. If the entry points are the same, a pointer to the previously loaded or built module is stored in the area addressed by func .


CAUTIONS

The name argument must point to a null-terminated string no more than eight characters long, not counting a leading asterisk. Leading and trailing blanks are not allowed.

The fpp argument must be a pointer to an object declared as "pointer to function returning (some C data type)".


EXAMPLE

This example illustrates a method of using inline machine code (see Chapter 13, "In-Line Machine Code Interface," in SAS/C Compiler and Library User's Guide) to load a load module under OS/390 or a TEXT file or TXTLIB member under CMS using SVC 8. The machine code instruction sequence is coded as a macro to enhance readability.

The example assumes that SIMPLE is a C _dynamn function returning void .

#include <svc.h>
#include <code.h>
#include <stdio.h>

#define LOAD(n,ep) (_ldregs(R0+R1,n,0),_ossvc(8),
        _stregs(R0,ep))

main()
{

   void (*fp)();
   char *ep;

      /* The name "SIMPLE" must be uppercased, left-adjusted, */
      /* and padded to eight characters with blanks when      */
      /* used by SVC 8.                                       */
   LOAD("SIMPLE  ",&ep);

      /* The name passed to buildm does not have to match     */
      /* the name of the loaded module, but it helps.         */
   buildm("simple",&fp,ep);
   if (fp)         /* If no errors, call SIMPLE               */
      (*fp)();
   else
      puts("simple didn't load.");

}


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.