Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions arch/x86/core/x86_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,11 +937,11 @@ static void apply_mem_partition(struct x86_page_tables *ptables,
}

__ASSERT(partition->start >= DT_PHYS_RAM_ADDR,
"region at %08lx[%u] extends below system ram start 0x%08x",
"region at %08lx[%zu] extends below system ram start 0x%08x",
partition->start, partition->size, DT_PHYS_RAM_ADDR);
__ASSERT(((partition->start + partition->size) <=
(DT_PHYS_RAM_ADDR + (DT_RAM_SIZE * 1024U))),
"region at %08lx[%u] end at %08lx extends beyond system ram end 0x%08x",
"region at %08lx[%zu] end at %08lx extends beyond system ram end 0x%08x",
partition->start, partition->size,
partition->start + partition->size,
(DT_PHYS_RAM_ADDR + (DT_RAM_SIZE * 1024U)));
Expand Down
4 changes: 2 additions & 2 deletions include/app_memory/app_memdomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ struct z_app_region {
extern char Z_APP_START(name)[]; \
extern char Z_APP_SIZE(name)[]; \
struct k_mem_partition name = { \
.start = (u32_t) &Z_APP_START(name), \
.size = (u32_t) &Z_APP_SIZE(name), \
.start = (uintptr_t) &Z_APP_START(name), \
.size = (size_t) &Z_APP_SIZE(name), \
.attr = K_MEM_PARTITION_P_RW_U_RW \
}; \
extern char Z_APP_BSS_START(name)[]; \
Expand Down
12 changes: 6 additions & 6 deletions include/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ enum k_objects {
/* Table generated by gperf, these objects are retrieved via
* z_object_find() */
struct _k_object {
char *name;
void *name;
u8_t perms[CONFIG_MAX_THREAD_BYTES];
u8_t type;
u8_t flags;
u32_t data;
uintptr_t data;
} __packed __aligned(4);

struct _k_object_assignment {
Expand Down Expand Up @@ -516,7 +516,7 @@ struct _thread_stack_info {
* the size of the actual area, starting from the start member,
* that should be writable by the thread
*/
u32_t size;
size_t size;
};

typedef struct _thread_stack_info _thread_stack_info_t;
Expand Down Expand Up @@ -4973,7 +4973,7 @@ extern void z_timer_expiration_handler(struct _timeout *t);
#define K_THREAD_STACK_LEN(size) ARCH_THREAD_STACK_LEN(size)
#define K_THREAD_STACK_MEMBER(sym, size) ARCH_THREAD_STACK_MEMBER(sym, size)
#define K_THREAD_STACK_SIZEOF(sym) ARCH_THREAD_STACK_SIZEOF(sym)
#define K_THREAD_STACK_RESERVED ARCH_THREAD_STACK_RESERVED
#define K_THREAD_STACK_RESERVED ((size_t)ARCH_THREAD_STACK_RESERVED)
static inline char *Z_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
{
return ARCH_THREAD_STACK_BUFFER(sym);
Expand Down Expand Up @@ -5082,7 +5082,7 @@ static inline char *Z_THREAD_STACK_BUFFER(k_thread_stack_t *sym)
* the stack object, and does not account for additional space used due to
* enforce alignment.
*/
#define K_THREAD_STACK_RESERVED 0
#define K_THREAD_STACK_RESERVED ((size_t)0U)

/**
* @brief Get a pointer to the physical stack buffer
Expand Down Expand Up @@ -5128,7 +5128,7 @@ struct k_mem_partition {
/** start address of memory partition */
uintptr_t start;
/** size of memory partition */
u32_t size;
size_t size;
#if defined(CONFIG_MEMORY_PROTECTION)
/** attribute of memory partition */
k_mem_partition_attr_t attr;
Expand Down
16 changes: 8 additions & 8 deletions include/syscall_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ extern int z_user_string_copy(char *dst, const char *src, size_t maxlen);
#define Z_SYSCALL_MEMORY(ptr, size, write) \
Z_SYSCALL_VERIFY_MSG(arch_buffer_validate((void *)ptr, size, write) \
== 0, \
"Memory region %p (size %u) %s access denied", \
(void *)(ptr), (u32_t)(size), \
"Memory region %p (size %zu) %s access denied", \
(void *)(ptr), (size_t)(size), \
write ? "write" : "read")

/**
Expand Down Expand Up @@ -354,12 +354,12 @@ extern int z_user_string_copy(char *dst, const char *src, size_t maxlen);

#define Z_SYSCALL_MEMORY_ARRAY(ptr, nmemb, size, write) \
({ \
u32_t product; \
Z_SYSCALL_VERIFY_MSG(!u32_mul_overflow((u32_t)(nmemb), \
(u32_t)(size), \
&product), \
"%ux%u array is too large", \
(u32_t)(nmemb), (u32_t)(size)) || \
size_t product; \
Z_SYSCALL_VERIFY_MSG(!size_mul_overflow((size_t)(nmemb), \
(size_t)(size), \
&product), \
"%zux%zu array is too large", \
(size_t)(nmemb), (size_t)(size)) || \
Z_SYSCALL_MEMORY(ptr, product, write); \
})

Expand Down
4 changes: 2 additions & 2 deletions kernel/mem_domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void k_mem_domain_init(struct k_mem_domain *domain, u8_t num_parts,
__ASSERT(parts[i] != NULL, "");
__ASSERT((parts[i]->start + parts[i]->size) >
parts[i]->start,
"invalid partition %p size %d",
"invalid partition %p size %zu",
parts[i], parts[i]->size);

#if defined(CONFIG_EXECUTE_XOR_WRITE) || \
Expand Down Expand Up @@ -151,7 +151,7 @@ void k_mem_domain_add_partition(struct k_mem_domain *domain,
__ASSERT(domain != NULL, "");
__ASSERT(part != NULL, "");
__ASSERT((part->start + part->size) > part->start,
"invalid partition %p size %d", part, part->size);
"invalid partition %p size %zu", part, part->size);

#if defined(CONFIG_EXECUTE_XOR_WRITE) || \
defined(CONFIG_MPU_REQUIRES_NON_OVERLAPPING_REGIONS)
Expand Down
12 changes: 6 additions & 6 deletions kernel/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread,
void *p1, void *p2, void *p3,
int prio, u32_t options, s32_t delay)
{
u32_t total_size;
size_t total_size;
struct _k_object *stack_object;

/* The thread and stack objects *must* be in an uninitialized state */
Expand All @@ -613,17 +613,17 @@ k_tid_t z_vrfy_k_thread_create(struct k_thread *new_thread,
/* Verify that the stack size passed in is OK by computing the total
* size and comparing it with the size value in the object metadata
*/
Z_OOPS(Z_SYSCALL_VERIFY_MSG(!u32_add_overflow(K_THREAD_STACK_RESERVED,
stack_size, &total_size),
"stack size overflow (%u+%u)",
(unsigned int) stack_size,
Z_OOPS(Z_SYSCALL_VERIFY_MSG(!size_add_overflow(K_THREAD_STACK_RESERVED,
stack_size, &total_size),
"stack size overflow (%zu+%zu)",
stack_size,
K_THREAD_STACK_RESERVED));

/* Testing less-than-or-equal since additional room may have been
* allocated for alignment constraints
*/
Z_OOPS(Z_SYSCALL_VERIFY_MSG(total_size <= stack_object->data,
"stack size %u is too big, max is %u",
"stack size %zu is too big, max is %lu",
total_size, stack_object->data));

/* User threads may only create other user threads and they can't
Expand Down
12 changes: 6 additions & 6 deletions kernel/userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static struct dyn_obj *dyn_object_find(void *obj)
*
* @return true if successful, false if failed
**/
static bool thread_idx_alloc(u32_t *tidx)
static bool thread_idx_alloc(uintptr_t *tidx)
{
int i;
int idx;
Expand Down Expand Up @@ -225,7 +225,7 @@ static bool thread_idx_alloc(u32_t *tidx)
*
* @param tidx The thread index to be freed
**/
static void thread_idx_free(u32_t tidx)
static void thread_idx_free(uintptr_t tidx)
{
/* To prevent leaked permission when index is recycled */
z_object_wordlist_foreach(clear_perms_cb, (void *)tidx);
Expand All @@ -236,7 +236,7 @@ static void thread_idx_free(u32_t tidx)
void *z_impl_k_object_alloc(enum k_objects otype)
{
struct dyn_obj *dyn_obj;
u32_t tidx;
uintptr_t tidx;

/* Stacks are not supported, we don't yet have mem pool APIs
* to request memory that is aligned
Expand Down Expand Up @@ -353,7 +353,7 @@ static int thread_index_get(struct k_thread *t)
return ko->data;
}

static void unref_check(struct _k_object *ko, int index)
static void unref_check(struct _k_object *ko, uintptr_t index)
{
k_spinlock_key_t key = k_spin_lock(&obj_lock);

Expand Down Expand Up @@ -445,14 +445,14 @@ void z_thread_perms_clear(struct _k_object *ko, struct k_thread *thread)

static void clear_perms_cb(struct _k_object *ko, void *ctx_ptr)
{
int id = (int)ctx_ptr;
uintptr_t id = (uintptr_t)ctx_ptr;

unref_check(ko, id);
}

void z_thread_perms_all_clear(struct k_thread *thread)
{
int index = thread_index_get(thread);
uintptr_t index = thread_index_get(thread);

if (index != -1) {
z_object_wordlist_foreach(clear_perms_cb, (void *)index);
Expand Down
6 changes: 3 additions & 3 deletions lib/os/mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static struct k_mutex *get_k_mutex(struct sys_mutex *mutex)
return (struct k_mutex *)obj->data;
}

static bool check_sys_mutex_addr(u32_t addr)
static bool check_sys_mutex_addr(struct sys_mutex *addr)
{
/* sys_mutex memory is never touched, just used to lookup the
* underlying k_mutex, but we don't want threads using mutexes
Expand All @@ -44,7 +44,7 @@ int z_impl_z_sys_mutex_kernel_lock(struct sys_mutex *mutex, s32_t timeout)
static inline int z_vrfy_z_sys_mutex_kernel_lock(struct sys_mutex *mutex,
s32_t timeout)
{
if (check_sys_mutex_addr((u32_t) mutex)) {
if (check_sys_mutex_addr(mutex)) {
return -EACCES;
}

Expand All @@ -70,7 +70,7 @@ int z_impl_z_sys_mutex_kernel_unlock(struct sys_mutex *mutex)

static inline int z_vrfy_z_sys_mutex_kernel_unlock(struct sys_mutex *mutex)
{
if (check_sys_mutex_addr((u32_t) mutex)) {
if (check_sys_mutex_addr(mutex)) {
return -EACCES;
}

Expand Down
6 changes: 3 additions & 3 deletions samples/userspace/shared_mem/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void main(void)
K_FOREVER);
k_thread_access_grant(tENC, &allforone);
/* use K_FOREVER followed by k_thread_start*/
printk("ENC Thread Created %08X\n", (unsigned int) tENC);
printk("ENC Thread Created %p\n", tENC);
k_mem_domain_init(&dom1, 3, dom1_parts);
printk("Partitions added to dom1\n");
k_mem_domain_add_thread(&dom1, tENC);
Expand All @@ -128,7 +128,7 @@ void main(void)
-1, K_USER,
K_FOREVER);
k_thread_access_grant(tPT, &allforone);
printk("PT Thread Created %08X\n", (unsigned int) tPT);
printk("PT Thread Created %p\n", tPT);
k_mem_domain_init(&dom0, 2, dom0_parts);
k_mem_domain_add_thread(&dom0, tPT);
printk("dom0 Created\n");
Expand All @@ -138,7 +138,7 @@ void main(void)
-1, K_USER,
K_FOREVER);
k_thread_access_grant(tCT, &allforone);
printk("CT Thread Created %08X\n", (unsigned int) tCT);
printk("CT Thread Created %p\n", tCT);
k_mem_domain_init(&dom2, 2, dom2_parts);
k_mem_domain_add_thread(&dom2, tCT);
printk("dom2 Created\n");
Expand Down
24 changes: 19 additions & 5 deletions scripts/elf_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def __init__(self, type_obj, addr):
self.data = thread_counter
thread_counter = thread_counter + 1
elif self.type_obj.name == "sys_mutex":
self.data = "(u32_t)(&kernel_mutexes[%d])" % sys_mutex_counter
self.data = "(uintptr_t)(&kernel_mutexes[%d])" % sys_mutex_counter
sys_mutex_counter += 1
elif self.type_obj.name == "k_futex":
self.data = "(u32_t)(&futex_data[%d])" % futex_counter
self.data = "(uintptr_t)(&futex_data[%d])" % futex_counter
futex_counter += 1
else:
self.data = 0
Expand Down Expand Up @@ -353,6 +353,19 @@ def analyze_typedef(die):
type_env[die.offset] = type_env[type_offset]


def unpack_pointer(elf, data, offset):
endian_code = "<" if elf.little_endian else ">"
if elf.elfclass == 32:
size_code = "I"
size = 4
else:
size_code = "Q"
size = 8

return struct.unpack(endian_code + size_code,
data[offset:offset + size])[0]


def addr_deref(elf, addr):
for section in elf.iter_sections():
start = section['sh_addr']
Expand All @@ -361,14 +374,15 @@ def addr_deref(elf, addr):
if start <= addr < end:
data = section.data()
offset = addr - start
return struct.unpack("<I" if elf.little_endian else ">I",
data[offset:offset + 4])[0]
return unpack_pointer(elf, data, offset)

return 0


def device_get_api_addr(elf, addr):
return addr_deref(elf, addr + 4)
# Read device->driver API
offset = 4 if elf.elfclass == 32 else 8
return addr_deref(elf, addr + offset)


def get_filename_lineno(die):
Expand Down
12 changes: 11 additions & 1 deletion scripts/gen_kobject_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,17 @@ def write_gperf_table(fp, eh, objs, static_begin, static_end):
initialized = static_begin <= obj_addr < static_end
is_driver = obj_type.startswith("K_OBJ_DRIVER_")

byte_str = struct.pack("<I" if eh.little_endian else ">I", obj_addr)
if "CONFIG_64BIT" in syms:
format_code = "Q"
else:
format_code = "I"

if eh.little_endian:
endian = "<"
else:
endian = ">"

byte_str = struct.pack(endian + format_code, obj_addr)
fp.write("\"")
for byte in byte_str:
val = "\\x%02x" % byte
Expand Down
10 changes: 5 additions & 5 deletions scripts/process_gperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def reformat_str(match_obj):

# Nip quotes
addr_str = addr_str[1:-1]
addr_vals = [0, 0, 0, 0]
ctr = 3
addr_vals = [0, 0, 0, 0, 0, 0, 0 , 0]
ctr = 7
i = 0

while True:
Expand All @@ -74,7 +74,7 @@ def reformat_str(match_obj):

ctr -= 1

return "(char *)0x%02x%02x%02x%02x" % tuple(addr_vals)
return "(char *)0x%02x%02x%02x%02x%02x%02x%02x%02x" % tuple(addr_vals)


def process_line(line, fp):
Expand All @@ -97,9 +97,9 @@ def process_line(line, fp):
warn("gperf %s is not tested, versions %s through %s supported" %
(v, v_lo, v_hi))

# Replace length lookups with constant len of 4 since we're always
# Replace length lookups with constant len since we're always
# looking at pointers
line = re.sub(r'lengthtable\[key\]', r'4', line)
line = re.sub(r'lengthtable\[key\]', r'sizeof(void *)', line)

# Empty wordlist entries to have NULLs instead of ""
line = re.sub(r'[{]["]["][}]', r'{}', line)
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/mem_protect/mem_protect/src/kobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void test_thread_without_kobject_permission(void *p1, void *p2, void *p3)
void kobject_user_test4(void *p1, void *p2, void *p3)
{
/* should cause a fault */
if ((u32_t)p1 == 1U) {
if ((uintptr_t)p1 == 1U) {
valid_fault = false;
} else {
valid_fault = true;
Expand Down
Loading