Mail Archives: djgpp/1997/03/03/15:16:50
I am wondering why this code works fine in the Win95 Dos box, yet doesn't
work under Win95 msdos mode w/ cwsdpmi or in dos 6.22 w/ qemm unless I
change the line:
info.address = (long) addr + __djgpp_base_address;
to
info.address = (long) addr - __djgpp_base_address;
(or "... + __djgpp_conventional_base" since they are equivalent.)
I compiled it simply with: gcc ?.c -o ?.exe
where ? is the filename.
By working fine I mean printing out "5Kb locked." or whatever instead of
"couldn't lock ..."
When the line is changed, it no longer works in the Win95 dos box.
---Code start----
#include <dpmi.h>
#include <sys/nearptr.h>
#include <stdio.h>
int dos_lockmem(void *addr, int size)
{
__dpmi_meminfo info;
info.address = (long) addr + __djgpp_base_address;
info.size = size;
if (__dpmi_lock_linear_region(&info))
return __dpmi_error;
else
return 0;
}
int main()
{
int i, j, checksum, end_of_memory;
if (!__djgpp_nearptr_enable()) { printf("Damn.\n"); return 0; }
end_of_memory = (int)sbrk(0);
if (dos_lockmem ((void *)0, end_of_memory - 0x1000))
{
printf ("Couldn't lock text and data\n");
return 0;
}
/* touch the entire image */
for (j=0 ; j<4 ; j++)
{
for(i=0x1000 ; i<(end_of_memory - 16 * 0x1000) ; i += 4)
{
checksum += *(int *)i;
checksum += *(int *)(i + 16 * 0x1000);
}
}
printf("%d Kb locked.\n", (end_of_memory - 0x1000) / 0x10000);
return 0;
}
---Code end----
- Raw text -