public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Matthias Scheidegger <mscheid@iam.unibe.ch>
Cc: linux-kernel@vger.kernel.org
Subject: Re: extending callbacks?
Date: 20 Mar 2002 08:59:15 -0700	[thread overview]
Message-ID: <m18z8nw7qk.fsf@frodo.biederman.org> (raw)
In-Reply-To: <Pine.GSO.4.44.0203191111320.20995-100000@speedy>

Matthias Scheidegger <mscheid@iam.unibe.ch> writes:

> Hi,
> 
> 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.

The general case requires self modifying code.  Where do you need this in the
kernel.  For most callbacks the kernel is already passing a fairly generic
parameter you can use.  So this trick should be unnecessary.  

In general it would be better to modify what the kernel is passing the function
than to build up an infrastructure to avoid fixing the code.  Especially
as runtime generated code tends to have a performance penalty.

Eric


  parent reply	other threads:[~2002-03-20 16:05 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
2002-03-20 18:32     ` H. Peter Anvin
2002-03-20 15:59 ` Eric W. Biederman [this message]
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=m18z8nw7qk.fsf@frodo.biederman.org \
    --to=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mscheid@iam.unibe.ch \
    /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