Skip to content

Commit

Permalink
include: add thread_pointer.h from Glibc
Browse files Browse the repository at this point in the history
Let's take thread_pointer() implementation from Glibc.
It will be useful in the further because Glibc stores
struct rseq on the TLS. Absolute address can be calculated
as __criu_thread_pointer() + __rseq_offset.
__rseq_offset is an exported symbol from Glibc itself.

We need to have an ability to determine where struct
rseq is stored to unregister it in CRIU during the restore
stage.

For different libc like musl-libc we will have to handle
rseq separately depends on how struct rseq is stored.

Right now that's not a problem because musl-libc has no
rseq support, so we don't need to unregister it.

https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=8dbeb0561eeb876f557ac9eef5721912ec074ea5
https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=cb976fba4c51ede7bf8cee5035888527c308dfbc

Signed-off-by: Alexander Mikhalitsyn <[email protected]>
  • Loading branch information
mihalicyn authored and avagin committed Apr 29, 2022
1 parent 267c1fd commit e1799e5
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 0 deletions.
27 changes: 27 additions & 0 deletions criu/arch/aarch64/include/asm/thread_pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* __thread_pointer definition. Generic version.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */

#ifndef _SYS_THREAD_POINTER_H
#define _SYS_THREAD_POINTER_H

static inline void *__criu_thread_pointer(void)
{
return __builtin_thread_pointer();
}

#endif /* _SYS_THREAD_POINTER_H */
27 changes: 27 additions & 0 deletions criu/arch/arm/include/asm/thread_pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* __thread_pointer definition. Generic version.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */

#ifndef _SYS_THREAD_POINTER_H
#define _SYS_THREAD_POINTER_H

static inline void *__criu_thread_pointer(void)
{
return __builtin_thread_pointer();
}

#endif /* _SYS_THREAD_POINTER_H */
27 changes: 27 additions & 0 deletions criu/arch/mips/include/asm/thread_pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* __thread_pointer definition. Generic version.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */

#ifndef _SYS_THREAD_POINTER_H
#define _SYS_THREAD_POINTER_H

static inline void *__criu_thread_pointer(void)
{
return __builtin_thread_pointer();
}

#endif /* _SYS_THREAD_POINTER_H */
33 changes: 33 additions & 0 deletions criu/arch/ppc64/include/asm/thread_pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* __thread_pointer definition. powerpc version.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */

#ifndef _SYS_THREAD_POINTER_H
#define _SYS_THREAD_POINTER_H

#ifdef __powerpc64__
register void *__thread_register asm("r13");
#else
register void *__thread_register asm("r2");
#endif

static inline void *__criu_thread_pointer(void)
{
return __thread_register;
}

#endif /* _SYS_THREAD_POINTER_H */
27 changes: 27 additions & 0 deletions criu/arch/s390/include/asm/thread_pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* __thread_pointer definition. Generic version.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */

#ifndef _SYS_THREAD_POINTER_H
#define _SYS_THREAD_POINTER_H

static inline void *__criu_thread_pointer(void)
{
return __builtin_thread_pointer();
}

#endif /* _SYS_THREAD_POINTER_H */
37 changes: 37 additions & 0 deletions criu/arch/x86/include/asm/thread_pointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* __thread_pointer definition. x86 version.
Copyright (C) 2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library. If not, see
<https://www.gnu.org/licenses/>. */

#ifndef _SYS_THREAD_POINTER_H
#define _SYS_THREAD_POINTER_H

static inline void *__criu_thread_pointer(void)
{
#if __GNUC_PREREQ(11, 1)
return __builtin_thread_pointer();
#else
void *__result;
#ifdef __x86_64__
__asm__("mov %%fs:0, %0" : "=r"(__result));
#else
__asm__("mov %%gs:0, %0" : "=r"(__result));
#endif
return __result;
#endif /* !GCC 11 */
}

#endif /* _SYS_THREAD_POINTER_H */

0 comments on commit e1799e5

Please sign in to comment.