Bug 97611 - Use precompiled closure if libffi closure is not working
Summary: Use precompiled closure if libffi closure is not working
Status: RESOLVED FIXED
Alias: None
Product: p11-glue
Classification: Unclassified
Component: p11-kit (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Stef Walter
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-06 12:50 UTC by Daiki Ueno
Modified: 2017-01-24 11:51 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
build: Generate wrapper functions on the fly (69.13 KB, patch)
2016-09-06 12:50 UTC, Daiki Ueno
Details | Splinter Review
build: Generate fixed closures (13.52 KB, patch)
2016-09-06 12:50 UTC, Daiki Ueno
Details | Splinter Review
build: Generate wrapper functions on the fly (69.05 KB, patch)
2016-10-06 13:40 UTC, Daiki Ueno
Details | Splinter Review
build: Generate fixed closures (13.61 KB, patch)
2016-10-06 13:40 UTC, Daiki Ueno
Details | Splinter Review

Description Daiki Ueno 2016-09-06 12:50:37 UTC
As discussed in:
https://lists.freedesktop.org/archives/p11-glue/2015-September/000576.html

The first patch is to make the latter implementation simpler.
Comment 1 Daiki Ueno 2016-09-06 12:50:40 UTC
Created attachment 126241 [details] [review]
build: Generate wrapper functions on the fly

Generate wrapper functions in p11-kit/virtual.c from the
definitions in common/pkcs11.h and common/pkcs11i.h, rather than
hard-coding them.
Comment 2 Daiki Ueno 2016-09-06 12:50:43 UTC
Created attachment 126242 [details] [review]
build: Generate fixed closures

libffi's closure support may fail at run time, if the caller program is
under a stricter SELinux policy.  In that case, fallback to use a
pre-compiled closures.
https://bugzilla.redhat.com/show_bug.cgi?id=1271501
Comment 3 Stef Walter 2016-10-05 13:23:04 UTC
Comment on attachment 126241 [details] [review]
build: Generate wrapper functions on the fly

Review of attachment 126241 [details] [review]:
-----------------------------------------------------------------

This introduces python as a build dependency. I'd like to keep it as a devel dependency. Would it be possible to distribute virtual-base.c and virtual-stack.c in the tarball, so that python is not necessary to build releases?
Comment 4 Stef Walter 2016-10-05 13:25:24 UTC
Comment on attachment 126242 [details] [review]
build: Generate fixed closures

Review of attachment 126242 [details] [review]:
-----------------------------------------------------------------

Looks good. Just one thing that needs fixing.

::: p11-kit/modules.c
@@ +1880,5 @@
> +				*module = p11_virtual_wrap_fixed (virt, index, destroyer);
> +				if (*module)
> +					gl.fixed_closures[index] = *module;
> +			}
> +		}

If there's not enough fixed modules ... then we fall through to the return_val_if_fail() below. These methods are used for programmer or unexpected system error.

Can we handle this error case better? Print a legible failure message explaining as best we can about the failure case. Otherwise this is going to lead to hard to diagnose problems.
Comment 5 Daiki Ueno 2016-10-06 13:40:50 UTC
Created attachment 127064 [details] [review]
build: Generate wrapper functions on the fly

Generate wrapper functions in p11-kit/virtual.c from the
definitions in common/pkcs11.h and common/pkcs11i.h, rather than
hard-coding them.
Comment 6 Daiki Ueno 2016-10-06 13:40:52 UTC
Created attachment 127065 [details] [review]
build: Generate fixed closures

libffi's closure support may fail at run time, if the caller program is
under a stricter SELinux policy.  In that case, fallback to use a
pre-compiled closures.
https://bugzilla.redhat.com/show_bug.cgi?id=1271501
Comment 7 Daiki Ueno 2016-10-06 13:44:27 UTC
(In reply to Stef Walter from comment #3)
> Comment on attachment 126241 [details] [review] [review]
> build: Generate wrapper functions on the fly
> 
> Review of attachment 126241 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> This introduces python as a build dependency. I'd like to keep it as a devel
> dependency. Would it be possible to distribute virtual-base.c and
> virtual-stack.c in the tarball, so that python is not necessary to build
> releases?

Yes, there was EXTRA_DIST += $(BUILT_SOURCES), but I made it more explicit.  Also fixed AM_PATH_PYTHON invocation in configure.ac so it does not abort configure.

(In reply to Stef Walter from comment #4)
> Comment on attachment 126242 [details] [review] [review]
> build: Generate fixed closures
> 
> Review of attachment 126242 [details] [review] [review]:
> -----------------------------------------------------------------
> 
> Looks good. Just one thing that needs fixing.
> 
> ::: p11-kit/modules.c
> @@ +1880,5 @@
> > +				*module = p11_virtual_wrap_fixed (virt, index, destroyer);
> > +				if (*module)
> > +					gl.fixed_closures[index] = *module;
> > +			}
> > +		}
> 
> If there's not enough fixed modules ... then we fall through to the
> return_val_if_fail() below. These methods are used for programmer or
> unexpected system error.
> 
> Can we handle this error case better? Print a legible failure message
> explaining as best we can about the failure case. Otherwise this is going to
> lead to hard to diagnose problems.

Added a log message there.
Comment 8 Daiki Ueno 2016-11-25 08:57:25 UTC
I realized that this could also make the libffi dependency optional while providing the "virtual" functionality.  That might improve portability on older platforms.

Opened a pull request doing that at:
https://github.com/p11-glue/p11-kit/pull/9
Comment 9 Stef Walter 2016-11-29 13:30:40 UTC
Has this contribution moved completely to a GitHub pull request?
Comment 10 Daiki Ueno 2017-01-24 11:51:12 UTC
(In reply to Stef Walter from comment #9)
> Has this contribution moved completely to a GitHub pull request?

Yes, and a simplified version has just been checked in as:
https://github.com/p11-glue/p11-kit/commit/9f632bed73c8800af16a69c97bd4c315bd350f8b


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.