Userfaultfd does not seem to catch faults on Android

400 views
Skip to first unread message

Panagiotis Apostolou

unread,
Jun 22, 2023, 10:42:56 AM6/22/23
to android-ndk
I've been trying to incorporate userfaultfd into a library in order to track accesses to specific memory region that I register with the userfaultfd mechanism but I have some problems getting it work on Android.

I found about userfaultfd recently so in order to get to know how it works I started by writing a standalone test app for desktop. When I got it to work as expected i ndk-build the c source for Android (12) and tried it out on an adb shell. When I saw that it was working there too I started applying the mechanism in the library.

The library is compiled in a .so and is used by other applications (executables) on desktop and (android apps) on Android. After I finished I tried it on desktop and it works. Unfortunately this is not the case for the Android apps. It seems that the thread that is causing the fault never get halted and the thread that is listening (polling/ALooping) on the userfaultfd file descriptor never gets any notification (only time outs)

Any ideas? What am I missing? 

enh

unread,
Jun 22, 2023, 10:47:50 AM6/22/23
to andro...@googlegroups.com
i've never used userfautfd personally so i don't know how it deals with multiple callers, but i think ART uses it for GC on devices where it's available, so if the kernel only reports events to _one_ fd rather than all fds, it might be that in an app, all the events are going to ART instead of you?

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/dfc6f165-a410-4335-ba3e-7d099dc08879n%40googlegroups.com.

Panagiotis Apostolou

unread,
Jun 23, 2023, 2:02:55 AM6/23/23
to android-ndk
Right. This didn't occur to me and I guess it kinda makes sense. I wonder how I can verify it.

enh

unread,
Jun 23, 2023, 1:52:30 PM6/23/23
to andro...@googlegroups.com
write a test program that opens two userfaultfds and checks whether they both see everything, or it just goes to the first?

Reply all
Reply to author
Forward
0 new messages