mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
OpenZFS release 2.2.5 Notable upstream pull request merges: #15609566841171Only provide execvpe(3) when needed #159409edf6af4aReplace P2ALIGN with P2ALIGN_TYPED and delete P2ALIGN #160380f1e8ba2fL2ARC: Cleanup buffer re-compression #16104b474dfad0Refactor dbuf_read() for safer decryption #16118938d1588eMake more taskq parameters writable #16131672474659Slightly improve dnode hash #161384c0fbd8d6FreeBSD: Add zfs_link_create() error handling #16159fa4b1a404ZAP: Fix leaf references on zap_expand_leaf() errors #1616241f2a9c81Fix scn_queue races on very old pools #161654c484d66bFix ZIL clone records for legacy holes #1620627cc6df76Use memset to zero stack allocations containing unions #162072eab4f7b3Fix assertion in Persistent L2ARC #1621413ccbbb47Some improvements to metaslabs eviction #16216ba3c7692cDestroy ARC buffer in case of fill error #162584d2f7f983vdev_open: clear async fault flag after reopen #16264ef08cb26dFix long_free_dirty accounting for small files #1627354ef0fdf6head_errlog: fix use-after-free #1628414cce09a6FreeBSD: Use a statement expression to implement SET_ERROR() #164066f27c4cadMake 'rmmod zfs' work after zfs-2.2.4 Obtained from: OpenZFS OpenZFS commit:33174af151OpenZFS tag: zfs-2.2.5
163 lines
3.9 KiB
C
163 lines
3.9 KiB
C
/*
|
|
* CDDL HEADER START
|
|
*
|
|
* The contents of this file are subject to the terms of the
|
|
* Common Development and Distribution License (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
*
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
* or https://opensource.org/licenses/CDDL-1.0.
|
|
* See the License for the specific language governing permissions
|
|
* and limitations under the License.
|
|
*
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
*
|
|
* CDDL HEADER END
|
|
*/
|
|
/*
|
|
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
|
|
* Use is subject to license terms.
|
|
*/
|
|
/*
|
|
* Copyright (c) 2024, Rob Norris <robn@despairlabs.com>
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <pthread.h>
|
|
|
|
#if defined(__linux__)
|
|
#include <errno.h>
|
|
#include <sys/prctl.h>
|
|
#ifdef HAVE_GETTID
|
|
#define libspl_gettid() gettid()
|
|
#else
|
|
#include <sys/syscall.h>
|
|
#define libspl_gettid() ((pid_t)syscall(__NR_gettid))
|
|
#endif
|
|
#define libspl_getprogname() (program_invocation_short_name)
|
|
#define libspl_getthreadname(buf, len) \
|
|
prctl(PR_GET_NAME, (unsigned long)(buf), 0, 0, 0)
|
|
#elif defined(__FreeBSD__) || defined(__APPLE__)
|
|
#if !defined(__APPLE__)
|
|
#include <pthread_np.h>
|
|
#define libspl_gettid() pthread_getthreadid_np()
|
|
#endif
|
|
#define libspl_getprogname() getprogname()
|
|
#define libspl_getthreadname(buf, len) \
|
|
pthread_getname_np(pthread_self(), buf, len);
|
|
#endif
|
|
|
|
#if defined(HAVE_LIBUNWIND)
|
|
#define UNW_LOCAL_ONLY
|
|
#include <libunwind.h>
|
|
|
|
static inline void
|
|
libspl_dump_backtrace(void)
|
|
{
|
|
unw_context_t uc;
|
|
unw_cursor_t cp;
|
|
unw_word_t ip, off;
|
|
char funcname[128];
|
|
#ifdef HAVE_LIBUNWIND_ELF
|
|
char objname[128];
|
|
unw_word_t objoff;
|
|
#endif
|
|
|
|
fprintf(stderr, "Call trace:\n");
|
|
unw_getcontext(&uc);
|
|
unw_init_local(&cp, &uc);
|
|
while (unw_step(&cp) > 0) {
|
|
unw_get_reg(&cp, UNW_REG_IP, &ip);
|
|
unw_get_proc_name(&cp, funcname, sizeof (funcname), &off);
|
|
#ifdef HAVE_LIBUNWIND_ELF
|
|
unw_get_elf_filename(&cp, objname, sizeof (objname), &objoff);
|
|
fprintf(stderr, " [0x%08lx] %s+0x%2lx (in %s +0x%2lx)\n",
|
|
ip, funcname, off, objname, objoff);
|
|
#else
|
|
fprintf(stderr, " [0x%08lx] %s+0x%2lx\n", ip, funcname, off);
|
|
#endif
|
|
}
|
|
}
|
|
#elif defined(HAVE_BACKTRACE)
|
|
#include <execinfo.h>
|
|
|
|
static inline void
|
|
libspl_dump_backtrace(void)
|
|
{
|
|
void *btptrs[100];
|
|
size_t nptrs = backtrace(btptrs, 100);
|
|
char **bt = backtrace_symbols(btptrs, nptrs);
|
|
fprintf(stderr, "Call trace:\n");
|
|
for (size_t i = 0; i < nptrs; i++)
|
|
fprintf(stderr, " %s\n", bt[i]);
|
|
free(bt);
|
|
}
|
|
#else
|
|
#define libspl_dump_backtrace()
|
|
#endif
|
|
|
|
#if defined(__APPLE__)
|
|
static inline uint64_t
|
|
libspl_gettid(void)
|
|
{
|
|
uint64_t tid;
|
|
|
|
if (pthread_threadid_np(NULL, &tid) != 0)
|
|
tid = 0;
|
|
|
|
return (tid);
|
|
}
|
|
#endif
|
|
|
|
static boolean_t libspl_assert_ok = B_FALSE;
|
|
|
|
void
|
|
libspl_set_assert_ok(boolean_t val)
|
|
{
|
|
libspl_assert_ok = val;
|
|
}
|
|
|
|
static pthread_mutex_t assert_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
/* printf version of libspl_assert */
|
|
void
|
|
libspl_assertf(const char *file, const char *func, int line,
|
|
const char *format, ...)
|
|
{
|
|
pthread_mutex_lock(&assert_lock);
|
|
|
|
va_list args;
|
|
char tname[64];
|
|
|
|
libspl_getthreadname(tname, sizeof (tname));
|
|
|
|
fprintf(stderr, "ASSERT at %s:%d:%s()\n", file, line, func);
|
|
|
|
va_start(args, format);
|
|
vfprintf(stderr, format, args);
|
|
va_end(args);
|
|
|
|
fprintf(stderr, "\n"
|
|
" PID: %-8u COMM: %s\n"
|
|
#if defined(__APPLE__)
|
|
" TID: %-8" PRIu64 " NAME: %s\n",
|
|
#else
|
|
" TID: %-8u NAME: %s\n",
|
|
#endif
|
|
getpid(), libspl_getprogname(),
|
|
libspl_gettid(), tname);
|
|
|
|
libspl_dump_backtrace();
|
|
|
|
#if !__has_feature(attribute_analyzer_noreturn) && !defined(__COVERITY__)
|
|
if (libspl_assert_ok) {
|
|
pthread_mutex_unlock(&assert_lock);
|
|
return;
|
|
}
|
|
#endif
|
|
abort();
|
|
}
|