Thomas Haupt
|
AW: Memory fault in resource manager
|
Thomas Haupt
07/14/2008 6:44 AM
post10448
|
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
>
|
|
|