static void domain_policy_test(const unsigned int before) { unsigned int after; int j; policy_file = "/sys/kernel/security/tomoyo/domain_policy"; for (j = 0; domain_testcases[j]; j++) { int i; FILE *fp = fopen(policy_file, "w"); if (!fp) BUG("BUG: Policy write error\n"); fprintf(fp, "<kernel>\n"); policy = domain_testcases[j]; printf("Processing: %s\n", policy); for (i = 0; i < 100; i++) { fprintf(fp, "%s\n", policy); if (!i) check_policy_written(fp, 1); fprintf(fp, "delete %s\n", policy); } check_policy_deleted(fp, 1); for (i = 0; i < 100; i++) fprintf(fp, "%s\n", policy); check_policy_written(fp, 2); fprintf(fp, "delete %s\n", policy); check_policy_deleted(fp, 2); fclose(fp); for (i = 0; i < 30; i++) { usleep(100000); get_meminfo(&after); if (before == after) break; } if (before != after) { printf("Policy: %d\n", after - before); BUG("Policy read/write test: Fail\n"); } } for (j = 0; j < 10; j++) { int i; FILE *fp = fopen(policy_file, "w"); if (!fp) BUG("BUG: Policy write error\n"); fprintf(fp, "<kernel> /sbin/init\n"); for (i = 0; domain_testcases[i]; i++) fprintf(fp, "%s\n", domain_testcases[i]); fprintf(fp, "delete <kernel> /sbin/init\n"); fclose(fp); for (i = 0; i < 50; i++) { usleep(100000); get_meminfo(&after); if (before == after) break; } if (before != after) { printf("Policy: %d\n", after - before); BUG("Policy read/write test: Fail\n"); } } }
/* * Reads the memory info and displays it. Returns the total memory * available, for use in percent memory usage calculations. */ unsigned show_meminfo(void) { unsigned long long **mem = get_meminfo(); /* read+parse /proc/meminfo */ if (!mem || mem[meminfo_main][meminfo_total] == 0) { /* cannot normalize mem usage */ fprintf(stderr, "Cannot get size of memory from /proc/meminfo\n"); error_end(1); } if (show_memory) { printf("Mem: %7LdK av, %7LdK used, %7LdK free, %7LdK shrd, %7LdK buff", mem[meminfo_main][meminfo_total] >> 10, mem[meminfo_main][meminfo_used] >> 10, mem[meminfo_main][meminfo_free] >> 10, mem[meminfo_main][meminfo_shared] >> 10, mem[meminfo_main][meminfo_buffers] >> 10); PUTP(top_clrtoeol); putchar('\n'); printf("Swap: %7LdK av, %7LdK used, %7LdK free %7LdK cached", mem[meminfo_swap][meminfo_total] >> 10, mem[meminfo_swap][meminfo_used] >> 10, mem[meminfo_swap][meminfo_free] >> 10, mem[meminfo_total][meminfo_cached] >> 10); PUTP(top_clrtoeol); putchar('\n'); } PUTP(me); PUTP(top_clrtoeol); putchar('\n'); return mem[meminfo_main][meminfo_total] >> 10; }
void refresh_perf_data_block(PERF_DATA_BLOCK *data, RuntimeSettings rt) { data->PerfTime100nSec = 0; get_meminfo(data); get_cpuinfo(data); get_processinfo(data); get_diskinfo(data); return; }
int main(int argc, char *argv[]) { unsigned int before; mount("/proc", "/proc/", "proc", 0, NULL); get_meminfo(&before); domain_policy_test(before); exception_policy_test(before); BUG("Policy read/write test: Success\n"); return 0; }
numa_node::numa_node( const char *node_path, int index) : my_index(index) { char path[MAXLINE]; snprintf(path, sizeof(path), "%s/cpulist", node_path); get_cpuinfo(path); snprintf(path, sizeof(path), "%s/meminfo", node_path); get_meminfo(path); }
void init_mem_data(PERF_DATA_BLOCK *data) { data->memInfo.data = calloc(1, sizeof(*data->memInfo.data)); if(!data->memInfo.data) { perror("init_memdata: out of memory"); exit(1); } init_memdata_desc(data); get_meminfo(data); return; }
static int get_root_array(char * page, int type, char **start, off_t offset, int length) { switch (type) { case PROC_LOADAVG: return get_loadavg(page); case PROC_UPTIME: return get_uptime(page); case PROC_MEMINFO: return get_meminfo(page); #ifdef CONFIG_PCI case PROC_PCI: return get_pci_list(page); #endif case PROC_CPUINFO: return get_cpuinfo(page); case PROC_VERSION: return get_version(page); #ifdef CONFIG_DEBUG_MALLOC case PROC_MALLOC: return get_malloc(page); #endif #ifdef CONFIG_MODULES case PROC_MODULES: return get_module_list(page); case PROC_KSYMS: return get_ksyms_list(page, start, offset, length); #endif case PROC_STAT: return get_kstat(page); case PROC_DEVICES: return get_device_list(page); case PROC_INTERRUPTS: return get_irq_list(page); case PROC_FILESYSTEMS: return get_filesystem_list(page); case PROC_DMA: return get_dma_list(page); case PROC_IOPORTS: return get_ioport_list(page); #ifdef CONFIG_BLK_DEV_MD case PROC_MD: return get_md_status(page); #endif #ifdef __SMP_PROF__ case PROC_SMP_PROF: return get_smp_prof_list(page); #endif case PROC_CMDLINE: return get_cmdline(page); case PROC_MTAB: return get_filesystem_info( page ); #ifdef CONFIG_RTC case PROC_RTC: return get_rtc_status(page); #endif case PROC_LOCKS: return get_locks_status(page); } return -EBADF; }
static int array_read(struct inode * inode, struct file * file,char * buf, int count) { char * page; int length; int end; unsigned int type, pid; if (count < 0) return -EINVAL; if (!(page = (char*) __get_free_page(GFP_KERNEL))) return -ENOMEM; type = inode->i_ino; pid = type >> 16; type &= 0x0000ffff; switch (type) { case 2: length = get_loadavg(page); break; case 3: length = get_uptime(page); break; case 4: length = get_meminfo(page); break; case 6: length = get_version(page); break; case 9: length = get_env(pid, page); break; case 10: length = get_arg(pid, page); break; case 11: length = get_stat(pid, page); break; case 12: length = get_statm(pid, page); break; #ifdef CONFIG_DEBUG_MALLOC case 13: length = get_malloc(page); break; #endif case 14: free_page((unsigned long) page); return read_core(inode, file, buf, count); case 15: length = get_maps(pid, page); break; case 16: length = get_module_list(page); break; case 17: length = get_kstat(page); break; default: free_page((unsigned long) page); return -EBADF; } if (file->f_pos >= length) { free_page((unsigned long) page); return 0; } if (count + file->f_pos > length) count = length - file->f_pos; end = count + file->f_pos; memcpy_tofs(buf, page + file->f_pos, count); free_page((unsigned long) page); file->f_pos = end; return count; }