mirror of
https://github.com/apache/nuttx.git
synced 2026-06-05 15:58:59 +08:00
fdcheck: Enable fdcheck to automatically detect ownership of fd
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
+11
-9
@@ -46,21 +46,22 @@ extern "C"
|
||||
*
|
||||
* Description: Obtain original fd information
|
||||
*
|
||||
* Val carries the pid and fd information.
|
||||
* Val carries the pid, tag and fd information.
|
||||
* The original fd information is stored in low bit of val.
|
||||
* The pid information is stored in the high bit of val.
|
||||
* The pid and tag information is stored in the high bit of val.
|
||||
* For ease of understanding, let's give an example where
|
||||
* the following information is represented in 32-bit binary format
|
||||
*
|
||||
* val 00000000 00000000 01010101 10001010
|
||||
* val 00000000 01010101 00000001 10001010
|
||||
* fd 00000000 00000000 00000000 10001010
|
||||
* pid 00000000 00000000 00000000 01010101
|
||||
* tag 00000000 00000000 00000000 00000001
|
||||
*
|
||||
* In this function, we also check if the pid information is correct.
|
||||
* In this function, we also check if the pid and tag information is correct.
|
||||
* If there is an error, it will panic.
|
||||
*
|
||||
* Input Parameters:
|
||||
* val - this val carrying pid and original fd information
|
||||
* val - this val carrying pid, tag and original fd information
|
||||
*
|
||||
* Returned Value: none
|
||||
*
|
||||
@@ -71,17 +72,18 @@ int fdcheck_restore(int fd);
|
||||
/****************************************************************************
|
||||
* Name: fdcheck_protect
|
||||
*
|
||||
* Description: Obtain the combined value of fd and pid
|
||||
* Description: Obtain the combined value of fd, pid and tag
|
||||
*
|
||||
* the return value carries the pid and fd information.
|
||||
* the return value carries the pid, tag and fd information.
|
||||
* The original fd information is stored in low bit of val.
|
||||
* The pid information is stored in high bit of val.
|
||||
* The pid and tag information is stored in high bit of val.
|
||||
* For ease of understanding, let's give an example where
|
||||
* the following information is represented in 32-bit binary format
|
||||
*
|
||||
* fd 00000000 00000000 00000000 10001010
|
||||
* pid 00000000 00000000 00000000 01010101
|
||||
* val 00000000 00000000 01010101 10001010
|
||||
* tag 00000000 00000000 00000000 00000001
|
||||
* val 00000000 01010101 00000001 10001010
|
||||
*
|
||||
* Input Parameters:
|
||||
* fd - original fd
|
||||
|
||||
@@ -468,7 +468,11 @@ struct file
|
||||
FAR struct inode *f_inode; /* Driver or file system interface */
|
||||
FAR void *f_priv; /* Per file driver private data */
|
||||
#ifdef CONFIG_FDSAN
|
||||
uint64_t f_tag; /* file owner tag, init to 0 */
|
||||
uint64_t f_tag_fdsan; /* File owner fdsan tag, init to 0 */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FDCHECK
|
||||
uint8_t f_tag_fdcheck; /* File owner fdcheck tag, init to 0 */
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
@@ -189,17 +189,29 @@
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_FDSAN
|
||||
#define FIOC_SETTAG _FIOC(0x000e) /* IN: FAR uint64_t *
|
||||
#define FIOC_SETTAG_FDSAN _FIOC(0x000e) /* IN: FAR uint64_t *
|
||||
* Pointer to file tag
|
||||
* OUT: None
|
||||
*/
|
||||
|
||||
#define FIOC_GETTAG _FIOC(0x000f) /* IN: FAR uint64_t *
|
||||
#define FIOC_GETTAG_FDSAN _FIOC(0x000f) /* IN: FAR uint64_t *
|
||||
* Pointer to file tag
|
||||
* OUT: None
|
||||
*/
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FDCHECK
|
||||
#define FIOC_SETTAG_FDCHECK _FIOC(0x0010) /* IN: FAR uint8_t *
|
||||
* Pointer to file fdcheck tag
|
||||
* OUT: None
|
||||
*/
|
||||
|
||||
#define FIOC_GETTAG_FDCHECK _FIOC(0x0011) /* IN: FAR uint8_t *
|
||||
* Pointer to file fdcheck tag
|
||||
* OUT: None
|
||||
*/
|
||||
#endif
|
||||
|
||||
/* NuttX file system ioctl definitions **************************************/
|
||||
|
||||
#define _DIOCVALID(c) (_IOC_TYPE(c)==_DIOCBASE)
|
||||
|
||||
Reference in New Issue
Block a user