Skip to content

Commit

Permalink
libc-wrappers: Added wrappers for pthread_attr_getstacksize, pthread_…
Browse files Browse the repository at this point in the history
…create and pthread_detach. Fixes containers#821
  • Loading branch information
olivergs committed Jul 5, 2021
1 parent 6c86cab commit 25853cd
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/go-build-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the License.
#

readonly WRAPPED_FUNCTIONS="--wrap,pthread_attr_getstacksize,--wrap,pthread_create,--wrap,pthread_detach,--wrap,pthread_sigmask"


if [ "$#" -ne 4 ]; then
echo "go-build-wrapper: wrong arguments" >&2
Expand All @@ -27,5 +29,5 @@ if ! cd "$1"; then
exit 1
fi

go build -trimpath -ldflags "-extldflags '-Wl,--wrap,pthread_sigmask $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
go build -trimpath -ldflags "-extldflags '-Wl,$WRAPPED_FUNCTIONS $4' -linkmode external -X github.com/containers/toolbox/pkg/version.currentVersion=$3" -o "$2/toolbox"
exit "$?"
87 changes: 87 additions & 0 deletions src/libc-wrappers/libc-wrappers.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,95 @@


#include <signal.h>
#include <pthread.h>


/*
pthread_attr_getstacksize wrapping
*/
#if defined __aarch64__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.1");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver pthread_attr_getstacksize,pthread_attr_getstacksize@GLIBC_2.2.5");
#else
#error "Please specify symbol version for pthread_attr_getstacksize"
#endif


int
__wrap_pthread_attr_getstacksize (const pthread_attr_t *attr, size_t *stacksize)
{
return pthread_attr_getstacksize (attr, stacksize);
}


/*
pthread_create wrapping
*/
#if defined __aarch64__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.0");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver pthread_create,pthread_create@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver pthread_create,pthread_create@GLIBC_2.2.5");
#else
#error "Please specify symbol version for pthread_create"
#endif


int
__wrap_pthread_create (pthread_t *newthread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg)
{
return pthread_create(newthread, attr, start_routine, arg);
}


/*
pthread_detach wrapping
*/
#if defined __aarch64__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.17");
#elif defined __arm__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.4");
#elif defined __i386__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.0");
#elif defined __powerpc64__ && _CALL_ELF == 2 /* ppc64le */
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.17");
#elif defined __s390x__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.2");
#elif defined __x86_64__
__asm__(".symver pthread_detach,pthread_detach@GLIBC_2.2.5");
#else
#error "Please specify symbol version for pthread_detach"
#endif


int
__wrap_pthread_detach (pthread_t th)
{
return pthread_detach (th);
}


/*
pthread_sigmask wrapping
*/

#if defined __aarch64__
__asm__(".symver pthread_sigmask,pthread_sigmask@GLIBC_2.17");
#elif defined __arm__
Expand Down

0 comments on commit 25853cd

Please sign in to comment.