3 * modules/us_manager/us_slot_manager.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin: SWAP us_manager implement
26 #include <linux/slab.h>
27 #include <linux/hardirq.h>
28 #include <linux/sched.h>
30 #include <linux/mman.h>
31 #include <linux/list.h>
32 #include <kprobe/dbi_insn_slots.h>
33 #include <kprobe/arch/asm/dbi_kprobes.h>
34 #include "us_manager_common.h"
37 static void *sm_alloc_us(struct slot_manager *sm)
41 addr = swap_do_mmap(NULL, 0, PAGE_SIZE, PROT_EXEC|PROT_READ|PROT_WRITE,
42 MAP_ANONYMOUS|MAP_PRIVATE, 0);
46 static void sm_free_us(struct slot_manager *sm, void *ptr)
49 * E. G.: This code provides kernel dump because of rescheduling while atomic.
50 * As workaround, this code was commented. In this case we will have memory leaks
51 * for instrumented process, but instrumentation process should functionate correctly.
52 * Planned that good solution for this problem will be done during redesigning KProbe
53 * for improving supportability and performance.
56 struct task_struct *task = sm->data;
58 mm = get_task_mm(task);
60 down_write(&mm->mmap_sem);
61 do_munmap(mm, (unsigned long)(ptr), PAGE_SIZE);
62 up_write(&mm->mmap_sem);
66 /* FIXME: implement the removal of memory for task */
69 struct slot_manager *create_sm_us(struct task_struct *task)
71 struct slot_manager *sm = kmalloc(sizeof(*sm), GFP_ATOMIC);
72 sm->slot_size = UPROBES_TRAMP_LEN;
73 sm->alloc = sm_alloc_us;
74 sm->free = sm_free_us;
75 INIT_HLIST_HEAD(&sm->page_list);
81 void free_sm_us(struct slot_manager *sm)