Linux是什么内核:Linux内核源代码中的“当前”是什么 (current linux kernel version)

我正在研究 Linux 内核,我有一个问题。

我看到很多 Linux 内核源文件都有current->files,那么什么是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;
 }
43

它是指向当前进程(即发出系统调用的进程)的指针。

在 x86 上,它在arch/x86/include/asm/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 章:

当前指针是指当前正在执行的用户进程。在系统调用的执行过程中,如打开或读取,当前进程是调用该调用的进程。内核代码可以通过使用 current 来使用特定于进程的信息,如果它需要这样做的话。[...]

3

Currentstruct task_struct类型的全局变量。您可以在 [1] 中找到它的定义。

Filesstruct files_struct,它包含当前进程使用的文件的信息。

[1]http://students.mimuw.edu.pl/SO/LabLinux/PROCESY/ZRODLA/sched.h.html
0

这是 ARM64 定义。在arch/arm64/include/asm/current.h中,https://elixir.bootlin.com/linux/latest/source/arch/arm64/include/asm/current.h

struct task_struct;
/*
 * We don't use read_sysreg() as we want the compiler to cache the value where
 * possible.
 */
static __always_inline struct task_struct *get_current(void)
{
    unsigned long sp_el0;
    asm ("mrs %0, sp_el0" : "=r" (sp_el0));
    return (struct task_struct *)sp_el0;
}
#define current get_current()

,它只使用sp_el0寄存器。作为指向当前进程task_struct的指针

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(803)
病娇chara:Bash:在字符之间设置文件(cat chara)
上一篇
Web渗透测试攻击流程:Web/网络/渗透测试开源工具(open source web application scanner)
下一篇

相关推荐

  • linux 编译静态库:```ar cr libtest.a *.o```4. 完成!

    我们要创建一个源文件,比如:mylib.c,内容如下:#include…

    2023-03-19 08:46:39
    0 14 77
  • securecrt连接不上linux:解决SecureCRT无法连接Linux的问题

    SecureCRT是一款功能强大的终端仿真软件,可以用来连接Linux服务器。但是有时候会出现连接不上Linux的情况,下面就来详细介绍如何解决SecureCRT连接不上Linux的问题:…

    2023-02-26 01:18:57
    0 58 23
  • linux 卸载gcc:sudo apt-get autoremove

    查看系统中安装的gcc版本:`gcc --version`…

    2023-01-30 06:21:55
    0 15 24
  • linux按照docker:如何在Linux上使用Docker

    Docker是一个开源的应用容器引擎,可以让开发者打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。…

    2023-01-27 14:57:25
    0 68 46
  • linux replace命令:如何使用Linux Replace命令替换文本

    示例示例Linux replace命令是一个用于替换文本字符串的工具。它可以搜索一个或多个文件,并将找到的字符串替换为指定的字符串。语法:…

    2023-03-03 15:20:14
    0 77 95
  • Linux系统恢复初始化:GLFW未在archlinux上初始化

    关于Linux系统恢复初始化的问题,在wayland arch中经常遇到,我试图用 gnome 在 arch linux 上构建一个 glfw 窗口。但是每次我尝试运行应用程序时,它都无法初始化窗口,它只是在 init之前打印,而不是在 init之后打印。…

    2022-11-23 08:27:46
    0 15 24
  • android 视频编码深入理解MediaCodec API

    Android 视频编码是指将原始视频数据经过压缩编码后,生成新的视频数据,以便减少视频文件的体积,提高传输速度,以及更好地在 Android 设备上播放。…

    2023-01-13 10:58:18
    0 40 77
  • cv小敢:如何利用CV小敢提升职业技能?

    cv小敢(Computer Vision Tiny-YOLO)是一种轻量级的物体检测算法,它可以在资源受限的设备上运行,如嵌入式设备、智能手机等。它是基于YOLO(You Only Look Once)算法的一个变体,由Joseph Redmon和Ali Farhadi开发,旨在提高深度学习模型的性能,同时减少模型的大小和计算复杂度。…

    2023-02-09 13:08:59
    0 12 24

发表评论

登录 后才能评论

评论列表(29条)