LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-24-2005, 09:01 AM   #1
tim_l
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Rep: Reputation: 0
Memory Permissions For Executing Processes


Is it possible to change the access permissions for the memory where a currently executing process resides?

Am trying to write some self-modifying code and am failing because I get a page fault because apparently I'm not allowed to write to the processes memory area.

Cheers,

Tim
 
Old 02-24-2005, 10:47 AM   #2
laopaishpe
LQ Newbie
 
Registered: Nov 2004
Posts: 10

Rep: Reputation: 0
Well, you shouldn't be able to do this, IN PRINCIPLE ! This is what multitasking and multi-user systems are all about.

It's a question of your code design: i f your code self-modifies itself (in user space), I do not see why you couldn't do that. But if your code calls system services and functions and tries to modify those (say, you're trying to write a virus maybe, or peek into other users' programs/data ..) then unless you defeat the security mechanisms of the OS you should not be able to do that !
 
Old 02-24-2005, 10:59 AM   #3
tim_l
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Original Poster
Rep: Reputation: 0
Cheers for the response.

It's the former rather than the later. I want to alter the memory where my code is - I actually want to change the code during execution. But is it not the case that during execution the code is no longer in user space, or am I misunderstanding something? As it stands I can look at the memory where my code resides, I can print it out, but any sort of modification causes a SIGFAULT.

I'm not entirely sure what you mean by multitasking or multi-user systems. Are you suggesting that the excuting process needs to spawn another process to modify itself?
 
Old 02-24-2005, 12:40 PM   #4
laopaishpe
LQ Newbie
 
Registered: Nov 2004
Posts: 10

Rep: Reputation: 0
Well, I do not know- I never tried to profile a program that deep.

Since you want to self-modify the same process, it looks like a problem of the "chicken and egg".

SO, I guess the way out would be to use threads or some other mechanism that allows you to SHARE the process' memory. So, YES, somehow my instinct is that you have to somehow "freeze" the initial process, and while it is "numb", cut it open (that is, modify it). You could while doing this, "cut the tree branch under your feet" - something all the textbooks in CS bark at as a bad practice. But if you really know what you're doing, I guess it may be possible.



Plus, I guess the detailed implementation would wildly differ on different platforms- Solaris is slightly different than Linux, which slightly differs from BSD, etc, etc.

Can you look at some SMP code and try to guess from there what to do? What you'd like to do is kind of defeating the "synchronization" before a "critical region" in a parallel program. . .

Good luck, sorry not to be able to help you past the conceptual level..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shared memory between two processes davidtexs3 Linux - Software 1 11-25-2005 02:25 PM
how 2 c the memory used by processes imppayel Linux - General 3 12-08-2004 07:40 AM
sharing memory between processes spuzzzzzzz Programming 2 10-13-2004 07:18 AM
Memory And Processes smartes Linux - General 5 01-07-2003 02:02 PM
Memory Leaks and Processes in Linux... Sonny Programming 10 03-04-2002 05:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration