Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ execseg(S) — OpenDesktop Software Development System 1.0.0d

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     EXECSEG(S)                UNIX System V                EXECSEG(S)



     Name
          execseg - makes a data region executable.

     Syntax
          #include <xdata.h>

          excode_t execseg(oldaddr, size)
          exdata_t oldaddr;
          unsigned size;

          int unexecseg(addr)
          excode_t addr;

     Description
          execseg(S) is passed the current data address and size of
          the region to be executed and it returns the starting
          address of a region that is at least size number of bytes
          which can safely be branched to.  On the Intel 8086 and
          80286, processor an alias CS descriptor is associated with
          the same memory as the data segment in which the oldaddr
          region lies. This means that offsets in the executable
          segment to access a given byte are essentially the same as
          the offsets in the original data segment, except the
          selector is different.

          Note that ``excode_t'' and ``exdata_t'' are ``far'' pointers
          on the 8086 and 80286 and segment selectors on the 386. On
          an architecture where pages in the same ``segment'' are any
          combination of read/write/execute, the returned address is
          identical to the parameter passed to execseg(S).

          We recommend that programs using this function on 8086- and
          80286-based processors be large model, or that programmers
          be very familiar with ``hybrid model'' as well as with the
          use and misuse of far data.

          When an error occurs, execseg(S) returns ((excode_t)-1),
          with errno set to ENONEM.  Errors include an invalid data
          address or size, and an inability to allocate a new data
          selector.

          The unexecseg() system call disables an addr previously
          returned from execseg(S) from being used as an executable
          region.  Specifically, on the 8086 and 80286 architectures,
          this call frees the selector used for the executable region.
          It returns 0 on success, or a -1 on error. For example, if
          addr is not an address returned by execseg(S), then a -1 is
          returned and it can be used as an executable region.

     Example
              excode_t funcp; char far *datap;
                 .
                 .
                 .
              datap=brkctl(BR_NEWSEG,1000L,0L);

               /* load executable code into
                   data region datap */
              load_with_code(datap,1000)

              funcp=execseg(datap,1000); (*funcp)()

              /*call subroutine*/ if (unexecseg (funcp)==-1){
               printf("unexecseg failed\n"); exit(1); }

     Notes
          On the Intel 8086 and 80286 architectures, execseg(S)
          expects far addresses to be passed.  Only experienced
          programmers should use this feature.

          Since the execseg return value and address arguments are
          ``far'' pointerson 86 and 286 machines, any program
          including xdata.h must be compiled using the -Me option.

          The following restrictions apply to the execute data system
          call.

          1.   Even though an address and size are passed to execseg,
               the entire segment containing the requested addresses
               are aliased.  The address and size are validated before
               the aliasing is allowed.

          2.   No part of the data segment that is aliased may be
               deallocated (via sbrk(S) or brkctl(S)) while it is
               aliased.  This restriction applies to the entire
               segment that is aliased, even if only a small piece of
               the segment was aliased.  After unexecseging the
               aliased segment, the data segment may be deallocated.

          3.   Each call to execseg results in a new alias segment
               being used, even if the data segment is already
               aliased.

          Due to compiler confusion, you may get the message ``at
          least one void operand'' when using execseg.  Please ignore
          it.

          Programs using this call must be compiled with the -lx
          option.

          Under UNIX-386 the oldaddr parameter passed to execseg() is
          a segment selector, not a pointer. execseg() returns a
          selector value which provides a code segment alias to the
          original segment.

          Similarly, the addr parameter passed to unexecseg() is a
          selector value that has previously been returned by
          execseg().

          Note that since execseg() returns a segment selector on 386
          machines, the return value from execseg() is not directly
          useable in a C program.  In an assembler program this
          selector value would be used as the top 16 bits of a 48 bit
          far pointer.

                                             (printed 6/20/89)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026