1132400Sgrehan/* 2132400Sgrehan * Copyright (c) 2003 Daniel Eischen <deischen@freebsd.org> 3161802Smarcel * Copyright (c) 2006 Marcel Moolenaar 4132400Sgrehan * All rights reserved. 5132400Sgrehan * 6132400Sgrehan * Redistribution and use in source and binary forms, with or without 7132400Sgrehan * modification, are permitted provided that the following conditions 8132400Sgrehan * are met: 9132400Sgrehan * 10132400Sgrehan * 1. Redistributions of source code must retain the above copyright 11132400Sgrehan * notice, this list of conditions and the following disclaimer. 12132400Sgrehan * 2. Neither the name of the author nor the names of its contributors 13132400Sgrehan * may be used to endorse or promote products derived from this software 14132400Sgrehan * without specific prior written permission. 15132400Sgrehan * 16132400Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17132400Sgrehan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18132400Sgrehan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19132400Sgrehan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20132400Sgrehan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21132400Sgrehan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22132400Sgrehan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23132400Sgrehan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24132400Sgrehan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25132400Sgrehan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26132400Sgrehan */ 27132400Sgrehan 28132400Sgrehan#include <sys/cdefs.h> 29132400Sgrehan__FBSDID("$FreeBSD$"); 30132400Sgrehan 31132400Sgrehan#include <stdlib.h> 32132400Sgrehan#include <strings.h> 33161802Smarcel 34161802Smarcel#include "rtld_tls.h" 35132400Sgrehan#include "pthread_md.h" 36132400Sgrehan 37132400Sgrehan/* 38132400Sgrehan * The constructors. 39132400Sgrehan */ 40132400Sgrehanstruct tcb * 41133806Sgrehan_tcb_ctor(struct pthread *thread, int initial) 42132400Sgrehan{ 43132400Sgrehan struct tcb *tcb; 44132400Sgrehan 45161828Smarcel tcb = _rtld_allocate_tls((initial) ? ppc_get_tp() : NULL, 46161802Smarcel sizeof(struct tcb), 8); 47161802Smarcel if (tcb == NULL) 48161802Smarcel return (NULL); 49161802Smarcel tcb->tcb_thread = thread; 50132400Sgrehan return (tcb); 51132400Sgrehan} 52132400Sgrehan 53132400Sgrehanvoid 54132400Sgrehan_tcb_dtor(struct tcb *tcb) 55132400Sgrehan{ 56161802Smarcel _rtld_free_tls(tcb, sizeof(struct tcb), 8); 57132400Sgrehan} 58132400Sgrehan 59132400Sgrehanstruct kcb * 60132400Sgrehan_kcb_ctor(struct kse *kse) 61132400Sgrehan{ 62132400Sgrehan struct kcb *kcb; 63132400Sgrehan 64161802Smarcel kcb = malloc(sizeof(struct kcb)); 65161802Smarcel if (kcb == NULL) 66161802Smarcel return (NULL); 67161802Smarcel bzero(kcb, sizeof(struct kcb)); 68161802Smarcel kcb->kcb_kse = kse; 69161802Smarcel kcb->kcb_faketcb.tcb_isfake = 1; 70161802Smarcel kcb->kcb_faketcb.tcb_tmbx.tm_flags = TMF_NOUPCALL; 71161802Smarcel kcb->kcb_curtcb = &kcb->kcb_faketcb; 72132400Sgrehan return (kcb); 73132400Sgrehan} 74132400Sgrehan 75132400Sgrehanvoid 76132400Sgrehan_kcb_dtor(struct kcb *kcb) 77132400Sgrehan{ 78132400Sgrehan free(kcb); 79132400Sgrehan} 80