libthread: reduce stack usage of threadkill*(), open /proc/n/ctl with OCEXEC flag

This commit is contained in:
cinap_lenrek 2020-12-07 14:31:02 +01:00
parent e45bd6814a
commit c10e21b491

View file

@ -76,24 +76,31 @@ threadint(int id)
threadxxx(id, 0); threadxxx(id, 0);
} }
static int
writeprocctl(int pid, char *ctl)
{
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 static void
tinterrupt(Proc *p, Thread *t) tinterrupt(Proc *p, Thread *t)
{ {
char buf[64];
int fd;
switch(t->state){ switch(t->state){
case Running: case Running:
snprint(buf, sizeof(buf), "/proc/%d/ctl", p->pid); if(writeprocctl(p->pid, "interrupt") < 0)
fd = open(buf, OWRITE|OCEXEC); postnote(PNPROC, p->pid, "threadint");
if(fd >= 0){
if(write(fd, "interrupt", 9) == 9){
close(fd);
break;
}
close(fd);
}
postnote(PNPROC, p->pid, "threadint");
break; break;
case Rendezvous: case Rendezvous:
_threadflagrendez(t); _threadflagrendez(t);