Print this page
OS-???? [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                  * arg1 -- Linux tid
1006                  * arg2 -- signal number
1007                  * arg3 -- union sigval
1008                  */
1009 
1010                 proc_t *pp, *cp = curproc;
1011                 int native_sig = ltos_signo[(int)arg2];
1012                 pid_t native_pid;
1013                 int native_tid;
1014                 sigqueue_t *sqp;
1015 
1016                 lx_lpid_to_spair((pid_t)arg1, &native_pid, &native_tid);
1017 
1018                 mutex_enter(&pidlock);
1019                 if (((pp = prfind(native_pid)) == NULL) || (pp->p_stat == SIDL)) {
1020                         mutex_exit(&pidlock);
1021                         return (ESRCH);
1022                 }
1023                 mutex_enter(&pp->p_lock);
1024                 mutex_exit(&pidlock);
1025 
1026                 if ((t = idtot(pp, native_tid)) == NULL) {
1027                         mutex_exit(&pp->p_lock);
1028                         return (ESRCH);
1029                 }
1030 
1031                 sqp = kmem_zalloc(sizeof (sigqueue_t), KM_SLEEP);
1032                 sqp->sq_info.si_signo = native_sig;
1033                 sqp->sq_info.si_code = SI_TIMER;
1034                 sqp->sq_info.si_pid = cp->p_pid;
1035                 sqp->sq_info.si_zoneid = getzoneid();
1036                 sqp->sq_info.si_uid = crgetruid(CRED());
1037                 sqp->sq_info.si_value = (union sigval)((void *)arg3);
1038                 sigaddqa(pp, t, sqp);
1039 
1040                 mutex_exit(&pp->p_lock);
1041                 return (0);
1042         }
1043 
1044         case B_SET_AFFINITY_MASK:
1045         case B_GET_AFFINITY_MASK:
1046                 /*
1047                  * Retrieve or store the CPU affinity mask for the
1048                  * requested linux pid.
1049                  *
1050                  * arg1 is a linux PID (0 means curthread).
1051                  * arg2 is the size of the given mask.
1052                  * arg3 is the address of the affinity mask.
1053                  */
1054                 return (lx_sched_affinity(cmd, arg1, arg2, arg3, rval));
1055 
1056         case B_PTRACE_STOP_FOR_OPT:
1057                 return (lx_ptrace_stop_for_option((int)arg1, arg2 == 0 ?
1058                     B_FALSE : B_TRUE, (ulong_t)arg3, arg4));
1059 
1060         case B_PTRACE_CLONE_BEGIN:
1061                 return (lx_ptrace_set_clone_inherit((int)arg1, arg2 == 0 ?
1062                     B_FALSE : B_TRUE));
1063