Skip to content

Commit 9ec1c1a

Browse files
carlocaionenashif
authored andcommitted
aarch64: userspace: Introduce arch_user_string_nlen
Introduce the arch_user_string_nlen() assembly routine and the necessary C code bits. Signed-off-by: Carlo Caione <[email protected]> Signed-off-by: Nicolas Pitre <[email protected]>
1 parent a7a3e80 commit 9ec1c1a

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

arch/arm/core/aarch64/fatal.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515

1616
#include <kernel.h>
1717
#include <logging/log.h>
18+
#include <exc_handle.h>
1819

1920
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
2021

22+
#ifdef CONFIG_USERSPACE
23+
Z_EXC_DECLARE(z_arm64_user_string_nlen);
24+
25+
static const struct z_exc_handle exceptions[] = {
26+
Z_EXC_HANDLE(z_arm64_user_string_nlen),
27+
};
28+
#endif /* CONFIG_USERSPACE */
29+
2130
#ifdef CONFIG_EXCEPTION_DEBUG
2231
static void dump_esr(uint64_t esr, bool *dump_far)
2332
{
@@ -168,7 +177,18 @@ static bool is_recoverable(z_arch_esf_t *esf, uint64_t esr, uint64_t far,
168177
if (!esf)
169178
return false;
170179

171-
/* Empty */
180+
#ifdef CONFIG_USERSPACE
181+
for (int i = 0; i < ARRAY_SIZE(exceptions); i++) {
182+
/* Mask out instruction mode */
183+
uint64_t start = (uint64_t)exceptions[i].start;
184+
uint64_t end = (uint64_t)exceptions[i].end;
185+
186+
if (esf->elr >= start && esf->elr < end) {
187+
esf->elr = (uint64_t)(exceptions[i].fixup);
188+
return true;
189+
}
190+
}
191+
#endif
172192

173193
return false;
174194
}

arch/arm/core/aarch64/userspace.S

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@
1313

1414
_ASM_FILE_PROLOGUE
1515

16+
/*
17+
* size_t arch_user_string_nlen(const char *s, size_t maxsize, int *err_arg)
18+
*/
19+
20+
GTEXT(z_arm64_user_string_nlen_fault_start)
21+
GTEXT(z_arm64_user_string_nlen_fault_end)
22+
GTEXT(z_arm64_user_string_nlen_fixup)
23+
24+
GTEXT(arch_user_string_nlen)
25+
SECTION_FUNC(TEXT, arch_user_string_nlen)
26+
27+
mov x3, x0
28+
mov x0, #0
29+
mov x4, #0
30+
31+
strlen_loop:
32+
33+
cmp x0, x1
34+
beq strlen_done
35+
36+
z_arm64_user_string_nlen_fault_start:
37+
ldrb w5, [x3, x0]
38+
z_arm64_user_string_nlen_fault_end:
39+
cbz x5, strlen_done
40+
41+
add x0, x0, #1
42+
b strlen_loop
43+
44+
z_arm64_user_string_nlen_fixup:
45+
mov x4, #-1
46+
mov x0, #0
47+
48+
strlen_done:
49+
str w4, [x2]
50+
ret
51+
1652
/*
1753
* Routine to jump into userspace
1854
*

0 commit comments

Comments
 (0)