Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ execseg(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

brkctl(S)

sbrk(S)


 execseg(S)                     6 January 1993                     execseg(S)


 Name

    execseg - makes a data region executable

 Syntax


    cc  . . .  -lx


    #include <xdata.h>

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

    int unexecseg(addr)
    excode_t addr;


 Description

    execseg 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 essen-
    tially the same as the offsets in the original data segment, except the
    selector is different.

    Note that excodet and exdatat 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.

    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 returns((excodet)-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 from being used as an executable region.  Specifically, on the
    8086 and 80286 architectures, this call frees the pointer used for the
    executable region.  It returns 0 on success, or a -1 on error. For exam-
    ple, if addr is not an address returned by execseg, 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_with_code(datap,1000);         /* load executable code into */
                                               /* data region datap */

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

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


 Notes

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

    Since the execseg return value and address arguments are ``far'' pointers
    on 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.

    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.

 See also

    brkctl(S), sbrk(S)

 Standards conformance

    execseg and unexecseg are not part of any currently supported standard;
    they are an extension of AT&T System V provided by the Santa Cruz Opera-
    tion.


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