加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 01:59:10 所属栏目:Linux 来源:网络整理
导读:我正在研究 linux内核,我有一个问题 我看到很多linux内核源文件都有current-文件.那么“现在”是什么呢? struct file *fget(unsigned int fd){ struct file *file; struct files_struct *files = current-files; rcu_read_lock(); file = fcheck_files(file
我正在研究 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. […]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读