| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * be found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Service Runtime Object Proxy. Used for the NaCl file system | 8 * NaCl Service Runtime Object Proxy. Used for the NaCl file system |
| 9 * and as a generic object proxy mechanism. | 9 * and as a generic object proxy mechanism. |
| 10 */ | 10 */ |
| 11 | 11 |
| 12 #include "native_client/src/include/portability.h" | 12 #include "native_client/src/include/portability.h" |
| 13 | 13 |
| 14 #include <string.h> | 14 #include <string.h> |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 NaClMutexDtor(&self->mu); | 236 NaClMutexDtor(&self->mu); |
| 237 } | 237 } |
| 238 | 238 |
| 239 | 239 |
| 240 uint8_t const *NaClObjProxyFindNameByObj(struct NaClObjProxy *self, | 240 uint8_t const *NaClObjProxyFindNameByObj(struct NaClObjProxy *self, |
| 241 void *obj) { | 241 void *obj) { |
| 242 struct NaClObjProxyEntry *found = NULL; | 242 struct NaClObjProxyEntry *found = NULL; |
| 243 struct NaClContainerHashTblIter iter; | 243 struct NaClContainerHashTblIter iter; |
| 244 uint8_t const *rv = NULL; | 244 uint8_t const *rv = NULL; |
| 245 | 245 |
| 246 NaClMutexLock(&self->mu); | 246 NaClXMutexLock(&self->mu); |
| 247 self->key->obj = obj; | 247 self->key->obj = obj; |
| 248 (*self->obj_to_name->vtbl->Find)(self->obj_to_name, | 248 (*self->obj_to_name->vtbl->Find)(self->obj_to_name, |
| 249 self->key, | 249 self->key, |
| 250 (struct NaClContainerIter *) &iter); | 250 (struct NaClContainerIter *) &iter); |
| 251 if (!(*iter.base.vtbl->AtEnd)((struct NaClContainerIter *) &iter)) { | 251 if (!(*iter.base.vtbl->AtEnd)((struct NaClContainerIter *) &iter)) { |
| 252 found = ((struct NaClObjProxyEntry *) | 252 found = ((struct NaClObjProxyEntry *) |
| 253 (*iter.base.vtbl->Star)((struct NaClContainerIter *) &iter)); | 253 (*iter.base.vtbl->Star)((struct NaClContainerIter *) &iter)); |
| 254 rv = found->name; | 254 rv = found->name; |
| 255 } | 255 } |
| 256 NaClMutexUnlock(&self->mu); | 256 NaClXMutexUnlock(&self->mu); |
| 257 | 257 |
| 258 return rv; | 258 return rv; |
| 259 } | 259 } |
| 260 | 260 |
| 261 | 261 |
| 262 int NaClObjProxyFindObjByName(struct NaClObjProxy *self, | 262 int NaClObjProxyFindObjByName(struct NaClObjProxy *self, |
| 263 uint8_t const *name, | 263 uint8_t const *name, |
| 264 void **out) { | 264 void **out) { |
| 265 struct NaClObjProxyEntry *found = NULL; | 265 struct NaClObjProxyEntry *found = NULL; |
| 266 struct NaClContainerHashTblIter iter; | 266 struct NaClContainerHashTblIter iter; |
| 267 int rv = 0; | 267 int rv = 0; |
| 268 | 268 |
| 269 NaClMutexLock(&self->mu); | 269 NaClXMutexLock(&self->mu); |
| 270 memcpy(self->key->name, name, self->name_bytes); | 270 memcpy(self->key->name, name, self->name_bytes); |
| 271 (*self->name_to_obj->vtbl->Find)(self->name_to_obj, | 271 (*self->name_to_obj->vtbl->Find)(self->name_to_obj, |
| 272 self->key, | 272 self->key, |
| 273 (struct NaClContainerIter *) &iter); | 273 (struct NaClContainerIter *) &iter); |
| 274 if (!(*iter.base.vtbl->AtEnd)((struct NaClContainerIter *) &iter)) { | 274 if (!(*iter.base.vtbl->AtEnd)((struct NaClContainerIter *) &iter)) { |
| 275 found = ((struct NaClObjProxyEntry *) | 275 found = ((struct NaClObjProxyEntry *) |
| 276 (*iter.base.vtbl->Star)((struct NaClContainerIter *) &iter)); | 276 (*iter.base.vtbl->Star)((struct NaClContainerIter *) &iter)); |
| 277 *out = found->obj; | 277 *out = found->obj; |
| 278 #if DEBUG | 278 #if DEBUG |
| 279 printf("ObjByName %d: %02x%02x%02x...\n", (int) found->obj, | 279 printf("ObjByName %d: %02x%02x%02x...\n", (int) found->obj, |
| 280 self->key->name[0], self->key->name[1], self->key->name[2]); | 280 self->key->name[0], self->key->name[1], self->key->name[2]); |
| 281 #endif | 281 #endif |
| 282 rv = 1; | 282 rv = 1; |
| 283 } | 283 } |
| 284 NaClMutexUnlock(&self->mu); | 284 NaClXMutexUnlock(&self->mu); |
| 285 return rv; | 285 return rv; |
| 286 } | 286 } |
| 287 | 287 |
| 288 | 288 |
| 289 uint8_t const *NaClObjProxyInsert(struct NaClObjProxy *self, void *obj) { | 289 uint8_t const *NaClObjProxyInsert(struct NaClObjProxy *self, void *obj) { |
| 290 struct NaClObjProxyEntry *entry = NULL; | 290 struct NaClObjProxyEntry *entry = NULL; |
| 291 struct NaClObjProxyEntry *entry2 = NULL; | 291 struct NaClObjProxyEntry *entry2 = NULL; |
| 292 uint8_t const *rv = NULL; | 292 uint8_t const *rv = NULL; |
| 293 #if PARANOID | 293 #if PARANOID |
| 294 void *out; | 294 void *out; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 317 } while (NaClObjProxyFindObjByName(self, entry->name, &out)); | 317 } while (NaClObjProxyFindObjByName(self, entry->name, &out)); |
| 318 #endif | 318 #endif |
| 319 memcpy(entry2, entry, (sizeof *entry) + self->name_bytes); | 319 memcpy(entry2, entry, (sizeof *entry) + self->name_bytes); |
| 320 #if DEBUG | 320 #if DEBUG |
| 321 printf("entry: %d: %02x%02x%02x...\n", (int) entry->obj, | 321 printf("entry: %d: %02x%02x%02x...\n", (int) entry->obj, |
| 322 entry->name[0], entry->name[1], entry->name[2]); | 322 entry->name[0], entry->name[1], entry->name[2]); |
| 323 printf("entry2: %d: %02x%02x%02x...\n", (int) entry2->obj, | 323 printf("entry2: %d: %02x%02x%02x...\n", (int) entry2->obj, |
| 324 entry2->name[0], entry2->name[1], entry2->name[2]); | 324 entry2->name[0], entry2->name[1], entry2->name[2]); |
| 325 #endif | 325 #endif |
| 326 | 326 |
| 327 NaClMutexLock(&self->mu); | 327 NaClXMutexLock(&self->mu); |
| 328 (*self->obj_to_name->vtbl->Insert)(self->obj_to_name, entry); | 328 (*self->obj_to_name->vtbl->Insert)(self->obj_to_name, entry); |
| 329 (*self->name_to_obj->vtbl->Insert)(self->name_to_obj, entry2); | 329 (*self->name_to_obj->vtbl->Insert)(self->name_to_obj, entry2); |
| 330 NaClMutexUnlock(&self->mu); | 330 NaClXMutexUnlock(&self->mu); |
| 331 | 331 |
| 332 rv = entry->name; | 332 rv = entry->name; |
| 333 cleanup: | 333 cleanup: |
| 334 return rv; | 334 return rv; |
| 335 } | 335 } |
| 336 | 336 |
| 337 | 337 |
| 338 int NaClObjProxyRemove(struct NaClObjProxy *self, void *obj) { | 338 int NaClObjProxyRemove(struct NaClObjProxy *self, void *obj) { |
| 339 /* | 339 /* |
| 340 * must first find the entry so we know its randomly assigned name, | 340 * must first find the entry so we know its randomly assigned name, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 361 NaClLog(LOG_FATAL, "object %08"NACL_PRIxPTR | 361 NaClLog(LOG_FATAL, "object %08"NACL_PRIxPTR |
| 362 " found in o2n tbl, but not in n2o\n", | 362 " found in o2n tbl, but not in n2o\n", |
| 363 (uintptr_t) obj); | 363 (uintptr_t) obj); |
| 364 return 0; /* internal error! */ | 364 return 0; /* internal error! */ |
| 365 } | 365 } |
| 366 (*o2niter.base.vtbl->Erase)((struct NaClContainerIter *) &o2niter); | 366 (*o2niter.base.vtbl->Erase)((struct NaClContainerIter *) &o2niter); |
| 367 (*n2oiter.base.vtbl->Erase)((struct NaClContainerIter *) &n2oiter); | 367 (*n2oiter.base.vtbl->Erase)((struct NaClContainerIter *) &n2oiter); |
| 368 | 368 |
| 369 return 1; | 369 return 1; |
| 370 } | 370 } |
| OLD | NEW |