Changeset 5a5269d in mainline for kernel/generic/src/ipc/sysipc.c


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
  • kernel/generic/src/ipc/sysipc.c

    raca97582 r5a5269d  
    419419 *
    420420 */
    421 sys_errno_t sys_ipc_call_async_slow(cap_phone_handle_t handle, ipc_data_t *data,
     421sys_errno_t sys_ipc_call_async_slow(cap_phone_handle_t handle, uspace_ptr_ipc_data_t data,
    422422    sysarg_t label)
    423423{
     
    437437        }
    438438
    439         errno_t rc = copy_from_uspace(&call->data.args, &data->args,
     439        errno_t rc = copy_from_uspace(&call->data.args, data + offsetof(ipc_data_t, args),
    440440            sizeof(call->data.args));
    441441        if (rc != EOK) {
     
    623623 */
    624624sys_errno_t sys_ipc_forward_slow(cap_call_handle_t chandle,
    625     cap_phone_handle_t phandle, ipc_data_t *data, unsigned int mode)
     625    cap_phone_handle_t phandle, uspace_ptr_ipc_data_t data, unsigned int mode)
    626626{
    627627        ipc_data_t newdata;
    628         errno_t rc = copy_from_uspace(&newdata.args, &data->args,
     628        errno_t rc = copy_from_uspace(&newdata.args, data + offsetof(ipc_data_t, args),
    629629            sizeof(newdata.args));
    630630        if (rc != EOK)
     
    700700 *
    701701 */
    702 sys_errno_t sys_ipc_answer_slow(cap_call_handle_t chandle, ipc_data_t *data)
     702sys_errno_t sys_ipc_answer_slow(cap_call_handle_t chandle, uspace_ptr_ipc_data_t data)
    703703{
    704704        kobject_t *kobj = cap_unpublish(TASK, chandle, KOBJECT_TYPE_CALL);
     
    718718                saved = false;
    719719
    720         errno_t rc = copy_from_uspace(&call->data.args, &data->args,
     720        errno_t rc = copy_from_uspace(&call->data.args, data + offsetof(ipc_data_t, args),
    721721            sizeof(call->data.args));
    722722        if (rc != EOK) {
     
    766766 * @return An error code on error.
    767767 */
    768 sys_errno_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
     768sys_errno_t sys_ipc_wait_for_call(uspace_ptr_ipc_data_t calldata, uint32_t usec,
    769769    unsigned int flags)
    770770{
     
    888888 */
    889889sys_errno_t sys_ipc_irq_subscribe(inr_t inr, sysarg_t imethod,
    890     irq_code_t *ucode, cap_irq_handle_t *uspace_handle)
     890    uspace_ptr_irq_code_t ucode, uspace_ptr_cap_irq_handle_t uspace_handle)
    891891{
    892892        if (!(perm_get(TASK) & PERM_IRQ_REG))
     
    918918 *
    919919 */
    920 sys_errno_t sys_ipc_connect_kbox(task_id_t *uspace_taskid,
    921     cap_phone_handle_t *uspace_phone)
     920sys_errno_t sys_ipc_connect_kbox(uspace_ptr_task_id_t uspace_taskid,
     921    uspace_ptr_cap_phone_handle_t uspace_phone)
    922922{
    923923#ifdef CONFIG_UDEBUG
Note: See TracChangeset for help on using the changeset viewer.