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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "nacl_io/mount_node.h"
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <string>
#include "nacl_io/kernel_wrap_real.h"
#include "nacl_io/mount.h"
#include "nacl_io/osmman.h"
#include "utils/auto_lock.h"
static const int USR_ID = 1001;
static const int GRP_ID = 1002;
MountNode::MountNode(Mount* mount)
: mount_(mount) {
memset(&stat_, 0, sizeof(stat_));
stat_.st_gid = GRP_ID;
stat_.st_uid = USR_ID;
// Mount should normally never be NULL, but may be null in tests.
if (mount_)
mount_->OnNodeCreated(this);
}
MountNode::~MountNode() {
}
bool MountNode::Init(int perm) {
stat_.st_mode |= perm;
return true;
}
void MountNode::Destroy() {
if (mount_) {
mount_->OnNodeDestroyed(this);
}
}
int MountNode::FSync() {
return 0;
}
int MountNode::GetDents(size_t offs, struct dirent* pdir, size_t count) {
errno = ENOTDIR;
return -1;
}
int MountNode::GetStat(struct stat* pstat) {
AutoLock lock(&lock_);
memcpy(pstat, &stat_, sizeof(stat_));
return 0;
}
int MountNode::Ioctl(int request, char* arg) {
errno = EINVAL;
return -1;
}
int MountNode::Read(size_t offs, void* buf, size_t count) {
errno = EINVAL;
return -1;
}
int MountNode::Truncate(size_t size) {
errno = EINVAL;
return -1;
}
int MountNode::Write(size_t offs, const void* buf, size_t count) {
errno = EINVAL;
return -1;
}
void* MountNode::MMap(void* addr, size_t length, int prot, int flags,
size_t offset) {
// Never allow mmap'ing PROT_EXEC. The passthrough node supports this, but we
// don't. Fortunately, glibc will fallback if this fails, so dlopen will
// continue to work.
if (prot & PROT_EXEC) {
errno = EPERM;
return MAP_FAILED;
}
// This default mmap support is just enough to make dlopen work.
// This implementation just reads from the mount into the mmap'd memory area.
void* new_addr = addr;
int err = _real_mmap(&new_addr, length, prot | PROT_WRITE, flags |
MAP_ANONYMOUS, -1, 0);
if (new_addr == MAP_FAILED) {
_real_munmap(new_addr, length);
errno = err;
return MAP_FAILED;
}
ssize_t cnt = Read(offset, new_addr, length);
if (cnt == -1) {
_real_munmap(new_addr, length);
errno = ENOSYS;
return MAP_FAILED;
}
return new_addr;
}
int MountNode::Munmap(void* addr, size_t length) {
return _real_munmap(addr, length);
}
int MountNode::GetLinks() {
return stat_.st_nlink;
}
int MountNode::GetMode() {
return stat_.st_mode & ~S_IFMT;
}
size_t MountNode::GetSize() {
return stat_.st_size;
}
int MountNode::GetType() {
return stat_.st_mode & S_IFMT;
}
bool MountNode::IsaDir() {
return (stat_.st_mode & S_IFDIR) != 0;
}
bool MountNode::IsaFile() {
return (stat_.st_mode & S_IFREG) != 0;
}
bool MountNode::IsaTTY() {
return (stat_.st_mode & S_IFCHR) != 0;
}
int MountNode:: AddChild(const std::string& name, MountNode* node) {
errno = ENOTDIR;
return -1;
}
int MountNode::RemoveChild(const std::string& name) {
errno = ENOTDIR;
return -1;
}
MountNode* MountNode::FindChild(const std::string& name) {
errno = ENOTDIR;
return NULL;
}
int MountNode::ChildCount() {
errno = ENOTDIR;
return -1;
}
void MountNode::Link() {
Acquire();
stat_.st_nlink++;
}
void MountNode::Unlink() {
stat_.st_nlink--;
Release();
}
|