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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_proxy.cc

Issue 18644009: [NaCl SDK] Upate atomic ops in nacl_io (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add declartions for newval and oldval Created 7 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 | Annotate | Revision Log
OLDNEW
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_proxy.h" 5 #include "nacl_io/kernel_proxy.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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 347 }
348 348
349 ssize_t KernelProxy::read(int fd, void* buf, size_t nbytes) { 349 ssize_t KernelProxy::read(int fd, void* buf, size_t nbytes) {
350 ScopedKernelHandle handle; 350 ScopedKernelHandle handle;
351 Error error = AcquireHandle(fd, &handle); 351 Error error = AcquireHandle(fd, &handle);
352 if (error) { 352 if (error) {
353 errno = error; 353 errno = error;
354 return -1; 354 return -1;
355 } 355 }
356 356
357 AutoLock lock(&handle->lock_);
358 int cnt = 0; 357 int cnt = 0;
359 error = handle->node_->Read(handle->offs_, buf, nbytes, &cnt); 358 error = handle->Read(buf, nbytes, &cnt);
360 if (error) { 359 if (error) {
361 errno = error; 360 errno = error;
362 return -1; 361 return -1;
363 } 362 }
364 363
365 if (cnt > 0)
366 handle->offs_ += cnt;
367
368 return cnt; 364 return cnt;
369 } 365 }
370 366
371 ssize_t KernelProxy::write(int fd, const void* buf, size_t nbytes) { 367 ssize_t KernelProxy::write(int fd, const void* buf, size_t nbytes) {
372 ScopedKernelHandle handle; 368 ScopedKernelHandle handle;
373 Error error = AcquireHandle(fd, &handle); 369 Error error = AcquireHandle(fd, &handle);
374 if (error) { 370 if (error) {
375 errno = error; 371 errno = error;
376 return -1; 372 return -1;
377 } 373 }
378 374
379 AutoLock lock(&handle->lock_);
380 int cnt = 0; 375 int cnt = 0;
381 error = handle->node_->Write(handle->offs_, buf, nbytes, &cnt); 376 error = handle->Write(buf, nbytes, &cnt);
382 if (error) { 377 if (error) {
383 errno = error; 378 errno = error;
384 return -1; 379 return -1;
385 } 380 }
386 381
387 if (cnt > 0)
388 handle->offs_ += cnt;
389
390 return cnt; 382 return cnt;
391 } 383 }
392 384
393 int KernelProxy::fstat(int fd, struct stat* buf) { 385 int KernelProxy::fstat(int fd, struct stat* buf) {
394 ScopedKernelHandle handle; 386 ScopedKernelHandle handle;
395 Error error = AcquireHandle(fd, &handle); 387 Error error = AcquireHandle(fd, &handle);
396 if (error) { 388 if (error) {
397 errno = error; 389 errno = error;
398 return -1; 390 return -1;
399 } 391 }
400 392
401 error = handle->node_->GetStat(buf); 393 error = handle->node()->GetStat(buf);
402 if (error) { 394 if (error) {
403 errno = error; 395 errno = error;
404 return -1; 396 return -1;
405 } 397 }
406 398
407 return 0; 399 return 0;
408 } 400 }
409 401
410 int KernelProxy::getdents(int fd, void* buf, unsigned int count) { 402 int KernelProxy::getdents(int fd, void* buf, unsigned int count) {
411 ScopedKernelHandle handle; 403 ScopedKernelHandle handle;
412 Error error = AcquireHandle(fd, &handle); 404 Error error = AcquireHandle(fd, &handle);
413 if (error) { 405 if (error) {
414 errno = error; 406 errno = error;
415 return -1; 407 return -1;
416 } 408 }
417 409
418 AutoLock lock(&handle->lock_);
419 int cnt = 0; 410 int cnt = 0;
420 error = handle->node_ 411 error = handle->GetDents(static_cast<dirent*>(buf), count, &cnt);
421 ->GetDents(handle->offs_, static_cast<dirent*>(buf), count, &cnt);
422 if (error) 412 if (error)
423 errno = error; 413 errno = error;
424 414
425 if (cnt > 0)
426 handle->offs_ += cnt;
427
428 return cnt; 415 return cnt;
429 } 416 }
430 417
431 int KernelProxy::ftruncate(int fd, off_t length) { 418 int KernelProxy::ftruncate(int fd, off_t length) {
432 ScopedKernelHandle handle; 419 ScopedKernelHandle handle;
433 Error error = AcquireHandle(fd, &handle); 420 Error error = AcquireHandle(fd, &handle);
434 if (error) { 421 if (error) {
435 errno = error; 422 errno = error;
436 return -1; 423 return -1;
437 } 424 }
438 425
439 error = handle->node_->FTruncate(length); 426 error = handle->node()->FTruncate(length);
440 if (error) { 427 if (error) {
441 errno = error; 428 errno = error;
442 return -1; 429 return -1;
443 } 430 }
444 431
445 return 0; 432 return 0;
446 } 433 }
447 434
448 int KernelProxy::fsync(int fd) { 435 int KernelProxy::fsync(int fd) {
449 ScopedKernelHandle handle; 436 ScopedKernelHandle handle;
450 Error error = AcquireHandle(fd, &handle); 437 Error error = AcquireHandle(fd, &handle);
451 if (error) { 438 if (error) {
452 errno = error; 439 errno = error;
453 return -1; 440 return -1;
454 } 441 }
455 442
456 error = handle->node_->FSync(); 443 error = handle->node()->FSync();
457 if (error) { 444 if (error) {
458 errno = error; 445 errno = error;
459 return -1; 446 return -1;
460 } 447 }
461 448
462 return 0; 449 return 0;
463 } 450 }
464 451
465 int KernelProxy::isatty(int fd) { 452 int KernelProxy::isatty(int fd) {
466 ScopedKernelHandle handle; 453 ScopedKernelHandle handle;
467 Error error = AcquireHandle(fd, &handle); 454 Error error = AcquireHandle(fd, &handle);
468 if (error) { 455 if (error) {
469 errno = error; 456 errno = error;
470 return -1; 457 return -1;
471 } 458 }
472 459
473 error = handle->node_->IsaTTY(); 460 error = handle->node()->IsaTTY();
474 if (error) { 461 if (error) {
475 errno = error; 462 errno = error;
476 return -1; 463 return -1;
477 } 464 }
478 465
479 return 0; 466 return 0;
480 } 467 }
481 468
482 int KernelProxy::ioctl(int d, int request, char* argp) { 469 int KernelProxy::ioctl(int d, int request, char* argp) {
483 ScopedKernelHandle handle; 470 ScopedKernelHandle handle;
484 Error error = AcquireHandle(d, &handle); 471 Error error = AcquireHandle(d, &handle);
485 if (error) { 472 if (error) {
486 errno = error; 473 errno = error;
487 return -1; 474 return -1;
488 } 475 }
489 476
490 error = handle->node_->Ioctl(request, argp); 477 error = handle->node()->Ioctl(request, argp);
491 if (error) { 478 if (error) {
492 errno = error; 479 errno = error;
493 return -1; 480 return -1;
494 } 481 }
495 482
496 return 0; 483 return 0;
497 } 484 }
498 485
499 off_t KernelProxy::lseek(int fd, off_t offset, int whence) { 486 off_t KernelProxy::lseek(int fd, off_t offset, int whence) {
500 ScopedKernelHandle handle; 487 ScopedKernelHandle handle;
501 Error error = AcquireHandle(fd, &handle); 488 Error error = AcquireHandle(fd, &handle);
502 if (error) { 489 if (error) {
503 errno = error; 490 errno = error;
504 return -1; 491 return -1;
505 } 492 }
506 493
507 AutoLock lock(&handle->lock_);
508 off_t new_offset; 494 off_t new_offset;
509 error = handle->Seek(offset, whence, &new_offset); 495 error = handle->Seek(offset, whence, &new_offset);
510 if (error) { 496 if (error) {
511 errno = error; 497 errno = error;
512 return -1; 498 return -1;
513 } 499 }
514 500
515 return new_offset; 501 return new_offset;
516 } 502 }
517 503
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 assert(fd != -1); 591 assert(fd != -1);
606 592
607 ScopedKernelHandle handle; 593 ScopedKernelHandle handle;
608 Error error = AcquireHandle(fd, &handle); 594 Error error = AcquireHandle(fd, &handle);
609 if (error) { 595 if (error) {
610 errno = error; 596 errno = error;
611 return MAP_FAILED; 597 return MAP_FAILED;
612 } 598 }
613 599
614 void* new_addr; 600 void* new_addr;
615 AutoLock lock(&handle->lock_); 601 error = handle->node()->MMap(addr, length, prot, flags, offset, &new_addr);
616 error = handle->node_->MMap(addr, length, prot, flags, offset, &new_addr);
617 if (error) { 602 if (error) {
618 errno = error; 603 errno = error;
619 return MAP_FAILED; 604 return MAP_FAILED;
620 } 605 }
621 606
622 return new_addr; 607 return new_addr;
623 } 608 }
624 609
625 int KernelProxy::munmap(void* addr, size_t length) { 610 int KernelProxy::munmap(void* addr, size_t length) {
626 // NOTE: The comment below is from a previous discarded implementation that 611 // NOTE: The comment below is from a previous discarded implementation that
(...skipping 23 matching lines...) Expand all
650 // Unfortunately, munmap still needs to acquire other locks; see the call to 635 // Unfortunately, munmap still needs to acquire other locks; see the call to
651 // ReleaseHandle below which takes the process lock. This is safe as long as 636 // ReleaseHandle below which takes the process lock. This is safe as long as
652 // this is never executed from free() -- we can be reasonably sure this is 637 // this is never executed from free() -- we can be reasonably sure this is
653 // true, because malloc only makes anonymous mmap() requests, and should only 638 // true, because malloc only makes anonymous mmap() requests, and should only
654 // be munmapping those allocations. We never add to mmap_info_list_ for 639 // be munmapping those allocations. We never add to mmap_info_list_ for
655 // anonymous maps, so the unmap_list should always be empty when called from 640 // anonymous maps, so the unmap_list should always be empty when called from
656 // free(). 641 // free().
657 return 0; 642 return 0;
658 } 643 }
659 644
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698