X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: shwonder AT gmail DOT com Newsgroups: comp.os.msdos.djgpp Subject: How to unmap memory, mapped by __djgpp_map_physical_memory Date: Thu, 21 Jun 2007 06:40:24 -0700 Organization: http://groups.google.com Lines: 70 Message-ID: <1182433224.712755.39270@n2g2000hse.googlegroups.com> NNTP-Posting-Host: 192.198.152.98 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1182433224 16871 127.0.0.1 (21 Jun 2007 13:40:24 GMT) X-Complaints-To: groups-abuse AT google DOT com NNTP-Posting-Date: Thu, 21 Jun 2007 13:40:24 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.1 hafwpr02.iil.intel.com:911 (squid/2.6.STABLE12) Complaints-To: groups-abuse AT google DOT com Injection-Info: n2g2000hse.googlegroups.com; posting-host=192.198.152.98; posting-account=oSbL2g0AAABEFAo8-nlGVXciDOlWy6Xt To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Hi, All I map device memory into virtual address space using __djgpp_map_physical_memory(). Is there a way to unmap it back. For example: void* AllocateDeviceMemory(unsigned long physicalAddress, unsigned long size) { /* disable interrupts */ bool bInterrupts = disable(); /* align size to page boundary */ (size += 0x0FFF) &= ~0x0FFF; /* allocate page aligned buffer in a heap */ void* virtualAddress = valloc(size); /* Has valloc succeed? */ if (!virtualAddress) return NULL; /* map virtual buffer to physical memory */ if (__djgpp_map_physical_memory(virtualAddress, size, physicalAddress) == 0) { __dpmi_meminfo info; info.address = (unsigned)virtualAddress + __djgpp_base_address; info.size = size; /* lock region */ if (__dpmi_lock_linear_region(&info) == 0) { /* restore interrupts flag */ if (bInterrupts) enable(); return virtualAddress; } } /* free allocated buffer */ /* NOTE, virtual memory still remains mapped to device address !!!!! */ /* HOW CAN WE AVOID THIS ??? */ free(virtualAddress); /* restore interrupts flag */ if (bInterrupts) enable(); return NULL; } void FreeDeviceMemory(void* virtualAddress) { __dpmi_meminfo info; info.address = (unsigned)virtualAddress + __djgpp_base_address; info.size = size; /* unlock region */ __dpmi_unlock_linear_region(&info); /* free allocated buffer */ /* NOTE, virtual memory still remains mapped to device address !!!!! */ /* HOW CAN WE AVOID THIS ??? */ free(virtualAddress); } How can we restore page mappings, for mapped pages (see FreeDeviceMemory() for example) ? Thanks.