Skip to content

Commit

Permalink
Hack for segmentation faults on Apple Silicon(Macos arm64)
Browse files Browse the repository at this point in the history
There are bugs in pyobject and gobject-introspection.
The API g_callable_info_prepare_closure() only returns the address
of exec not closure.
On linux arm64 and x86_64 platforms, exec address is same as
closure. However, on Macos arm64, it is not true. Then segmentation
fault happens while calling g_callable_info_free_closure() on exec ptr.

Try the C code:

========================================================================

void puts_binding(ffi_cif *cif, void *ret, void* args[],
                  void *stream)
{
  *(ffi_arg *)ret = fputs(*(char **)args[0], (FILE *)stream);
}

typedef int (*puts_t)(char *);

int main()
{
  ffi_cif cif;
  ffi_type *args[1];
  ffi_closure *closure;

  void *bound_puts;
  int rc;

  /* Allocate closure and bound_puts */
  closure = ffi_closure_alloc(sizeof(ffi_closure), &bound_puts);

  if (closure)
    {
      /* Initialize the argument info vectors */
      args[0] = &ffi_type_pointer;

      /* Initialize the cif */
      if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
                       &ffi_type_sint, args) == FFI_OK)
        {
          /* Initialize the closure, setting stream to stdout */
          if (ffi_prep_closure_loc(closure, &cif, puts_binding,
                                   stdout, bound_puts) == FFI_OK)
            {
              rc = ((puts_t)bound_puts)("");
              /* rc now holds the result of the call to fputs */
            }
        }

  printf("closure:%p exec: %p\n", closure, bound_puts);
  /* Deallocate both closure, and bound_puts */
  ffi_closure_free(closure);

  return 0;
}
========================================================================

I tried to fix it but there are some bugs in pyobject which also cause
segmentation faults.

I'm not a pundit in these messy code so just do hacks in pyobject to
fix it.

Link: https://gitlab.gnome.org/GNOME/pygobject/-/issues/455
Link: jeffreywildman/homebrew-virt-manager#166 (comment)
Signed-off-by: Su Yue <l@damenly.su>
  • Loading branch information
Damenly committed Sep 4, 2021
1 parent c8518e1 commit 01013b1
Show file tree
Hide file tree
Showing 3 changed files with 496 additions and 4 deletions.
Loading

0 comments on commit 01013b1

Please sign in to comment.