Re: [PATCH] fix crashing on amd64



On Wed, 2006-01-11 at 16:29 +0100, Thierry Vignaud wrote:

On x86_64, the conversions from ptr to int and from int to ptr will
loose the highest bits of the pointer, leading to memory access
violations. Use the safer macros that perl provides instead.

Applied to HEAD, is present in Glib 1.114.  I had to add some casts to
avoid compiler warnings, though:

@@ -552,7 +552,7 @@ gobject_destroy_wrapper (SV *obj)
         warn ("gobject_destroy_wrapper (%p)[%d]", obj,
               SvREFCNT ((SV*)REVIVE_UNDEAD(obj)));
 #endif
-        obj = REVIVE_UNDEAD(obj);
+        obj = (SV *) REVIVE_UNDEAD(obj);
         sv_unmagic (obj, PERL_MAGIC_ext);

         /* we might want to optimize away the call to DESTROY here for non-perl classes. */
@@ -733,7 +733,7 @@ gperl_new_object (GObject * object,
                 /* if the SV is undead, revive it */
                 if (IS_UNDEAD(obj)) {
                     g_object_ref (object);
-                    obj = REVIVE_UNDEAD(obj);
+                    obj = (SV *) REVIVE_UNDEAD(obj);
                     update_wrapper (object, obj);
                     sv = newRV_noinc (obj);
                     /* printf("reviving undead wrapper for [%p] (%p)\n", object, obj); */
@@ -892,7 +892,7 @@ _gperl_fetch_wrapper_key (GObject * obje

        /* we don't care whether the wrapper is alive or undead.  forcibly
         * remove the undead bit, or the pointer will be unusable. */
-       wrapper_hash = REVIVE_UNDEAD (wrapper_hash);
+       wrapper_hash = (HV *) REVIVE_UNDEAD (wrapper_hash);

        svname = newSVpv (name, strlen (name));
        svp = hv_fetch (wrapper_hash, SvPV_nolen (svname), SvLEN (svname)-1,
@@ -1007,7 +1007,7 @@ DESTROY (SV *sv)
                 if (object->ref_count > 1) {
                     /* become undead */
                     SV *obj = SvRV(sv);
-                    update_wrapper (object, MAKE_UNDEAD(obj));
+                    update_wrapper (object, (SV *) MAKE_UNDEAD(obj));
                     /* printf("zombies! [%p] (%p)\n", object, obj);*/
                 }
         }

Is there a safe way to avoid these?  Perhaps by using these?

#define IS_UNDEAD(x) (PTR2UV(x) & 1)
#define MAKE_UNDEAD(x) INT2PTR(gpointer,PTR2UV(x) | 1)
#define REVIVE_UNDEAD(x) INT2PTR(gpointer,PTR2UV(x) & ~1)

Or will that break on 64-bit platforms again?

If this issue is settled, the patch can go into stable-1-10 and a new
stable release can be made.

-- 
Bye,
-Torsten




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]