[v6,1/5] Add cast_to_pointer to cast an integer to void * pointer

Message ID 20210522035018.2652112-2-hjl.tools@gmail.com
State Committed
Commit 94bc766ec627b2c44a6c72bc40013957ffc4b6cd
Headers
Series Add an internal wrapper for clone, clone2 and clone3 |

Commit Message

H.J. Lu May 22, 2021, 3:50 a.m. UTC
  ---
 include/libc-pointer-arith.h | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Florian Weimer May 22, 2021, 7:17 a.m. UTC | #1
* H. J. Lu:

> ---
>  include/libc-pointer-arith.h | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/include/libc-pointer-arith.h b/include/libc-pointer-arith.h
> index 72e722c5aa..04ba537617 100644
> --- a/include/libc-pointer-arith.h
> +++ b/include/libc-pointer-arith.h
> @@ -37,6 +37,9 @@
>  /* Cast an integer or a pointer VAL to integer with proper type.  */
>  # define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
>  
> +/* Cast an integer VAL to void * pointer.  */
> +# define cast_to_pointer(val) ((void *) (uintptr_t) (val))
> +
>  /* Align a value by rounding down to closest size.
>     e.g. Using size of 4096, we get this behavior:
>  	{4095, 4096, 4097} = {0, 4096, 4096}.  */

Looks good.

Thanks,
Florian
  

Patch

diff --git a/include/libc-pointer-arith.h b/include/libc-pointer-arith.h
index 72e722c5aa..04ba537617 100644
--- a/include/libc-pointer-arith.h
+++ b/include/libc-pointer-arith.h
@@ -37,6 +37,9 @@ 
 /* Cast an integer or a pointer VAL to integer with proper type.  */
 # define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val))
 
+/* Cast an integer VAL to void * pointer.  */
+# define cast_to_pointer(val) ((void *) (uintptr_t) (val))
+
 /* Align a value by rounding down to closest size.
    e.g. Using size of 4096, we get this behavior:
 	{4095, 4096, 4097} = {0, 4096, 4096}.  */