|
|
1.1.1.2 ! root 1: /* This example illustrates the use of the following MS OS/2 function: ! 2: * DosCreateCSAlias 1.1 root 3: * 1.1.1.2 ! root 4: * A data segment is allocated by calling DosAllocSeg. A small assembly 1.1 root 5: * language routine is created in this data segment. An alias code selector 1.1.1.2 ! root 6: * for this data segment is obtained by calling DosCreateCSAlias. Using the 1.1 root 7: * alias code selector, the routine in the data segment is called. After 8: * returning from the routine, the alias code selector and the data segment 1.1.1.2 ! root 9: * are freed by calling DosFreeSeg. 1.1 root 10: * 11: * This program illustrates the function - it does not do anything useful. 12: * A more likely use of aliasing code to data is where the code is actually 13: * generated at run time, rather than statically declared in this example. 14: * 1.1.1.2 ! root 15: * Created by Microsoft Corp. 1986 1.1 root 16: */ 17: 1.1.1.2 ! root 18: #define INCL_DOSMEMMGR ! 19: ! 20: #include <os2def.h> /* SELECTOROF and OFFSETOF macros */ ! 21: #include <bsedos.h> /* MS OS/2 function declarations */ 1.1 root 22: #include <stdio.h> /* printf C lib function declaration */ 1.1.1.2 ! root 23: 1.1 root 24: 25: #define PRIVATE 0 /* segment will not be shared */ 26: #define SOMENUM 3 /*to be squared by proc in CSAlias'ed segment*/ 27: 1.1.1.2 ! root 28: UCHAR square[] = { /*a routine that computes the square of an integer*/ 1.1 root 29: 0x55, /* push bp */ 30: 0x8b, 0xec, /* mov bp,sp */ 31: 0x8b, 0x46, 0x06, /* mov ax,[bp+6] */ 32: 0xf7, 0xe0, /* mul ax */ 33: 0x8b, 0xe5, /* mov sp,bp */ 34: 0x5d, /* pop bp */ 35: 0xcb, /* retf */ 36: '\0' /* terminate with null */ 37: }; 38: 39: main () 40: { 1.1.1.2 ! root 41: SEL DataSelector, /* selector to data segment */ 1.1 root 42: CodeSelector; /* alias code segment selector */ 43: char *DataSeg; /* pointer to data segemnet */ 44: long (*proc)(int); /* pointer to a procedure */ 45: long SquareOfInt; /* to hold square of an integer*/ 46: 47: /* allocate a segment */ 1.1.1.2 ! root 48: DosAllocSeg (sizeof(square), &DataSelector, PRIVATE); 1.1 root 49: 50: /* construct a far pointer to the data segment */ 1.1.1.2 ! root 51: SELECTOROF(DataSeg) = DataSelector; ! 52: OFFSETOF(DataSeg) = 0; 1.1 root 53: 54: /* copy an assembly language procedure into the data segment */ 55: strcpy(DataSeg, square); 56: 57: /* get a csalias selector for the data segment */ 1.1.1.2 ! root 58: DosCreateCSAlias (DataSelector, &CodeSelector); 1.1 root 59: 60: /* construct the address to the procedure in the csalias'ed segment */ 1.1.1.2 ! root 61: SELECTOROF(proc) = CodeSelector; ! 62: OFFSETOF(proc) = 0; 1.1 root 63: 64: /* execute the code in the csalias'ed data segment */ 65: if ((SquareOfInt = (*proc)(SOMENUM)) != (SOMENUM * SOMENUM)) 66: printf ("*** error: procedure in CSAlias'ed segment failed ***\n"); 67: 68: /* free the alias code selector */ 1.1.1.2 ! root 69: DosFreeSeg(CodeSelector); 1.1 root 70: 71: /* free the data segment */ 1.1.1.2 ! root 72: DosFreeSeg(DataSelector); 1.1 root 73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.