Merge all the copies of _tcb_ctor and _tcb_dtor.
The amd64, i386, and sparc64 versions were identical, with the one difference where the former two used inline asm instead of _tcb_get. I have compared the function before and after replacing the asm with _tcb_get and found the object files to be identical. The arm, mips, and powerpc versions were almost identical. The only difference was the powerpc version used an alignment of 1 where arm and mips used 16. As this is an increase in alignment is will be safe. Along with this arm, mips, and powerpc all passed, when initial was true, the value returned from _tcb_get as the first argument to _rtld_allocate_tls. This would then return this pointer back to the caller. We can remove these extra calls by checking if initial is set and setting the thread control block directly. As this is what the sparc64 code does we can use it directly. As after these observations all the architectures can now have identical code we can merge them into a common file. Differential Revision: https://reviews.freebsd.org/D1556 Reviewed by: kib Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
fe63170115
commit
20fe2c9465
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=277490
@ -45,7 +45,9 @@ PRECIOUSLIB=
|
||||
|
||||
.PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}
|
||||
|
||||
.if exists(${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc)
|
||||
.include "${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc"
|
||||
.endif
|
||||
.include "${.CURDIR}/sys/Makefile.inc"
|
||||
.include "${.CURDIR}/thread/Makefile.inc"
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
#$FreeBSD$
|
||||
|
||||
SRCS+= pthread_md.c _umtx_op_err.S
|
||||
SRCS+= _umtx_op_err.S
|
||||
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Neither the name of the author nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <rtld_tls.h>
|
||||
|
||||
#include "pthread_md.h"
|
||||
|
||||
/*
|
||||
* The constructors.
|
||||
*/
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
if (initial)
|
||||
__asm __volatile("movq %%fs:0, %0" : "=r" (tcb));
|
||||
else
|
||||
tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
|
||||
if (tcb)
|
||||
tcb->tcb_thread = thread;
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
void
|
||||
_tcb_dtor(struct tcb *tcb)
|
||||
{
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
|
||||
}
|
@ -77,9 +77,6 @@ struct tcb {
|
||||
__result; \
|
||||
})
|
||||
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *tcb);
|
||||
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
|
@ -1,3 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= pthread_md.c
|
@ -1,53 +0,0 @@
|
||||
/*-
|
||||
* Copyright (C) 2005 David Xu <davidxu@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Neither the name of the author nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <rtld_tls.h>
|
||||
|
||||
#include "pthread_md.h"
|
||||
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
|
||||
sizeof(struct tcb), 16);
|
||||
if (tcb)
|
||||
tcb->tcb_thread = thread;
|
||||
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
void
|
||||
_tcb_dtor(struct tcb *tcb)
|
||||
{
|
||||
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
|
||||
}
|
@ -47,12 +47,6 @@ struct tcb {
|
||||
struct pthread *tcb_thread; /* our hook */
|
||||
};
|
||||
|
||||
/*
|
||||
* The tcb constructors.
|
||||
*/
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *);
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
|
@ -1,3 +1,3 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= pthread_md.c _umtx_op_err.S
|
||||
SRCS+= _umtx_op_err.S
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*-
|
||||
* Copyright (C) 2003 David Xu <davidxu@freebsd.org>
|
||||
* Copyright (c) 2001,2003 Daniel Eischen <deischen@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Neither the name of the author nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/segments.h>
|
||||
#include <machine/sysarch.h>
|
||||
#include <string.h>
|
||||
#include <rtld_tls.h>
|
||||
|
||||
#include "pthread_md.h"
|
||||
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
if (initial)
|
||||
__asm __volatile("movl %%gs:0, %0" : "=r" (tcb));
|
||||
else
|
||||
tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
|
||||
if (tcb)
|
||||
tcb->tcb_thread = thread;
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
void
|
||||
_tcb_dtor(struct tcb *tcb)
|
||||
{
|
||||
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
|
||||
}
|
@ -76,12 +76,6 @@ struct tcb {
|
||||
__result; \
|
||||
})
|
||||
|
||||
/*
|
||||
* The constructors.
|
||||
*/
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *tcb);
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
|
@ -1,3 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= pthread_md.c
|
@ -50,12 +50,6 @@ struct tcb {
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
/*
|
||||
* The tcb constructors.
|
||||
*/
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *);
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
|
@ -1,59 +0,0 @@
|
||||
/*-
|
||||
* Copyright (C) 2005 David Xu <davidxu@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Neither the name of the author nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: src/lib/libthr/arch/arm/arm/pthread_md.c,v 1.2 2005/10/29 13:40:31 davidxu
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <rtld_tls.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include <machine/sysarch.h>
|
||||
|
||||
#include "pthread_md.h"
|
||||
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
|
||||
sizeof(struct tcb), 16);
|
||||
if (tcb)
|
||||
tcb->tcb_thread = thread;
|
||||
|
||||
return (tcb);
|
||||
}
|
||||
|
||||
void
|
||||
_tcb_dtor(struct tcb *tcb)
|
||||
{
|
||||
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= pthread_md.c
|
@ -55,9 +55,6 @@ struct tcb {
|
||||
struct pthread *tcb_thread;
|
||||
};
|
||||
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *);
|
||||
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
{
|
||||
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Neither the name of the author nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <rtld_tls.h>
|
||||
|
||||
#include "pthread_md.h"
|
||||
|
||||
/*
|
||||
* The constructors.
|
||||
*/
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
||||
{
|
||||
struct tcb *tcb;
|
||||
|
||||
tcb = _rtld_allocate_tls((initial) ? _tcb_get() : NULL,
|
||||
sizeof(struct tcb), 1);
|
||||
if (tcb)
|
||||
tcb->tcb_thread = thread;
|
||||
return (tcb);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
_tcb_dtor(struct tcb *tcb)
|
||||
{
|
||||
_rtld_free_tls(tcb, sizeof(struct tcb), 1);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= _umtx_op_err.S pthread_md.c
|
||||
SRCS+= _umtx_op_err.S
|
||||
|
@ -50,12 +50,6 @@ struct tcb {
|
||||
void *tcb_spare[1];
|
||||
};
|
||||
|
||||
/*
|
||||
* The tcb constructors.
|
||||
*/
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *);
|
||||
|
||||
/* Called from the thread to set its private data. */
|
||||
static __inline void
|
||||
_tcb_set(struct tcb *tcb)
|
||||
|
@ -14,6 +14,7 @@ SRCS+= \
|
||||
thr_cond.c \
|
||||
thr_condattr.c \
|
||||
thr_create.c \
|
||||
thr_ctrdtr.c \
|
||||
thr_detach.c \
|
||||
thr_equal.c \
|
||||
thr_event.c \
|
||||
|
@ -32,7 +32,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/types.h>
|
||||
#include <rtld_tls.h>
|
||||
|
||||
#include "pthread_md.h"
|
||||
#include "thr_private.h"
|
||||
|
||||
struct tcb *
|
||||
_tcb_ctor(struct pthread *thread, int initial)
|
@ -928,6 +928,9 @@ int __thr_sigwait(const sigset_t *set, int *sig);
|
||||
int __thr_sigwaitinfo(const sigset_t *set, siginfo_t *info);
|
||||
int __thr_swapcontext(ucontext_t *oucp, const ucontext_t *ucp);
|
||||
|
||||
struct tcb *_tcb_ctor(struct pthread *, int);
|
||||
void _tcb_dtor(struct tcb *);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_THR_PRIVATE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user