dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / abi / apptrace / common / interceptlib.c
blobc17f0767a362ebbb94c494665a9cb97b7fc8d4cf
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <dlfcn.h>
33 #include <apptrace.h>
34 #include <assert.h>
35 #include "abienv.h"
37 #define NOTID 0xffffffff
40 * This file is meant to contain support functions
41 * for interceptors. They are built into the auditing
42 * object making the namespace available to "children"
43 * objects.
46 static lwp_mutex_t abi_stdio_mutex = DEFAULTMUTEX;
47 static volatile thread_t locktid = NOTID;
48 static volatile int count;
50 /* Return true on empty */
51 int
52 is_empty_string(char const *s)
54 if (s != NULL && *s != '\0')
55 return (0);
57 return (1);
60 void
61 abilock(sigset_t *mask)
63 thread_t tid;
65 if ((*abi_thr_main)() != -1) {
66 tid = (*abi_thr_self)();
68 if (tid == locktid) {
69 count++;
70 } else {
71 (void) _lwp_mutex_lock(&abi_stdio_mutex);
72 (void) sigprocmask(SIG_BLOCK, &abisigset, mask);
73 locktid = tid;
74 count = 1;
79 void
80 abiunlock(sigset_t *mask)
82 thread_t tid;
84 (void) fflush(ABISTREAM);
86 if ((*abi_thr_main)() != -1) {
87 tid = (*abi_thr_self)();
88 assert(tid == locktid);
89 count--;
90 if (count <= 0) {
91 count = 0;
92 locktid = NOTID;
93 (void) sigprocmask(SIG_SETMASK, mask, NULL);
94 (void) _lwp_mutex_unlock(&abi_stdio_mutex);