void info() { printf("\n:==========: :System info: :==========:\n\n"); // Kernel info printf( "Version: '%s'\n" "Patchlevel: '%s'\n" "Extraversion: '%s'\n" "Name: '%s'\n" "Revision: '%s'\n",VERSION,PATCHLEVEL,EXTRAVERSION,NAME,REV_NUM); // CPU Info _kputs (LNG_CPU); _kcolor (4); _kgoto (61, _kgetline()); _kputs (cpu_vendor); _kcolor(7); printf("\n"); // Memory RAM Info printf("Memory RAM: "); _kgoto(60, _kgetline()); printf(" %d Kb\n", get_memsize()/1024); // Memory free RAM Info printf(LNG_FREERAM); _kgoto(60, _kgetline()); printf(" %d Kb\n", get_numpages()); printf("\n"); // Bitmap Info printf("Number bitmap's elements: "); _kgoto(60, _kgetline()); printf(" %d", get_bmpelements()); _kgoto(60, _kgetline()); // Mem_area Info printf("\nSize of mem_area: "); _kgoto(60, _kgetline()); printf(" %d\n", sizeof(mem_area)); // Page Dir Info printf("Page Dir Entry n.0 is: "); _kgoto(60, _kgetline()); printf(" %d\n", get_pagedir_entry(0)); // Page Table Info printf("Page Table Entry n.4 in Page dir 0 is: "); _kgoto(60, _kgetline()); printf(" %d\n", get_pagetable_entry(0,4)); printf("\n:==========: :===========: :==========:\n\n"); }
static void start_kernel() { init_clock(); //clock interrupt init get_memsize(&main_memory_end); main_memory_end &= 0xfffff000; paging_init(); init_mem(); //memeory management init buffer_init(); /* scheduler init */ init_sched(); init_hd(); //hard disk init init_fs(); //filesystem init init_task(); /*init_sock();*/ }
static void __init parse_memsize_param(void) { int offset; const uint64_t *prop_value; int prop_len; uint32_t memsize = get_memsize(); if (!memsize) return; offset = fdt_path_offset(&__dtb_start, "/memory"); if (offset > 0) { uint64_t new_value; /* * reg contains 2 32-bits BE values, offset and size. We just * want to replace the size value without affecting the offset */ prop_value = fdt_getprop(&__dtb_start, offset, "reg", &prop_len); new_value = be64_to_cpu(*prop_value); new_value = (new_value & ~0xffffffffllu) | memsize; fdt_setprop_inplace_u64(&__dtb_start, offset, "reg", new_value); } }
int main(int argc, char *argv[]) { size_t memsize = 0; /* at first in MB, limited to 4Gb on 32 bits */ int pagesize; int i; int lc; const char *msg; char *p, *bigmalloc; int loop_count; /* limited to 16Go on 32 bits systems */ pagesize = sysconf(_SC_PAGESIZE); if ((msg = parse_opts(argc, argv, options, help)) != (char *)NULL) tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); if (m_opt) { memsize = (size_t) atoi(m_copt) * 1024 * 1024; if (memsize < 1) { tst_brkm(TBROK, cleanup, "Invalid arg for -m: %s", m_copt); } } if (r_opt) srand(time(NULL)); setup(); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; if (!m_opt) { /* find out by ourselves! */ memsize = get_memsize(); if (memsize < 1) { tst_brkm(TBROK, cleanup, "Unable to guess maxmemsize from /proc/meminfo"); } } /* Allocate (virtual) memory */ bigmalloc = p = malloc(memsize); if (!p) { tst_resm(TFAIL, "malloc - alloc of %zuMB failed", memsize / 1024 / 1024); cleanup(); } /* * Dirty all the pages, to force physical RAM allocation * and exercise eventually the swapper */ tst_resm(TINFO, "touching %zuMB of malloc'ed memory (%s)", memsize / 1024 / 1024, r_opt ? "random" : "linear"); loop_count = memsize / pagesize; for (i = 0; i < loop_count; i++) { if (v_opt && (i % (PROGRESS_LEAP * 1024 / pagesize) == 0)) { printf("."); fflush(stdout); } /* * Make the page dirty, * and make sure compiler won't optimize it away * Touching more than one word per page is useless * because of cache. */ *(int *)p = 0xdeadbeef ^ i; if (r_opt) { p = bigmalloc + (size_t) ((double)(memsize - sizeof(int)) * rand() / (RAND_MAX + 1.0)); } else { p += pagesize; } } if (v_opt) printf("\n"); /* This is not mandatory (except in a loop), but it exercise mm again */ free(bigmalloc); /* * seems that if the malloc'ed area was bad, we'd get SEGV (or kicked * somehow by the OOM killer?), hence we can indicate a PASS. */ tst_resm(TPASS, "malloc - alloc of %zuMB succeeded", memsize / 1024 / 1024); } cleanup(); return 0; }
/* This queries for BIOS information. */ void init_bios_info (void) { #ifndef STAGE1_5 unsigned long cont, memtmp, addr; int drive; #endif /* * Get information from BIOS on installed RAM. */ mbi.mem_lower = get_memsize (0); mbi.mem_upper = get_memsize (1); #ifndef STAGE1_5 /* * We need to call this somewhere before trying to put data * above 1 MB, since without calling it, address line 20 will be wired * to 0. Not too desirable. */ gateA20 (1); /* Store the size of extended memory in EXTENDED_MEMORY, in order to tell it to non-Multiboot OSes. */ extended_memory = mbi.mem_upper; /* * The "mbi.mem_upper" variable only recognizes upper memory in the * first memory region. If there are multiple memory regions, * the rest are reported to a Multiboot-compliant OS, but otherwise * unused by GRUB. */ addr = get_code_end (); mbi.mmap_addr = addr; mbi.mmap_length = 0; cont = 0; do { cont = get_mmap_entry ((void *) addr, cont); /* If the returned buffer's length is zero, quit. */ if (! *((unsigned long *) addr)) break; mbi.mmap_length += *((unsigned long *) addr) + 4; addr += *((unsigned long *) addr) + 4; } while (cont); if (mbi.mmap_length) { unsigned long long max_addr; unsigned long mem_lower = mmap_avail_at (0) >> 10; /* * This is to get the lower memory, and upper memory (up to the * first memory hole), into the "mbi.mem_{lower,upper}" * elements. This is for OS's that don't care about the memory * map, but might care about total RAM available. */ if (mem_lower < mbi.mem_lower) mbi.mem_lower = mem_lower; mbi.mem_upper = mmap_avail_at (0x100000) >> 10; /* Find the maximum available address. Ignore any memory holes. */ for (max_addr = 0, addr = mbi.mmap_addr; addr < mbi.mmap_addr + mbi.mmap_length; addr += *((unsigned long *) addr) + 4) { struct AddrRangeDesc *desc = (struct AddrRangeDesc *) addr; if (desc->Type == MB_ARD_MEMORY && desc->Length > 0 && desc->BaseAddr + desc->Length > max_addr) max_addr = desc->BaseAddr + desc->Length; } extended_memory = (max_addr - 0x100000) >> 10; }
void __init prom_meminit(void) { ptv_memsize = get_memsize(); register_address_space(ptv_memsize); }
int main(){ struct Handler *handler_p, *next_handler; unsigned hid; unsigned oep; // This is NOT THE PROPER WAY!!! unsigned siginfo[512]; unsigned baseaddr, memsize; enum __ptrace_request pr, pr2; //struct user_regs_struct regs; //char inst_str[128]; // Test const char *prog = "./try"; //char indirect = 0; //char manual = 0; //char plt = 1; //int pop = 0; //ban = 0x0804841b; int wait_status; struct user_regs_struct regs; init(); pid_t pid = fork(); if (pid == 0){ Ptrace(PTRACE_TRACEME, 0, NULL, NULL); execl(prog, prog, NULL); }else if (pid > 0){ oep = get_entry_point(prog); // On loaded wait(&wait_status); if (WIFSTOPPED(wait_status)){ // Test, wrong memsize = get_memsize(prog); baseaddr = get_baseaddr(prog); add_module(&whitelist, baseaddr, memsize); get_handler(pid, oep, get_trace_option(fopen("/tmp/trace","w"), whitelist)); get_handler(pid, 0x8048380, get_disable_option(API_TYPE_PLT)); Ptrace(PTRACE_CONT, pid, NULL, NULL); } wait(&wait_status); // Withdraw control from plugins while (WIFSTOPPED(wait_status)){ Ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo); // Caused by breakpoint if (siginfo[2] == 0x80){ // Discard the 0xcc int 3 instruction // So move the eip upper by 1 Ptrace(PTRACE_GETREGS, pid, NULL, ®s); regs.eip --; Ptrace(PTRACE_SETREGS, pid ,NULL, ®s); } // PTRACE_CONT by default because it has the lowest priority pr = PTRACE_CONT; hid = GETID(regs.eip); for (handler_p=global_handler;handler_p;handler_p=next_handler){ next_handler = handler_p->next_handler; pr2 = dispatch(pid, handler_p); pr = PRIORITY(pr, pr2); pr2 = global_expire(pid, handler_p, &next_handler); pr = PRIORITY(pr, pr2); } for (handler_p=handlers[hid];handler_p;handler_p=next_handler){ next_handler = handler_p->next_handler; pr2 = dispatch(pid, handler_p); pr = PRIORITY(pr, pr2); pr2 = expire(pid, handler_p, hid, &next_handler); pr = PRIORITY(pr, pr2); } Ptrace(pr, pid, NULL, NULL); wait(&wait_status); } }else{ perror("Folk failed: "); exit(-1); } finalize(); return 0; }