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

front
cinap_lenrek 2020-12-07 14:31:02 +01:00
parent e45bd6814a
commit c10e21b491
1 changed files with 20 additions and 13 deletions

View File

@ -76,24 +76,31 @@ threadint(int id)
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
tinterrupt(Proc *p, Thread *t)
{
char buf[64];
int fd;
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);