27
27
extern void arm_core_mpu_disable (void );
28
28
#endif
29
29
30
+ #if defined(CONFIG_CPU_AARCH32_CORTEX_R ) || defined(CONFIG_CPU_AARCH32_CORTEX_A )
31
+ #define PERMISSION_EXCEPTION K_ERR_ARM_PERMISSION_FAULT
32
+ #elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE )
33
+ #define PERMISSION_EXCEPTION K_ERR_ARM_MEM_DATA_ACCESS
34
+ #else
35
+ #define PERMISSION_EXCEPTION K_ERR_CPU_EXCEPTION
36
+ #endif
37
+
30
38
#define INFO (fmt , ...) printk(fmt, ##__VA_ARGS__)
31
39
#define PIPE_LEN 1
32
40
#define BYTES_TO_READ_WRITE 1
@@ -151,7 +159,11 @@ ZTEST_USER(userspace, test_write_control)
151
159
#else
152
160
uint32_t val ;
153
161
162
+ #if defined(CONFIG_CPU_AARCH32_CORTEX_R ) || defined(CONFIG_CPU_AARCH32_CORTEX_A )
163
+ set_fault (K_ERR_ARM_UNDEFINED_INSTRUCTION );
164
+ #else
154
165
set_fault (K_ERR_CPU_EXCEPTION );
166
+ #endif
155
167
156
168
val = __get_SCTLR ();
157
169
val |= SCTLR_DZ_Msk ;
@@ -218,7 +230,13 @@ ZTEST_USER(userspace, test_disable_mmu_mpu)
218
230
219
231
#elif defined(CONFIG_ARM )
220
232
#ifndef CONFIG_TRUSTED_EXECUTION_NONSECURE
233
+ #if defined(CONFIG_CPU_AARCH32_CORTEX_R ) || defined(CONFIG_CPU_AARCH32_CORTEX_A )
234
+ set_fault (K_ERR_ARM_UNDEFINED_INSTRUCTION );
235
+ #elif defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE )
236
+ set_fault (K_ERR_ARM_BUS_PRECISE_DATA_BUS );
237
+ #else
221
238
set_fault (K_ERR_CPU_EXCEPTION );
239
+ #endif
222
240
223
241
arm_core_mpu_disable ();
224
242
#else
@@ -258,7 +276,7 @@ ZTEST_USER(userspace, test_read_kernram)
258
276
/* Try to read from kernel RAM. */
259
277
void * p ;
260
278
261
- set_fault (K_ERR_CPU_EXCEPTION );
279
+ set_fault (PERMISSION_EXCEPTION );
262
280
263
281
p = _current -> init_data ;
264
282
printk ("%p\n" , p );
@@ -273,7 +291,7 @@ ZTEST_USER(userspace, test_read_kernram)
273
291
ZTEST_USER (userspace , test_write_kernram )
274
292
{
275
293
/* Try to write to kernel RAM. */
276
- set_fault (K_ERR_CPU_EXCEPTION );
294
+ set_fault (PERMISSION_EXCEPTION );
277
295
278
296
_current -> init_data = NULL ;
279
297
zassert_unreachable ("Write to kernel RAM did not fault" );
@@ -308,7 +326,7 @@ ZTEST_USER(userspace, test_write_kernro)
308
326
zassert_true (in_rodata ,
309
327
"_k_neg_eagain is not in rodata" );
310
328
311
- set_fault (K_ERR_CPU_EXCEPTION );
329
+ set_fault (PERMISSION_EXCEPTION );
312
330
313
331
_k_neg_eagain = - EINVAL ;
314
332
zassert_unreachable ("Write to kernel RO did not fault" );
@@ -322,7 +340,7 @@ ZTEST_USER(userspace, test_write_kernro)
322
340
ZTEST_USER (userspace , test_write_kerntext )
323
341
{
324
342
/* Try to write to kernel text. */
325
- set_fault (K_ERR_CPU_EXCEPTION );
343
+ set_fault (PERMISSION_EXCEPTION );
326
344
327
345
memset (& z_is_thread_essential , 0 , 4 );
328
346
zassert_unreachable ("Write to kernel text did not fault" );
@@ -337,7 +355,7 @@ static int kernel_data;
337
355
*/
338
356
ZTEST_USER (userspace , test_read_kernel_data )
339
357
{
340
- set_fault (K_ERR_CPU_EXCEPTION );
358
+ set_fault (PERMISSION_EXCEPTION );
341
359
342
360
printk ("%d\n" , kernel_data );
343
361
zassert_unreachable ("Read from data did not fault" );
@@ -350,7 +368,7 @@ ZTEST_USER(userspace, test_read_kernel_data)
350
368
*/
351
369
ZTEST_USER (userspace , test_write_kernel_data )
352
370
{
353
- set_fault (K_ERR_CPU_EXCEPTION );
371
+ set_fault (PERMISSION_EXCEPTION );
354
372
355
373
kernel_data = 1 ;
356
374
zassert_unreachable ("Write to data did not fault" );
@@ -383,7 +401,7 @@ ZTEST_USER(userspace, test_read_priv_stack)
383
401
#else
384
402
#error "Not implemented for this architecture"
385
403
#endif
386
- set_fault (K_ERR_CPU_EXCEPTION );
404
+ set_fault (PERMISSION_EXCEPTION );
387
405
388
406
printk ("%c\n" , * priv_stack_ptr );
389
407
zassert_unreachable ("Read from privileged stack did not fault" );
@@ -407,7 +425,7 @@ ZTEST_USER(userspace, test_write_priv_stack)
407
425
#else
408
426
#error "Not implemented for this architecture"
409
427
#endif
410
- set_fault (K_ERR_CPU_EXCEPTION );
428
+ set_fault (PERMISSION_EXCEPTION );
411
429
412
430
* priv_stack_ptr = 42 ;
413
431
zassert_unreachable ("Write to privileged stack did not fault" );
@@ -472,7 +490,7 @@ static void uthread_read_body(void *p1, void *p2, void *p3)
472
490
{
473
491
unsigned int * vptr = p1 ;
474
492
475
- set_fault (K_ERR_CPU_EXCEPTION );
493
+ set_fault (PERMISSION_EXCEPTION );
476
494
printk ("%u\n" , * vptr );
477
495
zassert_unreachable ("Read from other thread stack did not fault" );
478
496
}
@@ -481,7 +499,7 @@ static void uthread_write_body(void *p1, void *p2, void *p3)
481
499
{
482
500
unsigned int * vptr = p1 ;
483
501
484
- set_fault (K_ERR_CPU_EXCEPTION );
502
+ set_fault (PERMISSION_EXCEPTION );
485
503
* vptr = 2U ;
486
504
zassert_unreachable ("Write to other thread stack did not fault" );
487
505
}
@@ -691,7 +709,7 @@ ZTEST(userspace_domain, test_1st_init_and_access_other_memdomain)
691
709
* contains default_bool. This should fault when we try to write it.
692
710
*/
693
711
k_mem_domain_add_thread (& alternate_domain , k_current_get ());
694
- set_fault (K_ERR_CPU_EXCEPTION );
712
+ set_fault (PERMISSION_EXCEPTION );
695
713
spawn_user (& default_bool );
696
714
}
697
715
@@ -742,7 +760,7 @@ ZTEST(userspace_domain, test_domain_remove_part_drop_to_user)
742
760
/* We added alt_part to the default domain in the previous test,
743
761
* remove it, and then try to access again.
744
762
*/
745
- set_fault (K_ERR_CPU_EXCEPTION );
763
+ set_fault (PERMISSION_EXCEPTION );
746
764
747
765
zassert_equal (
748
766
k_mem_domain_remove_partition (& k_mem_domain_default , & alt_part ),
@@ -792,7 +810,7 @@ ZTEST(userspace_domain_ctx, test_domain_remove_part_context_switch)
792
810
/* We added alt_part to the default domain in the previous test,
793
811
* remove it, and then try to access again.
794
812
*/
795
- set_fault (K_ERR_CPU_EXCEPTION );
813
+ set_fault (PERMISSION_EXCEPTION );
796
814
797
815
zassert_equal (
798
816
k_mem_domain_remove_partition (& k_mem_domain_default , & alt_part ),
0 commit comments