Skip to content

Commit

Permalink
let runc work with glibc lt 2.32 in go 1.22.x
Browse files Browse the repository at this point in the history
Signed-off-by: lifubang <[email protected]>
  • Loading branch information
lifubang committed Jun 6, 2024
1 parent 8fc5be4 commit bef89d4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions libcontainer/nsenter/nsenter_go122.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
//go:build go1.22
//go:build go1.22 && !go1.23

package nsenter

/*
// We know for sure that glibc has issues with pthread_self() when called from
// Go after nsenter has run. This is likely a more general problem with how we
// ignore the rules in signal-safety(7), and so it's possible musl will also
// have issues, but as this is just a hotfix let's only block glibc builds.
// In glibc versions older than 2.32 (before commit 4721f95058),
// pthread_getattr_np does not always initialize the `attr` argument,
// and when it fails, it results in a NULL pointer dereference in
// pthread_attr_destroy down the road. This has been fixed in go 1.22.4.
// We hack this to let runc can work with glibc < 2.32 in go 1.22.x,
// once runc doesn't support 1.22, we can remove this hack.
#include <features.h>
#ifdef __GLIBC__
# error "runc does not currently work properly with Go >=1.22. See <https://github.com/opencontainers/runc/issues/4233>."
#if __GLIBC__ && !__GLIBC_PREREQ(2, 32)
#include <pthread.h>
#cgo LDFLAGS: -Wl,--wrap=pthread_getattr_np
int __real_pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr);
int __wrap_pthread_getattr_np (pthread_t __th, pthread_attr_t *__attr) {
pthread_attr_init(__attr);
return __real_pthread_getattr_np(__th, __attr);
}
#endif
*/
import "C"

0 comments on commit bef89d4

Please sign in to comment.