-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsyscall.c
More file actions
89 lines (65 loc) · 1.3 KB
/
syscall.c
File metadata and controls
89 lines (65 loc) · 1.3 KB
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
#include "u.h"
#include "defs.h"
#include "file.h"
#include "proc.h"
int
argint(int n, int *ip)
{
long l;
if (n < 0 || n > 5)
panic("argint");
if (arglong(n, &l) < 0)
return -1;
*ip = (int)l;
return 0;
}
int
argptr(int n, uintptr *p, usize size)
{
long l;
if (n < 0 || n > 5)
panic("argptr");
if (arglong(n, &l) < 0)
return -1;
if ((uintptr)l >= proc->sz || (uintptr)l+size > proc->sz)
return -1;
*p = (uintptr)l;
return 0;
}
// returns length of string, not including null
long
argstr(int n, char **pp)
{
long l;
uintptr addr;
char *p;
if (n < 0 || n > 5)
panic("argstr");
if (arglong(n, &l) < 0)
return -1;
addr = (uintptr)l;
if (addr >= proc->sz)
return -1;
*pp = (char *)addr;
for (p = (char *)addr; p < (char *)proc->sz; p++)
if (*p == 0)
return p - *pp;
return -1;
}
int
argfd(int n, int *fd)
{
int i;
if (n < 0 || n > 5)
panic("argfd");
if (argint(n, &i) < 0)
return -1;
if (i >= proc->nextfd || proc->files[i] == nil) {
// todo errstr
return -1;
}
if (proc->files[i]->ref < 1)
panic("argfd - proc->files[fd] references unallocated file");
*fd = i;
return 0;
}