Detach on linux does not work on the first attempt

60 views
Skip to first unread message

Artem Shcherbak

unread,
Mar 22, 2024, 8:45:28 AMMar 22
to DynamoRIO Users
Hi, @derekbruening!
I have a question about detach on Linux for Aarch64.

I do detach by sending "/bin64/drconfig -detach pid" signal to application (I already attached to this app.). 

And the detach doesn't work the first attempt. (sometimes from the first, but in general the number of attempts is not defined) And after debugging it turned out that in when we can successfully detach in the case of safe nolinking spot. See the code below. If these checks do not pass, then the detach does not occur and it is necessary to send a signal again.

I plan to make the detach work on the first attempt and send PR. Could you tell me how to implement this? It is possible to check the marker at the time when it is possible to accurately make the detach?

core/unix/signal.c:8723
    /* We need to handle the nudge at a safe, nolinking spot */
    if (safe_is_in_fcache(dcontext, (byte *)sc->SC_XIP, (byte *)sc->SC_XSP) &&
        dcontext->interrupted_for_nudge == NULL) {
        /* We unlink the interrupted fragment and skip any inlined syscalls to
         * bound the nudge delivery time.  If we already unlinked one we assume
         * that's sufficient.
         */
        fragment_t wrapper;
        fragment_t *f = fragment_pclookup(dcontext, (byte *)sc->SC_XIP, &wrapper);
        if (f != NULL) {
            if (unlink_fragment_for_signal(dcontext, f, (byte *)sc->SC_XIP))
                dcontext->interrupted_for_nudge = f;
        }
    }

    /* No lock is needed since thread-private and this signal is blocked now */
    nudge_add_pending(dcontext, arg);

Derek Bruening

unread,
Mar 22, 2024, 3:56:49 PMMar 22
to Artem Shcherbak, DynamoRIO Users
The code you show is unlinking to ensure the thread goes back to dispatch and sees the pending nudge.  But if the thread is not in the cache it should end up at dispatch within a reasonable time frame on its own: so the question is why didn't that happen in your cases?  Where did the signal arrive?  Was it successfully marked pending but the thread never reached dispatch before you re-sent it?  Did you end up with multiple pending nudges?  Did it arrive at fcache_enter or other glue code? I thought the pending signal code had handling for all of those corner cases: but maybe only for app signals and not nudge signals?

--
You received this message because you are subscribed to the Google Groups "DynamoRIO Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dynamorio-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dynamorio-users/7f398ff8-a052-43d9-b63a-2a21c4ceb448n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages