Changeset 5a5269d in mainline for abi/include/_bits/native.h


Ignore:
Timestamp:
2019-07-02T12:03:55Z (5 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98c4c16
Parents:
aca97582
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-07-02 12:03:55)
git-committer:
GitHub <noreply@…> (2019-07-02 12:03:55)
Message:

Change type of uspace pointers in kernel from pointer type to numeric (#170)

From kernel's perspective, userspace addresses are not valid pointers,
and can only be used in calls to copy_to/from_uspace().
Therefore, we change the type of those arguments and variables to
uspace_addr_t which is an alias for sysarg_t.

This allows the compiler to catch accidental direct accesses to
userspace addresses.

Additionally, to avoid losing the type information in code,
a macro uspace_ptr(type) is used that translates to uspace_addr_t.
I makes no functional difference, but allows keeping the type information
in code in case we implement some sort of static checking for it in the future.

However, ccheck doesn't like that, so instead of using uspace_ptr(char),
we use uspace_ptr_char which is defined as
#define uspace_ptr_char uspace_ptr(char).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abi/include/_bits/native.h

    raca97582 r5a5269d  
    5656typedef intptr_t  native_t;
    5757
     58#ifdef KERNEL
     59
     60typedef sysarg_t uspace_addr_t;
     61/* We might implement a way to check validity of the type some day. */
     62#define uspace_ptr(type) uspace_addr_t
     63#define USPACE_NULL 0
     64
     65#else /* !KERNEL */
     66
     67typedef void *uspace_addr_t;
     68#define uspace_ptr(type) type *
     69
     70#endif
     71
     72// TODO: Put this in a better location.
     73#define uspace_ptr_as_area_info_t uspace_ptr(as_area_info_t)
     74#define uspace_ptr_as_area_pager_info_t uspace_ptr(as_area_pager_info_t)
     75#define uspace_ptr_cap_irq_handle_t uspace_ptr(cap_irq_handle_t)
     76#define uspace_ptr_cap_phone_handle_t uspace_ptr(cap_phone_handle_t)
     77#define uspace_ptr_cap_waitq_handle_t uspace_ptr(cap_waitq_handle_t)
     78#define uspace_ptr_char uspace_ptr(char)
     79#define uspace_ptr_const_char uspace_ptr(const char)
     80#define uspace_ptr_ddi_ioarg_t uspace_ptr(ddi_ioarg_t)
     81#define uspace_ptr_ipc_data_t uspace_ptr(ipc_data_t)
     82#define uspace_ptr_irq_code_t uspace_ptr(irq_code_t)
     83#define uspace_ptr_size_t uspace_ptr(size_t)
     84#define uspace_ptr_struct_uspace_arg uspace_ptr(struct uspace_arg)
     85#define uspace_ptr_sysarg64_t uspace_ptr(sysarg64_t)
     86#define uspace_ptr_task_id_t uspace_ptr(task_id_t)
     87#define uspace_ptr_thread_id_t uspace_ptr(thread_id_t)
     88#define uspace_ptr_uintptr_t uspace_ptr(uintptr_t)
     89#define uspace_ptr_uspace_arg_t uspace_ptr(uspace_arg_t)
     90#define uspace_ptr_uspace_thread_function_t uspace_ptr(uspace_thread_function_t)
     91
    5892__HELENOS_DECLS_END;
    5993
Note: See TracChangeset for help on using the changeset viewer.