Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/native_client/src/trusted/desc/nacl_desc_wrapper.cc

Issue 2961004: Plugin: Remove __socketAddressFactory() and toString() on SocketAddresses (Closed)
Patch Set: Apply HTML changes to copies in "prebuilt" too Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2009 The Native Client 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 <limits> 5 #include <limits>
6 #include <new> 6 #include <new>
7 #include "native_client/src/include/portability.h" 7 #include "native_client/src/include/portability.h"
8 #include "native_client/src/include/portability_string.h" 8 #include "native_client/src/include/portability_string.h"
9 #include "native_client/src/shared/imc/nacl_imc.h" 9 #include "native_client/src/shared/imc/nacl_imc.h"
10 #include "native_client/src/shared/platform/nacl_log.h" 10 #include "native_client/src/shared/platform/nacl_log.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 #endif // NACL_STANDALONE 319 #endif // NACL_STANDALONE
320 320
321 DescWrapper* DescWrapperFactory::MakeGeneric(struct NaClDesc* desc) { 321 DescWrapper* DescWrapperFactory::MakeGeneric(struct NaClDesc* desc) {
322 // Return an error if the factory wasn't properly initialized. 322 // Return an error if the factory wasn't properly initialized.
323 if (!common_data_->is_initialized()) { 323 if (!common_data_->is_initialized()) {
324 return NULL; 324 return NULL;
325 } 325 }
326 return new(std::nothrow) DescWrapper(common_data_, desc); 326 return new(std::nothrow) DescWrapper(common_data_, desc);
327 } 327 }
328 328
329 DescWrapper* DescWrapperFactory::MakeSocketAddress(const char* str) {
330 struct NaClDescConnCap* conn_cap = NULL;
331 DescWrapper* wrapper = NULL;
332
333 // Ensure argument is a valid string short enough to be a socket address.
334 if (NULL == str) {
335 return NULL;
336 }
337 size_t len = strnlen(str, NACL_PATH_MAX);
338 // strnlen ensures NACL_PATH_MAX >= len. If NACL_PATH_MAX == len, then
339 // there is not enough room to hold the address.
340 if (NACL_PATH_MAX == len) {
341 return NULL;
342 }
343 // Create a NaClSocketAddress from the string.
344 struct NaClSocketAddress sock_addr;
345 // We need len + 1 to guarantee the zero byte is written. This is safe,
346 // since NACL_PATH_MAX >= len + 1 from above.
347 strncpy(sock_addr.path, str, len + 1);
348 // Create a NaClDescConnCap from the socket address.
349 conn_cap = reinterpret_cast<NaClDescConnCap*>(
350 calloc(1, sizeof(*conn_cap)));
351 if (NULL == conn_cap) {
352 goto cleanup;
353 }
354 if (!NaClDescConnCapCtor(conn_cap, &sock_addr)) {
355 free(conn_cap);
356 conn_cap = NULL;
357 goto cleanup;
358 }
359 wrapper = MakeGeneric(reinterpret_cast<struct NaClDesc*>(conn_cap));
360 if (NULL == wrapper) {
361 goto cleanup;
362 }
363 // If wrapper was created, it took ownership. If not, NaClDescUnref freed it.
364 conn_cap = NULL;
365 return wrapper;
366
367 cleanup:
368 NaClDescSafeUnref(reinterpret_cast<struct NaClDesc*>(conn_cap));
369 return NULL;
370 }
371
372 int DescWrapperFactory::MakeSocketPair(DescWrapper* pair[2]) { 329 int DescWrapperFactory::MakeSocketPair(DescWrapper* pair[2]) {
373 // Return an error if the factory wasn't properly initialized. 330 // Return an error if the factory wasn't properly initialized.
374 if (!common_data_->is_initialized()) { 331 if (!common_data_->is_initialized()) {
375 return -1; 332 return -1;
376 } 333 }
377 struct NaClDesc* descs[2] = { NULL, NULL }; 334 struct NaClDesc* descs[2] = { NULL, NULL };
378 DescWrapper* tmp_pair[2] = { NULL, NULL }; 335 DescWrapper* tmp_pair[2] = { NULL, NULL };
379 336
380 int ret = NaClCommonDescSocketPair(descs); 337 int ret = NaClCommonDescSocketPair(descs);
381 if (0 != ret) { 338 if (0 != ret) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 } 423 }
467 424
468 DescWrapper::~DescWrapper() { 425 DescWrapper::~DescWrapper() {
469 if (NULL != common_data_) { 426 if (NULL != common_data_) {
470 common_data_->Unref(); 427 common_data_->Unref();
471 } 428 }
472 NaClDescSafeUnref(desc_); 429 NaClDescSafeUnref(desc_);
473 desc_ = NULL; 430 desc_ = NULL;
474 } 431 }
475 432
476 const char* DescWrapper::conn_cap_path() const {
477 if (NULL == desc_ || NACL_DESC_CONN_CAP != type_tag()) {
478 return NULL;
479 }
480 struct NaClDescConnCap* conn_cap =
481 reinterpret_cast<struct NaClDescConnCap*>(desc_);
482 return conn_cap->cap.path;
483 }
484
485 int DescWrapper::Map(void** addr, size_t* size) { 433 int DescWrapper::Map(void** addr, size_t* size) {
486 return NaClDescMapDescriptor(desc_, common_data_->effp(), addr, size); 434 return NaClDescMapDescriptor(desc_, common_data_->effp(), addr, size);
487 } 435 }
488 436
489 int DescWrapper::Unmap(void* start_addr, size_t len) { 437 int DescWrapper::Unmap(void* start_addr, size_t len) {
490 return desc_->vtbl->Unmap(desc_, common_data_->effp(), start_addr, len); 438 return desc_->vtbl->Unmap(desc_, common_data_->effp(), start_addr, len);
491 } 439 }
492 440
493 ssize_t DescWrapper::Read(void* buf, size_t len) { 441 ssize_t DescWrapper::Read(void* buf, size_t len) {
494 return desc_->vtbl->Read(desc_, common_data_->effp(), buf, len); 442 return desc_->vtbl->Read(desc_, common_data_->effp(), buf, len);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 663
716 int DescWrapper::SemWait() { 664 int DescWrapper::SemWait() {
717 return desc_->vtbl->SemWait(desc_, common_data_->effp()); 665 return desc_->vtbl->SemWait(desc_, common_data_->effp());
718 } 666 }
719 667
720 int DescWrapper::GetValue() { 668 int DescWrapper::GetValue() {
721 return desc_->vtbl->GetValue(desc_, common_data_->effp()); 669 return desc_->vtbl->GetValue(desc_, common_data_->effp());
722 } 670 }
723 671
724 } // namespace nacl 672 } // namespace nacl
OLDNEW
« no previous file with comments | « src/native_client/src/trusted/desc/nacl_desc_wrapper.h ('k') | src/native_client/src/trusted/plugin/srpc/plugin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698