do_fork(): fix tids memory leak; additional sanity checks

This commit is contained in:
Balazs Gerofi
2016-08-18 14:31:52 +09:00
parent bd6a2c2311
commit 7ebc34ddcc
6 changed files with 23 additions and 5 deletions

View File

@ -87,11 +87,19 @@ void ihk_mc_free_pages(void *p, int npages)
void *ihk_mc_allocate(int size, int flag)
{
if (!cpu_local_var(kmalloc_initialized)) {
kprintf("%s: error, kmalloc not yet initialized\n", __FUNCTION__);
return NULL;
}
return kmalloc(size, IHK_MC_AP_NOWAIT);
}
void ihk_mc_free(void *p)
{
if (!cpu_local_var(kmalloc_initialized)) {
kprintf("%s: error, kmalloc not yet initialized\n", __FUNCTION__);
return;
}
kfree(p);
}

View File

@ -373,6 +373,11 @@ static int process_msg_prepare_process(unsigned long rphys)
}
n = p->num_sections;
if (n > 16) {
kprintf("%s: ERROR: more ELF sections than 16??\n",
__FUNCTION__);
return -ENOMEM;
}
dkprintf("# of sections: %d\n", n);
if((pn = kmalloc(sizeof(struct program_load_desc)

View File

@ -73,6 +73,7 @@ struct cpu_local_var {
int in_interrupt;
int no_preempt;
int timer_enabled;
int kmalloc_initialized;
} __attribute__((aligned(64)));

View File

@ -664,8 +664,8 @@ static struct alloc *allochash[HASHNUM];
static struct location *lochash[HASHNUM];
static ihk_spinlock_t alloclock;
int runcount;
static unsigned char *page;
static int space;
static unsigned char *page = NULL;
static int space = 0;
static void *dalloc(unsigned long size)
{
@ -896,14 +896,17 @@ void kmalloc_init(void)
h->size = 0;
register_kmalloc();
v->kmalloc_initialized = 1;
memdebug = find_command_line("memdebug");
for (i = 0; i < HASHNUM; i++) {
allochash[i] = NULL;
lochash[i] = NULL;
}
page = allocate_pages(16, IHK_MC_AP_NOWAIT);
space = 16 * 4096;
if (!page) {
page = allocate_pages(16, IHK_MC_AP_NOWAIT);
space = 16 * 4096;
}
ihk_mc_spinlock_init(&alloclock);
}

View File

@ -963,7 +963,6 @@ enum ihk_mc_pt_attribute common_vrflag_to_ptattr(unsigned long flag, uint64_t fa
return attr;
}
/* XXX: インデントを揃える必要がある */
int add_process_memory_range(struct process_vm *vm,
unsigned long start, unsigned long end,
unsigned long phys, unsigned long flag,

View File

@ -1937,6 +1937,8 @@ unsigned long do_fork(int clone_flags, unsigned long newsp,
newproc->tids[i].thread = NULL;
++newproc->nr_tids;
}
kfree(tids);
}
/* Find an unused TID */