Я хочу прочитать стек памяти ядра из базовой программы на Си.
Я работаю на компьютере с Linux x86-64 бит.
Моя цель - прочитать структуру thread_info
.
Вот что я сделал:
#include <stdio.h>
#include <unistd.h>
typedef unsigned int __u32;
struct thread_info {
struct task_struct *task;
struct exec_domain *exec_domain;
__u32 flags;
__u32 status;
__u32 cpu;
int saved_preempt_count;
/* ... */
};
static inline struct thread_info *stack_thread_info(void)
{
int PAGE_SIZE = 8 * 1024; // 8Kb on 64 bits
int THREAD_SIZE = PAGE_SIZE << 2;
struct thread_info *ti;
__asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (~(THREAD_SIZE - 1)));
return ti;
}
void main()
{
struct thread_info *ti = stack_thread_info();
printf("%lx\n",ti->task);
}
При попытке отобразить адрес task_struct
я получаю ошибку сегмента.