include: add thread_pointer.h from Glibc

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 <alexander.mikhalitsyn@virtuozzo.com>
This commit is contained in:
Alexander Mikhalitsyn 2022-02-22 14:58:10 +03:00 committed by Andrei Vagin
parent 267c1fdade
commit e1799e5305
6 changed files with 178 additions and 0 deletions

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */