Skip to content

Commit d13082b

Browse files
committed
Improve documentation of '__djgpp_map_physical_memory'.
Document requirements / restrictions for out_addr/num_bytes parameters, and extend example of how to use this function. Patch from Pali <pali@pali.im>.
1 parent 20bfcb6 commit d13082b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/libc/dpmi/helper/mapmem.txh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ be set to @code{EINVAL} and the routine will fail.
2121
This routine properly handles memory ranges that span multiple DPMI
2222
handles, while @code{__dpmi_map_device_in_memory_block} does not.
2323

24+
Every page in the specified address range @var{out_addr}, @var{num_bytes}
25+
must belong to some DPMI handle in @code{__djgpp_memory_handle_list}
26+
allocated by @code{sbrk}.
27+
28+
To accommodate page-aligning and existence of DPMI handle for memory
29+
@var{out_addr}, the easiest option is to allocate page-aligned memory
30+
by @code{valloc} function (which internally uses @code{sbrk}) and
31+
then pass it to @code{__djgpp_map_physical_memory}.
32+
33+
To unmap physical memory range created by @code{__djgpp_map_physical_memory},
34+
use @code{__djgpp_set_page_attributes} function and change page
35+
attributes of every page to committed type and read/write access
36+
without setting initial page access and dirty bits. After that
37+
@var{our_addr} memory allocated by @code{valloc} can be returned
38+
back to the memory pool by @code{free}.
39+
2440
Consult DPMI documentation on function 0508H for details on how this
2541
function works. Note: since 0508H is a DPMI service new with DPMI
2642
1.0, this call will fail on most DPMI 0.9 servers. For your program
@@ -42,7 +58,30 @@ DPMI server rejected the mapping request.
4258
@subheading Example
4359

4460
@example
61+
void *my_page_aligned_memory = valloc (16384);
62+
if (!my_page_aligned_memory)
63+
{
64+
printf ("Failed to allocate page-aligned memory!\n");
65+
return;
66+
}
67+
4568
if (__djgpp_map_physical_memory (my_page_aligned_memory, 16384,
4669
0x40000000))
70+
{
4771
printf ("Failed to map physical addresses!\n");
72+
}
73+
else
74+
{
75+
/* code which access mapped my_page_aligned_memory */
76+
}
77+
78+
if (__djgpp_set_page_attributes (my_page_aligned_memory, 16384,
79+
(0<<4) | (1<<3) | 1))
80+
{
81+
printf ("Failed to unmap physical addresses!\n");
82+
}
83+
else
84+
{
85+
free (my_page_aligned_memory);
86+
}
4887
@end example

0 commit comments

Comments
 (0)