summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2020-12-07 14:31:02 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2020-12-07 14:31:02 +0100
commitc10e21b491937315a096e3e83840886fd7ba9ae8 (patch)
tree6d1c0cc7e0d3a004db1c55e1070da1fe8ac4ff92
parente45bd6814a125e7a175ff19e23252608a060d847 (diff)
downloadplan9front-c10e21b491937315a096e3e83840886fd7ba9ae8.tar.xz
libthread: reduce stack usage of threadkill*(), open /proc/n/ctl with OCEXEC flag
-rw-r--r--sys/src/libthread/kill.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/sys/src/libthread/kill.c b/sys/src/libthread/kill.c
index 9160df016..e7292437c 100644
--- a/sys/src/libthread/kill.c
+++ b/sys/src/libthread/kill.c
@@ -76,24 +76,31 @@ threadint(int id)
threadxxx(id, 0);
}
-static void
-tinterrupt(Proc *p, Thread *t)
+static int
+writeprocctl(int pid, char *ctl)
{
- char buf[64];
+ char buf[32];
int fd;
+ snprint(buf, sizeof(buf), "/proc/%lud/ctl", (ulong)pid);
+ fd = open(buf, OWRITE|OCEXEC);
+ if(fd < 0)
+ return -1;
+ if(write(fd, ctl, strlen(ctl)) < 0){
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
+
+static void
+tinterrupt(Proc *p, Thread *t)
+{
switch(t->state){
case Running:
- snprint(buf, sizeof(buf), "/proc/%d/ctl", p->pid);
- fd = open(buf, OWRITE|OCEXEC);
- if(fd >= 0){
- if(write(fd, "interrupt", 9) == 9){
- close(fd);
- break;
- }
- close(fd);
- }
- postnote(PNPROC, p->pid, "threadint");
+ if(writeprocctl(p->pid, "interrupt") < 0)
+ postnote(PNPROC, p->pid, "threadint");
break;
case Rendezvous:
_threadflagrendez(t);