forked from mirrors/linux
		
	 af0a76e126
			
		
	
	
		af0a76e126
		
	
	
	
	
		
			
			There are a few __weak functions in kernel/fork.c, which architectures can override. If there is no prototype, the compiler warns about them: kernel/fork.c:164:13: error: no previous prototype for 'arch_release_task_struct' [-Werror=missing-prototypes] kernel/fork.c:991:20: error: no previous prototype for 'arch_task_cache_init' [-Werror=missing-prototypes] kernel/fork.c:1086:12: error: no previous prototype for 'arch_dup_task_struct' [-Werror=missing-prototypes] There are already prototypes in a number of architecture specific headers that have addressed those warnings before, but it's much better to have these in a single place so the warning no longer shows up anywhere. Link: https://lkml.kernel.org/r/20230517131102.934196-14-arnd@kernel.org Signed-off-by: Arnd Bergmann <arnd@arndb.de> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christoph Lameter <cl@linux.com> Cc: Dennis Zhou <dennis@kernel.org> Cc: Eric Paris <eparis@redhat.com> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Helge Deller <deller@gmx.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Moore <paul@paul-moore.com> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J. Wysocki <rafael@kernel.org> Cc: Russell King <linux@armlinux.org.uk> Cc: Tejun Heo <tj@kernel.org> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
		
			
				
	
	
		
			266 lines
		
	
	
	
		
			7.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			266 lines
		
	
	
	
		
			7.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /* SPDX-License-Identifier: GPL-2.0 */
 | |
| /* thread_info.h: common low-level thread information accessors
 | |
|  *
 | |
|  * Copyright (C) 2002  David Howells (dhowells@redhat.com)
 | |
|  * - Incorporating suggestions made by Linus Torvalds
 | |
|  */
 | |
| 
 | |
| #ifndef _LINUX_THREAD_INFO_H
 | |
| #define _LINUX_THREAD_INFO_H
 | |
| 
 | |
| #include <linux/types.h>
 | |
| #include <linux/limits.h>
 | |
| #include <linux/bug.h>
 | |
| #include <linux/restart_block.h>
 | |
| #include <linux/errno.h>
 | |
| 
 | |
| #ifdef CONFIG_THREAD_INFO_IN_TASK
 | |
| /*
 | |
|  * For CONFIG_THREAD_INFO_IN_TASK kernels we need <asm/current.h> for the
 | |
|  * definition of current, but for !CONFIG_THREAD_INFO_IN_TASK kernels,
 | |
|  * including <asm/current.h> can cause a circular dependency on some platforms.
 | |
|  */
 | |
| #include <asm/current.h>
 | |
| #define current_thread_info() ((struct thread_info *)current)
 | |
| #endif
 | |
| 
 | |
| #include <linux/bitops.h>
 | |
| 
 | |
| /*
 | |
|  * For per-arch arch_within_stack_frames() implementations, defined in
 | |
|  * asm/thread_info.h.
 | |
|  */
 | |
| enum {
 | |
| 	BAD_STACK = -1,
 | |
| 	NOT_STACK = 0,
 | |
| 	GOOD_FRAME,
 | |
| 	GOOD_STACK,
 | |
| };
 | |
| 
 | |
| #ifdef CONFIG_GENERIC_ENTRY
 | |
| enum syscall_work_bit {
 | |
| 	SYSCALL_WORK_BIT_SECCOMP,
 | |
| 	SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT,
 | |
| 	SYSCALL_WORK_BIT_SYSCALL_TRACE,
 | |
| 	SYSCALL_WORK_BIT_SYSCALL_EMU,
 | |
| 	SYSCALL_WORK_BIT_SYSCALL_AUDIT,
 | |
| 	SYSCALL_WORK_BIT_SYSCALL_USER_DISPATCH,
 | |
| 	SYSCALL_WORK_BIT_SYSCALL_EXIT_TRAP,
 | |
| };
 | |
| 
 | |
| #define SYSCALL_WORK_SECCOMP		BIT(SYSCALL_WORK_BIT_SECCOMP)
 | |
| #define SYSCALL_WORK_SYSCALL_TRACEPOINT	BIT(SYSCALL_WORK_BIT_SYSCALL_TRACEPOINT)
 | |
| #define SYSCALL_WORK_SYSCALL_TRACE	BIT(SYSCALL_WORK_BIT_SYSCALL_TRACE)
 | |
| #define SYSCALL_WORK_SYSCALL_EMU	BIT(SYSCALL_WORK_BIT_SYSCALL_EMU)
 | |
| #define SYSCALL_WORK_SYSCALL_AUDIT	BIT(SYSCALL_WORK_BIT_SYSCALL_AUDIT)
 | |
| #define SYSCALL_WORK_SYSCALL_USER_DISPATCH BIT(SYSCALL_WORK_BIT_SYSCALL_USER_DISPATCH)
 | |
| #define SYSCALL_WORK_SYSCALL_EXIT_TRAP	BIT(SYSCALL_WORK_BIT_SYSCALL_EXIT_TRAP)
 | |
| #endif
 | |
| 
 | |
| #include <asm/thread_info.h>
 | |
| 
 | |
| #ifdef __KERNEL__
 | |
| 
 | |
| #ifndef arch_set_restart_data
 | |
| #define arch_set_restart_data(restart) do { } while (0)
 | |
| #endif
 | |
| 
 | |
| static inline long set_restart_fn(struct restart_block *restart,
 | |
| 					long (*fn)(struct restart_block *))
 | |
| {
 | |
| 	restart->fn = fn;
 | |
| 	arch_set_restart_data(restart);
 | |
| 	return -ERESTART_RESTARTBLOCK;
 | |
| }
 | |
| 
 | |
| #ifndef THREAD_ALIGN
 | |
| #define THREAD_ALIGN	THREAD_SIZE
 | |
| #endif
 | |
| 
 | |
| #define THREADINFO_GFP		(GFP_KERNEL_ACCOUNT | __GFP_ZERO)
 | |
| 
 | |
| /*
 | |
|  * flag set/clear/test wrappers
 | |
|  * - pass TIF_xxxx constants to these functions
 | |
|  */
 | |
| 
 | |
| static inline void set_ti_thread_flag(struct thread_info *ti, int flag)
 | |
| {
 | |
| 	set_bit(flag, (unsigned long *)&ti->flags);
 | |
| }
 | |
| 
 | |
| static inline void clear_ti_thread_flag(struct thread_info *ti, int flag)
 | |
| {
 | |
| 	clear_bit(flag, (unsigned long *)&ti->flags);
 | |
| }
 | |
| 
 | |
| static inline void update_ti_thread_flag(struct thread_info *ti, int flag,
 | |
| 					 bool value)
 | |
| {
 | |
| 	if (value)
 | |
| 		set_ti_thread_flag(ti, flag);
 | |
| 	else
 | |
| 		clear_ti_thread_flag(ti, flag);
 | |
| }
 | |
| 
 | |
| static inline int test_and_set_ti_thread_flag(struct thread_info *ti, int flag)
 | |
| {
 | |
| 	return test_and_set_bit(flag, (unsigned long *)&ti->flags);
 | |
| }
 | |
| 
 | |
| static inline int test_and_clear_ti_thread_flag(struct thread_info *ti, int flag)
 | |
| {
 | |
| 	return test_and_clear_bit(flag, (unsigned long *)&ti->flags);
 | |
| }
 | |
| 
 | |
| static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
 | |
| {
 | |
| 	return test_bit(flag, (unsigned long *)&ti->flags);
 | |
| }
 | |
| 
 | |
| /*
 | |
|  * This may be used in noinstr code, and needs to be __always_inline to prevent
 | |
|  * inadvertent instrumentation.
 | |
|  */
 | |
| static __always_inline unsigned long read_ti_thread_flags(struct thread_info *ti)
 | |
| {
 | |
| 	return READ_ONCE(ti->flags);
 | |
| }
 | |
| 
 | |
| #define set_thread_flag(flag) \
 | |
| 	set_ti_thread_flag(current_thread_info(), flag)
 | |
| #define clear_thread_flag(flag) \
 | |
| 	clear_ti_thread_flag(current_thread_info(), flag)
 | |
| #define update_thread_flag(flag, value) \
 | |
| 	update_ti_thread_flag(current_thread_info(), flag, value)
 | |
| #define test_and_set_thread_flag(flag) \
 | |
| 	test_and_set_ti_thread_flag(current_thread_info(), flag)
 | |
| #define test_and_clear_thread_flag(flag) \
 | |
| 	test_and_clear_ti_thread_flag(current_thread_info(), flag)
 | |
| #define test_thread_flag(flag) \
 | |
| 	test_ti_thread_flag(current_thread_info(), flag)
 | |
| #define read_thread_flags() \
 | |
| 	read_ti_thread_flags(current_thread_info())
 | |
| 
 | |
| #define read_task_thread_flags(t) \
 | |
| 	read_ti_thread_flags(task_thread_info(t))
 | |
| 
 | |
| #ifdef CONFIG_GENERIC_ENTRY
 | |
| #define set_syscall_work(fl) \
 | |
| 	set_bit(SYSCALL_WORK_BIT_##fl, ¤t_thread_info()->syscall_work)
 | |
| #define test_syscall_work(fl) \
 | |
| 	test_bit(SYSCALL_WORK_BIT_##fl, ¤t_thread_info()->syscall_work)
 | |
| #define clear_syscall_work(fl) \
 | |
| 	clear_bit(SYSCALL_WORK_BIT_##fl, ¤t_thread_info()->syscall_work)
 | |
| 
 | |
| #define set_task_syscall_work(t, fl) \
 | |
| 	set_bit(SYSCALL_WORK_BIT_##fl, &task_thread_info(t)->syscall_work)
 | |
| #define test_task_syscall_work(t, fl) \
 | |
| 	test_bit(SYSCALL_WORK_BIT_##fl, &task_thread_info(t)->syscall_work)
 | |
| #define clear_task_syscall_work(t, fl) \
 | |
| 	clear_bit(SYSCALL_WORK_BIT_##fl, &task_thread_info(t)->syscall_work)
 | |
| 
 | |
| #else /* CONFIG_GENERIC_ENTRY */
 | |
| 
 | |
| #define set_syscall_work(fl)						\
 | |
| 	set_ti_thread_flag(current_thread_info(), TIF_##fl)
 | |
| #define test_syscall_work(fl) \
 | |
| 	test_ti_thread_flag(current_thread_info(), TIF_##fl)
 | |
| #define clear_syscall_work(fl) \
 | |
| 	clear_ti_thread_flag(current_thread_info(), TIF_##fl)
 | |
| 
 | |
| #define set_task_syscall_work(t, fl) \
 | |
| 	set_ti_thread_flag(task_thread_info(t), TIF_##fl)
 | |
| #define test_task_syscall_work(t, fl) \
 | |
| 	test_ti_thread_flag(task_thread_info(t), TIF_##fl)
 | |
| #define clear_task_syscall_work(t, fl) \
 | |
| 	clear_ti_thread_flag(task_thread_info(t), TIF_##fl)
 | |
| #endif /* !CONFIG_GENERIC_ENTRY */
 | |
| 
 | |
| #ifdef _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H
 | |
| 
 | |
| static __always_inline bool tif_need_resched(void)
 | |
| {
 | |
| 	return arch_test_bit(TIF_NEED_RESCHED,
 | |
| 			     (unsigned long *)(¤t_thread_info()->flags));
 | |
| }
 | |
| 
 | |
| #else
 | |
| 
 | |
| static __always_inline bool tif_need_resched(void)
 | |
| {
 | |
| 	return test_bit(TIF_NEED_RESCHED,
 | |
| 			(unsigned long *)(¤t_thread_info()->flags));
 | |
| }
 | |
| 
 | |
| #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
 | |
| 
 | |
| #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
 | |
| static inline int arch_within_stack_frames(const void * const stack,
 | |
| 					   const void * const stackend,
 | |
| 					   const void *obj, unsigned long len)
 | |
| {
 | |
| 	return 0;
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #ifdef CONFIG_HARDENED_USERCOPY
 | |
| extern void __check_object_size(const void *ptr, unsigned long n,
 | |
| 					bool to_user);
 | |
| 
 | |
| static __always_inline void check_object_size(const void *ptr, unsigned long n,
 | |
| 					      bool to_user)
 | |
| {
 | |
| 	if (!__builtin_constant_p(n))
 | |
| 		__check_object_size(ptr, n, to_user);
 | |
| }
 | |
| #else
 | |
| static inline void check_object_size(const void *ptr, unsigned long n,
 | |
| 				     bool to_user)
 | |
| { }
 | |
| #endif /* CONFIG_HARDENED_USERCOPY */
 | |
| 
 | |
| extern void __compiletime_error("copy source size is too small")
 | |
| __bad_copy_from(void);
 | |
| extern void __compiletime_error("copy destination size is too small")
 | |
| __bad_copy_to(void);
 | |
| 
 | |
| void __copy_overflow(int size, unsigned long count);
 | |
| 
 | |
| static inline void copy_overflow(int size, unsigned long count)
 | |
| {
 | |
| 	if (IS_ENABLED(CONFIG_BUG))
 | |
| 		__copy_overflow(size, count);
 | |
| }
 | |
| 
 | |
| static __always_inline __must_check bool
 | |
| check_copy_size(const void *addr, size_t bytes, bool is_source)
 | |
| {
 | |
| 	int sz = __builtin_object_size(addr, 0);
 | |
| 	if (unlikely(sz >= 0 && sz < bytes)) {
 | |
| 		if (!__builtin_constant_p(bytes))
 | |
| 			copy_overflow(sz, bytes);
 | |
| 		else if (is_source)
 | |
| 			__bad_copy_from();
 | |
| 		else
 | |
| 			__bad_copy_to();
 | |
| 		return false;
 | |
| 	}
 | |
| 	if (WARN_ON_ONCE(bytes > INT_MAX))
 | |
| 		return false;
 | |
| 	check_object_size(addr, bytes, is_source);
 | |
| 	return true;
 | |
| }
 | |
| 
 | |
| #ifndef arch_setup_new_exec
 | |
| static inline void arch_setup_new_exec(void) { }
 | |
| #endif
 | |
| 
 | |
| void arch_task_cache_init(void); /* for CONFIG_SH */
 | |
| void arch_release_task_struct(struct task_struct *tsk);
 | |
| int arch_dup_task_struct(struct task_struct *dst,
 | |
| 				struct task_struct *src);
 | |
| 
 | |
| #endif	/* __KERNEL__ */
 | |
| 
 | |
| #endif /* _LINUX_THREAD_INFO_H */
 |