This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

using pointers in C to access other memory  RSS feed

 
Ranch Hand
Posts: 151
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when incrementing a pointer:
does this only increment within the memory allocated to your program or does it increment through the entire system memory?
am i able to read and manipulate the contents of memory of other programs? for example, i could write nulls to the memory the os itself was using and crash it?
how would i know which program owns any given area in memory, and what the variables there are being used for?
what kind of useful things can you do with this? or can it be done at all...
 
author
Posts: 23811
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

S Fox wrote:
does this only increment within the memory allocated to your program or does it increment through the entire system memory?



Most modern computers uses virtual memory addresses that is managed by an MMU (memory management unit). This prevents different applications from accidentally stepping on each other. This also allows the application to keep the same addresses for variables, while the OS can move the application around in memory (or swap it out entirely) as needed.

Incrementing the address pointer simply increments the virtual address -- so no accessing memory that your application doesn't own.

S Fox wrote:
am i able to read and manipulate the contents of memory of other programs? for example, i could write nulls to the memory the os itself was using and crash it?
how would i know which program owns any given area in memory, and what the variables there are being used for?



You can increment (and actually set) to any address that you want. However, it will be a virtual address. If you set it to an invalid virtual address (not found in the MMU), or one without the correct permissions (such as code being read only), when it is used in a way that is not allowed, you will get a segmentation fault / violation, and if configured, a core dump.

Henry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!