Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Memory fault in resource manager: (4 Items)
   
Memory fault in resource manager  
In multithreaded resource manager example from neutrino programmers guide I try to write to global char  string from 
io_read function. This produces memory fault. How can I have  not only read, bul also write access to global variables 
in io_xxx procedures attached in res mgr?

Souce attached. This is only an example to illustrate my problem, I am not just curious about writing 'X' to some char 
string :)

RobertL
Attachment: Text rmmtrw.c 5.75 KB
AW: Memory fault in resource manager  
Hi Bob,

this has nothing to do with resmgr issues. You are trying to modify the 
contents of a constant string literal. Bad, Bad, boy! 

In your code, you declare a pointer to char and initialize it to point 
to a constant string:
 17  char *buffer = "Hello world\n";
  ...

That's ok. Well - not really. IMHO, if you tried compiling with all
warnings 
on, the compiler should tell you 'warning: initialization discards
qualifiers 
from pointer target type', because the literal on the right is constant,
while 
the target of your pointer is not. The strange thing is: The compiler
doesn't
warn. Any compiler gurus around? Is this a bug or a feature?

Anyway, with the string literal being implicitly treated as 'constant',
it 
ends up in the ".rodata" (read-only-data) section of your executable and

resides in a memory portion that is mapped read-only, i.e., any
attempted 
write-access will cause a memory fault, thus enforcing the constantness
of 
your constant strings.

To avoid this, you could e.g. replace the  '*buffer=""' by
   char buffer[] = "Hello world\n";

That way, you'd get an initialized array (just large enough for the
initial 
string) that will actually be writable.

- Thomas 

> -----Ursprungliche Nachricht-----
> Von: bob lipka [mailto:bobik@os.pl]
> Gesendet: 14 July 2008 12:19
> An: ostech-core_os
> Betreff: Memory fault in resource manager
> 
> 
> In multithreaded resource manager example from neutrino 
> programmers guide I try to write to global char  string from 
> io_read function. This produces memory fault. How can I have  
> not only read, bul also write access to global variables in 
> io_xxx procedures attached in res mgr?
> 
> Souce attached. This is only an example to illustrate my 
> problem, I am not just curious about writing 'X' to some char 
> string :)
> 
> RobertL
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post10447
> 
Re: AW: Memory fault in resource manager  
> Anyway, with the string literal being implicitly treated as 'constant',

Thank you, you are very helpful. Some other compilers I use are not so proper so I obviously have developed to many bad 
habits...
AW: AW: Memory fault in resource manager  
Don't feel too bad about it. 

C, I think, is one of the best languages to develop some /really/
bad habits... which makes me like it so much....  =8-)

- thomas

> -----Ursprungliche Nachricht-----
> Von: bob lipka [mailto:bobik@os.pl]
> Gesendet: 14 July 2008 13:34
> An: ostech-core_os
> Betreff: Re: AW: Memory fault in resource manager
> 
> 
> > Anyway, with the string literal being implicitly treated as 
> 'constant',
> 
> Thank you, you are very helpful. Some other compilers I use 
> are not so proper so I obviously have developed to many bad habits...
> 
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post10449
> 
>