diff options
| author | serpilliere <devnull@localhost> | 2011-10-21 10:15:59 +0200 |
|---|---|---|
| committer | serpilliere <devnull@localhost> | 2011-10-21 10:15:59 +0200 |
| commit | 2455b3506b8a06e0d5ead8f47174339a74bfdca5 (patch) | |
| tree | 593762e72e5a8d3d0e88155c7118ce6a22cc6f89 | |
| parent | 3e12c8b8d6795bf3d86e045eb3c386ccfcb2da38 (diff) | |
| download | miasm-2455b3506b8a06e0d5ead8f47174339a74bfdca5.tar.gz miasm-2455b3506b8a06e0d5ead8f47174339a74bfdca5.zip | |
raise exception in case of double page mapping
| -rw-r--r-- | miasm/tools/emul_lib/libcodenat.c | 18 | ||||
| -rw-r--r-- | miasm/tools/emul_lib/libcodenat.h | 1 | ||||
| -rw-r--r-- | miasm/tools/emul_lib/libcodenat_interface.c | 5 |
3 files changed, 22 insertions, 2 deletions
diff --git a/miasm/tools/emul_lib/libcodenat.c b/miasm/tools/emul_lib/libcodenat.c index aedbce49..5d598f8c 100644 --- a/miasm/tools/emul_lib/libcodenat.c +++ b/miasm/tools/emul_lib/libcodenat.c @@ -1002,12 +1002,12 @@ struct memory_page_node * create_memory_page_node(uint64_t ad, unsigned int size mpn = malloc(sizeof(*mpn)); if (!mpn){ fprintf(stderr, "cannot alloc mpn\n"); - exit(-1); + return NULL; } p = malloc(size); if (!p){ fprintf(stderr, "cannot alloc %d\n", size); - exit(-1); + return NULL; } mpn->ad = ad; mpn->size = size; @@ -1104,6 +1104,20 @@ void reset_code_bloc_pool(void) code_bloc_pool_ad_max = 0; } +int is_mpn_in_tab(struct memory_page_node* mpn_a) +{ + unsigned int i; + for (i=mpn_a->ad >> MEMORY_PAGE_POOL_MASK_BIT; + i<(mpn_a->ad + mpn_a->size + PAGE_SIZE - 1)>>MEMORY_PAGE_POOL_MASK_BIT; + i++){ + if (memory_page_pool_tab[i] !=NULL){ + return 1; + } + } + + return 0; +} + void insert_mpn_in_tab(struct memory_page_node* mpn_a) { unsigned int i; diff --git a/miasm/tools/emul_lib/libcodenat.h b/miasm/tools/emul_lib/libcodenat.h index d91532c0..d4047f16 100644 --- a/miasm/tools/emul_lib/libcodenat.h +++ b/miasm/tools/emul_lib/libcodenat.h @@ -347,6 +347,7 @@ unsigned int get_memory_page_max_address(void); unsigned int get_memory_page_max_user_address(void); +int is_mpn_in_tab(struct memory_page_node* mpn_a); void _func_free(void); diff --git a/miasm/tools/emul_lib/libcodenat_interface.c b/miasm/tools/emul_lib/libcodenat_interface.c index 2bf78de3..ce402e07 100644 --- a/miasm/tools/emul_lib/libcodenat_interface.c +++ b/miasm/tools/emul_lib/libcodenat_interface.c @@ -348,6 +348,11 @@ PyObject* _vm_add_memory_page(PyObject *item, PyObject *access, PyObject *item_s mpn = create_memory_page_node(page_addr, buf_size, page_access); + if (mpn == NULL) + RAISE(PyExc_TypeError,"cannot create page"); + if (is_mpn_in_tab(mpn)) + RAISE(PyExc_TypeError,"known page in memory"); + memcpy(mpn->ad_hp, buf_data, buf_size); add_memory_page(mpn); |