public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: extending callbacks?
Date: 19 Mar 2002 15:08:23 -0800	[thread overview]
Message-ID: <a78gd7$jk$1@cesium.transmeta.com> (raw)
In-Reply-To: <Pine.GSO.4.44.0203191111320.20995-100000@speedy>

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.

	-hpa
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt	<amsp@zytor.com>

  reply	other threads:[~2002-03-19 23:09 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 [this message]
2002-03-19 19:32   ` Andreas Dilger
2002-03-20 15:55   ` Eric W. Biederman
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='a78gd7$jk$1@cesium.transmeta.com' \
    --to=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