mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-11 09:06:47 +00:00
新增错误判断的宏,以及返回值使用检测
This commit is contained in:
parent
1872d9bd4a
commit
edef02286e
@ -9,4 +9,9 @@
|
||||
// 内存屏障
|
||||
#define barrier() __asm__ __volatile__("" :: \
|
||||
: "memory");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// 编译器属性
|
||||
|
||||
// 当函数的返回值未被使用时,编译器抛出警告信息
|
||||
#define __must_check __attribute__((__warn_unused_result__))
|
30
kernel/common/err.h
Normal file
30
kernel/common/err.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <common/compiler.h>
|
||||
#include <stdint.h>
|
||||
#define MAX_ERRNO 4095
|
||||
|
||||
#define IS_ERR_VALUE(x) unlikely((x) >= (uint64_t)-MAX_ERRNO)
|
||||
|
||||
/**
|
||||
* @brief 判断返回的指针是否为errno
|
||||
*
|
||||
* @param ptr 待校验的指针
|
||||
* @return long 1 => 是错误码
|
||||
* 0 => 不是错误码
|
||||
*/
|
||||
static inline long __must_check IS_ERR(const void* ptr)
|
||||
{
|
||||
return IS_ERR_VALUE((uint64_t)ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 判断返回的指针是否为errno或者为空
|
||||
*
|
||||
* @param ptr 待校验的指针
|
||||
* @return long 1 => 是错误码或NULL
|
||||
* 0 => 不是错误码或NULL
|
||||
*/
|
||||
static inline long __must_check IS_ERR_OR_NULL(const void* ptr)
|
||||
{
|
||||
return !ptr || IS_ERR_VALUE((uint64_t)ptr);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user