mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-02-11 18:01:20 +03:00
![Rob Norris](/assets/img/avatar_default.png)
All of our thread entry functions have this signature:
void (*)(void*) __attribute__((noreturn))
The low-level `__thread_create()` function accepts a `thread_func_t` as
the entry point, which is defined more simply as:
void (*)(void *)
And then the `thread_create()` and `thread_create_named()` macros cast
the passed-in function point down to `thread_func_t`, that is, casting
away the `noreturn` attribute.
Clang considers casting between these two types to be invalid because
both the caller and the callee may have elided parts of the stack frame
save and restore, knowing that they won't be needed.
Recent Linux appears to be setting `-Wcast-function-type-strict`, which
causes this invalid cast to emit a warning, which with `-Werror` is
converted to an error, breaking the build.
This commit fixes this in the simplest possible way: adding `noreturn`
to the `thread_func_t` attribute. Since all our thread entry functions
already have this attribute, it's arguably a just a consistency fix
anyway.
I considered removing the casts in the macros, which silences the
warnings, but it turns out that Clang has a bug that won't emit this
error for implicit conversions, only explicit casts. So leaving them
there seems like a reasonable belt-and-suspenders approach. Also,
frankly, this whole mechanism seems a little undercooked inside LLVM, so
I'm content go with my intuition about the smallest, least invaisve
change.
**NOTE**: `__thread_create` is exported by `spl.ko` and has a
`thread_func_t` arg, so this is an ABI break. Whether that matters in
practice, I have no idea.
Further reading:
- 1aad641c79
- https://github.com/llvm/llvm-project/issues/7325
- https://github.com/llvm/llvm-project/issues/41465
Sponsored-by: https://despairlabs.com/sponsor/
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <robn@despairlabs.com>
Closes #16672
Closes #16673
84 lines
2.5 KiB
C
84 lines
2.5 KiB
C
/*
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
|
* UCRL-CODE-235197
|
|
*
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
|
*
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef _SPL_THREAD_H
|
|
#define _SPL_THREAD_H
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/kthread.h>
|
|
#include <sys/types.h>
|
|
#include <sys/sysmacros.h>
|
|
#include <sys/tsd.h>
|
|
|
|
/*
|
|
* Thread interfaces
|
|
*/
|
|
#define TP_MAGIC 0x53535353
|
|
|
|
#define TS_SLEEP TASK_INTERRUPTIBLE
|
|
#define TS_RUN TASK_RUNNING
|
|
#define TS_ZOMB EXIT_ZOMBIE
|
|
#define TS_STOPPED TASK_STOPPED
|
|
|
|
typedef void (*thread_func_t)(void *) __attribute__((noreturn));
|
|
|
|
#define thread_create_named(name, stk, stksize, func, arg, len, \
|
|
pp, state, pri) \
|
|
__thread_create(stk, stksize, (thread_func_t)func, \
|
|
name, arg, len, pp, state, pri)
|
|
|
|
#define thread_create(stk, stksize, func, arg, len, pp, state, pri) \
|
|
__thread_create(stk, stksize, (thread_func_t)func, #func, \
|
|
arg, len, pp, state, pri)
|
|
|
|
#define thread_exit() spl_thread_exit()
|
|
#define thread_join(t) VERIFY(0)
|
|
#define curthread current
|
|
#define getcomm() current->comm
|
|
#define getpid() current->pid
|
|
|
|
extern kthread_t *__thread_create(caddr_t stk, size_t stksize,
|
|
thread_func_t func, const char *name, void *args, size_t len, proc_t *pp,
|
|
int state, pri_t pri);
|
|
extern struct task_struct *spl_kthread_create(int (*func)(void *),
|
|
void *data, const char namefmt[], ...);
|
|
|
|
static inline __attribute__((noreturn)) void
|
|
spl_thread_exit(void)
|
|
{
|
|
tsd_exit();
|
|
SPL_KTHREAD_COMPLETE_AND_EXIT(NULL, 0);
|
|
}
|
|
|
|
extern proc_t p0;
|
|
|
|
#ifdef HAVE_SIGINFO
|
|
typedef kernel_siginfo_t spl_kernel_siginfo_t;
|
|
#else
|
|
typedef siginfo_t spl_kernel_siginfo_t;
|
|
#endif
|
|
|
|
#endif /* _SPL_THREAD_H */
|