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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/trusted/service_runtime/sys_filename.c
diff --git a/src/trusted/service_runtime/sys_filename.c b/src/trusted/service_runtime/sys_filename.c
index d179b8b48d4f42adf4de99c4d36b25f3c5fde0df..37c699aeaab94c066027069403a04016361a0853 100644
--- a/src/trusted/service_runtime/sys_filename.c
+++ b/src/trusted/service_runtime/sys_filename.c
@@ -339,3 +339,292 @@ int32_t NaClSysUnlink(struct NaClAppThread *natp,
cleanup:
return retval;
}
+
+int32_t NaClSysTruncate(struct NaClAppThread *natp,
+ uint32_t pathname,
+ nacl_abi_off_t length) {
+ struct NaClApp *nap = natp->nap;
+ char path[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysTruncate(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%"NACL_PRIx64")\n"),
+ (uintptr_t) natp, (uintptr_t) pathname, length);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, path, sizeof path, pathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescTruncate(path, length);
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysLstat(struct NaClAppThread *natp,
+ uint32_t pathname,
+ struct nacl_abi_stat *buf) {
+ struct NaClApp *nap = natp->nap;
+ char path[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+ nacl_host_stat_t stbuf;
+
+ NaClLog(3,
+ ("Entered NaClSysLstat(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%08"NACL_PRIxPTR")\n"),
+ (uintptr_t) natp, (uintptr_t) pathname, (uintptr_t) buf);
+
+ retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClStatAclCheck(nap, path);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescLstat(path, &stbuf);
+ if (0 == retval) {
+ struct nacl_abi_stat abi_stbuf;
+
+ retval = NaClAbiStatHostDescStatXlateCtor(&abi_stbuf,
+ &stbuf);
+ if (!NaClCopyOutToUser(nap, (uintptr_t) buf,
+ &abi_stbuf, sizeof abi_stbuf)) {
+ retval = -NACL_ABI_EFAULT;
+ }
+ }
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysLink(struct NaClAppThread *natp,
+ uint32_t oldpathname,
+ uint32_t newpathname) {
+ struct NaClApp *nap = natp->nap;
+ char oldpath[NACL_CONFIG_PATH_MAX];
+ char newpath[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysLink(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%08"NACL_PRIxPTR")\n"),
+ (uintptr_t) natp, (uintptr_t) oldpathname, (uintptr_t) newpathname);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, oldpath, sizeof oldpath,
+ (uintptr_t) oldpathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, newpath, sizeof newpath,
+ (uintptr_t) newpathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescLink(oldpath, newpath);
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysChmod(struct NaClAppThread *natp,
+ uint32_t pathname,
+ int mode) {
+ struct NaClApp *nap = natp->nap;
+ char path[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysChmod(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%x)\n"),
+ (uintptr_t) natp, (uintptr_t) pathname, mode);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescChmod(path, mode);
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysAccess(struct NaClAppThread *natp,
+ uint32_t pathname,
+ int mode) {
+ struct NaClApp *nap = natp->nap;
+ char path[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysAccess(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " %d)\n"),
+ (uintptr_t) natp, (uintptr_t) pathname, mode);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescAccess(path, mode);
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysRename(struct NaClAppThread *natp,
+ uint32_t oldpathname,
+ uint32_t newpathname) {
+ struct NaClApp *nap = natp->nap;
+ char oldpath[NACL_CONFIG_PATH_MAX];
+ char newpath[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysRename(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%08"NACL_PRIxPTR")\n"),
+ (uintptr_t) natp, (uintptr_t) oldpathname, (uintptr_t) newpathname);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, oldpath, sizeof oldpath, oldpathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, newpath, sizeof newpath, newpathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescRename(oldpath, newpath);
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysReadlink(struct NaClAppThread *natp,
+ uint32_t pathname,
+ uint32_t buf,
+ size_t bufsize) {
+ struct NaClApp *nap = natp->nap;
+ char path[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+ char pathbuf[NACL_CONFIG_PATH_MAX];
+
+ NaClLog(3,
+ ("Entered NaClSysReadlink(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%08"NACL_PRIxPTR", 0x%"NACL_PRIuS")\n"),
+ (uintptr_t) natp, (uintptr_t) pathname, (uintptr_t) buf, bufsize);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, path, sizeof path, (uintptr_t) pathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescReadlink(path, pathbuf, sizeof pathbuf);
+ NaClLog(4, "path %s, buf %s\n", path, pathbuf);
+ if (0 == retval) {
+ if (!NaClCopyOutToUser(nap, (uintptr_t) buf, &pathbuf, bufsize)) {
+ retval = -NACL_ABI_EFAULT;
+ }
+ }
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysSymlink(struct NaClAppThread *natp,
+ uint32_t oldpathname,
+ uint32_t newpathname) {
+ struct NaClApp *nap = natp->nap;
+ char oldpath[NACL_CONFIG_PATH_MAX];
+ char newpath[NACL_CONFIG_PATH_MAX];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysSymlink(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%08"NACL_PRIxPTR")\n"),
+ (uintptr_t) natp, (uintptr_t) oldpathname, (uintptr_t) newpathname);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, oldpath, sizeof oldpath, oldpathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, newpath, sizeof newpath, newpathname);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ retval = NaClHostDescSymlink(oldpath, newpath);
+cleanup:
+ return retval;
+}
+
+int32_t NaClSysUtimes(struct NaClAppThread *natp,
+ uint32_t path,
+ uint32_t times) {
+ struct NaClApp *nap = natp->nap;
+ char kern_path[NACL_CONFIG_PATH_MAX];
+ struct nacl_abi_timeval kern_times[2];
+ int32_t retval = -NACL_ABI_EINVAL;
+
+ NaClLog(3,
+ ("Entered NaClSysUtimes(0x%08"NACL_PRIxPTR", 0x%08"NACL_PRIxPTR","
+ " 0x%08"NACL_PRIxPTR")\n"),
+ (uintptr_t) natp, (uintptr_t) path, (uintptr_t) times);
+
+ if (!NaClAclBypassChecks) {
+ retval = -NACL_ABI_EACCES;
+ goto cleanup;
+ }
+
+ retval = CopyPathFromUser(nap, kern_path, sizeof kern_path, path);
+ if (0 != retval) {
+ goto cleanup;
+ }
+
+ if (!NaClCopyInFromUser(nap, &kern_times, (uintptr_t) times,
+ sizeof kern_times)) {
+ retval = -NACL_ABI_EFAULT;
+ goto cleanup;
+ }
+
+ retval = NaClHostDescUtimes(kern_path, kern_times);
+cleanup:
+ return retval;
+}
« 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