public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue@us.ibm.com>
To: Mike Frysinger <vapier@gentoo.org>
Cc: LTP list <ltp-list@lists.sourceforge.net>,
	Nathan T Lynch <natlynch@us.ibm.com>
Subject: Re: [LTP] [PATCH RFC] ltp: define and use common clone helpers
Date: Tue, 22 Sep 2009 23:05:46 -0500	[thread overview]
Message-ID: <20090923040546.GC9662@us.ibm.com> (raw)
In-Reply-To: <200909221100.42467.vapier@gentoo.org>

Quoting Mike Frysinger (vapier@gentoo.org):
> On Monday 21 September 2009 19:06:44 Serge E. Hallyn wrote:
> > Define ltp_clone() and ltp_clone_malloc() in libltp, and convert existing
> > clone usages to them.  (clone04 can't use it bc it wants to pass NULL,
> > which ltp_clone() will for many arches convert to NULL+stacksize-1).
> 
> so have the code handle NULL specially:
> (stack ? stack + stack_size - 1 : NULL)

<grumble> yeah that occurred to me but I was rebelling against the clone04.c
code...  But I guess I should.

> > +ltp_clone(unsigned long clone_flags, void *stack, int stack_size,
> > +		int (*fn)(void *arg), void *arg)
> > +{
> > +	int ret;
> > +
> > +#if defined(__hppa__)
> > +	ret = clone(fn, stack, clone_flags, arg);
> > +#elif defined(__ia64__)
> > +	ret = clone2(fn, stack, stack_size, clone_flags, arg, NULL, NULL, NULL);
> > +#else
> > +	ret = clone(fn, stack + stack_size - 1, clone_flags, arg);
> > +#endif
> > +
> > +	if (ret == -1)
> > +		perror("clone");
> 
> we cant be sure why the higher layers are calling clone.  maybe the args given 
> expect the clone() call to fail.  so we dont want any perror() invocation 
> here.

Makes sense.

> > +/***********************************************************************
> > + * ltp_clone_malloc: also does the memory allocation for clone.
> > + * Experience thus far suggests that one page is often insufficient,
> > + * while 4*getpagesize() seems adequate.
> > + ***********************************************************************/
> 
> a malloc() function implies you should be giving it a size.  i think there 
> should be another helper here.
> ltp_clone_malloc() - takes a size
> ltp_clone_quick() - calls ltp_clone_malloc() with getpagesize() * 4
> 
> or a better name than "quick" ...
> 
> > +int
> > +ltp_clone_malloc(unsigned long clone_flags, int (*fn)(void *arg), void
> >  *arg)
> 
> i think argument order should be consistent.  i.e. have all ltp_clone_* calls 
> start with (flags, func, arg) and then the malloc/etc... calls can add on 
> (..., size) and (..., size, buffer).

makes sense.

> > +	void *stack = malloc (stack_size);
> 
> no spacing around function calls
> 
> > +	if (!stack) {
> > +		perror("malloc");
> > +		return -1;
> > +	}
> 
> since people are linking in -lltp to get these clone helpers, we can assume 
> the tst_* funcs exist.  so this should invoke one of them with TBROK|TERRNO.

True.

> > +	ret = ltp_clone(clone_flags, stack, stack_size, fn, arg);
> > +
> > +	if (ret == -1) {
> > +		perror("clone");
> > +		free(stack);
> > +	}
> 
> same issue as the other func -- dont call perror()
> 
> i think we should make sure to save/restore errno across the free() invocation 
> so that the caller gets the result from clone() ...

Good point.

> otherwise this looks great.  thanks for doing the footwork here.
> -mike

Will hopefully whip up a new patch later this week and resend.

thanks,
-serge

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  reply	other threads:[~2009-09-23  4:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-21 23:06 [LTP] [PATCH RFC] ltp: define and use common clone helpers Serge E. Hallyn
2009-09-22 15:00 ` Mike Frysinger
2009-09-23  4:05   ` Serge E. Hallyn [this message]
2009-09-27 18:15     ` Subrata Modak
2009-09-28  3:56       ` Serge E. Hallyn

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=20090923040546.GC9662@us.ibm.com \
    --to=serue@us.ibm.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=natlynch@us.ibm.com \
    --cc=vapier@gentoo.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