Skip to content

Commit

Permalink
Merge branch 'main' into release-0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jxyang committed Feb 5, 2021
2 parents 37f32bc + e69013c commit e37b6b0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
11 changes: 5 additions & 6 deletions kernel/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,11 @@ int myst_enter_kernel(myst_kernel_args_t* args)
exit_status = thread->exit_status;

/* release the fdtable */
// ATTN: remove this once GH #9 fixed
// if (thread->fdtable)
// {
// myst_fdtable_free(thread->fdtable);
// thread->fdtable = NULL;
// }
if (thread->fdtable)
{
myst_fdtable_free(thread->fdtable);
thread->fdtable = NULL;
}

/* release signal related heap memory */
myst_signal_free(thread);
Expand Down
6 changes: 5 additions & 1 deletion kernel/tcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <myst/strings.h>
#include <myst/tcall.h>
#include <myst/thread.h>
#include <myst/signal.h>

long myst_tcall_random(void* data, size_t size)
{
Expand Down Expand Up @@ -63,7 +64,10 @@ long myst_tcall_wait(uint64_t event, const struct timespec* timeout)
long params[6] = {0};
params[0] = (long)event;
params[1] = (long)timeout;
return myst_tcall(MYST_TCALL_WAIT, params);
long ret = myst_tcall(MYST_TCALL_WAIT, params);
// check for signals
myst_signal_process(myst_thread_self());
return ret;
}

long myst_tcall_wake(uint64_t event)
Expand Down
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ DIRS += round
DIRS += signal
DIRS += libcxx
DIRS += tlscert
DIRS += wake_and_kill

ifndef MYST_USE_OECACHE
DIRS += curl
Expand Down
20 changes: 20 additions & 0 deletions tests/wake_and_kill/Makefile
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
42 changes: 42 additions & 0 deletions tests/wake_and_kill/wake_and_kill.c
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;
}

0 comments on commit e37b6b0

Please sign in to comment.