lkml.org 
[lkml]   [2002]   [Mar]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: extending callbacks?
From
Date
"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



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:22    [W:0.095 / U:1.736 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site