Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1. #include "userprog/syscall.h"
  2. #include <stdio.h>
  3. #include <syscall-nr.h>
  4. #include "threads/interrupt.h"
  5. #include "threads/thread.h"
  6.  
  7. static void syscall_handler (struct intr_frame *);
  8. void
  9. exit_code_init(void)
  10. {
  11.     struct exit_code *tmp=(struct exit_code*)malloc(sizeof(struct exit_code));
  12.     tmp->exitCode=0;
  13.     strlcpy (tmp->name, "NULL", sizeof tmp->name);
  14.     root_ex=tmp;
  15.     tmp->next=NULL;
  16.     printf("Struct exit_code was init\n");
  17. }
  18. void
  19. exit_code_add(struct exit_code *t, int exCode, const char *name_ex)
  20. {
  21.     struct exit_code *tmp=malloc(sizeof(struct exit_code));
  22.     tmp=t->next;
  23.     if (tmp==NULL)
  24.     {
  25.         tmp->exitCode=exCode;
  26.         strlcpy (tmp->name, name_ex, sizeof tmp->name);
  27.         tmp->next=NULL;
  28.         printf("Was Add %s with %d exit code\n", tmp->name, tmp->exitCode);
  29.     }
  30.     else
  31.     {
  32.         exit_code_add(tmp, exCode, name_ex);
  33.     }
  34. }
  35. int
  36. exit_code_search_target_proc(struct thread *t, struct exit_code *temp) //
  37. {
  38.     struct exit_code *tmp=malloc(sizeof(struct exit_code));
  39. }
  40. void
  41. syscall_init (void)
  42. {
  43.   intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
  44. }
  45.  
  46. static void
  47. syscall_handler (struct intr_frame *f)
  48. {
  49.    if ( *(int*) f->esp == SYS_WRITE) // системный вызов write
  50.    {      
  51.         putbuf( ((const char**) f->esp)[2], ((size_t*) f->esp)[3]);      
  52.         return;  
  53.    }
  54.    if (*(int*) f->esp == SYS_EXIT)
  55.    {      
  56.         int exit_status = ((size_t*) f->esp)[1];  
  57.         struct thread *cur=thread_current();
  58.         exit_code_add(root_ex, exit_status, cur->name);      
  59.         thread_exit();// вызов exit() должен завершать программу  
  60.    }
  61.   printf ("system call!\n");
  62.   thread_exit ();
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement