ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
of course its going to print the memory address is there any way i can change the value of it
like is there a way i can write an other program and run them both at the same time like when i run the 1st program it puts the variable x into memory with the value of x as 1024 but when i run the second one it will overide the value of x to something else basicly a buffer exploit i guess
im still getting the hang of C (as can be seen from previous posts), but the address spaces for the variables will be allocated and freed once the code block is completed. so once u ran this program, by the end of it, it would have freed up the memory (as it is a local var)?
i would use pointers and threads for this - to pass the location of the var u got here to the other code block which runs as the thread...
I am not sure I understanded your meaning exactly, if so please excuse me.
Code:
#include<iostream>
using namespace std;
int main ()
{
int x=1024;
cout<<"x="<<x<<endl;
cout<<"&x="<<&x<<endl;
int* p=&x;
cout<<"p="<<p<<endl;
cout<<"*p="<<*p<<endl;
*p=5;
cout<<"p="<<p<<endl;
cout<<"x="<<x<<endl;
}
No, you cannot do that. Simple reason, because both the program will have different address space and hence cannot interfere with each others address space. The address which will be printed on the screen will be the logical address and not the actual physical address. Use IPC if you want to setup communication between the two programs.
Yes, as it have been mentioned above, every process has its own memory address space, so it cannot simply change address space which belongs to other process. The case for U is some kind of IPC. The best in this case is shared memory.
See man shm_open, mmap, ... for POSIX standard IPC,
man shmget, ... for UNIX98 IPC.
You're kindof right....I'm going to take a stab at explaining this in detail (please excuse errors)
In the world of execution, there are two major modes of operation under the x86 architecture: Real mode and Protected Mode. They each deal with the way memory becomes segmented for the execution of the program. In the case of protected mode (the "right" mode as far as OS developers are concerned), when a piece of code tries to access new memory, it throws the appropriate Page Fault exception which causes the kernel to look at the process and handle the exception properly. IE: a malloc() will throw a request for new pages page fault exception and the kernel will either return a new block of memory, or a NULL if no memory is available.
In protected, a piece of code entering another process' address space throws a Segmentation Page Fault exception. This is why that process dies with a SYSSEGV error code. Under this system, what he's trying to accomplish will never happen.
Under real mode, however, the system doesn't use a paged approach to memory (which is why there is a significantly smaller amount of memory available to the process running) and a program can fairly easily encraoch on another's address space (corewars without an emulator ). This is why DOS had some crazy issues with multi-tasking programs. Sometimes, even, a process under real mode would accidentally overwrite the kernel routines and cause the OS to do funky things. Under that system declaring a pointer to memory like char *p = (char *)<address> would surely get you access to any arbitrary point in memory.
Even under protected mode, if you're executing in kernel space, you can access raw points of memory (how do you think the video driver works?? char *vid = (char *)0xB80000; for vga and char *vid = 0x080000; for monochrome ) but doing such things is risky and should be avoided at all costs.
This is, I believe, the information relevant for the x86 platform. This all translates into, under a proper OS, you can't accomplish this.
basiclly, i was talking about a buffer overrun
when you have a buffer defined for a program i was trying to overrun the buffer and have it point to another instruction
i was just wondering how to do it easier or if anyone has anything that would explian it better . I have read phrack 49 - smashing the stack but i need more. you can all understand that right.
i would like to see some code that does it too, so if you could post it, it owuld be great. umm, it wouldnt be some code that does a gets() in a loop. would it?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.