-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into release-0.1.0
- Loading branch information
Showing
5 changed files
with
73 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
TOP=$(abspath ../..) | ||
include $(TOP)/defs.mak | ||
|
||
PROG = wake_and_kill | ||
APPDIR = appdir | ||
CFLAGS = -fPIC -g | ||
LDFLAGS = -Wl,-rpath=$(MUSL_LIB) | ||
|
||
all: rootfs | ||
|
||
rootfs: $(PROG).c | ||
mkdir -p $(APPDIR)/bin | ||
$(MUSL_GCC) $(CFLAGS) -o $(APPDIR)/bin/$(PROG) $(PROG).c $(LDFLAGS) | ||
$(MYST) mkcpio $(APPDIR) rootfs | ||
|
||
tests: | ||
$(RUNTEST) $(MYST_EXEC) rootfs /bin/$(PROG) $(OPTS) | ||
|
||
clean: | ||
rm -rf $(APPDIR) rootfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
#include <assert.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <syscall.h> | ||
#include <unistd.h> | ||
|
||
void* thread_func(void* args) | ||
{ | ||
int readFd = *(int*)args; | ||
while (1) | ||
{ | ||
int ret, data; | ||
// read is blocking until writer writes to pipe | ||
while ((ret = read(readFd, &data, 1)) < 0 | ||
&& errno == EINTR); | ||
|
||
if (ret < 0) | ||
{ | ||
close(readFd); | ||
return; | ||
} | ||
} | ||
printf("unreachable (%s)\n", __FUNCTION__); | ||
} | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
int pipeFds[2]; | ||
int flags = O_CLOEXEC; | ||
int ret = pipe2(pipeFds, flags); | ||
assert(ret == 0); | ||
pthread_t child; | ||
pthread_create(&child, NULL, thread_func, &pipeFds[0]); | ||
printf("main thread exiting w/o writing to pipe...\n"); | ||
// CRT will call sys_exit_group as part of exit sequence | ||
// this should kill the child thread | ||
return 0; | ||
} |