Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Apr 2019 07:59:06 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Mark Millard <marklmi@yahoo.com>
Cc:        Poul-Henning Kamp <phk@phk.freebsd.dk>, FreeBSD Hackers <freebsd-hackers@freebsd.org>,  Alan Somers <asomers@freebsd.org>
Subject:   Re: buf(9) woes: when does bcopy do nothing at all?
Message-ID:  <CANCZdfp2ksLkmWhb=1RmTt-GiODt678vxiafoHbYdf1rJjVLuA@mail.gmail.com>
In-Reply-To: <6CF6472E-1100-475D-987C-071E916D64E8@yahoo.com>
References:  <CAOtMX2gdw%2BeQQU_-DC%2BEgimbCyw6ynbX1haGLUmn1dApk4rMZw@mail.gmail.com> <23438.1556267575@critter.freebsd.dk> <6CF6472E-1100-475D-987C-071E916D64E8@yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Apr 26, 2019 at 12:44 PM Mark Millard via freebsd-hackers <
freebsd-hackers@freebsd.org> wrote:

> On 2019-Apr-26, at 01:32, Poul-Henning Kamp <phk@phk.freebsd.dk> wrote:
>
> > --------
> > In message <
> CAOtMX2gdw+eQQU_-DC+EgimbCyw6ynbX1haGLUmn1dApk4rMZw@mail.gmail.com>, Alan
> Somers writes:
> >
> >> How is it possible that bcopy() doesn't affect its output array at all?
> >
> > That conclusion does not follow from your example:
> >
> >> bcopy(cp, iov->iov_base, cnt);
> >> r = memcmp(cp, iov->iov_base, cnt);
> >> if (r)
> >>   printf("uiomove: miscompare\n");
> >
> > If [cp:cp+cnt] and [iov_base:iov_base+cnt] overlap the bcopy result
> > is undefined.
> >
> > Try memmove instead ?
>
> I only see a bcopy man page bcopy(3) but it says:
>
> DESCRIPTION
>      The bcopy() function copies len bytes from string src to string dst.
> The
>      two strings may overlap.  If len is zero, no bytes are copied.
>
> Is a kernel bcopy likely to be any different?
>

kernel bcopy works with overlapping strings. It's always done this on x86,
and different archs behaved different, so we fixed that so the all handle
it properly. memcpy is still an issue here, potentially, but memmove isn't.

But it was also reported things weren't overlapping, etc. so that's not the
issue.

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfp2ksLkmWhb=1RmTt-GiODt678vxiafoHbYdf1rJjVLuA>