191100Sdes/*-
2115619Sdes * Copyright (C) 2003 David Xu <davidxu@freebsd.org>
3228690Sdes * Copyright (c) 2001,2003 Daniel Eischen <deischen@freebsd.org>
491100Sdes * All rights reserved.
591100Sdes *
691100Sdes * Redistribution and use in source and binary forms, with or without
799158Sdes * modification, are permitted provided that the following conditions
899158Sdes * are met:
999158Sdes * 1. Redistributions of source code must retain the above copyright
1091100Sdes *    notice, this list of conditions and the following disclaimer.
1191100Sdes * 2. Neither the name of the author nor the names of its contributors
1291100Sdes *    may be used to endorse or promote products derived from this software
1391100Sdes *    without specific prior written permission.
1491100Sdes *
1591100Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1691100Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1791100Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1891100Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1991100Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2091100Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2191100Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2291100Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2391100Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2491100Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2591100Sdes * SUCH DAMAGE.
2691100Sdes *
2791100Sdes * $FreeBSD: releng/10.3/lib/libthr/arch/i386/i386/pthread_md.c 157461 2006-04-04 03:26:06Z davidxu $
2891100Sdes */
2991100Sdes
3091100Sdes#include <sys/types.h>
3191100Sdes#include <machine/segments.h>
3291100Sdes#include <machine/sysarch.h>
3391100Sdes#include <string.h>
3491100Sdes#include <rtld_tls.h>
35255376Sdes
3691100Sdes#include "pthread_md.h"
3791100Sdes
38228690Sdesstruct tcb *
39228690Sdes_tcb_ctor(struct pthread *thread, int initial)
40228690Sdes{
41228690Sdes	struct tcb *tcb;
4291100Sdes
4391100Sdes	if (initial)
4491100Sdes		__asm __volatile("movl %%gs:0, %0" : "=r" (tcb));
4591100Sdes	else
4691100Sdes		tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
4791100Sdes	if (tcb)
4891100Sdes		tcb->tcb_thread = thread;
4991100Sdes	return (tcb);
50228690Sdes}
5191100Sdes
5291100Sdesvoid
5391100Sdes_tcb_dtor(struct tcb *tcb)
5491100Sdes{
5591100Sdes
5691100Sdes	_rtld_free_tls(tcb, sizeof(struct tcb), 16);
5791100Sdes}
5891100Sdes