Partial application in C

mcdonald at uxe.cso.uiuc.edu mcdonald at uxe.cso.uiuc.edu
Sat Jul 2 00:23:00 AEST 1988



>Every segment on the 286 (in 286 mode, of course) has a descriptor. 
>Each descriptor has a byte, called the Access Rights Byte, that
>contains protection bits for the segment.  Bit 4 is the 'executable'
>flag; if 0, this is a Data Segment Descriptor, if 1, this is a
>Executable Code Segment Descriptor.

>Now, if this is a Data Segment Descriptor, bit 1 describes whether
>this segment is read-only (0), or read-write (1).  If, on the other
>tentacle, this is an Executable Code Segment Descriptor, bit 1
>describes whether the segment can be read (1) or not (0).  You cannot
>write to an Executable Code Segment!  The system, of course, loads a
>program as data segments and then modifies the segment descriptors to
>make them executable.

And, for all but brain-dead compilers and/or operating systems,
a cast of a data pointer to a code pointer (or vice-versa) should
still work. The compiler either does it directly, or, in the case
of aggressively over-protective operating systems, calls a system
routine which generates a segment descriptor of the proper type which
points to the same location in memory. I would presume that the ANSI
standard would describe in detail the requirements for this. If
a facility such as this is missing, C would be a seriously restricted
language: no Forth written in C, no Turbo Pascal or Turbo C, no
incremental compilation! OS/2, for example, has a system call to do this;
whether the compiler automatically makes that call I doubt.
I believe it is called DOSCreateAlias or DOSCreateCodeAlias. What is
the equivalent call in UNIX?

Doug McDonald



More information about the Comp.lang.c mailing list