EXPORT_C void __attribute__((constructor)) mdbg_init_mem_alloc(void) { get_malloc(); get_realloc(); get_free(); get_posix_memalign(); get_memalign(); get_valloc(); set_core_unlimited(); }
void* operator new[] (size_t sz) { void *ret; ret = get_malloc() (sz); INIT( ret, sz ); return ret; }
EXPORT_C void *malloc(size_t sz) { void *ret; if (dlsym_nesting) { return 0; } ret = get_malloc() (sz); INIT( ret, sz ); return ret; }
void *realloc(void *ptr, size_t size) { static t_zone *ptr_realloc = NULL; t_zone *current; int ret; if (size <= 0) return (NULL); if (!ptr_realloc) ptr_realloc = get_malloc(); current = ptr_realloc; while (42) { if ((ret = found_inter(ptr, current)) != -1) return (ft_realloc(ptr_realloc, ptr, current, size)); if (!current->next) break ; current = current->next; } return (NULL); }
void show_alloc_mem(void) { static t_zone *ptr_view = NULL; t_zone *current; if (!ptr_view) ptr_view = get_malloc(); current = ptr_view; while (42) { if (current->index) print_view(current); if (current->next) current = current->next; else break ; } ft_putstr("Total : "); ft_putnbr(ptr_view->total); ft_putendl(" octets"); }
void *realloc(void *ptr, size_t size) { char *char_ptr; char *mem; char **ptr_mem; int *int_mem; ft_putstr("trying to realloc\n"); char_ptr = (char *)ptr; mem = get_malloc(0, size); while (mem != NULL) { ptr_mem = (char **)(mem + 5); if (is_pointer_in_page(mem, ptr) == 1) { int_mem = (int *)(mem + 1); return (realloc_page(mem, *int_mem, ptr, size)); } mem = *ptr_mem; } return (NULL); }
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; }
void * operator new(size_t size) { return get_malloc()(size); }