-
Notifications
You must be signed in to change notification settings - Fork 220
* Fixed SEGFAULT when calling remove_event_detect() from python callback #233
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
Merged
pdp7
merged 1 commit into
adafruit:master
from
zserg8:fixed_segfault_in_event_detection
Feb 18, 2018
Merged
* Fixed SEGFAULT when calling remove_event_detect() from python callback #233
pdp7
merged 1 commit into
adafruit:master
from
zserg8:fixed_segfault_in_event_detection
Feb 18, 2018
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@zsserg thank you. I will review and try out on a BeagleBone. |
pdp7
approved these changes
Feb 18, 2018
Testing of @zsserg's branch
|
thanks @zsserg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is an old issue with the library which results in SEGFAULT if remove_event_detect() function is called from within the python callback.
More information can be found here:
https://sourceforge.net/p/raspberry-gpio-python/tickets/136/
https://raspberrypi.stackexchange.com/questions/73791/gpio-callbacks-throw-segmentation-fault
https://stackoverflow.com/questions/35632689/how-to-correctly-remove-interrupt-callback-in-beaglebone-black
http://schlierf.info/raspberry/pi/gpio/python/2016/04/15/RPi.GPIO_SegFault.html
The origin of the problem is the way of handling callbacks - C code stores them in a linked list structure, and, while it correctly removes/inserts new items it doesn't do any sanity checks inside the wrapper that iterates over the list. That results in dereferencing zero pointer if last callback in the chain was removed inside the callback function.
I provide a possible solution to this. Two places need to be patched. While the base C code (event_gpio.c) requires only minor alteration to prevent SEGFAULTs, upper-level python library (py_gpio.c) needs a bit more elaborate workaround to stop traversing the callback chain immediately if event detection was removed while running one of the callback functions.
Typical example when this functionality might be needed is programming interrupt-like behavior with event detection system (see 3rd link above).