Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Aug 2016 13:52:07 +0300
From:      Slawa Olhovchenkov <slw@zxy.spb.ru>
To:        Ed Schouten <ed@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r304555 - head/sys/compat/cloudabi
Message-ID:  <20160821105207.GS22212@zxy.spb.ru>
In-Reply-To: <201608210741.u7L7fBnN075023@repo.freebsd.org>
References:  <201608210741.u7L7fBnN075023@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Aug 21, 2016 at 07:41:11AM +0000, Ed Schouten wrote:

> Author: ed
> Date: Sun Aug 21 07:41:11 2016
> New Revision: 304555
> URL: https://svnweb.freebsd.org/changeset/base/304555
> 
> Log:
>   Use memcpy() to copy 64-bit timestamps into the syscall return values.
>   
>   On 32-bit platforms, our 64-bit timestamps need to be split up across
>   two registers. A simple assignment to td_retval[0] will cause the top 32
>   bits to get lost. By using memcpy(), we will automatically either use 1
>   or 2 registers depending on the size of register_t.
> 
> Modified:
>   head/sys/compat/cloudabi/cloudabi_clock.c
> 
> Modified: head/sys/compat/cloudabi/cloudabi_clock.c
> ==============================================================================
> --- head/sys/compat/cloudabi/cloudabi_clock.c	Sun Aug 21 07:28:38 2016	(r304554)
> +++ head/sys/compat/cloudabi/cloudabi_clock.c	Sun Aug 21 07:41:11 2016	(r304555)
> @@ -117,7 +117,7 @@ cloudabi_sys_clock_res_get(struct thread
>  	error = cloudabi_convert_timespec(&ts, &cts);
>  	if (error != 0)
>  		return (error);
> -	td->td_retval[0] = cts;
> +	memcpy(td->td_retval, &cts, sizeof(cts));
>  	return (0);
>  }
>  
> @@ -129,6 +129,6 @@ cloudabi_sys_clock_time_get(struct threa
>  	int error;
>  
>  	error = cloudabi_clock_time_get(td, uap->clock_id, &ts);
> -	td->td_retval[0] = ts;
> +	memcpy(td->td_retval, &ts, sizeof(ts));
>  	return (error);

Why do not use more simple solution:

*(cloudabi_timestamp_t *)td->td_retval = cts;

This is eliminate call to memcpy and allow compiler to use most
effeicient way.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160821105207.GS22212>