Mail Archives: djgpp/1997/12/05/09:16:06
I am working on a function that will remap DOS memory into my heap.
I know that this won't work under Win95 (I think), but I am putting it
into my library and I need some suggestions.
First question, am I doing it right? Here's the source:
int GL_RemapDOSMemory(void **pmode_ptr, void **map_block, unsigned
phys_addr,
unsigned size)
{
unsigned alloc_size = size * 2 + 4096;
void *mapping_block;
// Allocate memory region to map the dma buffer into
if (!(*map_block = mapping_block = malloc(alloc_size)))
return 0;
// Page align
if ((unsigned)mapping_block & 0xfffff000)
*pmode_ptr = (unsigned char *)
(((unsigned)mapping_block & 0xfffff000) + 0x1000);
else
*pmode_ptr = mapping_block;
// Map physical memory into memory block
if (__djgpp_map_physical_memory(*pmode_ptr, size, phys_addr) == -1)
return 0;
return 1;
}
(I know the comments mention DMA, but don't pay attention to this, it
was a copy/modify of my GL_RemapDMABuffer(...) function that allocates
DOS memory and avoids 64K boundaries) :)
(If you want the source for GL_RemapDMABuffer() just ask! Programmers,
especially DJGPP users, should GIVE GIVE GIVE!)
"pmode_ptr" is what the caller will use to access the remapped memory
from protected mode
"map_block" is the address (returned by malloc()) on the heap where the
memory is mapped in.
If I free() "map_block", the DOS memory is still remapped (isn't it?)
I was thinking of using dpmi calls to undo it, but I don't know what to
pass as a handle/selector because the __djgpp_memory_handle_list is a
mystery to me.
How to I "unmap" the memory. As I said, it's going into a library, and I
would like to provide a function that un-does this. I am also afraid
that I might leave a dpmi server in a weird state when I exit the
program.
BTW, I WILL NOT use __djgpp_nearptr_enable(). I LIKE SIGSEGV! :)
Thanks.
- Raw text -