linux内核源代码中的“current”是什么?

linux内核源代码中的“current”是什么?,第1张

概述我正在研究 linux内核,我有一个问题 我看到很多linux内核源文件都有current->文件.那么“现在”是什么呢? struct file *fget(unsigned int fd){ struct file *file; struct files_struct *files = current->files; rcu_read_lock(); 我正在研究 linux内核,我有一个问题

我看到很多linux内核源文件都有current->文件.那么“现在”是什么呢?

struct file *fget(unsigned int fd){     struct file *file;     struct files_struct *files = current->files;     rcu_read_lock();     file = fcheck_files(files,fd);     if (file) {             /* file object ref Couldn't be taken */             if (file->f_mode & FMODE_PATH ||                 !atomic_long_inc_not_zero(&file->f_count))                     file = NulL;     }     rcu_read_unlock();     return file; }
解决方法 它是指向当前进程的指针(即发出系统调用的进程).

在x86上,它在arch / x86 / include / current.h(其他archs的类似文件)中定义.

#ifndef _ASM_X86_CURRENT_H#define _ASM_X86_CURRENT_H#include <linux/compiler.h>#include <asm/percpu.h>#ifndef __ASSEMBLY__struct task_struct;DECLARE_PER_cpu(struct task_struct *,current_task);static __always_inline struct task_struct *get_current(voID){    return percpu_read_stable(current_task);}#define current get_current()#endif /* __ASSEMBLY__ */#endif /* _ASM_X86_CURRENT_H */

Linux Device Drivers更多信息第2章:

The current pointer refers to the user process currently executing. During the execution of a system call,such as open or read,the current process is the one that invoked the call. Kernel code can use process-specific information by using current,if it needs to do so. […]

总结

以上是内存溢出为你收集整理的linux内核源代码中的“current”是什么?全部内容,希望文章能够帮你解决linux内核源代码中的“current”是什么?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/yw/1031166.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存