Skip to content

Instantly share code, notes, and snippets.

@comex
Created January 3, 2022 06:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comex/d80d45e05379e08769df5abe838d5528 to your computer and use it in GitHub Desktop.
Save comex/d80d45e05379e08769df5abe838d5528 to your computer and use it in GitHub Desktop.
--- glibc-2.33/nptl/pthreadP.h 2022-01-02 23:37:20.000000000 -0500
+++ glibc-2.33-modified/nptl/pthreadP.h 2022-01-03 00:56:39.622447597 -0500
@@ -220,7 +220,7 @@
hidden_proto (__pthread_keys)
/* Number of threads running. */
-extern unsigned int __nptl_nthreads attribute_hidden;
+extern unsigned int __nptl_nthreads;
#ifndef __ASSUME_SET_ROBUST_LIST
/* Negative if we do not have the system call and we can use it. */
diff -x build-tree -x debian -x stamp-dir -ruN glibc-2.33/nptl/Versions glibc-2.33-modified/nptl/Versions
--- glibc-2.33/nptl/Versions 2021-02-01 00:13:19.000000000 -0500
+++ glibc-2.33-modified/nptl/Versions 2022-01-03 00:22:34.529713961 -0500
@@ -305,5 +305,6 @@
__futex_abstimed_wait64; __futex_abstimed_wait_cancelable64;
__shm_directory;
__libpthread_freeres;
+ __nptl_nthreads;
}
}
diff -x build-tree -x debian -x stamp-dir -ruN glibc-2.33/stdlib/putenv.c glibc-2.33-modified/stdlib/putenv.c
--- glibc-2.33/stdlib/putenv.c 2021-02-01 00:13:19.000000000 -0500
+++ glibc-2.33-modified/stdlib/putenv.c 2022-01-02 23:44:52.822680109 -0500
@@ -46,11 +46,13 @@
# endif /* HAVE_ALLOCA_H */
#endif /* _LIBC */
+#include "sthack.h"
/* Put STRING, which is of the form "NAME=VALUE", in the environment. */
int
putenv (char *string)
{
+ sthack("putenv(\"%s\")", string);
const char *const name_end = strchr (string, '=');
if (name_end != NULL)
diff -x build-tree -x debian -x stamp-dir -ruN glibc-2.33/stdlib/setenv.c glibc-2.33-modified/stdlib/setenv.c
--- glibc-2.33/stdlib/setenv.c 2021-02-01 00:13:19.000000000 -0500
+++ glibc-2.33-modified/stdlib/setenv.c 2022-01-02 23:52:42.523901386 -0500
@@ -44,6 +44,8 @@
# include <unistd.h>
#endif
+#include "sthack.h"
+
#if !_LIBC
# define __environ environ
# ifndef HAVE_ENVIRON_DECL
@@ -250,6 +252,7 @@
int
setenv (const char *name, const char *value, int replace)
{
+ sthack("setenv(\"%s\", \"%s\", %d)", name, value, replace);
if (name == NULL || *name == '\0' || strchr (name, '=') != NULL)
{
__set_errno (EINVAL);
diff -x build-tree -x debian -x stamp-dir -ruN glibc-2.33/stdlib/sthack.h glibc-2.33-modified/stdlib/sthack.h
--- glibc-2.33/stdlib/sthack.h 1969-12-31 19:00:00.000000000 -0500
+++ glibc-2.33-modified/stdlib/sthack.h 2022-01-03 01:39:14.256978553 -0500
@@ -0,0 +1,23 @@
+#pragma once
+#include <syslog.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+extern unsigned int __nptl_nthreads __attribute__((weak));
+#define STHACK_ENABLE_GCORE 1
+#define sthack(...) \
+ do { \
+ unsigned int *nthreads_p = &__nptl_nthreads; \
+ if (nthreads_p && *nthreads_p > 1) \
+ { \
+ syslog(LOG_ERR, "sthack: " __VA_ARGS__); \
+ if (STHACK_ENABLE_GCORE) \
+ { \
+ char buf[256]; \
+ snprintf(buf, sizeof(buf), \
+ "cd /tmp && gcore %d >/dev/null 2>&1", getpid()); \
+ system(buf); \
+ } \
+ } \
+ } while (0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment