[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
DosCreateCSAlias() Create executable (code) selector corresponding to data selector.
------------------------------------------------------------------------------
Function : Create an executable (code) selector corresponding to a data
selector.
Syntax : USHORT BLXAPI DosCreateCSAlias( SEL datasel,
PSEL codesel);
datasel Data selector to be aliased. This selector must belong to a
single data segment less than or equal to 64kb.
codesel Pointer to an integer to receive the code selector (alias).
Return : Executable selector corresponding to data selector. The returned
selector has the same linear base address and limit as the
original data selector, but has a read / execute code attribute.
This function allows code to be executed in a data segment.
Note: The original data selector should be locked in memory (using
DosLockSeg()) prior to creating the alias selector. This ensures that the
original selector will not be swapped out of memory, which could later cause
the linear base address of the segment to change when the segment is
reloaded from disk. This is necessary because alias selectors do not track
changes to the original selector. The original data selector may be unlocked
by calling DosUnlockSeg() after the alias selector has been freed using
DosFreeSelector().
Example:
#include <stdio.h>
#include <blx286.h>
#define TOSCREEN 2
#define TOPRINT 5
unsigned char codebyte[] =
{
0xb8, 0x00, 0x00, /* mov AX, 0 */
0xba, 0x00, 0x00, /* mov DX, 0 */
0xcd, 0x21, /* int 21 */
0xcb /* retf */
};
void (far *execdata) (void);
void output(char *string, unsigned char device)
{
while (*string)
{
codebyte[2] = device; /* screen or printer */
codebyte[4] = *string; /* char to output */
(*execdata)();
string++;
}
}
void main(void)
{
/* This is a contrived example */
void far *fp;
SEL codesel ;
/* Lock the segment first */
fp = (void far *)(codebyte);
DosLockSeg(SELECTOROF(fp));
if (DosCreateCSAlias(SELECTOROF(fp),&codesel) == 0)
{
execdata = MK_FP(codesel, OFFSETOF(fp));
output("This is a contrived example\n",TOSCREEN);
output("This is a contrived example\n",TOPRINT);
DosFreeSelector(codesel);
}
}
See Also:
DosCreateDSAlias()
DosLockSeg()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson