Why are mm_struct-> start_stack and vm_area_struct-> start not pointing to the same address?

As far as I understand memory management in the Linux kernel, in every process there is a mm_struct structure responsible for the address space. One important area of ​​memory is the stack. This should be identified by the vm_area_struct memory region, and mm_struct itself has a pointer mm_struct-> stack_start, which is the address of the stack.

I came from the code below and I don’t understand why any of the start / end addresses of the memory area is not equal to the value mm_struct-> stack_start. Any help in understanding this would be greatly appreciated. Thanks

Some of the results of loading a compiled kernel module:

Vma number 14: starts at 0x7fff4bb68000, ends at 0x7fff4bb8a000 Vma number 15: starts at 0x7fff4bbffe000, Vma number 16: starts at 0x7fff4bbfe000, ends at 0x7fff4bbfe000, code 0x4008 = 0 segment 0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0x600a94 Starting stack segment = 0x7fff4bb88420

You may find that the beginning of the stack segment (0x7fff4bb88420) refers to vma 14, but I don’t know that the addresses are different.

Source code of the kernel module:

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/mm.h>

static int pid_mem = 1;

static void print_mem(struct task_struct *task)
{
        struct mm_struct *mm;
        struct vm_area_struct *vma;
        int count = 0;
        mm = task->mm;
        printk("\nThis mm_struct has %d vmas.\n", mm->map_count);
        for (vma = mm->mmap ; vma ; vma = vma->vm_next) {
                printk ("\nVma number %d: \n", ++count);
                printk("  Starts at 0x%lx, Ends at 0x%lx\n",
                          vma->vm_start, vma->vm_end);
        }
        printk("\nCode  Segment start = 0x%lx, end = 0x%lx \n"
                 "Data  Segment start = 0x%lx, end = 0x%lx\n"
                 "Stack Segment start = 0x%lx\n",
                 mm->start_code, mm->end_code,
                 mm->start_data, mm->end_data,
                 mm->start_stack);
}

static int mm_exp_load(void){
        struct task_struct *task;
        printk("\nGot the process id to look up as %d.\n", pid_mem);
        for_each_process(task) {
                if ( task->pid == pid_mem) {
                        printk("%s[%d]\n", task->comm, task->pid);
                        print_mem(task);
                }
        }
        return 0;
}

static void mm_exp_unload(void)
{
        printk("\nPrint segment information module exiting.\n");
}

module_init(mm_exp_load);
module_exit(mm_exp_unload);
module_param(pid_mem, int, 0);

MODULE_AUTHOR ("Krishnakumar. R, rkrishnakumar@gmail.com");
MODULE_DESCRIPTION ("Print segment information");
MODULE_LICENSE("GPL");
+4
source share
2 answers

, start_stack - . , . , . start_stack : , vma "" ( /proc//maps ), vma, , () .

, () ; - . , vmas, , , start_stack. vma. vmas - , .

+1

mm_struct, vm_area_struct, mmaped .

, 32- 4 , mm_struct. 4 . vm_area_struct, vm_area_struct- > start vm_area_struct- > . , mm_struct vm_area_struct.

.

+1

Source: https://habr.com/ru/post/1569782/


All Articles