summaryrefslogtreecommitdiff
path: root/debian/patches/task-load.patch
blob: bae757441279300e84c3b504338cda9b5fa4a172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
From 270c3cd23333668696da3e81c3f60ff5d4fc1ad8 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Fri, 21 Nov 2014 00:23:39 +0100
Subject: [PATCH gnumach] XXX

---
 kern/bootstrap.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/kern/bootstrap.c b/kern/bootstrap.c
index 4edae7b..9c2eb87 100644
--- a/kern/bootstrap.c
+++ b/kern/bootstrap.c
@@ -35,6 +35,7 @@
 
 #include <mach/port.h>
 #include <mach/message.h>
+#include <mach/exec/elf.h>
 #include <machine/locore.h>
 #include <machine/vm_param.h>
 #include <machine/pcb.h>
@@ -422,23 +423,19 @@ boot_read(void *handle, vm_offset_t file_ofs, void *buf, vm_size_t size,
 }
 
 static int
-read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size,
+read_in(void *handle, vm_offset_t file_ofs, vm_size_t file_size,
 		     vm_offset_t mem_addr, vm_size_t mem_size,
-		     exec_sectype_t sec_type)
+		     vm_prot_t mem_prot)
 {
   struct multiboot_module *mod = handle;
 
 	vm_map_t user_map = current_task()->map;
 	vm_offset_t start_page, end_page;
-	vm_prot_t mem_prot = sec_type & EXEC_SECTYPE_PROT_MASK;
 	int err;
 
 	if (mod->mod_start + file_ofs + file_size > mod->mod_end)
 	  return -1;
 
-	if (!(sec_type & EXEC_SECTYPE_ALLOC))
-		return 0;
-
 	assert(mem_size > 0);
 	assert(mem_size >= file_size);
 
@@ -470,6 +467,19 @@ read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size,
 	return 0;
 }
 
+static int
+read_exec(void *handle, vm_offset_t file_ofs, vm_size_t file_size,
+		     vm_offset_t mem_addr, vm_size_t mem_size,
+		     exec_sectype_t sec_type)
+{
+	if (!(sec_type & EXEC_SECTYPE_ALLOC))
+	  return 0;
+
+	return read_in (handle, file_ofs, file_size,
+			mem_addr, mem_size,
+			sec_type & EXEC_SECTYPE_PROT_MASK);
+}
+
 static void copy_bootstrap(void *e, exec_info_t *boot_exec_info)
 {
 	//register vm_map_t	user_map = current_task()->map;
@@ -746,9 +756,20 @@ static void user_bootstrap(void)
   exec_info_t boot_exec_info;
   int err;
   char **av;
+  boolean_t executable = TRUE;
 
   /* Load this task up from the executable file in the module.  */
   err = exec_load(boot_read, read_exec, info->mod, &boot_exec_info);
+  if (err == EX_NOT_EXECUTABLE)
+    {
+      struct multiboot_module *mod = info->mod;
+      printf("reading %d bytes into map %p\n", mod->mod_end - mod->mod_start, current_task()->map);
+      err = read_in (mod,
+		     0, mod->mod_end - mod->mod_start,
+		     0, mod->mod_end - mod->mod_start,
+		     VM_PROT_READ);
+      executable = FALSE;
+    }
   if (err)
     panic ("Cannot load user executable module (error code %d): %s",
 	   err, info->argv[0]);
@@ -770,6 +791,9 @@ static void user_bootstrap(void)
   info->done = 1;
   thread_wakeup ((event_t) info);
 
+  if (! executable)
+    thread_terminate (current_thread ());
+
   /*
    * Exit to user thread.
    */
-- 
2.1.4