Hi,
Is there any way to get information about stack and heap at runtime in a C function? I'm looking for a var/table/way to get Stack_Base, Heap_base, Stack_limit and heap_limit at runtime.
That's because I'm trying to make a very very small multitasking kernel for Cortex-M3 and I need somehow to know the Stack memory avail for my alloc routines.
Regards,
Christos Houtouridis, Electrical Engineer
Dear Per,
For start I have to say that I agree with both of your messages. It is exactly how you describe it. Now. You said "There is a startup file, where _you_ specify stack size and heap size"
And this is the reason I need to pass this _user_demand_ to my kernel. I dont want to specify the avail RAM sizes in two places both the startupxxx.s and in some xxconfig.h header. I need to know how much memory the _user_ (probably me again) decide to left for stack/heap in the startupxxx.s. So my kernel will read this information and do its magic. That's why I ask for a way to read the Stack_base etc...(the labels used in the startup file).
Of course there are ways like "read the SP just after the system init" or "do a search using exception handler", or even "do specify eventually RAM sizes and addresses in two places", but I seek for a much more elegant way.
I have to say that this is not the first time i make my own kernel. I have made one for x86. It is just the first time that i build something so freaking small. And I will make it a small module to use it beside any "my-kernel-compatible" project.
Christos Houtouridis
Again - you don't seem to have read the above comments very well - there is no real advantage in having a configuration indicating the amount of memory avail to the kernel. Now rewind, read this sentence once again (exit infinite loop). You don't need this if you allocate all the memory you need in compile time - end of discussion. What is the problem?
Dear Tamir,
There is no problem with that. I just want to avoid the "compile time alloc" thing. Of-course if I can not find a solution i'll use something like that
uint8_t kstack_privil[KERNEL_PRIVILEGED_STACK_SIZE]; uint8_t kstack_unprivil[KERNEL_UNPRIVILEGED_STACK_SIZE];
And I'll make the allocator to give stack slices from these tables.
Christos.
You can always allocate memory from the heap. But remember that systems that are built using such a kernel will require the have heap space allocated as well.