LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   whats an illegal address (https://www.linuxquestions.org/questions/programming-9/whats-an-illegal-address-300612/)

kapsikum 03-11-2005 10:55 PM

whats an illegal address
 
what do we reffer as an illegal address?

any references. or ideas

btmiller 03-11-2005 11:27 PM

What kind of address? An illegal memory address is an address that your program is not permitted to access. Modern operating systems give processes virtual address spaces and map address onto physical memory. A program that tries to access unmapped memory will not be allowed to do so (this is something of a simplification, but basically accurate).

kapsikum 03-11-2005 11:32 PM

thanx for response ,btmiller,

u mean to say except for the allocated range of addresses to our program/task/process, anything every address our 'entity' tries to access is illegal.

kapsikum 03-11-2005 11:34 PM

or its a particular set of addresses in the memory our program should not address at all

Mega Man X 03-11-2005 11:46 PM

The only thing that I can think about right now that could lead into an illegal address, is when using pointers, for example:

Code:


/* test.c */

#include <stdio.h>

int main()
{
    int someInt = 3;        /* declares an integer */
    int *somePoint;        /* declares a pointer */
    int *anotherPoint;    /* declares yet another pointer */

    somePoint = &someInt;  /* here we assign the pointer to the address
                              of someInt */
   
    printf("%d\n", *somePoint);
    printf("%d\n", *anotherPoint);    /* this is an illegal address */

    return 0;
}

The line "printf("%d\n", *anotherPoint);" should be an illegal address because the pointer has not been initialized. Some compilers should compile it without telling any erros, some should say that the value was not initialized and the program would either crash during the execution or print wrong things...

kapsikum 03-12-2005 01:56 AM

thanx Megaman X,

for the illustration :-)

Mega Man X 03-12-2005 02:12 AM

You are welcome kapsikum ;). I hope I got that address thing right though... I've not been very accurate replying to posts here lately... gheh.

kapsikum 03-12-2005 02:55 AM

well , u r right
Megaman X

fssengg 03-12-2005 04:28 AM

well is there any way in linux to know which are the address range which the program can access?

ganta.rajesh 05-29-2006 01:04 AM

Hello, On Windows there is an API named VirtualQuery, using which one
can find whether a memory region is legal or illegal, can anybody
tell me an API with the same functionality on Linux.


All times are GMT -5. The time now is 04:20 AM.