assert.c (b985c9cafd2aedac5cf92428c0211485ea4ede24) assert.c (3c1be0b2615e7bd6b8107f62f9ad625871397786)
1/*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 27 unchanged lines hidden (view full) ---

36#define libspl_gettid() gettid()
37#else
38#include <sys/syscall.h>
39#define libspl_gettid() ((pid_t)syscall(__NR_gettid))
40#endif
41#define libspl_getprogname() (program_invocation_short_name)
42#define libspl_getthreadname(buf, len) \
43 prctl(PR_GET_NAME, (unsigned long)(buf), 0, 0, 0)
1/*
2 * CDDL HEADER START
3 *
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.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 27 unchanged lines hidden (view full) ---

36#define libspl_gettid() gettid()
37#else
38#include <sys/syscall.h>
39#define libspl_gettid() ((pid_t)syscall(__NR_gettid))
40#endif
41#define libspl_getprogname() (program_invocation_short_name)
42#define libspl_getthreadname(buf, len) \
43 prctl(PR_GET_NAME, (unsigned long)(buf), 0, 0, 0)
44#elif defined(__FreeBSD__)
44#elif defined(__FreeBSD__) || defined(__APPLE__)
45#if !defined(__APPLE__)
45#include <pthread_np.h>
46#define libspl_gettid() pthread_getthreadid_np()
46#include <pthread_np.h>
47#define libspl_gettid() pthread_getthreadid_np()
48#endif
47#define libspl_getprogname() getprogname()
48#define libspl_getthreadname(buf, len) \
49 pthread_getname_np(pthread_self(), buf, len);
50#endif
51
52#if defined(HAVE_LIBUNWIND)
53#define UNW_LOCAL_ONLY
54#include <libunwind.h>

--- 38 unchanged lines hidden (view full) ---

93 for (size_t i = 0; i < nptrs; i++)
94 fprintf(stderr, " %s\n", bt[i]);
95 free(bt);
96}
97#else
98#define libspl_dump_backtrace()
99#endif
100
49#define libspl_getprogname() getprogname()
50#define libspl_getthreadname(buf, len) \
51 pthread_getname_np(pthread_self(), buf, len);
52#endif
53
54#if defined(HAVE_LIBUNWIND)
55#define UNW_LOCAL_ONLY
56#include <libunwind.h>

--- 38 unchanged lines hidden (view full) ---

95 for (size_t i = 0; i < nptrs; i++)
96 fprintf(stderr, " %s\n", bt[i]);
97 free(bt);
98}
99#else
100#define libspl_dump_backtrace()
101#endif
102
103#if defined(__APPLE__)
104static inline uint64_t
105libspl_gettid(void)
106{
107 uint64_t tid;
108
109 if (pthread_threadid_np(NULL, &tid) != 0)
110 tid = 0;
111
112 return (tid);
113}
114#endif
115
101static boolean_t libspl_assert_ok = B_FALSE;
102
103void
104libspl_set_assert_ok(boolean_t val)
105{
106 libspl_assert_ok = val;
107}
108

--- 14 unchanged lines hidden (view full) ---

123 fprintf(stderr, "ASSERT at %s:%d:%s()\n", file, line, func);
124
125 va_start(args, format);
126 vfprintf(stderr, format, args);
127 va_end(args);
128
129 fprintf(stderr, "\n"
130 " PID: %-8u COMM: %s\n"
116static boolean_t libspl_assert_ok = B_FALSE;
117
118void
119libspl_set_assert_ok(boolean_t val)
120{
121 libspl_assert_ok = val;
122}
123

--- 14 unchanged lines hidden (view full) ---

138 fprintf(stderr, "ASSERT at %s:%d:%s()\n", file, line, func);
139
140 va_start(args, format);
141 vfprintf(stderr, format, args);
142 va_end(args);
143
144 fprintf(stderr, "\n"
145 " PID: %-8u COMM: %s\n"
146#if defined(__APPLE__)
147 " TID: %-8" PRIu64 " NAME: %s\n",
148#else
131 " TID: %-8u NAME: %s\n",
149 " TID: %-8u NAME: %s\n",
150#endif
132 getpid(), libspl_getprogname(),
133 libspl_gettid(), tname);
134
135 libspl_dump_backtrace();
136
137#if !__has_feature(attribute_analyzer_noreturn) && !defined(__COVERITY__)
138 if (libspl_assert_ok) {
139 pthread_mutex_unlock(&assert_lock);
140 return;
141 }
142#endif
143 abort();
144}
151 getpid(), libspl_getprogname(),
152 libspl_gettid(), tname);
153
154 libspl_dump_backtrace();
155
156#if !__has_feature(attribute_analyzer_noreturn) && !defined(__COVERITY__)
157 if (libspl_assert_ok) {
158 pthread_mutex_unlock(&assert_lock);
159 return;
160 }
161#endif
162 abort();
163}