10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
22*6812Sraf /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*6812Sraf * Use is subject to license terms.
25*6812Sraf */
26*6812Sraf
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include "libelf.h"
330Sstevel@tonic-gate #include "decl.h"
340Sstevel@tonic-gate #include "msg.h"
350Sstevel@tonic-gate
360Sstevel@tonic-gate
370Sstevel@tonic-gate Elf_Data *
elf_newdata(Elf_Scn * s)380Sstevel@tonic-gate elf_newdata(Elf_Scn * s)
390Sstevel@tonic-gate {
400Sstevel@tonic-gate Dnode * d;
410Sstevel@tonic-gate Elf_Data * rc;
420Sstevel@tonic-gate Elf * elf;
430Sstevel@tonic-gate unsigned work;
440Sstevel@tonic-gate
450Sstevel@tonic-gate if (s == 0)
460Sstevel@tonic-gate return (0);
470Sstevel@tonic-gate elf = s->s_elf;
480Sstevel@tonic-gate READLOCKS(elf, s)
490Sstevel@tonic-gate if (s->s_index == SHN_UNDEF) {
500Sstevel@tonic-gate _elf_seterr(EREQ_SCNNULL, 0);
510Sstevel@tonic-gate READUNLOCKS(elf, s)
520Sstevel@tonic-gate return (0);
530Sstevel@tonic-gate }
540Sstevel@tonic-gate
550Sstevel@tonic-gate if ((s->s_myflags & SF_READY) == 0) {
560Sstevel@tonic-gate UPGRADELOCKS(elf, s)
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * re-confirm that another 'thread' hasn't come along
590Sstevel@tonic-gate * and cooked this section while the locks were
600Sstevel@tonic-gate * obtained.
610Sstevel@tonic-gate */
620Sstevel@tonic-gate if ((s->s_myflags & SF_READY) == 0)
630Sstevel@tonic-gate (void) _elf_cookscn(s);
640Sstevel@tonic-gate DOWNGRADELOCKS(elf, s)
650Sstevel@tonic-gate }
660Sstevel@tonic-gate
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate * If this is the first new node, use the one allocated
690Sstevel@tonic-gate * in the scn itself. Update data buffer in both cases.
700Sstevel@tonic-gate */
710Sstevel@tonic-gate ELFACCESSDATA(work, _elf_work)
720Sstevel@tonic-gate if (s->s_hdnode == 0) {
730Sstevel@tonic-gate s->s_dnode.db_uflags |= ELF_F_DIRTY;
740Sstevel@tonic-gate s->s_dnode.db_myflags |= DBF_READY;
750Sstevel@tonic-gate s->s_hdnode = &s->s_dnode;
760Sstevel@tonic-gate s->s_tlnode = &s->s_dnode;
770Sstevel@tonic-gate s->s_dnode.db_scn = s;
780Sstevel@tonic-gate s->s_dnode.db_data.d_version = work;
790Sstevel@tonic-gate rc = &s->s_dnode.db_data;
800Sstevel@tonic-gate READUNLOCKS(elf, s)
810Sstevel@tonic-gate return (rc);
820Sstevel@tonic-gate }
830Sstevel@tonic-gate if ((d = _elf_dnode()) == 0) {
840Sstevel@tonic-gate READUNLOCKS(elf, s)
850Sstevel@tonic-gate return (0);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*d))
880Sstevel@tonic-gate d->db_data.d_version = work;
890Sstevel@tonic-gate d->db_scn = s;
900Sstevel@tonic-gate d->db_uflags |= ELF_F_DIRTY;
910Sstevel@tonic-gate d->db_myflags |= DBF_READY;
920Sstevel@tonic-gate s->s_tlnode->db_next = d;
930Sstevel@tonic-gate s->s_tlnode = d;
940Sstevel@tonic-gate rc = &d->db_data;
950Sstevel@tonic-gate NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*d))
960Sstevel@tonic-gate READUNLOCKS(elf, s)
970Sstevel@tonic-gate return (rc);
980Sstevel@tonic-gate }
99