<html><head></head><body><div>Hi,</div><div><br></div><div>El mar, 21-08-2018 a las 09:29 +0200, Victor Toso escribió:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>Hi,</pre><pre><br></pre><pre>On Tue, Aug 21, 2018 at 03:18:35AM -0400, Frediano Ziglio wrote:</pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre><br></pre><pre>Hi,</pre><pre>On Fri, 2018-08-17 at 15:24 +0200, Victor Toso wrote:</pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>Hi,</pre><pre><br></pre><pre>On Fri, Aug 17, 2018 at 03:12:35PM +0200, <a href="mailto:jorge.olmos@flexvdi.com">jorge.olmos@flexvdi.com</a></pre><pre>wrote:</pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>From: Jorge Olmos <<a href="mailto:jorge.olmos@flexvdi.com">jorge.olmos@flexvdi.com</a>></pre><pre><br></pre><pre>When building spice-gtk for windows:</pre><pre>- libusb uses __stdcall calling convention when compiled for win32.</pre><pre>It does</pre><pre>not include an option to be compiled with __cdecl calling</pre><pre>convention.</pre><pre>Directly calling libusb functions works fine. But it is a problem</pre><pre>when its</pre><pre>functions are passed as callbacks to a function that expects other</pre><pre>calling</pre><pre>convention.</pre><pre>- glib uses __cdecl calling convention and expects the functions it</pre><pre>receives as parameters to follow __cdecl convention.</pre><pre><br></pre><pre>So the lines included in spice-gtk like:</pre><pre>     g_clear_pointer(&priv->device, libusb_unref_device);</pre><pre>cause libusb_unref_device (compiled with _stdcall convention) to be</pre><pre>called</pre><pre>with __cdecl convention. This causes stack corruption, and hence</pre><pre>crashes.</pre><pre></pre><pre><br></pre><pre>Have you raised a bug in glib? We use this libraries to help with</pre><pre>portability so I'd hope it is possible to fix in glib.</pre><pre><br></pre><pre></pre><pre><br></pre><pre>I don't think it is even possible to fix this cleanly in glib. A</pre><pre>compilation of glib can work well with __stdcall OR with __cdecl. But</pre><pre>not with both of them.</pre><pre><br></pre><pre></pre><pre><br></pre><pre>It's possible, the function is called just once in the macro so won't</pre><pre>need all the hackish casts that are currently present. I have a fixed</pre><pre>version of the macro (somewhere!).</pre><pre></pre><pre><br></pre><pre>Ah, that would be cool.</pre><pre><br></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre><br></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>Right now I have just found another patch in spice-gtk, where the same</pre><pre>problem was solved with the same solution, which also has no</pre><pre>portability issues:</pre><pre><br></pre><pre><a href="https://patchwork.freedesktop.org/patch/92705/">https://patchwork.freedesktop.org/patch/92705/</a></pre><pre><br></pre><pre></pre><pre><br></pre><pre>Yes, this problem can cause a stack corruption (as you confirmed) and</pre><pre>should be merged GLib or not.</pre><pre></pre><pre><br></pre><pre>Yes, not against merging the fix. But if we can get it fixed in</pre><pre>Glib, it is matter to help other projects that port code to</pre><pre>windows to be fixed as well, etc.</pre><pre><br></pre><pre>Please open a bug in Glib and add a reference to it in the code</pre></blockquote><div><br></div><div>Are you talking to Jorge or to Frediano (since he has a fixed macro)? Jorge is on holidays anyway, he will return in a couple of weeks. I can open the bug report in Glib, but if you already have a working version of the macro...</div><div><br></div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><pre>(to avoid people reverting this change while the bug is not fixed</pre><pre>there)</pre><pre><br></pre><pre>    <a href="https://gitlab.gnome.org/GNOME/glib/issues">https://gitlab.gnome.org/GNOME/glib/issues</a></pre><pre><br></pre><pre>Cheers,</pre><pre>Victor</pre><pre><br></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>---</pre><pre> src/channel-usbredir.c | 9 ++++++---</pre><pre> 1 file changed, 6 insertions(+), 3 deletions(-)</pre><pre><br></pre><pre>diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c</pre><pre>index 6ffe546..1d9c380 100644</pre><pre>--- a/src/channel-usbredir.c</pre><pre>+++ b/src/channel-usbredir.c</pre><pre>@@ -352,7 +352,8 @@ static void spice_usbredir_channel_open_acl_cb(</pre><pre>         spice_usbredir_channel_open_device(channel, &err);</pre><pre>     }</pre><pre>     if (err) {</pre><pre>-        g_clear_pointer(&priv->device, libusb_unref_device);</pre><pre>+        libusb_unref_device(priv->device);</pre><pre>+        priv->device = NULL;</pre><pre>         g_boxed_free(spice_usb_device_get_type(), priv-</pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>spice_device);</pre><pre></pre><pre>         priv->spice_device = NULL;</pre><pre>         priv->state  = STATE_DISCONNECTED;</pre><pre>@@ -383,7 +384,8 @@ _open_device_async_cb(GTask *task,</pre><pre>     spice_usbredir_channel_lock(channel);</pre><pre> </pre><pre>     if (!spice_usbredir_channel_open_device(channel, &err)) {</pre><pre>-        g_clear_pointer(&priv->device, libusb_unref_device);</pre><pre>+        libusb_unref_device(priv->device);</pre><pre>+        priv->device = NULL;</pre><pre>         g_boxed_free(spice_usb_device_get_type(), priv-</pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>spice_device);</pre><pre></pre><pre>         priv->spice_device = NULL;</pre><pre>     }</pre><pre>@@ -504,7 +506,8 @@ void</pre><pre>spice_usbredir_channel_disconnect_device(SpiceUsbredirChannel</pre><pre>*channel)</pre><pre> </pre><pre>         /* This also closes the libusb handle we passed from</pre><pre>open_device */</pre><pre>         usbredirhost_set_device(priv->host, NULL);</pre><pre>-        g_clear_pointer(&priv->device, libusb_unref_device);</pre><pre>+        libusb_unref_device(priv->device);</pre><pre>+        priv->device = NULL;</pre><pre>         g_boxed_free(spice_usb_device_get_type(), priv-</pre><pre><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"></blockquote></pre><pre>spice_device);</pre><pre></pre><pre>         priv->spice_device = NULL;</pre><pre>         priv->state  = STATE_DISCONNECTED;</pre><pre></pre><pre></pre><pre></pre><pre><br></pre><pre>Frediano</pre><pre></pre><pre>_______________________________________________</pre><pre>Spice-devel mailing list</pre><pre><a href="mailto:Spice-devel@lists.freedesktop.org">Spice-devel@lists.freedesktop.org</a></pre><pre><a href="https://lists.freedesktop.org/mailman/listinfo/spice-devel">https://lists.freedesktop.org/mailman/listinfo/spice-devel</a></pre><pre><br></pre></blockquote><div><span><pre>-- <br></pre>


<br> 
<br>

<table id="sig" width="480" cellspacing="0" cellpadding="0" border-spacing="0" style="width:480px;margin:0;padding:0;"><tbody><tr><td text-align="right" style="border-right:2px solid #4a4b4a;padding-right:10px;" valign="top">
<p style="padding: 0px; text-align: right;">
              <a href="http://www.flexvdi.com" title="flexVDI"><img src="https://www.flexvdi.com/signature/logo.flexvdi.png" moz-do-not-send="true" alt="flexVDI" border="0" height="45" width="151">
              </a>
          </p>
          <p style="padding: 5px 10px 0px 0px; font-size: 15px; font-weight: bold; color: rgb(62, 93, 107); line-height: 17px; height: 17px; text-align: right;">
            <span style="float:right">Javier Celaya Alastrué</span>
          </p>
           <p style="padding: 0px 10px 0px 0px; font-size: 13px; font-style: italic; color: rgb(0, 161, 193); line-height: 17px; height: 17px; text-align: right;">Chief Technology Officer</p>
      </td>
      <td style="padding-left:18px;display:block;">
        <p style="padding: 5px 0px 0px;">
           <img src="https://flexvdi.com/signature/mail.png" moz-do-not-send="true" style="margin:1px 7px 0 0;" alt="email" align="left" height="17" width="17">
        <a href="mailto:javier.celaya@flexvdi.com" style="font-size:14px;color:#727272;line-height:17px;height:17px;">javier.celaya@flexvdi.com</a>
        </p>
        <p style="padding: 5px 0px 0px;">
          <img src="https://flexvdi.com/signature/phone.png" moz-do-not-send="true" style="margin:0 7px 0 0;" alt="Phone" align="left" height="17" width="17">
        <span style="font-size:14px;color:#727272;line-height:17px;height:17px;">+34696969959</span> 
      </p>
        <p style="padding: 5px 0px 0px;"> <img src="https://flexvdi.com/signature/skype.png" moz-do-not-send="true" style="margin:0 7px 0 0;" alt="Skype" align="left" height="17" width="17"> 
        <span style="font-size:14px;color:#727272;line-height:17px;height:17px;">j_celaya</span>
        </p>
        <p style="padding: 5px 0px 0px;">
          <img src="https://flexvdi.com/signature/legal.png" moz-do-not-send="true" style="margin:0 7px 0 0;" alt="Legal" align="left" height="17" width="17">
        <a href="https://flexvdi.com/es/legal" style="font-size:14px;font-style:italic;color:#727272;line-height:17px;height:17px;">Legal Information and Privacy Policy</a>
          </p>
      </td>
    </tr>
    <tr>
        <td colspan="2" height="300">
            <p style="font-family:Helvetica,Arial;font-size:14px;font-style:italic;color:#313131;text-align: center; font-weight: bold">Política de confidencialidad</p>
            <p style="font-family:Helvetica,Arial;font-size:10px;font-style:italic;color:#313131;text-align: justify">Este mensaje y los ficheros anexos son confidenciales dirigiéndose exclusivamente al destinatario mencionado en el encabezamiento. Si usted ha recibido este correo por error, tenga la amabilidad de eliminarlo de su sistema y no divulgar el contenido a terceros. Los datos personales facilitados por usted o por terceros serán tratados por FLEXIBLE SOFTWARE SOLUTIONS S.L.U. con la finalidad de gestionar y mantener los contactos y relaciones que se produzcan como consecuencia de la relación que mantiene con FLEXIBLE SOFTWARE SOLUTIONS S.L.U. Normalmente, la base jurídica que legitima este tratamiento, será su consentimiento, el interés legítimo o la necesidad para gestionar una relación contractual o similar. El plazo de conservación de sus datos vendrá determinado por la relación que mantiene con nosotros. Para más información al respecto, o para ejercer sus derechos de acceso, rectificación, supresión, oposición, limitación o portabilidad, dirija una comunicación por escrito a FLEXIBLE SOFTWARE SOLUTIONS S.L.U: Avenida de Ranillas 1D, Planta 3, Oficina 3G, Zaragoza o al correo electrónico <a href="mailto:pdo@flexvdi.com" style="color:#313131">pdo@flexvdi.com</a>. En caso de considerar vulnerado su derecho a la protección de datos personales, podrá interponer una reclamación ante la Agencia Española de Protección de Datos (<a href="http://www.agpd.es" style="color:#313131">www.agpd.es</a>). </p>
        </td>
    </tr>
</tbody></table></span></div></body></html>