This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: instruction-space modification


Gerard Visser writes:

 > I was wondering if you could help me with a problem. I can't seem to find an
 > answer anywhere.
 > When I try to alter data in instruction space in a c-programme, like:
 > call 0
 > pop bx
 > mov byte ptr [bx+7], 3

This writes to memory at %ebx.  But %ebx points to write-protected
memory.

If you want to write-enable that memory, you have to ask your
operating system to make it possible.  That may or may not work: code
segments are usually write protected and shared between processes.

So, this is nothing to do with gcc, but with whatever OS you are
using.

 > shl ax, 2
 > 
 > I get a "segmentation fault" because of the third instruction.
 > Could you tell me how to avoid this, or where I could find literature that
 > explains these kinds of questions.
 > I'm trying to do this, because "shl ax, cl" is not pairable and much slower
 > than a shift with an immediate constant second operand.

Nothing like as slow as altering code segments, I suspect.  This
typically has a large overhead.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]