···11+/*
22+ * Darling Mach Linux Kernel Module
33+ * Copyright (C) 2015 Lubos Dolezel
44+ *
55+ * This program is free software; you can redistribute it and/or
66+ * modify it under the terms of the GNU General Public License
77+ * as published by the Free Software Foundation; either version 2
88+ * of the License, or (at your option) any later version.
99+ *
1010+ * This program is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+ * GNU General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU General Public License
1616+ * along with this program; if not, write to the Free Software
1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818+ */
1919+2020+#include "../mach_includes.h"
2121+#include "pthread_kill.h"
2222+#include <asm/siginfo.h>
2323+#include <linux/uaccess.h>
2424+#include <asm/siginfo.h>
2525+#include <linux/rcupdate.h>
2626+#include <linux/sched.h>
2727+#include "../servers/thread_act.h"
2828+#include "../ipc_types.h"
2929+#include "../ipc_space.h"
3030+#include "../ipc_right.h"
3131+#include "../darling_task.h"
3232+3333+int pthread_kill_trap(mach_task_t* task,
3434+ struct pthread_kill_args* in_args)
3535+{
3636+ struct pthread_kill_args args;
3737+ darling_mach_port_right_t* right = NULL;
3838+ int ret;
3939+ pid_t tid;
4040+ struct siginfo info;
4141+ struct task_struct *t;
4242+4343+ if (copy_from_user(&args, in_args, sizeof(args)))
4444+ return -EFAULT;
4545+4646+ ipc_space_lock(&task->namespace);
4747+ right = ipc_space_lookup(&task->namespace, args.thread_port);
4848+4949+ ipc_space_unlock(&task->namespace);
5050+ if (right == NULL)
5151+ {
5252+ ret = -EINVAL;
5353+ goto err;
5454+ }
5555+5656+ tid = get_thread_pid(right->port);
5757+ ipc_port_unlock(right->port);
5858+5959+ if (tid == 0)
6060+ {
6161+ // Not a thread port
6262+ ret = -EINVAL;
6363+ goto err;
6464+ }
6565+6666+ rcu_read_lock();
6767+ t = pid_task(find_pid_ns(tid, &init_pid_ns), PIDTYPE_PID);
6868+6969+ if (t == NULL)
7070+ {
7171+ rcu_read_unlock();
7272+ ret = -ESRCH;
7373+ goto err;
7474+ }
7575+7676+ info.si_signo = args.sig;
7777+ info.si_code = SI_TKILL;
7878+ info.si_pid = t->tgid;
7979+ info.si_uid = from_kuid_munged(current_user_ns(), current_uid());
8080+ info.si_errno = 0;
8181+8282+ ret = send_sig_info(args.sig, &info, t);
8383+ rcu_read_unlock();
8484+8585+err:
8686+ return ret;
8787+}
+30
src/lkm/psynch/pthread_kill.h
···11+/*
22+ * Darling Mach Linux Kernel Module
33+ * Copyright (C) 2015 Lubos Dolezel
44+ *
55+ * This program is free software; you can redistribute it and/or
66+ * modify it under the terms of the GNU General Public License
77+ * as published by the Free Software Foundation; either version 2
88+ * of the License, or (at your option) any later version.
99+ *
1010+ * This program is distributed in the hope that it will be useful,
1111+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313+ * GNU General Public License for more details.
1414+ *
1515+ * You should have received a copy of the GNU General Public License
1616+ * along with this program; if not, write to the Free Software
1717+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818+ */
1919+2020+#ifndef PTHREAD_KILL_H
2121+#define PTHREAD_KILL_H
2222+#include "../api.h"
2323+#include "../ipc_types.h"
2424+2525+int pthread_kill_trap(mach_task_t* task,
2626+ struct pthread_kill_args* args);
2727+2828+2929+#endif /* PTHREAD_KILL_H */
3030+