Message-ID: <34879CFA.1D51@mailexcite.com> Date: Fri, 05 Dec 1997 01:19:39 -0500 From: Doug Gale Reply-To: dgale AT mailexcite DOT com MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Un-map physical memory? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: embernet31.idirect.com Lines: 57 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk 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.