![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#21 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
1. You can read and write memory (for the most part) memory in your own process's address space. However, accessing memory not in your process's address space will give a protection fault (or equivalent). The OS will try to handle this fault (For example, if the OS swaps a chunk of memory to disk and unmaps it from your address space, it will reload the chunk of memory and execution of your process can continue).
2. The "address space" term is important to understand. In the x86 architecture at least, the OS will store a table in memory for the processor that more or less says that the section of memory X is actually the section of memory Y. These tables are per-process, as in address A for process A is actually B, but address A for process C is actually D. The result of that is if you try to access address A in process A and expect to get something from process C, you are sadly mistaken. And you will prolly crash if you try that on process E, with address A not mapped to anything... 3. However, whatever is running in "kernel" mode uses real addresses. I'm sure you can guess why. 4. As such, if you want to access memory from another process, go through the kernel. Don't write a device driver or anything crazy. There are debugging facilities built in to most OSes that allow you to do all sorts of wonderful things to other processes. On Windows, take a look at WriteProcessMemory Note that this doesn't cirumvent the concept of protecting programs from each other at all...execution of such API calls is entirely up to the kernel. If it decides that you don't have permission to fiddle with other processes, then you don't. 5. At this point, your questions haven't even led me to believe you are asking specifically about inter-process memory access or the dangers of accessing random addresses in your own address space. That was assumed. In the very specific instance that you are doing this as an exercise to understand pointers and memory, then yes, that's how you would assign a pointer to an arbitrary address. Yes, if the memory is mapped to your address space, you will probably be able to use that pointer. But mind you, in the real world, whether or not you are running in user-mode, whether or not there's an OS at all, that's not great practice on accessing memory.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#22 | |
|
SEXY SHOELESS GOD OF WAR!
![]() Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,193
Rep Power: 5
![]() |
Quote:
Both C and C++ provide the capacity to access memory by using addresses, but then, so do many other languages, like BASIC and assembly, but as described, this is not the issue. To put it another way, what you are talking about doing is in the domain of operating system code (kernel and device drivers), or possibly in the domain of debuggers (since these generally need access to another process's address space). It is not in the domain of application programs, and if you keep looking at it that way, you're just going to be banging your head against the wall. [edit] Perhaps you could tell us what it is you're trying to accomplish. It might well be that you do not need to access the address space of other processes. [/edit]
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot. - Vaarsuvius, Order of the Stick |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|