微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在研究 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. […]

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐