Solved

reading out gdt

Posted on 2000-05-08
8
496 Views
Last Modified: 2013-12-03

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')
0
Comment
Question by:grimlock
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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.

0
 
LVL 15

Expert Comment

by:NickRepin
Comment Utility
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?!
0
 

Author Comment

by:grimlock
Comment Utility
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???
0
 

Author Comment

by:grimlock
Comment Utility
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???
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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...

0
 

Author Comment

by:grimlock
Comment Utility
does virtualprotect work under win95/98???

how to build a VxD?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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.




0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
Comment Utility
Hmm, as we didn't hear from you that you still need to know something, I'll lock this Q...
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now