]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin helgrind: change api error handling for pthread_rwlock_trywrlock
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 23 Dec 2025 13:29:19 +0000 (14:29 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 23 Dec 2025 13:29:19 +0000 (14:29 +0100)
This may return EDEADLK is the rwlock is already locked by the same
thread. Darwin seems to be the only OS that does this.

helgrind/hg_intercepts.c

index aa48ce02ac561ce0460c3825a741cc0968d4142b..95da238688f5e6d79d1d573002f2725e1d08f829 100644 (file)
@@ -2656,7 +2656,19 @@ static int pthread_rwlock_trywrlock_WRK(pthread_rwlock_t* rwlock)
                  pthread_rwlock_t*,rwlock, long,1/*isW*/,
                  long, (ret == 0) ? True : False);
    if (ret != 0) {
+      Bool api_error = False;
+#if defined(VGO_darwin)
+      // When rwlock is locked and there is an attempt to trylock it on the
+      // same thread POSIX says that it may return EADADLK. Darwin is the
+      // only one to do this, Linux, FreeBSD and Solaris all return EBUSY.
+      if (ret != EBUSY && ret != EDEADLK)
+         api_error = True;
+#else
       if (ret != EBUSY)
+         api_error = True;
+#endif
+
+      if (api_error)
          DO_PthAPIerror( "pthread_rwlock_trywrlock", ret );
    }