Fixed problems with running static programs
authorKevin Klues <klueska@ros-dev.(none)>
Fri, 2 Apr 2010 22:04:44 +0000 (15:04 -0700)
committerKevin Klues <klueska@cs.berkeley.edu>
Thu, 3 Nov 2011 00:35:39 +0000 (17:35 -0700)
Fixed the sys_brk system call, and made the tests/pthread_test application
thread safe as well as removed some erroneous print statements.

kern/src/syscall.c
tests/Makefrag
tests/pthread_test.c
user/parlib/hart.c

index ba9447e..ea65abc 100644 (file)
@@ -499,7 +499,7 @@ static void* sys_brk(struct proc *p, void* addr) {
 
        if (range > 0) {
                if(__do_mmap(p, real_heap_top, range, PROT_READ | PROT_WRITE,
-                            MAP_FIXED | MAP_ANONYMOUS, NULL, 0))
+                            MAP_FIXED | MAP_ANONYMOUS, NULL, 0) == MAP_FAILED)
                        goto out;
        }
        else if (range < 0) {
index 165e12a..1575bb7 100644 (file)
@@ -1,9 +1,10 @@
-TESTS_DIR = $(TOP_DIR)/tests
+TESTS_DIR = tests
 TESTS_CFLAGS += $(USER_CFLAGS)
 OBJDIRS += $(TESTS_DIR)
 
 TESTS_CFLAGS := $(USER_CFLAGS)  \
-                -I$(USER_DIR)/include
+                -I$(USER_DIR)/include \
+#                -static
 
 ALL_TEST_FILES = $(shell ls $(TESTS_DIR)/*.c)
 
index bc10c24..7abbdc4 100644 (file)
@@ -1,23 +1,38 @@
 #include <stdio.h>
 #include <pthread.h>
 
+pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+#define printf_safe(...) \
+       pthread_mutex_lock(&lock); \
+       printf(__VA_ARGS__); \
+       pthread_mutex_unlock(&lock);
+
 int thread_num;
 pthread_t t0;
 pthread_t t1;
+pthread_t t2;
 
 __thread int my_id;
 void *thread(void* arg)
 {      
        my_id = thread_num++;
-       printf("thread %d\n", my_id);
+       printf_safe("thread %d\n", my_id);
 }
 
 int main(int argc, char** argv) 
 {
        thread_num = 0;
+       printf_safe("About to create thread 0\n");
        pthread_create(&t0, NULL, &thread, NULL);
-//     pthread_create(&t1, NULL, &thread, NULL);
+       printf_safe("About to create thread 1\n");
+       pthread_create(&t1, NULL, &thread, NULL);
+       printf_safe("About to create thread 2\n");
+       pthread_create(&t2, NULL, &thread, NULL);
 
+       printf_safe("About to join on thread 0\n");
        pthread_join(t0, NULL);
-//     pthread_join(t1, NULL);
+       printf_safe("About to join on thread 1\n");
+       pthread_join(t1, NULL);
+       printf_safe("About to join on thread 2\n");
+       pthread_join(t2, NULL);
 } 
index 7983580..f99c83e 100644 (file)
@@ -38,11 +38,8 @@ static int hart_allocate_tls(int id)
        // reallocating it, we could instead just reinitialize it.
        hart_free_tls(id);
 
-       printf("About to allocate tls\n");
        void* tls = _dl_allocate_tls(NULL);
-       printf("Allocated tls: %p\n", tls);
-       if((hart_thread_control_blocks[id] = tls) == NULL)
-       {
+       if((hart_thread_control_blocks[id] = tls) == NULL) {
                errno = ENOMEM;
                return -1;
        }