Link to home
Start Free TrialLog in
Avatar of grimlock
grimlock

asked on

reading out gdt


I want to write a programm which reads out the gdt                         so i wrote (compiled with Vc++ 5.0) a console app.:

#include <conio.h>
typedef struct gdt_info {
              unsigned short length;
              unsigned char *addr;
              }gdt_info;

gdt_info gdt;
unsigned short temp,c;
void main()
{
_asm {
   sgdt gdt
   }
printf("%u %lu",gdt.length,gdt.addr);
getch();
printf("%u",gdt.addr[0]); //at this line of code the program exits                                      //because of an
getch();                         //'ungültige' page with this nice box                                      //    close,debug,detail
}                                   //you know what i mean :-)

so i ask how can i get access to the address i got from sgdt.I also wondered about the termination: it was no GP# Fault but an illegal page in my code (don't know english word for 'ungueltig')
Avatar of jkr
jkr
Flag of Germany image

Is suppose that the output of

printf("%u %lu",gdt.length,gdt.addr);


is sth. like

<some number> <some small number or even 0>

Windows protects the lower pages in memory in order to detect NULL pointer access, thus 'invalid page fault' (or "Diese Anwendung verursachte einen Fehler durch eine ungültige Seite...")

By accessing 'gdt.addr[0]' you're doing something similar like

char* pc = 0x0000000a;
char c = *p;

which causes this.

Avatar of NickRepin
NickRepin

jkr is absolutely right.
You have an access to your own address space only, but not to the system-controlled areas.

BTW, Intel says: The SGDT/SIDT instructions are only useful in operating-system software.

Why do you need this?!
Avatar of grimlock

ASKER

i need it to do my own mem.management
because i don't want windows to swap my accessed memory even if i don't use it for at while.
So i thought building my own descriptors for my own segments.
but say is the ldt accessed in my process address space or is it even possible by building an device driver to acces to gdt/ldt and how???
additional:

your right the length of the ldt was 4095 bytes, that is right because if i do sgdt with a dos app. its the same and the address is 49405 decimal

and there is another curious thing:

in the book advanced windows(jeff richter) is said that windows partitions first 4191305 bytes for MS-DOS and 16bit Windows, but in a program which walkes throught virtual mem. it is wrote that these 4 Megs are free and the author doesn't say anything about this???
>>because i don't want windows to swap
>>my accessed memory even if i don't
>>use it for at while.
>>So i thought building my own
>>descriptors for my own segments.

What about simply using

VirtualProtect( ..., ..., PAGE_NOCACHE);

BTW: You cannot alter the GDT or build a descriptor from within a user mode program, only a VxD could do this...

does virtualprotect work under win95/98???

how to build a VxD?
does virtualprotect work under win95/98???

From the docs:

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.


>>how to build a VxD?

This can be done using the DDK (Device Driver Kit, available for free (!) at 'http://www.microsoft.com/hwdev/ddk/' - On Win9x, this is still mostly assembler coding). The DDK comes with documentation and a bunch of samples.




ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial