Print this page
OS-4514 [lx] SIGEV_THREAD_ID emulation needed


 973                 id_t s_tid;
 974 
 975                 if ((pid_t)arg1 == 1) {
 976                         s_pid = p->p_zone->zone_proc_initpid;
 977                         /* handle the dead/missing init(1M) case */
 978                         if (s_pid == -1)
 979                                 s_pid = 1;
 980                         s_tid = 1;
 981                 } else if (lx_lpid_to_spair((pid_t)arg1, &s_pid, &s_tid) < 0) {
 982                         return (ESRCH);
 983                 }
 984 
 985                 if (copyout(&s_pid, (void *)arg2, sizeof (s_pid)) != 0 ||
 986                     copyout(&s_tid, (void *)arg3, sizeof (s_tid)) != 0) {
 987                         return (EFAULT);
 988                 }
 989 
 990                 return (0);
 991         }
 992 























































 993         case B_SET_AFFINITY_MASK:
 994         case B_GET_AFFINITY_MASK:
 995                 /*
 996                  * Retrieve or store the CPU affinity mask for the
 997                  * requested linux pid.
 998                  *
 999                  * arg1 is a linux PID (0 means curthread).
1000                  * arg2 is the size of the given mask.
1001                  * arg3 is the address of the affinity mask.
1002                  */
1003                 return (lx_sched_affinity(cmd, arg1, arg2, arg3, rval));
1004 
1005         case B_PTRACE_STOP_FOR_OPT:
1006                 return (lx_ptrace_stop_for_option((int)arg1, arg2 == 0 ?
1007                     B_FALSE : B_TRUE, (ulong_t)arg3, arg4));
1008 
1009         case B_PTRACE_CLONE_BEGIN:
1010                 return (lx_ptrace_set_clone_inherit((int)arg1, arg2 == 0 ?
1011                     B_FALSE : B_TRUE));
1012 




 973                 id_t s_tid;
 974 
 975                 if ((pid_t)arg1 == 1) {
 976                         s_pid = p->p_zone->zone_proc_initpid;
 977                         /* handle the dead/missing init(1M) case */
 978                         if (s_pid == -1)
 979                                 s_pid = 1;
 980                         s_tid = 1;
 981                 } else if (lx_lpid_to_spair((pid_t)arg1, &s_pid, &s_tid) < 0) {
 982                         return (ESRCH);
 983                 }
 984 
 985                 if (copyout(&s_pid, (void *)arg2, sizeof (s_pid)) != 0 ||
 986                     copyout(&s_tid, (void *)arg3, sizeof (s_tid)) != 0) {
 987                         return (EFAULT);
 988                 }
 989 
 990                 return (0);
 991         }
 992 
 993         case B_SIGEV_THREAD_ID: {
 994                 /*
 995                  * Emulate Linux's timer_create(2) SIGEV_THREAD_ID
 996                  * notification method. This mechanism is only meant
 997                  * for userland threading libraries such as glibc and
 998                  * is documented as such. Therefore, assume this is
 999                  * only ever invoked for the purpose of alerting a
1000                  * Linux threading library. Assume that the tid is a
1001                  * member of the caller's process and the signal
1002                  * number is valid. See lx_sigev_thread_id() for the
1003                  * userland side of this emulation.
1004                  *
1005                  * The return code from this function is not checked
1006                  * by the caller since it executes in an asynchronous
1007                  * context and there is nothing much to be done. If
1008                  * this function does fail then it will manifest as
1009                  * Linux threads waiting for a signal they will never
1010                  * receive.
1011                  *
1012                  * arg1 -- Linux tid
1013                  * arg2 -- Linux signal number
1014                  * arg3 -- union sigval
1015                  */
1016 
1017                 int native_sig = lx_ltos_signo((int)arg2, 0);
1018                 pid_t native_pid;
1019                 int native_tid;
1020                 sigqueue_t *sqp;
1021 
1022                 if (native_sig == 0)
1023                         return (EINVAL);
1024 
1025                 lx_lpid_to_spair((pid_t)arg1, &native_pid, &native_tid);
1026                 sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP);
1027                 mutex_enter(&curproc->p_lock);
1028 
1029                 if ((t = idtot(curproc, native_tid)) == NULL) {
1030                         mutex_exit(&curproc->p_lock);
1031                         kmem_free(sqp, sizeof (sigqueue_t));
1032                         return (ESRCH);
1033                 }
1034 
1035                 sqp->sq_info.si_signo = native_sig;
1036                 sqp->sq_info.si_code = SI_TIMER;
1037                 sqp->sq_info.si_pid = curproc->p_pid;
1038                 sqp->sq_info.si_zoneid = getzoneid();
1039                 sqp->sq_info.si_uid = crgetruid(CRED());
1040                 sqp->sq_info.si_value.sival_ptr = (void *)arg3;
1041                 sigaddqa(curproc, t, sqp);
1042 
1043                 mutex_exit(&curproc->p_lock);
1044 
1045                 return (0);
1046         }
1047 
1048         case B_SET_AFFINITY_MASK:
1049         case B_GET_AFFINITY_MASK:
1050                 /*
1051                  * Retrieve or store the CPU affinity mask for the
1052                  * requested linux pid.
1053                  *
1054                  * arg1 is a linux PID (0 means curthread).
1055                  * arg2 is the size of the given mask.
1056                  * arg3 is the address of the affinity mask.
1057                  */
1058                 return (lx_sched_affinity(cmd, arg1, arg2, arg3, rval));
1059 
1060         case B_PTRACE_STOP_FOR_OPT:
1061                 return (lx_ptrace_stop_for_option((int)arg1, arg2 == 0 ?
1062                     B_FALSE : B_TRUE, (ulong_t)arg3, arg4));
1063 
1064         case B_PTRACE_CLONE_BEGIN:
1065                 return (lx_ptrace_set_clone_inherit((int)arg1, arg2 == 0 ?
1066                     B_FALSE : B_TRUE));
1067