In addition to loading segments, the LoadAppSeg function reloads segments
that the Windows kernel has discarded. Because the LoadAppSeg function is
responsible for reloading segments, it must update bits 1 and 2 of the 16-bit
flag value in the segment table. (Only self-loading applications should alter the
Windows header or the data tables that follow it.) Bit 1 specifies whether memory is allocated for the segment, and bit 2 specifies whether the segment is currently loaded. For a complete description of the segment table, see the Microsoft Windows Programmer's Reference, Volume 4.
If the loader allocates memory for a segment but the segment is not loaded (that
is, bit 1 is set and bit 2 is not), the LoadAppSeg function should call the
Windows GlobalHandle function to determine whether memory is allocated
for the segment. If memory is not allocated, the LoadAppSeg function should
call the Windows GlobalReAlloc function to reallocate memory for the segment.
Once memory is allocated, the LoadAppSeg function should read the segment from the executable file and call the PatchCodeHandle function to correct each function prolog that occurs in the segment. Once the function prologs are altered, the LoadAppSeg function should resolve any far pointers that occur in the segment. If the pointer is specified by an ordinal value, the LoadAppSeg function should call the kernel-supplied EntryAddrProc function to resolve the address.