diff mbox series

[4/7] examples: fix the type of search_hint

Message ID 20200420223418.117186-5-mhorne@FreeBSD.org
State New
Headers show
Series Add support for CONFIG_API on RISC-V | expand

Commit Message

Mitchell Horne April 20, 2020, 10:34 p.m. UTC
From: Mitchell Horne <mhorne at FreeBSD.org>

search_hint is defined in assembly as a .long, and is intended to hold
the initial stack pointer as a hint to the api_search_sig() routine.
Convert this to a uintptr_t, to avoid possible truncation on 64-bit
systems.

Signed-off-by: Mitchell Horne <mhorne at FreeBSD.org>
---
 examples/api/glue.c | 6 +++---
 examples/api/glue.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Bin Meng April 23, 2020, 2:18 p.m. UTC | #1
On Tue, Apr 21, 2020 at 7:28 AM <mhorne at freebsd.org> wrote:
>
> From: Mitchell Horne <mhorne at FreeBSD.org>
>
> search_hint is defined in assembly as a .long, and is intended to hold
> the initial stack pointer as a hint to the api_search_sig() routine.
> Convert this to a uintptr_t, to avoid possible truncation on 64-bit
> systems.
>
> Signed-off-by: Mitchell Horne <mhorne at FreeBSD.org>
> ---
>  examples/api/glue.c | 6 +++---
>  examples/api/glue.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
diff mbox series

Patch

diff --git a/examples/api/glue.c b/examples/api/glue.c
index 91d13157a1..c223306319 100644
--- a/examples/api/glue.c
+++ b/examples/api/glue.c
@@ -42,8 +42,8 @@  static int valid_sig(struct api_signature *sig)
 int api_search_sig(struct api_signature **sig)
 {
 	unsigned char *sp;
-	uint32_t search_start = 0;
-	uint32_t search_end = 0;
+	uintptr_t search_start = 0;
+	uintptr_t search_end = 0;
 
 	if (sig == NULL)
 		return 0;
@@ -51,7 +51,7 @@  int api_search_sig(struct api_signature **sig)
 	if (search_hint == 0)
 		search_hint = 255 * 1024 * 1024;
 
-	search_start = search_hint & ~0x000fffff;
+	search_start = search_hint & ~0xffffful;
 	search_end = search_start + API_SEARCH_LEN - API_SIG_MAGLEN;
 
 	sp = (unsigned char *)search_start;
diff --git a/examples/api/glue.h b/examples/api/glue.h
index f9745604b6..dd662fc872 100644
--- a/examples/api/glue.h
+++ b/examples/api/glue.h
@@ -18,7 +18,7 @@ 
 #define UB_MAX_DEV	6	/* max devices number */
 
 extern void *syscall_ptr;
-extern uint32_t search_hint;
+extern unsigned long search_hint;
 
 int	syscall(int, int *, ...);
 int	api_search_sig(struct api_signature **sig);