Skip to content

Commit 69d47c1

Browse files
Andrew Boieandrewboie
authored andcommitted
tests: mem_protect: don't cast pointers to u32_t
Use uintptr_t instead. Fixes some 64-bit issues. Signed-off-by: Andrew Boie <[email protected]>
1 parent dfab6ef commit 69d47c1

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

tests/kernel/mem_protect/mem_protect/src/kobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void test_thread_without_kobject_permission(void *p1, void *p2, void *p3)
129129
void kobject_user_test4(void *p1, void *p2, void *p3)
130130
{
131131
/* should cause a fault */
132-
if ((u32_t)p1 == 1U) {
132+
if ((uintptr_t)p1 == 1U) {
133133
valid_fault = false;
134134
} else {
135135
valid_fault = true;

tests/kernel/mem_protect/mem_protect/src/mem_domain.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static inline void set_valid_fault_value(int test_case_number)
9191
/* Userspace function */
9292
void mem_domain_for_user(void *tc_number, void *p2, void *p3)
9393
{
94-
set_valid_fault_value((u32_t)tc_number);
94+
set_valid_fault_value((uintptr_t)tc_number);
9595

9696
mem_domain_buf[0] = 10U;
9797
if (valid_fault == false) {
@@ -104,7 +104,7 @@ void mem_domain_for_user(void *tc_number, void *p2, void *p3)
104104

105105
void mem_domain_test_1(void *tc_number, void *p2, void *p3)
106106
{
107-
if ((u32_t)tc_number == 1U) {
107+
if ((uintptr_t)tc_number == 1U) {
108108
mem_domain_buf[0] = 10U;
109109
k_mem_domain_remove_thread(k_current_get());
110110
k_mem_domain_add_thread(&mem_domain_mem_domain,
@@ -125,7 +125,7 @@ void mem_domain_test_1(void *tc_number, void *p2, void *p3)
125125
*/
126126
void test_mem_domain_valid_access(void *p1, void *p2, void *p3)
127127
{
128-
u32_t tc_number = 1U;
128+
uintptr_t tc_number = 1U;
129129

130130
mem_domain_init();
131131

@@ -151,7 +151,7 @@ void test_mem_domain_valid_access(void *p1, void *p2, void *p3)
151151
*/
152152
void test_mem_domain_invalid_access(void *p1, void *p2, void *p3)
153153
{
154-
u32_t tc_number = 2U;
154+
uintptr_t tc_number = 2U;
155155

156156
k_thread_create(&mem_domain_2_tid,
157157
mem_domain_2_stack,
@@ -325,16 +325,17 @@ struct k_mem_domain mem_domain_tc3_mem_domain;
325325

326326
void mem_domain_for_user_tc3(void *max_partitions, void *p2, void *p3)
327327
{
328-
u32_t index;
328+
uintptr_t index;
329329

330330
valid_fault = true;
331331
USERSPACE_BARRIER;
332332

333333
/* fault should be hit on the first index itself. */
334334
for (index = 0U;
335-
(index < (u32_t)max_partitions) && (index < 8);
335+
(index < (uintptr_t)max_partitions) && (index < 8);
336336
index++) {
337-
*(u32_t *)mem_domain_tc3_partition_array[index]->start = 10U;
337+
*(uintptr_t *)mem_domain_tc3_partition_array[index]->start =
338+
10U;
338339
}
339340

340341
zassert_unreachable(ERROR_STR);
@@ -387,7 +388,7 @@ void test_mem_domain_add_partitions_invalid(void *p1, void *p2, void *p3)
387388
k_current_get());
388389

389390
k_thread_user_mode_enter(mem_domain_for_user_tc3,
390-
(void *)(u32_t)max_partitions,
391+
(void *)(uintptr_t)max_partitions,
391392
NULL,
392393
NULL);
393394

@@ -396,13 +397,14 @@ void test_mem_domain_add_partitions_invalid(void *p1, void *p2, void *p3)
396397
/****************************************************************************/
397398
void mem_domain_for_user_tc4(void *max_partitions, void *p2, void *p3)
398399
{
399-
u32_t index;
400+
uintptr_t index;
400401

401402
valid_fault = false;
402403
USERSPACE_BARRIER;
403404

404-
for (index = 0U; (index < (u32_t)p2) && (index < 8); index++) {
405-
*(u32_t *)mem_domain_tc3_partition_array[index]->start = 10U;
405+
for (index = 0U; (index < (uintptr_t)p2) && (index < 8); index++) {
406+
*(uintptr_t *)mem_domain_tc3_partition_array[index]->start =
407+
10U;
406408
}
407409

408410
ztest_test_pass();
@@ -439,7 +441,7 @@ void test_mem_domain_add_partitions_simple(void *p1, void *p2, void *p3)
439441
k_current_get());
440442

441443
k_thread_user_mode_enter(mem_domain_for_user_tc4,
442-
(void *)(u32_t)max_partitions,
444+
(void *)(uintptr_t)max_partitions,
443445
NULL,
444446
NULL);
445447

0 commit comments

Comments
 (0)