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

Side by Side Diff: src/trusted/service_runtime/sys_filename.c

Issue 24889002: Provides some of the missing POSIX file syscalls Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 2 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
« no previous file with comments | « src/trusted/service_runtime/sys_filename.h ('k') | src/untrusted/irt/irt_fdio.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include "native_client/src/trusted/service_runtime/sys_filename.h" 7 #include "native_client/src/trusted/service_runtime/sys_filename.h"
8 8
9 #include <string.h> 9 #include <string.h>
10 10
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 332 }
333 333
334 retval = CopyPathFromUser(nap, path, sizeof path, pathname); 334 retval = CopyPathFromUser(nap, path, sizeof path, pathname);
335 if (0 != retval) 335 if (0 != retval)
336 goto cleanup; 336 goto cleanup;
337 337
338 retval = NaClHostDescUnlink(path); 338 retval = NaClHostDescUnlink(path);
339 cleanup: 339 cleanup:
340 return retval; 340 return retval;
341 } 341 }
342
343 int32_t NaClSysTruncate(struct NaClAppThread *natp,
344 uint32_t pathname,
345 nacl_abi_off_t length) {
346 struct NaClApp *nap = natp->nap;
347 char path[NACL_CONFIG_PATH_MAX];
348 int32_t retval = -NACL_ABI_EINVAL;
349
350 NaClLog(3,
351 ("Entered NaClSysTruncate(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
352 " 0x%"NACL_PRIx64")\n"),
353 (uintptr_t) natp, (uintptr_t) pathname, length);
354
355 if (!NaClAclBypassChecks) {
356 retval = -NACL_ABI_EACCES;
357 goto cleanup;
358 }
359
360 retval = CopyPathFromUser(nap, path, sizeof path, pathname);
361 if (0 != retval) {
362 goto cleanup;
363 }
364
365 retval = NaClHostDescTruncate(path, length);
366 cleanup:
367 return retval;
368 }
369
370 int32_t NaClSysLstat(struct NaClAppThread *natp,
371 uint32_t pathname,
372 struct nacl_abi_stat *buf) {
373 struct NaClApp *nap = natp->nap;
374 char path[NACL_CONFIG_PATH_MAX];
375 int32_t retval = -NACL_ABI_EINVAL;
376 nacl_host_stat_t stbuf;
377
378 NaClLog(3,
379 ("Entered NaClSysLstat(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
380 " 0x%08"NACL_PRIxPTR")\n"),
381 (uintptr_t) natp, (uintptr_t) pathname, (uintptr_t) buf);
382
383 retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
384 if (0 != retval) {
385 goto cleanup;
386 }
387
388 retval = NaClStatAclCheck(nap, path);
389 if (0 != retval) {
390 goto cleanup;
391 }
392
393 retval = NaClHostDescLstat(path, &stbuf);
394 if (0 == retval) {
395 struct nacl_abi_stat abi_stbuf;
396
397 retval = NaClAbiStatHostDescStatXlateCtor(&abi_stbuf,
398 &stbuf);
399 if (!NaClCopyOutToUser(nap, (uintptr_t) buf,
400 &abi_stbuf, sizeof abi_stbuf)) {
401 retval = -NACL_ABI_EFAULT;
402 }
403 }
404 cleanup:
405 return retval;
406 }
407
408 int32_t NaClSysLink(struct NaClAppThread *natp,
409 uint32_t oldpathname,
410 uint32_t newpathname) {
411 struct NaClApp *nap = natp->nap;
412 char oldpath[NACL_CONFIG_PATH_MAX];
413 char newpath[NACL_CONFIG_PATH_MAX];
414 int32_t retval = -NACL_ABI_EINVAL;
415
416 NaClLog(3,
417 ("Entered NaClSysLink(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
418 " 0x%08"NACL_PRIxPTR")\n"),
419 (uintptr_t) natp, (uintptr_t) oldpathname, (uintptr_t) newpathname);
420
421 if (!NaClAclBypassChecks) {
422 retval = -NACL_ABI_EACCES;
423 goto cleanup;
424 }
425
426 retval = CopyPathFromUser(nap, oldpath, sizeof oldpath,
427 (uintptr_t) oldpathname);
428 if (0 != retval) {
429 goto cleanup;
430 }
431
432 retval = CopyPathFromUser(nap, newpath, sizeof newpath,
433 (uintptr_t) newpathname);
434 if (0 != retval) {
435 goto cleanup;
436 }
437
438 retval = NaClHostDescLink(oldpath, newpath);
439 cleanup:
440 return retval;
441 }
442
443 int32_t NaClSysChmod(struct NaClAppThread *natp,
444 uint32_t pathname,
445 int mode) {
446 struct NaClApp *nap = natp->nap;
447 char path[NACL_CONFIG_PATH_MAX];
448 int32_t retval = -NACL_ABI_EINVAL;
449
450 NaClLog(3,
451 ("Entered NaClSysChmod(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
452 " 0x%x)\n"),
453 (uintptr_t) natp, (uintptr_t) pathname, mode);
454
455 if (!NaClAclBypassChecks) {
456 retval = -NACL_ABI_EACCES;
457 goto cleanup;
458 }
459
460 retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
461 if (0 != retval) {
462 goto cleanup;
463 }
464
465 retval = NaClHostDescChmod(path, mode);
466 cleanup:
467 return retval;
468 }
469
470 int32_t NaClSysAccess(struct NaClAppThread *natp,
471 uint32_t pathname,
472 int mode) {
473 struct NaClApp *nap = natp->nap;
474 char path[NACL_CONFIG_PATH_MAX];
475 int32_t retval = -NACL_ABI_EINVAL;
476
477 NaClLog(3,
478 ("Entered NaClSysAccess(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
479 " %d)\n"),
480 (uintptr_t) natp, (uintptr_t) pathname, mode);
481
482 if (!NaClAclBypassChecks) {
483 retval = -NACL_ABI_EACCES;
484 goto cleanup;
485 }
486
487 retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
488 if (0 != retval) {
489 goto cleanup;
490 }
491
492 retval = NaClHostDescAccess(path, mode);
493 cleanup:
494 return retval;
495 }
496
497 int32_t NaClSysRename(struct NaClAppThread *natp,
498 uint32_t oldpathname,
499 uint32_t newpathname) {
500 struct NaClApp *nap = natp->nap;
501 char oldpath[NACL_CONFIG_PATH_MAX];
502 char newpath[NACL_CONFIG_PATH_MAX];
503 int32_t retval = -NACL_ABI_EINVAL;
504
505 NaClLog(3,
506 ("Entered NaClSysRename(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
507 " 0x%08"NACL_PRIxPTR")\n"),
508 (uintptr_t) natp, (uintptr_t) oldpathname, (uintptr_t) newpathname);
509
510 if (!NaClAclBypassChecks) {
511 retval = -NACL_ABI_EACCES;
512 goto cleanup;
513 }
514
515 retval = CopyPathFromUser(nap, oldpath, sizeof oldpath, oldpathname);
516 if (0 != retval) {
517 goto cleanup;
518 }
519
520 retval = CopyPathFromUser(nap, newpath, sizeof newpath, newpathname);
521 if (0 != retval) {
522 goto cleanup;
523 }
524
525 retval = NaClHostDescRename(oldpath, newpath);
526 cleanup:
527 return retval;
528 }
529
530 int32_t NaClSysReadlink(struct NaClAppThread *natp,
531 uint32_t pathname,
532 uint32_t buf,
533 size_t bufsize) {
534 struct NaClApp *nap = natp->nap;
535 char path[NACL_CONFIG_PATH_MAX];
536 int32_t retval = -NACL_ABI_EINVAL;
537 char pathbuf[NACL_CONFIG_PATH_MAX];
538
539 NaClLog(3,
540 ("Entered NaClSysReadlink(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
541 " 0x%08"NACL_PRIxPTR", 0x%"NACL_PRIuS")\n"),
542 (uintptr_t) natp, (uintptr_t) pathname, (uintptr_t) buf, bufsize);
543
544 if (!NaClAclBypassChecks) {
545 retval = -NACL_ABI_EACCES;
546 goto cleanup;
547 }
548
549 retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
550 if (0 != retval) {
551 goto cleanup;
552 }
553
554 retval = NaClHostDescReadlink(path, pathbuf, sizeof pathbuf);
555 NaClLog(4, "path %s, buf %s\n", path, pathbuf);
556 if (0 == retval) {
557 if (!NaClCopyOutToUser(nap, (uintptr_t) buf, &pathbuf, bufsize)) {
558 retval = -NACL_ABI_EFAULT;
559 }
560 }
561 cleanup:
562 return retval;
563 }
564
565 int32_t NaClSysSymlink(struct NaClAppThread *natp,
566 uint32_t oldpathname,
567 uint32_t newpathname) {
568 struct NaClApp *nap = natp->nap;
569 char oldpath[NACL_CONFIG_PATH_MAX];
570 char newpath[NACL_CONFIG_PATH_MAX];
571 int32_t retval = -NACL_ABI_EINVAL;
572
573 NaClLog(3,
574 ("Entered NaClSysSymlink(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
575 " 0x%08"NACL_PRIxPTR")\n"),
576 (uintptr_t) natp, (uintptr_t) oldpathname, (uintptr_t) newpathname);
577
578 if (!NaClAclBypassChecks) {
579 retval = -NACL_ABI_EACCES;
580 goto cleanup;
581 }
582
583 retval = CopyPathFromUser(nap, oldpath, sizeof oldpath, oldpathname);
584 if (0 != retval) {
585 goto cleanup;
586 }
587
588 retval = CopyPathFromUser(nap, newpath, sizeof newpath, newpathname);
589 if (0 != retval) {
590 goto cleanup;
591 }
592
593 retval = NaClHostDescSymlink(oldpath, newpath);
594 cleanup:
595 return retval;
596 }
597
598 int32_t NaClSysUtimes(struct NaClAppThread *natp,
599 uint32_t path,
600 uint32_t times) {
601 struct NaClApp *nap = natp->nap;
602 char kern_path[NACL_CONFIG_PATH_MAX];
603 struct nacl_abi_timeval kern_times[2];
604 int32_t retval = -NACL_ABI_EINVAL;
605
606 NaClLog(3,
607 ("Entered NaClSysUtimes(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
608 " 0x%08"NACL_PRIxPTR")\n"),
609 (uintptr_t) natp, (uintptr_t) path, (uintptr_t) times);
610
611 if (!NaClAclBypassChecks) {
612 retval = -NACL_ABI_EACCES;
613 goto cleanup;
614 }
615
616 retval = CopyPathFromUser(nap, kern_path, sizeof kern_path, path);
617 if (0 != retval) {
618 goto cleanup;
619 }
620
621 if (!NaClCopyInFromUser(nap, &kern_times, (uintptr_t) times,
622 sizeof kern_times)) {
623 retval = -NACL_ABI_EFAULT;
624 goto cleanup;
625 }
626
627 retval = NaClHostDescUtimes(kern_path, kern_times);
628 cleanup:
629 return retval;
630 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/sys_filename.h ('k') | src/untrusted/irt/irt_fdio.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698