LibC: Add LibC wrapper for sys$readlink()

To avoid having to make direct syscalls in LibCore, let's add a wrapper
for the kernel's readlink syscall in LibC.
This commit is contained in:
Andreas Kling 2021-02-02 19:48:39 +01:00
parent 775ae27a55
commit 1658df9b6e
Notes: sideshowbarker 2024-07-18 22:37:45 +09:00
2 changed files with 16 additions and 2 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -27,6 +27,7 @@
#include <Kernel/API/Syscall.h>
#include <errno.h>
#include <serenity.h>
#include <string.h>
extern "C" {
@ -118,4 +119,14 @@ int anon_create(size_t size, int options)
int rc = syscall(SC_anon_create, size, options);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
int serenity_readlink(const char* path, size_t path_length, char* buffer, size_t buffer_size)
{
Syscall::SC_readlink_params small_params {
{ path, path_length },
{ buffer, buffer_size }
};
int rc = syscall(SC_readlink, &small_params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -28,6 +28,7 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
__BEGIN_DECLS
@ -103,6 +104,8 @@ int get_stack_bounds(uintptr_t* user_stack_base, size_t* user_stack_size);
int anon_create(size_t size, int options);
int serenity_readlink(const char* path, size_t path_length, char* buffer, size_t buffer_size);
#ifdef __i386__
ALWAYS_INLINE void send_secret_data_to_userspace_emulator(uintptr_t data1, uintptr_t data2, uintptr_t data3)
{