interceptlib.c revision 2
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <sys/types.h>
2N/A#include <string.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A#include <dlfcn.h>
2N/A#include <apptrace.h>
2N/A#include <assert.h>
2N/A#include "abienv.h"
2N/A
2N/A#define NOTID 0xffffffff
2N/A
2N/A/*
2N/A * This file is meant to contain support functions
2N/A * for interceptors. They are built into the auditing
2N/A * object making the namespace available to "children"
2N/A * objects.
2N/A */
2N/A
2N/Astatic lwp_mutex_t abi_stdio_mutex = DEFAULTMUTEX;
2N/Astatic volatile thread_t locktid = NOTID;
2N/Astatic volatile int count;
2N/A
2N/A/* Return true on empty */
2N/Aint
2N/Ais_empty_string(char const *s)
2N/A{
2N/A if (s != NULL && *s != '\0')
2N/A return (0);
2N/A
2N/A return (1);
2N/A}
2N/A
2N/Avoid
2N/Aabilock(sigset_t *mask)
2N/A{
2N/A thread_t tid;
2N/A
2N/A if ((*abi_thr_main)() != -1) {
2N/A tid = (*abi_thr_self)();
2N/A
2N/A if (tid == locktid) {
2N/A count++;
2N/A } else {
2N/A (void) _lwp_mutex_lock(&abi_stdio_mutex);
2N/A (void) sigprocmask(SIG_BLOCK, &abisigset, mask);
2N/A locktid = tid;
2N/A count = 1;
2N/A }
2N/A }
2N/A}
2N/A
2N/Avoid
2N/Aabiunlock(sigset_t *mask)
2N/A{
2N/A thread_t tid;
2N/A
2N/A (void) fflush(ABISTREAM);
2N/A
2N/A if ((*abi_thr_main)() != -1) {
2N/A tid = (*abi_thr_self)();
2N/A assert(tid == locktid);
2N/A count--;
2N/A if (count <= 0) {
2N/A count = 0;
2N/A locktid = NOTID;
2N/A (void) sigprocmask(SIG_SETMASK, mask, NULL);
2N/A (void) _lwp_mutex_unlock(&abi_stdio_mutex);
2N/A }
2N/A }
2N/A}