From: ebiederm@xmission.com (Eric W. Biederman)
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: extending callbacks?
Date: 20 Mar 2002 08:55:08 -0700 [thread overview]
Message-ID: <m1d6xzw7xf.fsf@frodo.biederman.org> (raw)
In-Reply-To: <Pine.GSO.4.44.0203191111320.20995-100000@speedy> <a78gd7$jk$1@cesium.transmeta.com>
"H. Peter Anvin" <hpa@zytor.com> writes:
> Followup to: <Pine.GSO.4.44.0203191111320.20995-100000@speedy>
> By author: Matthias Scheidegger <mscheid@iam.unibe.ch>
> In newsgroup: linux.dev.kernel
> >
> > I've got the following problem: I want to register a callback in a kernel
> > structure, but I need to supply an additional argument to my own code. I.e. I
> > need a callback
> >
> > int (*cb)(int u)
> >
> > to really call
> >
> > int (*real_cb)(int u, void* my_arg)
> >
> > At the moment, I'm only focussing on the i386 architecture.
> > In user space, I'd do this by generating some machine code, which takes the
> > original args, pushes my_fixed_arg and calls real_cb (using mprotect to make
> > the generated code callable). That way I'd use a function
> >
> > int (*)(int) create_callback(int (*real_cb)(int, void*), void *arg);
> >
> > Is there a good way to do that in the kernel?
> > Not necessarily using self modifying code, I'll only use it if I must.
> >
>
> In general, it's impossible. On a lot of architectures, it happens to
> "just work" with the appropriate cast, but that's completely dependent
> on the ABI.
>
> The extra arguemnt, of course, contains garbage.
???
static void *my_fixed_arg;
int temp_cb(int u)
{
return real_cb(u, my_fixed_arg);
}
Generally works. The variant that builds that code on the fly for
create_callback is a little more interesting of course.
Eric
next prev parent reply other threads:[~2002-03-20 16:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-03-19 10:23 extending callbacks? Matthias Scheidegger
2002-03-19 23:08 ` H. Peter Anvin
2002-03-19 19:32 ` Andreas Dilger
2002-03-20 15:55 ` Eric W. Biederman [this message]
2002-03-20 18:32 ` H. Peter Anvin
2002-03-20 15:59 ` Eric W. Biederman
2002-03-20 21:02 ` Matthias Scheidegger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1d6xzw7xf.fsf@frodo.biederman.org \
--to=ebiederm@xmission.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox