www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2008/03/25/15:46:33

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: James <countingtoten AT gmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Segfault reading memory address > 0xFFFFF000
Date: Tue, 25 Mar 2008 13:30:19 -0700 (PDT)
Organization: http://groups.google.com
Lines: 95
Message-ID: <c76e39a6-8268-4d92-9ed7-f4a8eaf568f6@m36g2000hse.googlegroups.com>
NNTP-Posting-Host: 15.235.153.106
Mime-Version: 1.0
X-Trace: posting.google.com 1206477020 27886 127.0.0.1 (25 Mar 2008 20:30:20 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: Tue, 25 Mar 2008 20:30:20 +0000 (UTC)
Complaints-To: groups-abuse AT google DOT com
Injection-Info: m36g2000hse.googlegroups.com; posting-host=15.235.153.106;
posting-account=0eZ2FQoAAAAH9Eu6ZsBYvAdTdeH7YxPs
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12)
Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe)
X-Original-Bytes: 3420
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

When I try to read a memory address higher than 0xFFFFF000 directly
using DJGPP in DOS the program seg faults, but if I step up to that
address by reading the addresses before it, the program works fine.
Why does stepping up to the address work but not reading the address
directly and is there a fix to just read the address directly?

Here is the affected code:

#define TRUE    1

#define FALSE 0

typedef int BOOL;

typedef unsigned char* PCHAR;

typedef unsigned char* PBYTE;

typedef unsigned char BYTE;

typedef unsigned short int WORD;

typedef unsigned long int DWORD;

BOOL ReadMemory(DWORD address, DWORD size, PBYTE buffer)
{
	DWORD offset;
	__dpmi_meminfo mi;

	if(address > 0xFFFFF000)
	{
		int temp, x = 0xFFFFF000;

		while( x < address)
		{
			mi.address = x;
			mi.size = 0x1000;
			if(__dpmi_physical_address_mapping(&mi) == -1)
			{
				printf("ERROR: __dpmi_physical_address_mapping\n");
			}
			selector = __dpmi_allocate_ldt_descriptors(1);

			if(__dpmi_set_segment_base_address(selector, mi.address) == -1)
			{
				printf("ERROR: __dpmi_set_segment_base_address\n");
			}
			if(__dpmi_set_segment_limit(selector, mi.size - 1))
			{
				printf("ERROR: __dpmi_set_segment_limit\n");

			}
			temp = _farpeekb(selector, 0);

			__dpmi_free_ldt_descriptor(selector);
			__dpmi_free_physical_address_mapping(&mi);

			x += 0x10;
		}
	}

	for(offset=0; offset<size; offset++) {
		if((address + offset) < 0x100000) {
			buffer[offset] = _farpeekb(_dos_ds, address + offset);
		} else {
			mi.address = address + offset;
			mi.size = 0x1000;
			if(__dpmi_physical_address_mapping(&mi) == -1)
			{
				printf("ERROR: __dpmi_physical_address_mapping\n");
				return FALSE;
			}
			selector = __dpmi_allocate_ldt_descriptors(1);

			if(__dpmi_set_segment_base_address(selector, mi.address) == -1)
			{
				printf("ERROR: __dpmi_set_segment_base_address\n");
				return FALSE;
			}
			if(__dpmi_set_segment_limit(selector, mi.size - 1))
			{
				printf("ERROR: __dpmi_set_segment_limit\n");
				return FALSE;
			}
			buffer[offset] = _farpeekb(selector, 0);

			__dpmi_free_ldt_descriptor(selector);
			__dpmi_free_physical_address_mapping(&mi);
		}
	}
	return (TRUE);
}

Thanks for your help,
James

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019