OLD | NEW |
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 #include "nacl_io/kernel_object.h" | 5 #include "nacl_io/kernel_object.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <pthread.h> | 10 #include <pthread.h> |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void KernelObject::ReleaseHandle(KernelHandle* handle) { | 108 void KernelObject::ReleaseHandle(KernelHandle* handle) { |
109 // The handle must already be held before taking the | 109 // The handle must already be held before taking the |
110 // kernel lock. | 110 // kernel lock. |
111 if (handle->node_) handle->mount_->ReleaseNode(handle->node_); | 111 if (handle->node_) handle->mount_->ReleaseNode(handle->node_); |
112 | 112 |
113 AutoLock lock(&process_lock_); | 113 AutoLock lock(&process_lock_); |
114 handle->Release(); | 114 handle->Release(); |
115 } | 115 } |
116 | 116 |
117 // Helper function to properly sort FD order in the heap, forcing | 117 // Helper function to properly sort FD order in the heap, forcing |
118 // lower numberd FD to be available first. | 118 // lower numbered FD to be available first. |
119 static bool FdOrder(int i, int j) { | 119 static bool FdOrder(int i, int j) { |
120 return i > j; | 120 return i > j; |
121 } | 121 } |
122 | 122 |
123 int KernelObject::AllocateFD(KernelHandle* handle) { | 123 int KernelObject::AllocateFD(KernelHandle* handle) { |
124 AutoLock lock(&process_lock_); | 124 AutoLock lock(&process_lock_); |
125 int id; | 125 int id; |
126 | 126 |
127 // Acquire the handle and its mount since we are about to track it with | 127 // Acquire the handle and its mount since we are about to track it with |
128 // this FD. | 128 // this FD. |
(...skipping 12 matching lines...) Expand all Loading... |
141 } | 141 } |
142 return id; | 142 return id; |
143 } | 143 } |
144 | 144 |
145 void KernelObject::FreeAndReassignFD(int fd, KernelHandle* handle) { | 145 void KernelObject::FreeAndReassignFD(int fd, KernelHandle* handle) { |
146 if (NULL == handle) { | 146 if (NULL == handle) { |
147 FreeFD(fd); | 147 FreeFD(fd); |
148 } else { | 148 } else { |
149 AutoLock lock(&process_lock_); | 149 AutoLock lock(&process_lock_); |
150 | 150 |
151 // Acquire the new handle first incase they are the same. | 151 // Acquire the new handle first in case they are the same. |
152 if (handle) { | 152 if (handle) { |
153 handle->Acquire(); | 153 handle->Acquire(); |
154 handle->mount_->Acquire(); | 154 handle->mount_->Acquire(); |
155 } | 155 } |
156 | 156 |
157 // If the required FD is larger than the current set, grow the set | 157 // If the required FD is larger than the current set, grow the set |
158 if (fd >= handle_map_.size()) { | 158 if (fd >= handle_map_.size()) { |
159 handle_map_.resize(fd + 1); | 159 handle_map_.resize(fd + 1); |
160 } else { | 160 } else { |
161 KernelHandle* old_handle = handle_map_[fd]; | 161 KernelHandle* old_handle = handle_map_[fd]; |
(...skipping 25 matching lines...) Expand all Loading... |
187 Path abs_path(cwd_); | 187 Path abs_path(cwd_); |
188 if (path[0] == '/') { | 188 if (path[0] == '/') { |
189 abs_path = path; | 189 abs_path = path; |
190 } else { | 190 } else { |
191 abs_path = cwd_; | 191 abs_path = cwd_; |
192 abs_path.Append(path); | 192 abs_path.Append(path); |
193 } | 193 } |
194 | 194 |
195 return abs_path; | 195 return abs_path; |
196 } | 196 } |
OLD | NEW |