Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Blinker 5.10 Online Reference - <b> doscreatecsalias()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 DosCreateCSAlias()
------------------------------------------------------------------------------
 Purpose:
 Create an executable (code) selector corresponding to a data selector.

 Syntax:
 USHORT BLXAPI DosCreateCSAlias(SEL datasel, PSEL codesel);

 Parameters:
 datasel  Data selector to be aliased. This selector must belong to a
          single data segment less than or equal to 64 Kb.
 codesel  Pointer to an integer to receive the code selector (alias).

 Returns:
 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.

 Description:
 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()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson