Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcing garbage collection by creating files result in NMI handler, fixable by making some fields volatile #291

Open
basprins opened this issue Aug 22, 2022 · 0 comments

Comments

@basprins
Copy link

Hi,
I ran into some strange issue, which I managed to reproduce by creating a lot of file entries (by overwriting the same one over and over again). At some point the garbage collector will kick in, and call the erase callback. That call fails, and my program jumps to the NMI handler straight away.

Debugging and many attempts further, I found out that it only happens when I run my optimized build. After some struggles forcing GDB to do what I want, I managed to located the function where the pointer fs->cfg gets corrupted. The function pointers somehow end up pointing to garbage (while the memory which is allocated by the spiffs member variable still holds the correct addresses of the function pointers).

The function which breaks stuff is spiffs_gc_find_candidate. So I cheated my way out, I made all stack variables which are used in the while loops volatile, and then the problem disappears. Now I can execute my for loop of 1000 file (re)creates, and the garbage collector kicks in many times, without mangling pointers.

Not sure if this is something you want to further investigate or maybe fix, but thought to at least drop you a message.

.
image

image

image

I am a huge fan of your library still, it saved me a great deal of hard work! Keep up the good work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant