How to create a writable .text section? 
Author Message
 How to create a writable .text section?

On Thu, 10 Oct 2002 21:35:09 GMT, "Andrew S. Haydon"



>How to create a writable .text section? Below is my example which causes
>invalid memory reference.

What is a writable .text section and what does it have to do with c?


>#include <stdio.h>
>#include <string.h>

>int (*myprintf)( const char *, ... );

>int foo( void )
>   myprintf( "foo\n" );
>   return 1;

>int bar( void )
>   myprintf( "bar\n" );
>   return 0;

>int main()
>   char *s1 = (char *)foo;

Object pointers and function pointers are basically incompatible.  The
ability to cast from one to the other is a common extension that is
"widely used in many systems, but ... not portable to all
implementations. The inclusion of any extension that may cause a
strictly conforming program to become invalid renders an
implementation nonconforming."

>   char *s2 = (char *)bar;

>   myprintf = printf;
>   printf( "first call foo()\n" );
>   foo();
>   memcpy( s1, s2, 31 ); // 31 is the code length from my compiler
>                         // gcc 2.96 under RedHat Linux 7.3.

Even if this successfully copies the code for bar into the area
currently occupied by foo, what makes you think the code is "self
relocating" (independent of the address where it resides).

>   printf( "call foo() after moving\n" );
>   foo();

>   return 0;

What are you really trying to do?

<<Remove the del for email>>

Tue, 29 Mar 2005 11:46:06 GMT  
 How to create a writable .text section?
You might be able to adjust that in the .def files or simply adjust .text's


Wed, 30 Mar 2005 16:54:35 GMT  
 [ 2 post ] 

 Relevant Pages 

1. How to put some text in CDATA section of XML file

2. creating my own section handler for .config files

3. creating / defining section attributes?

4. Preserving writable server cursor after rollback (7.0, vc++, CDatabase/CRecordset)

5. Problem writing to a writable file

6. My .rc file must be writable when compiling

7. My .rc file must be writable when compiling

8. Create "UserDefined" property section in a new mdb file just created

9. Create "UserDefined" property section in a new mdb file just created

10. creating a text file in a specific folder

11. Creating separate text files from one large one

12. creating graphic and text file through c


Powered by phpBB® Forum Software