lkml.org 
[lkml]   [2004]   [Nov]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: var args in kernel?
On Mon, Nov 22, 2004 at 10:43:12AM +0100, Gerd Knorr wrote:
> On Fri, Nov 19, 2004 at 02:41:46PM -0700, Kevin P. Fleming wrote:
> > Gerd Knorr wrote:
> > >Yet another kobject bug. It uses the varargs list twice in a illegal
> > >way. That doesn't harm on i386 by pure luck, but blows things up on
> > >amd64 machines. The patch below fixes it.
> >
> > Is this safe? The normal glibc varargs implementation says you can't
> > even call va_start on the same args list twice, you have to use va_copy
> > to make a clone and then call va_start on that, _before_ you ever call
> > va_start the first time.
>
> Hmm, maybe. I'm not sure who actually implements the varargs (gcc?
> Or glibc/kernel?) and whenever the above applies to the kernel as well
> or not ...

varargs is implemented entirely by GCC (GCC owns the stdarg.h header
and implements the builtin functions that are used in the va_* macros).

You can call va_start on the same args list twice, both:
void foo (int x, ...)
{
va_list ap, ap2;
va_start (ap, x);
va_start (ap2, x);
...
va_end (ap);
va_end (ap2);
}
and
void foo (int x, ...)
{
va_list ap;
va_start (ap, x);
...
va_end (ap);
va_start (ap, x);
...
va_end (ap);
}
are ok. What you can't do is e.g.
va_list ap;
va_start (ap, x);
bar (x, ap);
bar (x, ap);
va_end (ap);
(i.e. once you pass the ap to some other function, the only thing that you
have to do with it in the caller is va_end).

Jakub
-
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 14:08    [W:0.110 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site