Solved

reading out gdt

Posted on 2000-05-08
8
500 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
ID: 2789065
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
ID: 2790290
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
ID: 2792098
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:grimlock
ID: 2792110
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
 
LVL 86

Expert Comment

by:jkr
ID: 2792246
>>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
ID: 2792343
does virtualprotect work under win95/98???

how to build a VxD?
0
 
LVL 86

Expert Comment

by:jkr
ID: 2792395
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
ID: 2797528
Hmm, as we didn't hear from you that you still need to know something, I'll lock this Q...
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…
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…

832 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