UbixOS  2.0
i386_exec.c
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2002-2018 The UbixOS Project.
3  * All rights reserved.
4  *
5  * This was developed by Christopher W. Olsen for the UbixOS Project.
6  *
7  * Redistribution and use in source and binary forms, with or without modification, are permitted
8  * provided that the following conditions are met:
9  *
10  * 1) Redistributions of source code must retain the above copyright notice, this list of
11  * conditions, the following disclaimer and the list of authors.
12  * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13  * conditions, the following disclaimer and the list of authors in the documentation and/or
14  * other materials provided with the distribution.
15  * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16  * endorse or promote products derived from this software without specific prior written
17  * permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <sys/_null.h>
30 #include <sys/types.h>
31 #include <sys/elf.h>
32 #include <sys/gdt.h>
33 #include <ubixos/exec.h>
34 #include <ubixos/ld.h>
35 #include <ubixos/kpanic.h>
36 #include <ubixos/endtask.h>
37 #include <vmm/vmm.h>
38 #include <lib/kmalloc.h>
39 #include <lib/kprintf.h>
40 #include <vfs/file.h>
41 #include <assert.h>
42 #include <string.h>
43 #include <sys/descrip.h>
44 
45 #define ENVP_PAGE 0x100
46 #define ARGV_PAGE 0x100
47 #define ELF_AUX 0x100
48 #define STACK_PAD 0x1000
49 
50 #define ENOEXEC -1
51 
52 #define AT_NULL 0 /* Terminates the vector. */
53 #define AT_IGNORE 1 /* Ignored entry. */
54 #define AT_EXECFD 2 /* File descriptor of program to load. */
55 #define AT_PHDR 3 /* Program header of program already loaded. */
56 #define AT_PHENT 4 /* Size of each program header entry. */
57 #define AT_PHNUM 5 /* Number of program header entries. */
58 #define AT_PAGESZ 6 /* Page size in bytes. */
59 #define AT_BASE 7 /* Interpreter's base address. */
60 #define AT_FLAGS 8 /* Flags (unused for i386). */
61 #define AT_ENTRY 9 /* Where interpreter should transfer control. */
62 
63 #define AUXARGS_ENTRY(pos, id, val) {*pos = id;pos++; *pos = val;pos++;}
64 
65 static int argv_count(char **argv) {
66  int i = 0;
67 
68  while (*argv++ != 0x0)
69  i++;
70 
71  return (i);
72 }
73 
74 static int envp_count(char **envp) {
75  int i = 0;
76 
77  while (*envp++ != 0x0)
78  i++;
79 
80  return (i);
81 }
82 
83 static int args_copyin(char **argv_in, char **argv_out, char **args_out) {
84 
85  int argc = argv_count(argv_in);
86 
87  uint32_t *argv_tmp = (uint32_t *) kmalloc(sizeof(char *) * (argc + 2)); // + 1 For ARGC + 1 For NULL TERM
88 
89  char *args_tmp = (char *) kmalloc(ARGV_PAGE);
90 
91  argv_tmp[0] = argc;
92 
93  uint32_t sp = 0x0;
94 
95  int i = 0x0;
96 
97  for (i = 1; i <= argc; i++) {
98  argv_tmp[i] = (uint32_t)(args_tmp + sp);
99  strcpy((char *)argv_tmp[i], argv_in[i - 1]);
100  sp += strlen(argv_in[i - 1]) + 1;
101  }
102 
103  argv_tmp[i++] = 0x0;
104 
105  *argv_out = (char *)argv_tmp;
106  *args_out = args_tmp;
107 
108  return (0);
109 
110 }
111 
112 static int envs_copyin(char **envp_in, char **envp_out, char **envs_out) {
113 
114  int envc = envp_count(envp_in);
115 
116  uint32_t *envp_tmp = (uint32_t *) kmalloc(sizeof(char *) * (envc + 1)); // + 1 For NULL TERM
117 
118  char *envs_tmp = (char *) kmalloc(ENVP_PAGE);
119 
120  uint32_t sp = 0x0;
121 
122  int i = 0x0;
123 
124  for (i = 0; i < envc; i++) {
125  envp_tmp[i] = (uint32_t)(envs_tmp + sp);
126  strcpy((char *)envp_tmp[i], envp_in[i]);
127  sp += strlen(envp_in[i]) + 1;
128  }
129  envp_tmp[i++] = 0x0;
130 
131  *envp_out = (char *)envp_tmp;
132  *envs_out = envs_tmp;
133  return (0);
134 }
135 
136 static int elf_parse_dynamic(elf_file_t ef);
137 
138 /*****************************************************************************************
139 
140  Function: execThread(void (*)(void),int,char *);
141  Description: This function will create a thread from code in the current memory space
142 
143  Notes:
144 
145  05/19/04 - This does not work the way I want it to it still makes a copy of kernel space
146  so do not use out side of kernel space
147 
148  *****************************************************************************************/
149 uint32_t execThread(void (*tproc)(void), uint32_t stack, char *arg) {
150 
151  kTask_t * newProcess = 0x0;
152  uint32_t stackAddr = 0x0;
153 
154  /* Find A New Thread */
155  newProcess = schedNewTask();
156  assert(newProcess);
157 
158  stackAddr = vmm_getFreeKernelPage(newProcess->id, stack / PAGE_SIZE);
159 
160  /* Set All The Correct Thread Attributes */
161  newProcess->tss.back_link = 0x0;
162  newProcess->tss.esp0 = 0x0;
163  newProcess->tss.ss0 = 0x0;
164  newProcess->tss.esp1 = 0x0;
165  newProcess->tss.ss1 = 0x0;
166  newProcess->tss.esp2 = 0x0;
167  newProcess->tss.ss2 = 0x0;
168  newProcess->tss.cr3 = (unsigned int) kernelPageDirectory;
169  newProcess->tss.eip = (unsigned int) tproc;
170  newProcess->tss.eflags = 0x206;
171  newProcess->tss.esp = stackAddr + (stack - 0x4); //stack;
172  newProcess->tss.ebp = 0x0;//stack;
173  newProcess->tss.esi = 0x0;
174  newProcess->tss.edi = 0x0;
175 
176  /* Ring 3 Selectors */
177  /*
178  newProcess->tss.es = 0x30+3;
179  newProcess->tss.cs = 0x28+3;
180  newProcess->tss.ss = 0x30+3;
181  newProcess->tss.ds = 0x30+3;
182  newProcess->tss.fs = 0x30+3;
183  newProcess->tss.gs = 0x30+3;
184  */
185 
186  /* Ring 0 Selectors */
187  newProcess->tss.es = 0x10;
188  newProcess->tss.cs = 0x08;
189  newProcess->tss.ss = 0x10;
190  newProcess->tss.ds = 0x10;
191  newProcess->tss.fs = 0x10;
192  newProcess->tss.gs = 0x10;
193 
194  newProcess->tss.ldt = 0x18;
195  newProcess->tss.trace_bitmap = 0x0000;
196  newProcess->tss.io_map = 0x8000;
197  newProcess->oInfo.vmStart = 0x6400000;
198 
199  if (newProcess->files[0] != 0x0)
200  kpanic("Problem With File Descriptors");
201 
202  newProcess->files[0] = 0x0;
203 
204  //kprintf("EIP: 0x%X(%i)", tproc, newProcess->id);
205 
206  /* Set up default stack for thread here filled with arg list 3 times */
207  asm volatile(
208  "pusha \n"
209  "movl %%esp,%%ecx \n"
210  "movl %1,%%eax \n"
211  "movl %%eax,%%esp \n"
212  "pushl %%ebx \n"
213  "pushl %%ebx \n"
214  "pushl %%ebx \n"
215  "movl %%esp,%%eax \n"
216  "movl %%eax,%1 \n"
217  "movl %%ecx,%%esp \n"
218  "popa \n"
219  :
220  : "b" (arg),"m" (newProcess->tss.esp)
221  );
222 
223  /* Put new thread into the READY state */
224  sched_setStatus(newProcess->id, READY);
225 
226  /* Return with the new process ID */
227  return ((uint32_t) newProcess);
228 }
229 
230 /*****************************************************************************************
231 
232  Function: void execFile(char *file);
233  Description: This Function Executes A Kile Into A New VM Space With Out
234  Having To Fork
235  Notes:
236 
237  07/30/02 - I Have Made Some Heavy Changes To This As Well As Fixed A Few
238  Memory Leaks The Memory Allocated To Load The Binary Into Is
239  Now Unmapped So It Can Be Used Again And Not Held Onto Until
240  The Program Exits
241 
242  07/30/02 - Now I Have To Make A Better Memory Allocator So We Can Set Up
243  The Freshly Allocated Pages With The Correct Permissions
244 
245  *****************************************************************************************/
246 void execFile(char *file, char **argv, char **envp, int console) {
247 
248  kTask_t *newProcess = 0x0;
249 
250  int i = 0x0;
251  int x = 0x0;
252 
253  uint32_t *tmp = 0x0;
254 
255  Elf_Ehdr *binaryHeader = 0x0;
256 
257  Elf_Phdr *programHeader = 0x0;
258 
259  int argc = argv_count(argv);
260  int envc = envp_count(envp);
261 
262  /* Get A New Task For This Proccess */
263  newProcess = schedNewTask();
264  assert(newProcess);
265 
266  newProcess->gid = 0x0;
267  newProcess->uid = 0x0;
268  newProcess->pgrp = newProcess->id;
269  newProcess->term = tty_find(console);
270 
271  if (newProcess->term == 0x0)
272  kprintf("Error: invalid console\n");
273 
274  /* Set tty ownership */
275  newProcess->term->owner = newProcess->id;
276 
277  /* Now We Must Create A Virtual Space For This Proccess To Run In */
278  newProcess->tss.cr3 = (uint32_t) vmm_createVirtualSpace(newProcess->id);
279 
280  /* To Better Load This Application We Will Switch Over To Its VM Space */
281  asm volatile(
282  "movl %0,%%eax \n"
283  "movl %%eax,%%cr3 \n"
284  : : "d" ((uint32_t *)(newProcess->tss.cr3))
285  );
286 
287  /* Lets Find The File */
288  if (newProcess->files[0] != 0x0)
289  kpanic("Problem With File Descriptors");
290  newProcess->files[0] = fopen(file, "r");
291 
292  /* If We Dont Find the File Return */
293  if (newProcess->files[0] == 0x0) {
294  kprintf("Exec Format Error: Binary File Not Executable1.\n");
295  fclose(newProcess->files[0]);
296  return;
297  }
298 
299  if (newProcess->files[0]->perms == 0x0) {
300  kprintf("Exec Format Error: Binary File Not Executable2.\n");
301  fclose(newProcess->files[0]);
302  return;
303  }
304 
305  /* Load ELF Header */
306  binaryHeader = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr));
307 
308  fread(binaryHeader, sizeof(Elf_Ehdr), 1, newProcess->files[0]);
309 
310  /* Check If App Is A Real Application */
311  if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) {
312  kprintf("Exec Format Error: Binary File Not Executable3.\n");
313  kfree(binaryHeader);
314  fclose(newProcess->files[0]);
315  return;
316  }
317  else if (binaryHeader->e_type != 2) {
318  kprintf("Exec Format Error: Binary File Not Executable4.\n");
319  kfree(binaryHeader);
320  fclose(newProcess->files[0]);
321  return;
322  }
323  else if (binaryHeader->e_entry == 0x300000) {
324  kprintf("Exec Format Error: Binary File Not Executable5.\n");
325  kfree(binaryHeader);
326  fclose(newProcess->files[0]);
327  return;
328  }
329 
330  newProcess->td.abi = binaryHeader->e_ident[EI_OSABI];
331 
332  /* Load The Program Header(s) */
333  programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum);
334  fseek(newProcess->files[0], binaryHeader->e_phoff, 0);
335 
336  fread(programHeader, (sizeof(Elf_Phdr) * binaryHeader->e_phnum), 1, newProcess->files[0]);
337 
338  /* Loop Through The Header And Load Sections Which Need To Be Loaded */
339  for (i = 0; i < binaryHeader->e_phnum; i++) {
340  if (programHeader[i].p_type == 1) {
341  /*
342  Allocate Memory Im Going To Have To Make This Load Memory With Correct
343  Settings so it helps us in the future
344  */
345  for (x = 0x0; x < (programHeader[i].p_memsz); x += 0x1000) {
346  /* Make readonly and read/write !!! */
347  if (vmm_remapPage(vmm_findFreePage(newProcess->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x), PAGE_DEFAULT, newProcess->id, 0) == 0x0)
348  K_PANIC("Remap Page Failed");
349 
350  memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x), 0x0, 0x1000);
351 
352  }
353 
354  /* Now Load Section To Memory */
355  fseek(newProcess->files[0], programHeader[i].p_offset, 0);
356 
357  fread((void *) programHeader[i].p_vaddr, programHeader[i].p_filesz, 1, newProcess->files[0]);
358 
359  if ((programHeader[i].p_flags & 0x2) != 0x2) {
360  for (x = 0x0; x < (programHeader[i].p_memsz); x += 0x1000) {
361  if ((vmm_setPageAttributes((programHeader[i].p_vaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0)
362  kpanic("Error: vmm_setPageAttributes failed, File: %s, Line: %i\n", __FILE__, __LINE__);
363  }
364  }
365  }
366  }
367 
368  /* Set Virtual Memory Start */
369  newProcess->oInfo.vmStart = 0x80000000;
370  newProcess->td.vm_daddr = (u_long) (programHeader[i].p_vaddr & 0xFFFFF000);
371 
372  /* Set Up Stack Space */
373  //MrOlsen (2016-01-14) FIX: is the stack start supposed to be addressable xhcnage x= 1 to x=0
374  //x = 0 because GS= stack address not address -1 fix!
375  for (x = 1; x <= 100; x++) {
376  vmm_remapPage(vmm_findFreePage(newProcess->id), (STACK_ADDR+1) - (x * PAGE_SIZE), PAGE_DEFAULT | PAGE_STACK, newProcess->id, 0);
377  bzero((void *)((STACK_ADDR+1) - (x * PAGE_SIZE)), PAGE_SIZE);
378  }
379 
380  /* Kernel Stack 0x2000 bytes long */
381 
382  //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BC000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id);
383  //vmm_remapPage(vmm_findFreePage(newProcess->id), 0x5BB000, KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id);
384  /*
385  for (x = 0; x < 2; x++)
386  vmm_remapPage(vmm_findFreePage(newProcess->id), 0xFFFFF000 - (PAGE_SIZE * x), KERNEL_PAGE_DEFAULT | PAGE_STACK, newProcess->id, 0);
387  */
388 
389  /* Set All The Proper Information For The Task */
390  newProcess->tss.back_link = 0x0;
391  newProcess->tss.esp0 = 0xFFFFFFFF; //0x5BC000;
392  newProcess->tss.ss0 = 0x10;
393  newProcess->tss.esp1 = 0x0;
394  newProcess->tss.ss1 = 0x0;
395  newProcess->tss.esp2 = 0x0;
396  newProcess->tss.ss2 = 0x0;
397  newProcess->tss.eip = (long) binaryHeader->e_entry;
398  newProcess->tss.eflags = 0x206;
399  newProcess->tss.esp = STACK_ADDR;
400  newProcess->tss.ebp = 0x0;//STACK_ADDR;
401  newProcess->tss.esi = 0x0;
402  newProcess->tss.edi = 0x0;
403 
404  /* Set these up to be ring 3 tasks */
405  newProcess->tss.es = 0x30 + 3;
406  newProcess->tss.cs = 0x28 + 3;
407  newProcess->tss.ss = 0x30 + 3;
408  newProcess->tss.ds = 0x30 + 3;
409  newProcess->tss.fs = 0x30 + 3;
410  newProcess->tss.gs = 0x8 + 3 + 4;//0x50 + 3; //0x30 + 3;
411 
412  newProcess->tss.ldt = 0x18;
413  newProcess->tss.trace_bitmap = 0x0000;
414  newProcess->tss.io_map = 0x8000;
415 
416  //sched_setStatus(newProcess->id, READY);
417 
418  kfree(binaryHeader);
419  kfree(programHeader);
420  fclose(newProcess->files[0]);
421  newProcess->files[0] = 0x0;
422 
423  tmp = (uint32_t *) newProcess->tss.esp0 - 5;
424 
425  tmp[0] = binaryHeader->e_entry;
426  tmp[3] = STACK_ADDR - 12;
427 
428  newProcess->tss.esp = STACK_ADDR - ARGV_PAGE - ENVP_PAGE - ELF_AUX - (argc + 1) - (envc + 1) - STACK_PAD;
429 
430  tmp = (uint32_t *) newProcess->tss.esp;
431 
432  tmp[0] = argc;
433 
434  uint32_t sp = 0x0;
435 
436  for (i = 1; i <= argc; i++) {
437  tmp[i] = STACK_ADDR - ARGV_PAGE + sp;
438  strcpy((char *) tmp[i], argv[i - 1]);
439  sp += strlen(argv[i - 1]) + 1;
440  }
441  tmp[i++] = 0x0;
442 
443  sp = 0;
444 
445  for (int x = 0; x < envc; x++) {
446  tmp[x + i] = STACK_ADDR - ARGV_PAGE - ENVP_PAGE + sp;
447  strcpy((char *) tmp[x + i], envp[x]);
448  sp += strlen(envp[x]) + 1;
449  }
450  tmp[i + x] = 0x0;
451 
452  /* Build LDT For GS and FS */
454 
455  if (vmm_remapPage(vmm_findFreePage(newProcess->id), VMM_USER_LDT, PAGE_DEFAULT, newProcess->id, 0) == 0x0) {
456  K_PANIC("Error: Remap Page Failed");
457  }
458 
459  struct gdtDescriptor *taskLDT = 0x0;
460 
461  taskLDT = (struct gdtDescriptor *)(VMM_USER_LDT + sizeof(struct gdtDescriptor));
462  uint32_t data_addr = 0x0;
463 
464  taskLDT->limitLow = (0xFFFFF & 0xFFFF);
465  taskLDT->baseLow = (data_addr & 0xFFFF);
466  taskLDT->baseMed = ((data_addr >> 16) & 0xFF);
467  taskLDT->access = ((dData + dWrite + dBig + dBiglim + dDpl3) + dPresent) >> 8;
468  taskLDT->limitHigh = (0xFFFFF >> 16);
469  taskLDT->granularity = ((dData + dWrite + dBig + dBiglim + dDpl3) & 0xFF) >> 4;
470  taskLDT->baseHigh = data_addr >> 24;
471 
472 
473  /* Switch Back To The Kernels VM Space */
474  asm volatile(
475  "movl %0,%%eax \n"
476  "movl %%eax,%%cr3 \n"
477  : : "d" ((uint32_t *)(kernelPageDirectory))
478  );
479 
480  sprintf(newProcess->oInfo.cwd, "/");
481 
482  //MrOlsen 2018 kprintf("execFile Return: 0x%X - %i\n", newProcess->tss.eip, newProcess->id);
483 
484  /* Put new thread into the READY state */
485  sched_setStatus(newProcess->id, READY);
486 
487  //_current = newProcess;
488 
489  /* Finally Return */
490  return;
491 }
492 
493 int sys_exec(struct thread *td, char *file, char **argv, char **envp) {
494 
495  int i = 0x0;
496  int x = 0x0;
497 
498  int argc = argv_count(argv);
499  int envc = envp_count(envp);
500 
501  uint32_t cr3 = 0x0;
502 
503  uint32_t *tmp = 0x0;
504 
505  uInt32 seg_size = 0x0;
506  uInt32 seg_addr = 0x0;
507 
508  char *interp = 0x0;
509  uint32_t ldAddr = 0x0;
510 
511  fileDescriptor_t *fd = 0x0;
512 
513  Elf_Ehdr *binaryHeader = 0x0;
514  Elf_Phdr *programHeader = 0x0;
515  Elf_Shdr *sectionHeader = 0x0;
516 
517  elf_file_t ef = 0x0;
518 
519  u_long text_addr = 0, text_size = 0;
520  u_long data_addr = 0, data_size = 0;
521 
522  struct i386_frame *iFrame = 0x0;
523 
524  asm("movl %%cr3, %0;" : "=r" (cr3));
525 
526  fd = fopen(file, "r");
527 
528  if (fd == 0x0) {
529  td->td_retval[0] = 2;
530  return (-1);
531  }
532 
533  /* Test If Executable */
534  if (fd->perms == 0) {
535  kprintf("Exec Format Error: Binary File Not Executable6.\n");
536  fclose(fd);
537  return (-1);
538  }
539 
540  /* Set Threads FD to open FD */
541  _current->files[0] = fd;
542 
543  /* Copy In ARGS & ENVS Before Cleaning Virtual Space */
544  uint32_t *argv_out = 0x0;
545  char *args_out = 0x0;
546 
547  args_copyin(argv, (char **)&argv_out, &args_out);
548 
549  uint32_t *envp_out = 0x0;
550  char *envs_out = 0x0;
551 
552  envs_copyin(envp, (char **)&envp_out, &envs_out);
553 
555  //vmm_cleanVirtualSpace( (uint32_t) _current->td.vm_daddr + (_current->td.vm_dsize << PAGE_SHIFT) );
556  //MrOlsen 2017-12-15 - FIX! - This should be done before it was causing a lot of problems why did I free space after loading binary????
557  //vmm_cleanVirtualSpace((uint32_t) 0x8048000);
559 
560  /* Clear Stack */
561  //bzero(STACK_ADDR - (100 * PAGE_SIZE), (PAGE_SIZE * 100));
562  for (x = 1; x <= 100; x++) {
564  bzero((void *)((STACK_ADDR+1) - (x * 0x1000)), 0x1000);
565  }
566 
567  /* Load ELF Header */
568  if ((binaryHeader = (Elf_Ehdr *) kmalloc(sizeof(Elf_Ehdr))) == 0x0)
569  K_PANIC("MALLOC FAILED");
570 
571  fread(binaryHeader, sizeof(Elf_Ehdr), 1, fd);
572  /* Done Loading ELF Header */
573 
574  /* Check If App Is A Real Application */
575  if ((binaryHeader->e_ident[1] != 'E') && (binaryHeader->e_ident[2] != 'L') && (binaryHeader->e_ident[3] != 'F')) {
576  kprintf("Exec Format Error: Binary File Not Executable7.\n");
577  kfree(binaryHeader);
578  fclose(fd);
579  return (-1);
580  }
581  else if (binaryHeader->e_type != ET_EXEC) {
582  kprintf("Exec Format Error: Binary File Not Executable8.\n");
583  kfree(binaryHeader);
584  fclose(fd);
585  return (-1);
586  }
587  else if (binaryHeader->e_entry == 0x300000) {
588  kprintf("Exec Format Error: Binary File Not Executable9.\n");
589  kfree(binaryHeader);
590  fclose(fd);
591  return (-1);
592  }
593 
594  /* Set Thread ABI */
595  td->abi = binaryHeader->e_ident[EI_OSABI];
596 
597  /* Load The Program Header(s) */
598  if ((programHeader = (Elf_Phdr *) kmalloc(sizeof(Elf_Phdr) * binaryHeader->e_phnum)) == 0x0)
599  K_PANIC("MALLOC FAILED");
600 
601  assert(programHeader);
602 
603  fseek(fd, binaryHeader->e_phoff, 0);
604  fread(programHeader, (sizeof(Elf_Phdr) * binaryHeader->e_phnum), 1, fd);
605  /* Done Loading Program Header(s) */
606 
607  /* Load The Section Header(s) */
608  if ((sectionHeader = (Elf_Shdr *) kmalloc(sizeof(Elf_Shdr) * binaryHeader->e_shnum)) == 0x0)
609  K_PANIC("MALLOC FAILED");
610 
611  assert(sectionHeader);
612  fseek(fd, binaryHeader->e_shoff, 0);
613  fread(sectionHeader, sizeof(Elf_Shdr) * binaryHeader->e_shnum, 1, fd);
614  /* Done Loading Section Header(s) */
615 
616  ef = kmalloc(sizeof(struct elf_file));
617  memset(ef, 0x0, sizeof(struct elf_file));
618 
619  /* Loop Through The Header And Load Sections Which Need To Be Loaded */
620  for (i = 0; i < binaryHeader->e_phnum; i++) {
621  switch (programHeader[i].p_type) {
622  case PT_LOAD:
623  if (programHeader[i].p_memsz == 0x0)
624  break;
625 
626  seg_addr = trunc_page(programHeader[i].p_vaddr);
627  seg_size = round_page(programHeader[i].p_memsz + programHeader[i].p_vaddr - seg_addr);
628 
629  /*
630  Allocate Memory Im Going To Have To Make This Load Memory With Correct
631  Settings so it helps us in the future
632  */
633  for (x = 0x0; x < (round_page(programHeader[i].p_memsz)); x += 0x1000) {
634  /* Make readonly and read/write !!! */
635  if (vmm_remapPage(vmm_findFreePage(_current->id), ((programHeader[i].p_vaddr & 0xFFFFF000) + x), PAGE_DEFAULT, _current->id, 0) == 0x0) {
636  K_PANIC("Error: Remap Page Failed");
637  }
638  else {
639  //MrOlsen 2018-01-15 kprintf("rP[0x%X]", (programHeader[i].p_vaddr & 0xFFFFF000) + x);
640  }
641 
642  memset((void *) ((programHeader[i].p_vaddr & 0xFFFFF000) + x), 0x0, 0x1000);
643 
644  }
645 
646  /* Now Load Section To Memory */
647  fseek(fd, programHeader[i].p_offset, 0);
648  fread((void *) programHeader[i].p_vaddr, programHeader[i].p_filesz, 1, fd);
649 
650  if ((programHeader[i].p_flags & 0x2) != 0x2) {
651  for (x = 0x0; x < (round_page(programHeader[i].p_memsz)); x += 0x1000) {
652  if ((vmm_setPageAttributes((programHeader[i].p_vaddr & 0xFFFFF000) + x, PAGE_PRESENT | PAGE_USER)) != 0x0)
653  kpanic("Error: vmm_setPageAttributes failed, File: %s,Line: %i\n", __FILE__, __LINE__);
654  }
655  }
656 
657  if ((programHeader[i].p_flags & PF_X) && text_size < seg_size) {
658  //MrOlsen 2018kprintf("setting text: 0x%X - 0x%X\n", seg_addr, seg_size);
659  text_size = seg_size;
660  text_addr = seg_addr;
661  }
662  else {
663  //MrOlsen 2018kprintf("setting data: 0x%X - 0x%X\n", seg_addr, seg_size);
664  data_size = seg_size;
665  data_addr = seg_addr;
666  /*
667  _current->td.vm_dsize = seg_size >> PAGE_SHIFT;
668  _current->td.vm_daddr = (char *) seg_addr;
669  kprintf( "setting daddr: 0x%X, dsiize: 0x%X\n", _current->td.vm_daddr, _current->td.vm_dsize );
670  */
671  }
672 
673  /*
674  * MrOlsen (2016-01-19) NOTE: Note Sure, I should Do This Later
675  * Thjis is for stack space
676  */
677  _current->oInfo.vmStart = ((programHeader[i].p_vaddr & 0xFFFFF000) + 0xA900000);
678  break;
679  case PT_DYNAMIC:
680  //newLoc = (char *)programHeader[i].phVaddr;
681  //elfDynamicS = (elfDynamic *) programHeader[i].p_vaddr;
682  ef->dynamic = (Elf_Dyn *) programHeader[i].p_vaddr;
683  //fseek( fd, programHeader[i].phOffset, 0 );
684  //fread( (void *) programHeader[i].phVaddr, programHeader[i].phFilesz, 1, fd );
685  break;
686  case PT_INTERP:
687  #ifdef DEBUG_EXEC
688  kprintf("%s:%i>Malloc: %i\n", _FILE_,_LINE_,programHeader[i].p_filesz);
689  #endif
690  interp = (char *) kmalloc(programHeader[i].p_filesz);
691  fseek(fd, programHeader[i].p_offset, 0);
692  fread((void *) interp, programHeader[i].p_filesz, 1, fd);
693  #ifdef DEBUG_EXEC
694  kprintf("Interp: [%s]\n", interp);
695  #endif
696  ldAddr = ldEnable(interp);
697  //ef->ld_addr = ldEnable();
698  break;
699  case PT_GNU_STACK:
700  asm("nop");
701  break;
702  default:
703  break;
704  }
705  }
706 
707  _current->td.vm_tsize = text_size >> PAGE_SHIFT;
708  _current->td.vm_taddr = text_addr;
709  _current->td.vm_dsize = data_size >> PAGE_SHIFT;
710  _current->td.vm_daddr = data_addr;
711 
712  //MrOlsen 2018kprintf("Done Looping\n");
713 
714  ef->preloaded = 1;
715  ef->address = 0x0;
716  elf_parse_dynamic(ef);
717 
718  //asm("cld");
719  //irqDisable(0);
720  iFrame = (struct i386_frame *) (_current->tss.esp0 - sizeof(struct i386_frame));
721 
722  //iFrame->ebp = 0x0;
723 
724  if (ldAddr != 0x0) {
725  iFrame->eip = ldAddr;
726  }
727  else {
728  iFrame->eip = binaryHeader->e_entry;
729  }
730 
731  //iFrame->edx = 0x0;
732 
733  iFrame->user_esp = (uint32_t) (STACK_ADDR - ARGV_PAGE - ENVP_PAGE - ELF_AUX - (argc + 1) - (envc + 1) - STACK_PAD) & 0xFFFFF000;
734 
735  tmp = (uint32_t *) iFrame->user_esp;
736 
737 // memset((char *) tmp, 0x0, ARGV_PAGE + ENVP_PAGE + ELF_AUX + (argc + 1) + (envc + 1) + STACK_PAD);
738 
739  tmp[0] = argc;
740 
741  uint32_t sp = 0x0;
742 
743  char *EXECP = 0x0;
744 
745  for (i = 1; i <= argc; i++) {
746  tmp[i] = (uint32_t) STACK_ADDR - ARGV_PAGE + sp;
747  if (i == 1) {
748  EXECP = (char *)tmp[i];
749  }
750  strcpy((char *)tmp[i], (const char *)argv_out[i]);
751  #ifdef EXEC_DEBUG
752  kprintf("argv[%i]:%s",i, (const char *)argv_out[i]);
753  #endif
754  sp += strlen((const char *)argv_out[i]) + 1;
755  }
756 
757  tmp[i++] = 0x0;
758 
759  kfree(argv_out);
760  kfree(args_out);
761 
762  sp = 0;
763 
764  x = 0;
765 
766  for (x = 0; x < envc; x++) {
767  tmp[x + i] = (uint32_t) STACK_ADDR - ARGV_PAGE - ENVP_PAGE + sp;
768  strcpy((char *) tmp[x + i], (const char *)envp_out[x]);
769  sp += strlen((const char *)envp_out[x]) + 1;
770  }
771 
772  tmp[i + x] = 0x0;
773 
774  kfree(envp_out);
775  kfree(envs_out);
776 
777  i = i + x + 1;
778 
779  struct file *tFP = 0x0;
780  int tFD = 0x0;
781 
782  fseek(_current->files[0], 0x0, 0x0); // Reset File Position
783  falloc(&_current->td, &tFP, &tFD);
784 
785  tFP->fd = _current->files[0];
786 
787 
788  tmp[i++] = 2;
789  tmp[i++] = -1;// tFD; // _current->imageFd;
790  _current->td.o_files[4] = tFP; // XXX - I had this -> _current->files[0]; not sure why changed to tFP on 2018-11-09
791  //MrOlsen 2018kprintf("AT_EXECFD: [%i:%i]", tmp[i - 1], tFD);
792 
793  tmp[i++] = 3;
794  tmp[i++] = binaryHeader->e_phoff + 0x08048000;
795  //MrOlsen 2018kprintf("AT_PHDR: [0x%X]", tmp[i - 1]);
796 
797  tmp[i++] = 4;
798  tmp[i++] = binaryHeader->e_phentsize;
799  //MrOlsen 2018kprintf("AT_PHENT: [0x%X]", tmp[i - 1]);
800 
801  tmp[i++] = 5;
802  tmp[i++] = binaryHeader->e_phnum;
803  //MrOlsen 2018kprintf("AT_PHNUM: [0x%X]", tmp[i - 1]);
804 
805  tmp[i++] = 6;
806  tmp[i++] = 0x1000;
807 
808  tmp[i++] = 7;
809  tmp[i++] = LD_START;
810  //MrOlsen 2018kprintf("AT_BASE: [0x%X]", tmp[i - 1]);
811 
812  tmp[i++] = 8;
813  tmp[i++] = 0x0;
814 
815  tmp[i++] = 9;
816  tmp[i++] = binaryHeader->e_entry;
817 
818  tmp[i++] = 11;
819  tmp[i++] = 0x0;
820 
821  tmp[i++] = 12;
822  tmp[i++] = 0x0;
823 
824  tmp[i++] = 13;
825  tmp[i++] = 0x0;
826 
827  tmp[i++] = 14;
828  tmp[i++] = 0x0;
829 
830  tmp[i++] = 15; //EXEC PATH
831  tmp[i++] = (uint32_t)EXECP;
832 
833  tmp[i++] = 19; //NCPUS
834  tmp[i++] = 0x1;
835 
836  tmp[i++] = 23; //STACKPROT
837  tmp[i++] = 0x3;
838 
839  tmp[i++] = 0;
840  tmp[i++] = 0;
841 
842  /* Now That We Relocated The Binary We Can Unmap And Free Header Info */
843  kfree(binaryHeader);
844  kfree(programHeader);
845  //irqEnable(0);
846  //asm("sti");
847 
848  /*
849  _current->tss.es = 0x30 + 3;
850  _current->tss.cs = 0x28 + 3;
851  _current->tss.ss = 0x30 + 3;
852  _current->tss.ds = 0x30 + 3;
853  _current->tss.fs = 0x30 + 3;
854  _current->tss.gs = 0x50 + 3; //0x30 + 3;
855 
856  _current->tss.ldt = 0x18;
857  _current->tss.trace_bitmap = 0x0000;
858  _current->tss.io_map = 0x8000;
859  */
860 
861  /*
862  kfree (iFrameNew);
863 
864  memAddr = (uint32_t) & (_current->tss);
865  ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF);
866  ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF);
867  ubixGDT[4].descriptor.baseHigh = (memAddr >> 24);
868  ubixGDT[4].descriptor.access = '\x89';
869 
870  ubixGDT[10].descriptor.baseLow = (STACK_ADDR & 0xFFFF);
871  ubixGDT[10].descriptor.baseMed = ((STACK_ADDR >> 16) & 0xFF);
872  ubixGDT[10].descriptor.baseHigh = (STACK_ADDR >> 24);
873 
874  */
875 
876  /* Build LDT For GS and FS */
877  vmm_unmapPage(VMM_USER_LDT, 1); // Can I Free This?
879  K_PANIC("Error: Remap Page Failed");
880  }
881 
882  struct gdtDescriptor *taskLDT = 0x0;
883 
884  taskLDT = (struct gdtDescriptor *)(VMM_USER_LDT + sizeof(struct gdtDescriptor));
885 
886  //data_addr = 0x0; //TEMP
887 
888  taskLDT->limitLow = (0xFFFFF & 0xFFFF);
889  taskLDT->baseLow = (data_addr & 0xFFFF);
890  taskLDT->baseMed = ((data_addr >> 16) & 0xFF);
891  taskLDT->access = ((dData + dWrite + dBig + dBiglim + dDpl3) + dPresent) >> 8;
892  taskLDT->limitHigh = (0xFFFFF >> 16);
893  taskLDT->granularity = ((dData + dWrite + dBig + dBiglim + dDpl3) & 0xFF) >> 4;
894  taskLDT->baseHigh = data_addr >> 24;
895 
896  _current->tss.gs = 0xF; //Select 0x8 + Ring 3 + LDT
897  _current->pgrp = _current->id;
898 
899  return (0x0);
900 }
901 
902 static int elf_parse_dynamic(elf_file_t ef) {
903  Elf32_Dyn *dynp;
904  int plttype = DT_REL;
905 
906  for (dynp = ef->dynamic; dynp->d_tag != 0x0; dynp++) {
907  switch (dynp->d_tag) {
908  case DT_NEEDED:
909  asm("nop");
910  break;
911  case DT_INIT:
912  asm("nop");
913  break;
914  case DT_FINI:
915  asm("nop");
916  break;
917  case DT_HASH:
918  asm("nop");
919  /* From src/libexec/rtld-elf/rtld.c */
920  const Elf_Hashelt *hashtab = (const Elf_Hashelt *) (ef->address + dynp->d_un.d_ptr);
921  ef->nbuckets = hashtab[0];
922  ef->nchains = hashtab[1];
923  ef->buckets = hashtab + 2;
924  ef->chains = ef->buckets + ef->nbuckets;
925  break;
926  case DT_STRTAB:
927  ef->strtab = (caddr_t) (ef->address + dynp->d_un.d_ptr);
928  break;
929  case DT_STRSZ:
930  ef->strsz = dynp->d_un.d_val;
931  break;
932  case DT_SYMTAB:
933  ef->symtab = (Elf_Sym *) (ef->address + dynp->d_un.d_ptr);
934  break;
935  case DT_SYMENT:
936  if (dynp->d_un.d_val != sizeof(Elf32_Sym))
937  return (ENOEXEC);
938  break;
939  case DT_REL:
940  ef->rel = (const Elf_Rel *) (ef->address + dynp->d_un.d_ptr);
941  break;
942  case DT_RELSZ:
943  ef->relsize = dynp->d_un.d_val;
944  break;
945  case DT_RELENT:
946  if (dynp->d_un.d_val != sizeof(Elf_Rel))
947  return (ENOEXEC);
948  break;
949  case DT_JMPREL:
950  ef->pltrel = (const Elf_Rel *) (ef->address + dynp->d_un.d_ptr);
951  break;
952  case DT_PLTRELSZ:
953  ef->pltrelsize = dynp->d_un.d_val;
954  break;
955  case DT_RELA:
956  ef->rela = (const Elf_Rela *) (ef->address + dynp->d_un.d_ptr);
957  break;
958  case DT_RELASZ:
959  ef->relasize = dynp->d_un.d_val;
960  break;
961  case DT_RELAENT:
962  if (dynp->d_un.d_val != sizeof(Elf_Rela))
963  return (ENOEXEC);
964  break;
965  case DT_PLTREL:
966  plttype = dynp->d_un.d_val;
967  if (plttype != DT_REL && plttype != DT_RELA)
968  return (ENOEXEC);
969  break;
970  case DT_PLTGOT:
971  ef->got = (Elf_Addr *) (ef->address + dynp->d_un.d_ptr);
972  /*
973  tmp = (void *) dynp->d_un.d_ptr; //elfDynamicS[i].dynPtr;
974  tmp[2] = (uInt32) ef->ld_addr;
975  tmp[1] = (uInt32) ef; //0x0;//0xBEEFEAD;//STACK_ADDR - 128;//_current->imageFd;//0xBEEFDEAD;//ef;
976  */
977  break;
978  default:
979  asm("nop");
980  //kprintf("t_tag: 0x%X>", dynp->d_tag);
981  break;
982  }
983  }
984 
985  if (plttype == DT_RELA) {
986  ef->pltrela = (const Elf_Rela *) ef->pltrel;
987  ef->pltrel = NULL;
988  ef->pltrelasize = ef->pltrelsize;
989  ef->pltrelsize = 0;
990  }
991 
992  ef->ddbsymtab = ef->symtab;
993  ef->ddbsymcnt = ef->nchains;
994  ef->ddbstrtab = ef->strtab;
995  ef->ddbstrcnt = ef->strsz;
996  return (0);
997 }
Elf32_Dyn::d_val
Elf32_Word d_val
Definition: elf32.h:124
u_long
unsigned long u_long
Definition: types.h:73
taskStruct
Definition: sched.h:62
i386_frame::user_esp
uint32_t user_esp
Definition: tss.h:105
DT_INIT
#define DT_INIT
Definition: elf_common.h:542
DT_JMPREL
#define DT_JMPREL
Definition: elf_common.h:555
vmm_cleanVirtualSpace
int vmm_cleanVirtualSpace(uint32_t)
Definition: paging.c:587
gdt.h
strcpy
char * strcpy(char *, const char *)
execFile
void execFile(char *file, char **argv, char **envp, int console)
Definition: i386_exec.c:244
DT_PLTREL
#define DT_PLTREL
Definition: elf_common.h:551
vmm_createVirtualSpace
void * vmm_createVirtualSpace(pidType)
Definition: createvirtualspace.c:53
elf_file::preloaded
int preloaded
Definition: elf.h:40
uInt32
unsigned long int uInt32
Definition: objgfx30.h:49
Elf32_Dyn
Definition: elf32.h:121
file.h
fopen
fileDescriptor_t * fopen(const char *file, const char *flags)
Definition: file.c:395
tssStruct::eip
long eip
Definition: tss.h:47
dPresent
#define dPresent
Definition: gdt.h:54
elf_file::pltrelsize
int pltrelsize
Definition: elf.h:53
thread::o_files
void * o_files[512]
Definition: thread.h:42
elf_file
Definition: elf.h:39
K_PANIC
#define K_PANIC(msg)
Definition: kpanic.h:32
string.h
PT_GNU_STACK
#define PT_GNU_STACK
Definition: elf_common.h:502
tssStruct::ss1
short ss1
Definition: tss.h:41
fileDescriptor
Definition: file.h:62
tssStruct::ldt
short ldt
Definition: tss.h:66
PT_DYNAMIC
#define PT_DYNAMIC
Definition: elf_common.h:493
fread
size_t fread(void *ptr, size_t size, size_t nmemb, fileDescriptor_t *fd)
Definition: file.c:297
file
Definition: descrip.h:67
kfree
void kfree(void *baseAddr)
Definition: kmalloc.c:342
thread
Definition: thread.h:40
tssStruct::ds
short ds
Definition: tss.h:60
assert
#define assert(e)
Definition: assert.h:64
assert.h
trunc_page
#define trunc_page(x)
Definition: paging.h:71
elf_file::pltrelasize
int pltrelasize
Definition: elf.h:55
VMM_USER_LDT
#define VMM_USER_LDT
Definition: vmm.h:56
tssStruct::eflags
long eflags
Definition: tss.h:48
vmm.h
tssStruct::esp0
long esp0
Definition: tss.h:37
tssStruct::back_link
short back_link
Definition: tss.h:35
round_page
#define round_page(x)
Definition: paging.h:72
elf_file::ddbstrcnt
long ddbstrcnt
Definition: elf.h:64
endtask.h
DT_STRSZ
#define DT_STRSZ
Definition: elf_common.h:540
elf_file::nchains
Elf_Hashelt nchains
Definition: elf.h:44
strlen
int strlen(const char *str)
Definition: strlen.c:55
taskStruct::tss
struct tssStruct tss
Definition: sched.h:67
exec.h
i386_frame::eip
uint32_t eip
Definition: tss.h:102
ET_EXEC
#define ET_EXEC
Definition: elf_common.h:191
tssStruct::ss0
short ss0
Definition: tss.h:38
STACK_ADDR
#define STACK_ADDR
Definition: exec.c:40
PT_LOAD
#define PT_LOAD
Definition: elf_common.h:492
falloc
int falloc(struct thread *, struct file **, int *)
Definition: descrip.c:97
kpanic
void kpanic(const char *fmt,...)
print panic message and halt system
Definition: kpanic.c:41
types.h
bzero
#define bzero(buf, size)
Definition: gpt.h:37
DT_NEEDED
#define DT_NEEDED
Definition: elf_common.h:530
DT_RELAENT
#define DT_RELAENT
Definition: elf_common.h:539
sys_exec
int sys_exec(struct thread *td, char *file, char **argv, char **envp)
Definition: i386_exec.c:491
tssStruct::ss2
short ss2
Definition: tss.h:44
gdtDescriptor::access
unsigned char access
Definition: gdt.h:70
vmm_unmapPage
void vmm_unmapPage(uint32_t, unmapFlags_t)
Definition: unmappage.c:47
DT_SYMENT
#define DT_SYMENT
Definition: elf_common.h:541
taskStruct::td
struct thread td
Definition: sched.h:78
gdtDescriptor::granularity
unsigned int granularity
Definition: gdt.h:72
ARGV_PAGE
#define ARGV_PAGE
Definition: i386_exec.c:46
sprintf
int sprintf(char *buf, const char *fmt,...)
Definition: kprintf.c:278
osInfo::vmStart
uInt32 vmStart
Definition: sched.h:54
i386_frame
Definition: tss.h:84
tssStruct::esp
long esp
Definition: tss.h:50
tty_find
tty_term * tty_find(uInt16)
Definition: tty.c:167
ELF_AUX
#define ELF_AUX
Definition: i386_exec.c:47
LD_START
#define LD_START
Definition: kmod.h:34
kpanic.h
taskStruct::id
pidType id
Definition: sched.h:63
elf_file::got
Elf_Addr * got
Definition: elf.h:51
vmm_findFreePage
uint32_t vmm_findFreePage(pidType pid)
Definition: vmm_memory.c:221
thread::vm_taddr
u_long vm_taddr
Definition: thread.h:45
gdtDescriptor
Definition: gdt.h:66
DT_RELA
#define DT_RELA
Definition: elf_common.h:537
file::fd
fileDescriptor_t * fd
Definition: descrip.h:71
elf_file::relasize
int relasize
Definition: elf.h:59
thread::td_retval
int td_retval[2]
Definition: thread.h:41
execThread
uint32_t execThread(void(*tproc)(void), uint32_t stack, char *arg)
Definition: i386_exec.c:148
vmm_setPageAttributes
int vmm_setPageAttributes(uint32_t, uint16_t)
Definition: setpageattributes.c:39
fclose
int fclose(fileDescriptor_t *fd)
Definition: file.c:533
kprintf.h
elf_file::address
caddr_t address
Definition: elf.h:41
dData
#define dData
Definition: gdt.h:42
taskStruct::term
tty_term * term
Definition: sched.h:77
kernelPageDirectory
uint32_t * kernelPageDirectory
Definition: paging.c:41
ldEnable
uInt32 ldEnable()
PAGE_STACK
#define PAGE_STACK
Definition: paging.h:65
elf_file::strtab
caddr_t strtab
Definition: elf.h:48
tssStruct::ss
short ss
Definition: tss.h:58
PAGE_DEFAULT
#define PAGE_DEFAULT
Definition: paging.h:68
taskStruct::files
fileDescriptor_t * files[MAX_OFILES]
Definition: sched.h:71
DT_PLTRELSZ
#define DT_PLTRELSZ
Definition: elf_common.h:532
elf_file::dynamic
Elf_Dyn * dynamic
Definition: elf.h:42
thread::abi
int abi
Definition: thread.h:48
Elf32_Dyn::d_un
union Elf32_Dyn::@9 d_un
tssStruct::esp1
long esp1
Definition: tss.h:40
vmm_remapPage
int vmm_remapPage(uint32_t, uint32_t, uint16_t, pidType, int haveLock)
Definition: paging.c:199
uint32_t
__uint32_t uint32_t
Definition: types.h:46
ld.h
EI_OSABI
#define EI_OSABI
Definition: elf_common.h:126
DT_RELSZ
#define DT_RELSZ
Definition: elf_common.h:549
elf_file::ddbsymcnt
long ddbsymcnt
Definition: elf.h:62
DT_SYMTAB
#define DT_SYMTAB
Definition: elf_common.h:536
tssStruct::es
short es
Definition: tss.h:54
DT_STRTAB
#define DT_STRTAB
Definition: elf_common.h:535
elf_file::strsz
int strsz
Definition: elf.h:49
Elf32_Dyn::d_ptr
Elf32_Addr d_ptr
Definition: elf32.h:125
caddr_t
char * caddr_t
Definition: types.h:41
thread::vm_dsize
u_long vm_dsize
Definition: thread.h:44
_current
kTask_t * _current
Definition: sched.c:50
elf_file::ddbsymtab
const Elf_Sym * ddbsymtab
Definition: elf.h:61
sched_setStatus
int sched_setStatus(pidType pid, tState state)
Definition: sched.c:265
fileDescriptor::perms
uint32_t perms
Definition: file.h:76
tssStruct::cs
short cs
Definition: tss.h:56
schedNewTask
kTask_t * schedNewTask()
Definition: sched.c:135
DT_PLTGOT
#define DT_PLTGOT
Definition: elf_common.h:533
DT_HASH
#define DT_HASH
Definition: elf_common.h:534
tssStruct::fs
short fs
Definition: tss.h:62
thread::vm_daddr
u_long vm_daddr
Definition: thread.h:43
STACK_PAD
#define STACK_PAD
Definition: i386_exec.c:48
elf_file::pltrela
const Elf_Rela * pltrela
Definition: elf.h:54
tssStruct::edi
long edi
Definition: tss.h:53
elf_file::symtab
const Elf_Sym * symtab
Definition: elf.h:50
taskStruct::uid
uint32_t uid
Definition: sched.h:73
tssStruct::io_map
short io_map
Definition: tss.h:69
gdtDescriptor::baseLow
unsigned short baseLow
Definition: gdt.h:68
DT_RELENT
#define DT_RELENT
Definition: elf_common.h:550
tssStruct::ebp
long ebp
Definition: tss.h:51
ENOEXEC
#define ENOEXEC
Definition: i386_exec.c:50
taskStruct::pgrp
uint32_t pgrp
Definition: sched.h:87
elf_file::ddbstrtab
caddr_t ddbstrtab
Definition: elf.h:63
kmalloc
void * kmalloc(uInt32 len)
Definition: kmalloc.c:241
descrip.h
Elf32_Dyn::d_tag
Elf32_Sword d_tag
Definition: elf32.h:122
elf_file::nbuckets
Elf_Hashelt nbuckets
Definition: elf.h:43
memset
void * memset(void *dst, int c, size_t length)
tssStruct::esi
long esi
Definition: tss.h:52
gdtDescriptor::baseMed
unsigned char baseMed
Definition: gdt.h:69
elf_file::relsize
int relsize
Definition: elf.h:57
VMM_USER_START
#define VMM_USER_START
Definition: vmm.h:58
vmm_getFreeKernelPage
void * vmm_getFreeKernelPage(pidType pid, uint16_t count)
Definition: paging.c:291
DT_FINI
#define DT_FINI
Definition: elf_common.h:543
gdtDescriptor::baseHigh
unsigned char baseHigh
Definition: gdt.h:73
READY
Definition: sched.h:47
dBiglim
#define dBiglim
Definition: gdt.h:63
dBig
#define dBig
Definition: gdt.h:62
PAGE_SHIFT
#define PAGE_SHIFT
Definition: paging.h:36
PAGE_SIZE
#define PAGE_SIZE
Definition: paging.h:37
elf_file::chains
const Elf_Hashelt * chains
Definition: elf.h:46
PAGE_USER
#define PAGE_USER
Definition: paging.h:57
_null.h
tssStruct::trace_bitmap
short trace_bitmap
Definition: tss.h:68
gdtDescriptor::limitLow
unsigned short limitLow
Definition: gdt.h:67
thread::vm_tsize
u_long vm_tsize
Definition: thread.h:46
kprintf
int kprintf(const char *,...)
Definition: kprintf.c:259
elf_file::pltrel
const Elf_Rel * pltrel
Definition: elf.h:52
DT_REL
#define DT_REL
Definition: elf_common.h:548
tty_termNode::owner
pidType owner
Definition: tty.h:42
elf_file::rel
const Elf_Rel * rel
Definition: elf.h:56
PF_X
#define PF_X
Definition: elf_common.h:519
tssStruct::cr3
long cr3
Definition: tss.h:46
tssStruct::esp2
long esp2
Definition: tss.h:43
elf_file::buckets
const Elf_Hashelt * buckets
Definition: elf.h:45
elf.h
DT_RELASZ
#define DT_RELASZ
Definition: elf_common.h:538
tssStruct::gs
short gs
Definition: tss.h:64
elf_file::rela
const Elf_Rela * rela
Definition: elf.h:58
PT_INTERP
#define PT_INTERP
Definition: elf_common.h:494
PAGE_PRESENT
#define PAGE_PRESENT
Definition: paging.h:55
kmalloc.h
Elf32_Sym
Definition: elf32.h:195
taskStruct::oInfo
struct osInfo oInfo
Definition: sched.h:69
osInfo::cwd
char cwd[1024]
Definition: sched.h:58
ENVP_PAGE
#define ENVP_PAGE
Definition: i386_exec.c:45
gdtDescriptor::limitHigh
unsigned int limitHigh
Definition: gdt.h:71
dDpl3
#define dDpl3
Definition: gdt.h:50
taskStruct::gid
uint32_t gid
Definition: sched.h:73
dWrite
#define dWrite
Definition: gdt.h:57
fseek
int fseek(fileDescriptor_t *tmpFd, long offset, int whence)
Definition: file.c:332
NULL
#define NULL
Definition: fat_string.h:17