Commit 5b343b40 authored by Pavel Emelyanov's avatar Pavel Emelyanov

kerndat: Introduce the storage of kernel run-time info

One of such things we use right now is the device for anon shmem
mappings backing. In the furure this can be extended to check for
various kernel features.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 41c7ca82
......@@ -45,6 +45,7 @@ obj-y += file-lock.o
obj-y += page-pipe.o
obj-y += page-xfer.o
obj-y += page-read.o
obj-y += kerndat.o
ifneq ($(MAKECMDGOALS),clean)
incdeps := y
......
......@@ -58,6 +58,7 @@
#include "elf.h"
#include "file-lock.h"
#include "page-xfer.h"
#include "kerndat.h"
#include "asm/dump.h"
......@@ -1552,6 +1553,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
pr_info("Dumping processes (pid: %d)\n", pid);
pr_info("========================================\n");
if (kerndat_init())
goto err;
if (cpu_init())
goto err;
......
#ifndef __CR_KERNDAT_H__
#define __CR_KERNDAT_H__
/*
* kerndat stands for "kernel data" and is a collection
* of run-time information about current kernel
*/
int kerndat_init(void);
extern dev_t kerndat_shmem_dev;
#endif
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "log.h"
#include "kerndat.h"
#include "asm/types.h"
dev_t kerndat_shmem_dev;
/*
* Anonymous shared mappings are backed by hidden tmpfs
* mount. Find out its dev to distinguish such mappings
* from real tmpfs files maps.
*/
static int kerndat_get_shmemdev(void)
{
void *map;
char maps[128];
struct stat buf;
map = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, 0, 0);
if (map == MAP_FAILED) {
pr_perror("Can't mmap piggie");
return -1;
}
sprintf(maps, "/proc/self/map_files/%lx-%lx",
(unsigned long)map, (unsigned long)map + PAGE_SIZE);
if (stat(maps, &buf) < 0) {
pr_perror("Can't stat piggie");
return -1;
}
munmap(map, PAGE_SIZE);
kerndat_shmem_dev = buf.st_dev;
pr_info("Found anon-shmem piggie at %"PRIx64"\n", kerndat_shmem_dev);
return 0;
}
int kerndat_init(void)
{
int ret;
ret = kerndat_get_shmemdev();
return ret;
}
......@@ -18,6 +18,7 @@
#include "file-lock.h"
#include "pstree.h"
#include "fsnotify.h"
#include "kerndat.h"
#include "proc_parse.h"
#include "protobuf.h"
......@@ -133,37 +134,9 @@ static int parse_vmflags(char *buf, struct vma_area *vma_area)
return 0;
}
static int is_anon_shmem_map(dev_t dev)
static inline int is_anon_shmem_map(dev_t dev)
{
static dev_t shmem_dev = 0;
if (!shmem_dev) {
void *map;
char maps[128];
struct stat buf;
map = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, 0, 0);
if (map == MAP_FAILED) {
pr_perror("Can't mmap piggie");
return -1;
}
sprintf(maps, "/proc/%d/map_files/%lx-%lx",
getpid(), (unsigned long)map,
(unsigned long)map + PAGE_SIZE);
if (stat(maps, &buf) < 0) {
pr_perror("Can't stat piggie");
return -1;
}
munmap(map, PAGE_SIZE);
shmem_dev = buf.st_dev;
pr_info("Found anon-shmem piggie at %"PRIx64"\n", shmem_dev);
}
return shmem_dev == dev;
return kerndat_shmem_dev == dev;
}
int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment