jmp OverData
TheData dword 0
OverData:
mov TheData,eax
Causes problems. that is just simplified version of what i am trying to accomplish. I am still searching but the words to describe the situation are very common with many topics that are not related.
Joe, writing data in the code section is OK, it is read only but just be careful of forward referencing, if its inserted in the code section after the location to call that data you may get errors.
you can use the VirtualProtect API call to alter access rights to pages of the code section
what Hutch says is true, and can be very tricky with newer processors, as they cache quite a bit of code
if the "data" gets altered after it has been loaded into the prefetch queue, then accessed,
the processor may see the unaltered data from the queue - not the altered data as you might expect or require
Dave's hit the nail on the head here, the processor will sometimes not see modifications in the code section, you should consider using FlushInstructionCache (http://msdn.microsoft.com/en-us/library/ms679350%28VS.85%29.aspx) when you modify anything in the code section.
Code pages are mapped as read only by default, and will throw an access violation if you try to fuss with them. You can override this in the linker through the use of the SECTION switch:
link /SUBSYSTEM:WINDOWS /SECTION:.text,W MyProg.obj
-r