[coldfire-gnu-discuss] M52235EVB - Problem using malloc - Access Error Attempted Write to Write-Protected Space
Daniel McLean
daniel.mclean at optusnet.com.au
Wed Feb 28 13:53:54 UTC 2007
Thanks for the quick response Nathan..
What test would you like in terms of a test case?
Currently my start and end of RAM pointers (as exported from the linker
control file) are ok. The start pointer is at about 0x2000418 (which seems
about right). What looks to be going on is that my sbrk routine is not
called. I've got printf statements in it, and never see any console output.
I am just trying to malloc a small amount of memory (5 bytes) as a test.
Here's the snippet of code in my main function:
int main(void)
{
extern char _end[];
void *temp;
mcf5223_unmask_all_interrupts();
mcf5xxx_irq_enable();
printD("End of used RAM is 0x%0X \n", _end);
temp = malloc(5);
printD("Malloced data is 0x%0X \n", temp);
....
I get two access write attempt interrupts when the program counter is inside
malloc_r
My sbrk routine is:
void *sbrk(ptrdiff_t nbytes)
{
char *base;
printD("SBRK end is 0x%0X \n", _end);
if (heap_ptr == NULL)
{
heap_ptr = (char *)&_end;
}
printD("Heap pointer is 0x%0X \n", heap_ptr);
base = heap_ptr;
heap_ptr += nbytes;
printD("Heap pointer now 0x%0X \n", heap_ptr);
return base;
}
I've also tried linking against the coldfire library that is in the
codesourcery tree and this makes no difference, which is why I am suspicious
of the malloc_r..
I'm wondering if I haven't done anything that would mean that malloc_r is
trying to write into flash, although as I said before I am using the same
linker control file as the one supplied...
Any further ideas?
-----Original Message-----
From: Nathan Sidwell [mailto:nathan at codesourcery.com]
Sent: Wednesday, 28 February 2007 11:36 PM
To: Daniel McLean
Cc: coldfire-gnu-discuss at codesourcery.com
Subject: Re: [coldfire-gnu-discuss] M52235EVB - Problem using malloc -
Access Error Attempted Write to Write-Protected Space
Daniel McLean wrote:
> the first lot of code that makes use of malloc. I've provided an
> implementation of sbrk so that it can request sections of memory.
> However it seems that malloc attempts to access write protected space
> and causes an interrupt. This is displayed via a printf on the serial
> port. It says that the program counter is at 0x000040CA when this
> occurs.. Below is the appropriate section of my map file:
> Any suggestions would be appreciated.
unfortunately, without an actual test case it's not possible to determine
what
is happening. Have you verified your sbrk is returning the values you
expect it to?
> I'd also be interested in knowing what compiler options the newlib
> libraries were compiled with? I am assuming that they are at least
> compiled with re-entrancy support considering the inclusion of files
> such as _/malloc/_r by the linker.
Newlib is compiled with -O2 -mcpu=FOO
for appropriate FOO values. You're correct that newlib is configured to be
reentrant.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery
nathan at codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.446 / Virus Database: 268.18.4/705 - Release Date: 27/02/2007
3:24 PM
More information about the coldfire-gnu-discuss
mailing list