[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH] lib/vfscore: Implement `getcwd` with a raw system call



Implements `getcwd` with a raw system call (`UK_SYSCALL_R_DEFINE`) instead.
This variant should be preferred because it avoids the usage of `errno`.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/vfscore/main.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/vfscore/main.c b/lib/vfscore/main.c
index bd1fcea5e..a3d3a7440 100644
--- a/lib/vfscore/main.c
+++ b/lib/vfscore/main.c
@@ -1346,7 +1346,7 @@ UK_TRACEPOINT(trace_vfs_getcwd, "%p %d", char*, size_t);
 UK_TRACEPOINT(trace_vfs_getcwd_ret, "\"%s\"", const char*);
 UK_TRACEPOINT(trace_vfs_getcwd_err, "%d", int);
 
-UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, size)
+UK_SYSCALL_R_DEFINE(char*, getcwd, char*, path, size_t, size)
 {
        trace_vfs_getcwd(path, size);
        struct task *t = main_task;
@@ -1355,7 +1355,7 @@ UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, 
size)
 
        if (size < len) {
                error = ERANGE;
-               goto out_errno;
+               goto out_error;
        }
 
        if (!path) {
@@ -1364,12 +1364,12 @@ UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, 
size)
                path = (char*)malloc(size);
                if (!path) {
                        error = ENOMEM;
-                       goto out_errno;
+                       goto out_error;
                }
        } else {
                if (!size) {
                        error = EINVAL;
-                       goto out_errno;
+                       goto out_error;
                }
        }
 
@@ -1377,10 +1377,9 @@ UK_SYSCALL_DEFINE(char*, getcwd, char*, path, size_t, 
size)
        trace_vfs_getcwd_ret(path);
        return path;
 
-       out_errno:
+out_error:
        trace_vfs_getcwd_err(error);
-       errno = error;
-       return NULL;
+       return ERR2PTR(-error);
 }
 
 UK_TRACEPOINT(trace_vfs_dup, "%d", int);
-- 
2.20.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.