From: Ian Campbell Subject: Re: [PATCH 21/29] tools/libxl: Allow adding larger amounts of prefixdata to datacopier Date: Thu, 11 Sep 2014 13:01:55 +0100 Message-ID: <1410436915.25388.3.camel@kazak.uk.xensource.com> References: <1410369067-1330-1-git-send-email-andrew.cooper3@citrix.com> <1410369067-1330-22-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1410369067-1330-22-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper Cc: Ross Lagerwall , Ian Jackson , Xen-devel List-Id: xen-devel@lists.xenproject.org On Wed, 2014-09-10 at 18:10 +0100, Andrew Cooper wrote: > From: Ross Lagerwall > > Previously, adding more than 1000 bytes of data would cause a segfault. Segfault is a symptom, not a cause, why does it happen? > Now, the maximum amount of data that can be added is limited by maxsz. > > Signed-off-by: Ross Lagerwall > --- > tools/libxl/libxl_aoutils.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c > index 3e0c0ae..caba637 100644 > --- a/tools/libxl/libxl_aoutils.c > +++ b/tools/libxl/libxl_aoutils.c > @@ -160,6 +160,8 @@ void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, > { > EGC_GC; > libxl__datacopier_buf *buf; > + const uint8_t *ptr; > + > /* > * It is safe for this to be called immediately after _start, as > * is documented in the public comment. _start's caller must have > @@ -170,12 +172,14 @@ void libxl__datacopier_prefixdata(libxl__egc *egc, libxl__datacopier_state *dc, > > assert(len < dc->maxsz - dc->used); > > - buf = libxl__zalloc(NOGC, sizeof(*buf)); > - buf->used = len; > - memcpy(buf->buf, data, len); > + for (ptr = data; len; len -= buf->used, ptr += buf->used) { > + buf = libxl__zalloc(NOGC, sizeof(*buf)); > + buf->used = len < sizeof(buf->buf) ? len : sizeof(buf->buf); > + memcpy(buf->buf, ptr, buf->used); > > - dc->used += len; > - LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry); > + dc->used += buf->used; > + LIBXL_TAILQ_INSERT_TAIL(&dc->bufs, buf, entry); > + } > } > > static int datacopier_pollhup_handled(libxl__egc *egc,