53 / 3 / 0
Регистрация: 08.10.2011
Сообщений: 200
|
|
1
|
системные вызовы (юзерпрограмма)
04.10.2012, 03:36. Показов 926. Ответов 0
добрый вечер!помогите ,пжлста, разобраться с пользовательской программой
как правильно передать полученные занчение пользовательской программе
C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| int
process_open(const char *name)
{
bool success = false;
int i = 0;
while(!success && i < 128){
if(files[i] == NULL){
files[i] = filesys_open(name);
printf("File opened. fd = %d\n", i);
success = true;
return i;
}
i++;
printf("File could not be opened.");
}
return -1;
}
void
process_close(int fd){
files[fd] = NULL;
printf("File closed. fd = %d\n", fd);
} |
|
C | 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
| /*syscall.c*/
#include "userprog/syscall.h"
#include <stdio.h>
#include <syscall-nr.h>
#include "threads/interrupt.h"
#include "threads/thread.h"
#include "threads/init.h"
#include "filesys/filesys.h"
#include <string.h>
#include "userprog/process.h"
static void syscall_handler (struct intr_frame *);
void sys_halt (void);
void sys_write (int fd, const void* buffer, unsigned size);
void sys_open (const char *name);
void sys_close (int fd);
void
syscall_init (void)
{
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
}
static void
syscall_handler (struct intr_frame *f UNUSED) //TODO: Write tests.
{
int *stack_pointer = f->esp; // Stack pointer
printf ("System call: "); // How to put out the name of the System call?
switch (stack_pointer[0]) {
case SYS_HALT:
printf ("SYS_HALT.\n");
sys_halt();
return;
case SYS_EXIT:
printf ("SYS_EXIT.\n");
return;
case SYS_EXEC:
printf ("SYS_EXEC.\n");
return;
case SYS_WAIT:
printf ("SYS_WAIT.\n");
return;
case SYS_CREATE:
printf ("SYS_CREATE.\n");
// filesys_create ( (const char*) stack_pointer[1], (unsigned) stack_pointer[2]);
return;
case SYS_REMOVE:
printf ("SYS_REMOVE.\n");
return;
case SYS_OPEN:
printf("SYS_OPEN.\n");
sys_open ((const char*) stack_pointer[1]);
return;
case SYS_FILESIZE:
printf("SYS_FILESIZE.\n");
return;
case SYS_READ:
printf("SYS_READ.\n");
return;
case SYS_WRITE:
printf("SYS_WRITE.\n");
sys_write ((int) stack_pointer[1], (char*) stack_pointer[2], (unsigned) stack_pointer[3]);
return;
case SYS_SEEK:
printf("SYS_SEEK.\n");
return;
case SYS_TELL:
printf("SYS_TELL.\n");
return;
case SYS_CLOSE:
printf("SYS_CLOSE.\n");
sys_close((int) stack_pointer[1]);
return;
case SYS_MMAP:
printf("SYS_MMAP.\n");
return;
case SYS_MUNMAP:
printf("SYS_MUNMAP.\n");
return;
case SYS_CHDIR:
printf("SYS_CHDIR.\n");
return;
case SYS_MKDIR:
printf("SYS_MKDIR.\n");
return;
case SYS_READDIR:
printf("SYS_READDIR.\n");
return;
case SYS_ISDIR:
printf("SYS_ISDIR.\n");
return;
case SYS_INUMBER:
printf("SYS_INUMBER.\n");
return;
default:
printf ("System call %i not implemented yet!\n", (int) stack_pointer[0]); // Prints the number of the system call not implemented yet!
return; // Can this line be left out?
}
}
void
sys_halt (void)
{
//TODO: Terminate user programme
power_off ();
}
void
sys_open (const char *name) {
process_open (name);
}
void
sys_close (int fd) {
process_close (fd);
}
void
sys_write (int fd, const void* buffer, unsigned size) // TODO rewrite
{
if (fd == STDOUT_FILENO) {
putbuf((char *) buffer, size);
} /* else if (is_thread_file(fd)) {
file_write(get_thread_file(fd), buffer, size);
} */
} |
|
C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| int process_open(const char *name)
{
bool success = false;
int i = 0;
while(!success && i < 128){
if(files[i] == NULL){
files[i] = filesys_open(name);
printf("File opened. fd = %d\n", i);
success = true;
return i;
}
i++;
printf("File could not be opened.");
}
return -1;
}
void
process_close(int fd){
files[fd] = NULL;
printf("File closed. fd = %d\n", fd);
} |
|
C | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| /*PROCESS.H*/
#ifndef USERPROG_PROCESS_H
#define USERPROG_PROCESS_H
#include "threads/thread.h"
tid_t process_execute (const char *file_name);
int process_wait (tid_t);
void process_exit (void);
void process_activate (void);
#endif /* userprog/process.h */
int process_open(const char *name);
void process_close(int fd); |
|
0
|