FS#11985 - Fix stack size calculation on 64bit sim/RaaA builds

Attached to Project: Rockbox
Opened by Thomas Jarosch (thomasjfox) - Thursday, 03 March 2011, 09:13 GMT
Last edited by Thomas Jarosch (thomasjfox) - Thursday, 03 March 2011, 12:29 GMT
Task Type Patches
Category Operating System/Drivers
Status Closed
Assigned To No-one
Operating System Generic RaaA
Severity Low
Priority Normal
Reported Version Daily build (which?)
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


Fix stack size calculation on 64bit sim/RaaA builds.

sizeof(long) is usually 8 bytes on 64bit and will
result in a too small stack size. Discovered while
writing the new "power" thread for RaaA.

When using sigaltstack + "DEFAULT_STACK_SIZE/sizeof(long)"
in firmware/hosted/powermgmt.c on 64bit, rockbox will stall during startup.

kugel, is that change correct? Or might there be an other issue?
This task depends upon

Closed by  Thomas Jarosch (thomasjfox)
Thursday, 03 March 2011, 12:29 GMT
Reason for closing:  Not a Bug
Comment by Frank Gevaerts (fg) - Thursday, 03 March 2011, 10:57 GMT
That looks wrong. The default stack size is supposed to be DEFAULT_STACK_SIZE bytes. It's allocated as an array of long for alignment reasons, so the number of elements of DEFAULT_STACK_SIZE/sizeof(long) is the correct one. If you suddenly make it DEFAULT_STACK_SIZE/sizeof(int), DEFAULT_STACK_SIZE is suddenly in units of two bytes, which really can't be correct.

It is of course possible that stack usage is bigger on 64 bit systems, in which case DEFAULT_STACK_SIZE itself should be increased.
Comment by Thomas Martitz (kugel.) - Thursday, 03 March 2011, 11:33 GMT
I agree with gevearts. Furthermore (except on windows) a long is what's actually put onto the stack.

I can't really imagine that the power thread needs more than DEFAULT_STACK_SIZE, but you can always bump that stack (or DEFAULT_STACK_SIZE).
Comment by Thomas Jarosch (thomasjfox) - Thursday, 03 March 2011, 12:29 GMT
Now I can see it, too...

That's also the reason my code wasn't working before as I first had this in firmware/target/hosted/powermgmnt.c:

static char power_stack[DEFAULT_STACK_SIZE/sizeof(long)];

Testing it with this works, too:
static long power_stack[DEFAULT_STACK_SIZE/sizeof(long)];

Will close the ticket. Thanks for looking into this, both of you.