]> Git Repo - linux.git/blob - tools/testing/selftests/bpf/progs/err.h
Linux 6.14-rc3
[linux.git] / tools / testing / selftests / bpf / progs / err.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ERR_H__
3 #define __ERR_H__
4
5 #define MAX_ERRNO 4095
6 #define IS_ERR_VALUE(x) (unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO
7
8 #define __STR(x) #x
9
10 #define set_if_not_errno_or_zero(x, y)                  \
11 ({                                                      \
12         asm volatile ("if %0 s< -4095 goto +1\n"        \
13                       "if %0 s<= 0 goto +1\n"           \
14                       "%0 = " __STR(y) "\n"             \
15                       : "+r"(x));                       \
16 })
17
18 static inline int IS_ERR_OR_NULL(const void *ptr)
19 {
20         return !ptr || IS_ERR_VALUE((unsigned long)ptr);
21 }
22
23 static inline long PTR_ERR(const void *ptr)
24 {
25         return (long) ptr;
26 }
27
28 #endif /* __ERR_H__ */
This page took 0.031771 seconds and 4 git commands to generate.