[tree-ssa libmudflap] unregister assert fix
Frank Ch. Eigler
fche@redhat.com
Thu Jun 19 19:33:00 GMT 2003
Hi -
The following patch is likely to fix Eyal's assert-related bug.
It does seem to be a real logic error, but it wasn't triggered
by the plain test suite for some reason.
+2003-06-19 Frank Ch. Eigler <fche@redhat.com>
+
+ * mf-hooks.c (struct pthread_info): Add "thread_errno" field.
+ (__mf_pthread_spawner, __mf_pthread_cleanup): Use it with GUESS
+ libmudflap object type.
+ * mf-runtime.c (__mfu_unregister): Correct cemetary logic to avoid
+ crashes on unregistering STATIC objects.
+
Index: mf-hooks.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-hooks.c,v
retrieving revision 1.1.2.37
diff -u -p -r1.1.2.37 mf-hooks.c
--- mf-hooks.c 18 Jun 2003 17:08:32 -0000 1.1.2.37
+++ mf-hooks.c 19 Jun 2003 19:11:02 -0000
@@ -943,6 +943,8 @@ struct pthread_info
/* If libmudflapth allocated the stack, store its base/size. */
void *stack;
size_t stack_size;
+
+ int *thread_errno;
};
@@ -960,7 +962,7 @@ __mf_pthread_cleanup (void *arg)
pi->dead_p = 1;
if (__mf_opts.heur_std_data)
- __mf_unregister (&errno, sizeof (errno));
+ __mf_unregister (pi->thread_errno, sizeof (int));
/* Some subsequent pthread_create will garbage_collect our stack. */
}
@@ -974,7 +976,13 @@ __mf_pthread_spawner (void *arg)
void *result = NULL;
if (__mf_opts.heur_std_data)
- __mf_register (&errno, sizeof (errno), __MF_TYPE_STATIC, "errno area (thread)");
+ {
+ pi->thread_errno = & errno;
+ __mf_register (pi->thread_errno, sizeof (int), __MF_TYPE_GUESS, "errno area (thread)");
+ // NB: we could use __MF_TYPE_STATIC above, but we guess that
+ // the thread errno is coming out of some dynamically allocated
+ // pool that we already know of as __MF_TYPE_HEAP.
+ }
pthread_cleanup_push (& __mf_pthread_cleanup, arg);
Index: mf-runtime.c
===================================================================
RCS file: /cvs/gcc/gcc/libmudflap/Attic/mf-runtime.c,v
retrieving revision 1.1.2.40
diff -u -p -r1.1.2.40 mf-runtime.c
--- mf-runtime.c 18 Jun 2003 17:08:32 -0000 1.1.2.40
+++ mf-runtime.c 19 Jun 2003 19:11:02 -0000
@@ -1249,7 +1249,8 @@ __mfu_unregister (void *ptr, size_t sz)
/* Manage the object cemetary. */
if (__mf_opts.persistent_count > 0 &&
- old_obj->data.type != __MF_TYPE_GUESS)
+ old_obj->data.type >= 0 &&
+ old_obj->data.type <= __MF_TYPE_MAX_CEM)
{
old_obj->data.deallocated_p = 1;
old_obj->left = old_obj->right = NULL;
@@ -1268,21 +1269,16 @@ __mfu_unregister (void *ptr, size_t sz)
/* Put this object into the cemetary. This may require this plot to
be recycled, and the previous resident to be designated del_obj. */
-
- assert (old_obj->data.type >= 0 &&
- old_obj->data.type <= __MF_TYPE_MAX_CEM);
{
unsigned row = old_obj->data.type;
unsigned plot = __mf_object_dead_head [row];
del_obj = __mf_object_cemetary [row][plot];
__mf_object_cemetary [row][plot] = old_obj;
-
plot ++;
if (plot == __mf_opts.persistent_count) plot = 0;
__mf_object_dead_head [row] = plot;
}
-
}
else
del_obj = old_obj;
More information about the Gcc-patches
mailing list