Solved

reading out gdt

Posted on 2000-05-08
8
506 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 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