Changeset 0016674 in mainline


Ignore:
Timestamp:
2017-12-09T18:04:23Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0722869
Parents:
569a51a
Message:

Properly handle errors in SYS_IPC_KBOX.

Also, merge the separate 32/64-bit versions.
There is no reason to optimize such a function this way.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/ipc/sysipc.h

    r569a51a r0016674  
    5959extern sysarg_t sys_ipc_irq_unsubscribe(sysarg_t);
    6060
    61 #ifdef __32_BITS__
    62 
    63 extern sysarg_t sys_ipc_connect_kbox(sysarg64_t *, cap_handle_t *);
    64 
    65 #endif  /* __32_BITS__ */
    66 
    67 #ifdef __64_BITS__
    68 
    69 extern sysarg_t sys_ipc_connect_kbox(sysarg_t, cap_handle_t *);
    70 
    71 #endif  /* __64_BITS__ */
     61extern sysarg_t sys_ipc_connect_kbox(task_id_t *, cap_handle_t *);
    7262
    7363#endif
  • kernel/generic/src/ipc/kbox.c

    r569a51a r0016674  
    232232        }
    233233       
    234         if (task->kb.finished != false) {
     234        if (task->kb.finished) {
    235235                mutex_unlock(&task->kb.cleanup_lock);
    236236                return EINVAL;
    237237        }
    238238       
     239        /* Create a kbox thread if necessary. */
     240        if (task->kb.thread == NULL) {
     241                thread_t *kb_thread = thread_create(kbox_thread_proc, NULL, task,
     242                    THREAD_FLAG_NONE, "kbox");
     243               
     244                if (!kb_thread) {
     245                        mutex_unlock(&task->kb.cleanup_lock);
     246                        return ENOMEM;
     247                }
     248               
     249                task->kb.thread = kb_thread;
     250                thread_ready(kb_thread);
     251        }
     252       
     253        /* Allocate a new phone. */
    239254        cap_handle_t phone_handle = phone_alloc(TASK);
    240255        if (phone_handle < 0) {
     
    249264        (void) ipc_phone_connect(phone_obj->phone, &task->kb.box);
    250265       
    251         if (task->kb.thread != NULL) {
    252                 mutex_unlock(&task->kb.cleanup_lock);
    253                 *out_phone = phone_handle;
    254                 return EOK;
    255         }
    256        
    257         /* Create a kbox thread */
    258         thread_t *kb_thread = thread_create(kbox_thread_proc, NULL, task,
    259             THREAD_FLAG_NONE, "kbox");
    260         if (!kb_thread) {
    261                 // FIXME: Shouldn't we clean up phone_handle?
    262                 mutex_unlock(&task->kb.cleanup_lock);
    263                 return ENOMEM;
    264         }
    265        
    266         task->kb.thread = kb_thread;
    267         thread_ready(kb_thread);
    268        
    269266        mutex_unlock(&task->kb.cleanup_lock);
    270        
    271267        *out_phone = phone_handle;
    272268        return EOK;
  • kernel/generic/src/ipc/sysipc.c

    r569a51a r0016674  
    897897}
    898898
    899 #ifdef __32_BITS__
    900 
    901 /** Syscall connect to a task by ID (32 bits)
     899/** Syscall connect to a task by ID
    902900 *
    903901 * @return Error code.
    904902 *
    905903 */
    906 sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid, cap_handle_t *uspace_phone)
     904sysarg_t sys_ipc_connect_kbox(task_id_t *uspace_taskid, cap_handle_t *uspace_phone)
    907905{
    908906#ifdef CONFIG_UDEBUG
    909         sysarg64_t taskid;
     907        task_id_t taskid;
    910908        cap_handle_t phone;
    911         int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
     909       
     910        int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(task_id_t));
    912911        if (rc == EOK) {
    913912                rc = ipc_connect_kbox((task_id_t) taskid, &phone);
    914913        }
     914       
    915915        if (rc == EOK) {
    916916                rc = copy_to_uspace(uspace_phone, &phone, sizeof(cap_handle_t));
    917                 // FIXME: Clean up phone on failure.
     917                if (rc != EOK) {
     918                        // Clean up the phone on failure.
     919                        sys_ipc_hangup(phone);
     920                }
    918921        }
    919922       
     
    924927}
    925928
    926 #endif  /* __32_BITS__ */
    927 
    928 #ifdef __64_BITS__
    929 
    930 /** Syscall connect to a task by ID (64 bits)
    931  *
    932  * @return Error code.
    933  *
    934  */
    935 sysarg_t sys_ipc_connect_kbox(sysarg_t taskid, cap_handle_t *uspace_phone)
    936 {
    937 #ifdef CONFIG_UDEBUG
    938         cap_handle_t phone;
    939         int rc = ipc_connect_kbox((task_id_t) taskid, &phone);
    940         if (rc == EOK) {
    941                 rc = copy_to_uspace(uspace_phone, &phone, sizeof(cap_handle_t));
    942         }
    943         return (sysarg_t) rc;
    944 #else
    945         return (sysarg_t) ENOTSUP;
    946 #endif
    947 }
    948 
    949 #endif  /* __64_BITS__ */
    950 
    951929/** @}
    952930 */
  • uspace/lib/c/generic/ipc.c

    r569a51a r0016674  
    379379int ipc_connect_kbox(task_id_t id, cap_handle_t *phone)
    380380{
    381 #ifdef __32_BITS__
    382         sysarg64_t arg = (sysarg64_t) id;
    383         return __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) &arg, (sysarg_t) phone);
    384 #endif
    385 #ifdef __64_BITS__
    386         return __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) id, (sysarg_t) phone);
    387 #endif
     381        return __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) &id, (sysarg_t) phone);
    388382}
    389383
Note: See TracChangeset for help on using the changeset viewer.