pavel-kirienko / o1heap

Constant-complexity deterministic memory allocator (heap) for hard real-time high-integrity embedded systems. There is very little activity because the project is finished and does not require further changes.
MIT License
253 stars 29 forks source link

o1heap asserting on frag == NULL #2

Closed asfishman closed 4 years ago

asfishman commented 4 years ago

I am on an STM32G474.

This assert is failing?

https://github.com/pavel-kirienko/o1heap/blob/master/o1heap/o1heap.c#L328

Here are the diagnostics at the time of the error.

capacity = {size_t} 9824
allocated = {size_t} 64
peak_allocated = {size_t} 576
peak_request_size = {size_t} 40
oom_count = {uint64_t} 0

How can I fix this? It crashes the program which is not good for something intended to be flying :(

Should the o1heap opaque pointer be declared volatile? How about the memory arena? Should it also be volatile?

o1heap is being used inside an interrupt in my application as I use libcanard.

pavel-kirienko commented 4 years ago

This is most likely a heap corruption.

o1heap is being used inside an interrupt in my application as I use libcanard.

How do you synchronize the access? Do you invoke the invariant check function at runtime?

pavel-kirienko commented 4 years ago

I do not do any synchronization, could you point me towards some examples on how to handle access from inside an interrupt? Currently, my critical section enter and leaves are NULL.

https://stackoverflow.com/questions/40019929/temporarily-disable-interrupts-on-arm

I am not using the invariant check either. What should I do if the invariant checker is false? How do I recover from that?

Crash the program with an error. This is an unrecoverable condition.

Could this be caused by GDB? I am now running a release build of my code with no GDB, and I have not seen any issues.

You just run out of luck.

asfishman commented 4 years ago

Yup...Figuered out what I was doing wrong