Commit 3bb19bfd authored by gtheveno's avatar gtheveno
Browse files

maybe

parent 13884efe
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <assert.h>
#define PAGE_SHIFT 12
#define BIT_IS_PRESENT (1UL << 63)
#define BIT_PFN (1UL << 55)
#define PFN_MASK (BIT_PFN - 1)
FILE* file_maps;
FILE* file_pagemap;
int main(int argc, char* argv[]) {
int pid;
int page_size = getpagesize();
char* line = (char*)malloc(256);
char *addr_deb_str, *addr_fin_str;
size_t sizelen=256;
int size_line;
u_int64_t page_start, page_end, page, map_entry;
bzero(line, 256);
/* on revient au début */
if(argc != 2) {
fprintf(stderr, "Bad usage : ./soft PID\n");
exit(1);
}
pid = atoi(argv[1]);
char path_maps[32];
char path_pagemap[32];
bzero(path_maps, 32);
bzero(path_pagemap, 32);
snprintf(path_pagemap, 32, "/proc/%d/pagemap", pid);
snprintf(path_maps, 32, "/proc/%d/maps", pid);
file_maps = fopen(path_maps, "r");
file_pagemap = fopen(path_pagemap, "r");
if(file_maps == NULL || file_pagemap == NULL) {
perror("Erreur lors de l'ouverture du fichier");
exit(1);
}
rewind(file_maps);
rewind(file_pagemap);
while(getline(&line, &sizelen, file_maps)>0) {
size_line = strlen(line);
if(!strcmp(line+size_line-7,"[heap]\n")) {
goto found;
}
}
fprintf(stderr, "Problème : pas de [heap] trouvé. On quitte...\n");
exit(1);
found:
addr_deb_str = strsep(&line,"-");
addr_fin_str = strsep(&line, " ");
page_start = strtol(addr_deb_str, NULL, 16) >> PAGE_SHIFT;
page_end = strtol(addr_fin_str, NULL, 16) >> PAGE_SHIFT;
fprintf(stdout, "@ limites du heap (virt) : %lu - %lu\n", page_start, page_end);
assert(page_start <= page_end && page_start > 0 && page_end > 0);
for(page = page_start; page <= page_end; page++) {
if(fseek(file_pagemap, sizeof(u_int64_t) * page , SEEK_SET)) {
perror("Erreur dans fseek");
exit(1);
}
fread(&map_entry, sizeof(u_int64_t), 1, file_pagemap);
//si la page est dans la RAM...
if(map_entry & BIT_IS_PRESENT) {
fprintf(stdout, "0x%08lx : %lu\n", map_entry, map_entry & PFN_MASK);
}
}
//pour vérifier que c'est bien fini
fprintf(stderr, "Over and out\n");
return 0;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#define SIZE 4096
int main() {
int *data = (int*)malloc(SIZE * sizeof(int));
int i;
int sens=0;
while(1) {
for(i=0; i<SIZE; i++) {
data[i] = sens ? i : SIZE-i;
}
sens = sens ? 0 : 1;
}
return 0;
}
\ No newline at end of file
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