-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The pthread cancelstate disable performed to ensure threads are not cancelled while holding mutexes which are used in library destructors does not currently support that those mutexes may be nested. It generates error messages when using the fork and fd helpers when running with LTTNG_UST_DEBUG=1. The effect of this is that the pthread cancelstate can be re-enabled too soon when the first unlock is performed (in a nested lock scenario), thus allowing the thread to be cancelled while still holding a lock, and causing a deadlock on application exit. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: Ife8b1fee04c7d7c480e59bdfc158abdee771994c
- Loading branch information
Showing
7 changed files
with
102 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
* | ||
* Copyright (C) 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | ||
*/ | ||
|
||
#ifndef _LTTNG_UST_UST_CANCELSTATE_H | ||
#define _LTTNG_UST_UST_CANCELSTATE_H | ||
|
||
int lttng_ust_cancelstate_disable_push(void); | ||
int lttng_ust_cancelstate_disable_pop(void); | ||
|
||
#endif |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
* | ||
* Copyright (C) 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | ||
*/ | ||
|
||
#include <pthread.h> | ||
#include <errno.h> | ||
#include <error.h> | ||
#include <urcu/tls-compat.h> | ||
#include <lttng/ust-cancelstate.h> | ||
|
||
#include "common/logging.h" | ||
|
||
struct ust_cancelstate { | ||
int nesting; | ||
int oldstate; /* oldstate for outermost nesting */ | ||
}; | ||
|
||
static DEFINE_URCU_TLS(struct ust_cancelstate, thread_state); | ||
|
||
int lttng_ust_cancelstate_disable_push(void) | ||
{ | ||
struct ust_cancelstate *state = &URCU_TLS(thread_state); | ||
int ret, oldstate; | ||
|
||
if (state->nesting++) | ||
goto end; | ||
ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); | ||
if (ret) { | ||
ERR("pthread_setcancelstate: %s", strerror(ret)); | ||
return -1; | ||
} | ||
state->oldstate = oldstate; | ||
end: | ||
return 0; | ||
} | ||
|
||
int lttng_ust_cancelstate_disable_pop(void) | ||
{ | ||
struct ust_cancelstate *state = &URCU_TLS(thread_state); | ||
int ret, oldstate; | ||
|
||
if (!state->nesting) | ||
return -1; | ||
if (--state->nesting) | ||
goto end; | ||
ret = pthread_setcancelstate(state->oldstate, &oldstate); | ||
if (ret) { | ||
ERR("pthread_setcancelstate: %s", strerror(ret)); | ||
return -1; | ||
} | ||
if (oldstate != PTHREAD_CANCEL_DISABLE) { | ||
ERR("pthread_setcancelstate: unexpected oldstate"); | ||
return -1; | ||
} | ||
end: | ||
return 0; | ||
} | ||
|
||
|
This file contains 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
This file contains 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