From: Alexander Aksenov Date: Mon, 29 Jan 2018 15:12:31 +0000 (+0300) Subject: Loader: add process data destructor X-Git-Tag: accepted/tizen/unified/20180314.062051~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F48%2F168748%2F4;p=platform%2Fkernel%2Fswap-modules.git Loader: add process data destructor Change-Id: Ie78123f3beedfd96b6618db91ea56dd4b8aa812b Signed-off-by: Alexander Aksenov --- diff --git a/modules/loader/loader_pd.c b/modules/loader/loader_pd.c index a7597e3..a7b6e54 100644 --- a/modules/loader/loader_pd.c +++ b/modules/loader/loader_pd.c @@ -254,6 +254,64 @@ get_handlers_out: return ret; } +static struct pd_t *do_create_pd(struct task_struct *task) +{ + struct pd_t *pd; + int ret; + + pd = __create_pd(); + if (pd == NULL) { + ret = -ENOMEM; + goto create_pd_exit; + } + + ret = __get_handlers(pd, task); + if (ret) + goto free_pd; + + __set_ld_mapped(pd, task->mm); + + return pd; + +free_pd: + kfree(pd); + +create_pd_exit: + printk(KERN_ERR LOADER_PREFIX "do_pd_create_pd: error=%d\n", ret); + return NULL; +} + +static void do_destroy_pd(struct pd_t *pd) +{ + struct hd_t *hd, *tmp; + + list_for_each_entry_safe(hd, tmp, &pd->handlers, list) { + list_del(&hd->list); + kfree(hd); + } + + kfree(pd); +} + +static void *pd_create(struct sspt_proc *proc) +{ + struct pd_t *pd; + + pd = do_create_pd(proc->leader); + + return (void *)pd; +} + +static void pd_destroy(struct sspt_proc *proc, void *data) +{ + do_destroy_pd((struct pd_t *)data); +} + +struct sspt_proc_cb pd_cb = { + .priv_create = pd_create, + .priv_destroy = pd_destroy +}; + enum ps_t lpd_get_state(struct hd_t *hd) @@ -372,11 +430,25 @@ struct pd_t *lpd_get(struct sspt_proc *proc) } EXPORT_SYMBOL_GPL(lpd_get); +void lpd_set(struct sspt_proc *proc, struct pd_t *pd) +{ + proc->private_data = pd; +} +EXPORT_SYMBOL_GPL(lpd_set); + struct pd_t *lpd_get_by_task(struct task_struct *task) { - struct sspt_proc *proc = sspt_proc_by_task(task); + struct sspt_proc *proc; + struct pd_t *pd; - return lpd_get(proc); + proc = sspt_proc_by_task(task); + pd = lpd_get(proc); + if (!pd) { + pd = do_create_pd(task); + lpd_set(proc, pd); + } + + return pd; } EXPORT_SYMBOL_GPL(lpd_get_by_task); @@ -407,52 +479,6 @@ void lpd_set_init_state(struct pd_t *pd, bool state) } EXPORT_SYMBOL_GPL(lpd_set_init_state); -static struct pd_t *do_create_pd(struct task_struct *task) -{ - struct pd_t *pd; - int ret; - - pd = __create_pd(); - if (pd == NULL) { - ret = -ENOMEM; - goto create_pd_exit; - } - - ret = __get_handlers(pd, task); - if (ret) - goto free_pd; - - __set_ld_mapped(pd, task->mm); - - return pd; - -free_pd: - kfree(pd); - -create_pd_exit: - printk(KERN_ERR LOADER_PREFIX "do_pd_create_pd: error=%d\n", ret); - return NULL; -} - -static void *pd_create(struct sspt_proc *proc) -{ - struct pd_t *pd; - - pd = do_create_pd(proc->leader); - - return (void *)pd; -} - -static void pd_destroy(struct sspt_proc *proc, void *data) -{ - /* FIXME: to be implemented */ -} - -struct sspt_proc_cb pd_cb = { - .priv_create = pd_create, - .priv_destroy = pd_destroy -}; - int lpd_init(void) { int ret;