Skip to content

[libc] Implement the 'rename' function on the GPU #109814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/config/gpu/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.stdio.putchar
libc.src.stdio.puts
libc.src.stdio.remove
libc.src.stdio.rename
libc.src.stdio.stderr
libc.src.stdio.stdin
libc.src.stdio.stdout
Expand Down
1 change: 1 addition & 0 deletions libc/docs/gpu/support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ fputs |check| |check|
fputc |check| |check|
fwrite |check| |check|
remove |check| |check|
rename |check| |check|
putc |check| |check|
printf |check| |check|
vprintf |check| |check|
Expand Down
1 change: 1 addition & 0 deletions libc/include/llvm-libc-types/rpc_opcodes_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef enum {
RPC_PRINTF_TO_STDERR_PACKED,
RPC_PRINTF_TO_STREAM_PACKED,
RPC_REMOVE,
RPC_RENAME,
RPC_SYSTEM,
RPC_LAST = 0xFFFF,
} rpc_opcode_t;
Expand Down
11 changes: 11 additions & 0 deletions libc/src/stdio/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ add_entrypoint_object(
.vfprintf_utils
)

add_entrypoint_object(
rename
SRCS
rename.cpp
HDRS
../rename.h
DEPENDS
libc.hdr.types.FILE
.gpu_file
)

add_entrypoint_object(
stdin
SRCS
Expand Down
30 changes: 30 additions & 0 deletions libc/src/stdio/gpu/rename.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//===-- GPU Implementation of rename --------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "src/stdio/rename.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/macros/config.h"
#include "src/stdio/gpu/file.h"

#include "hdr/types/FILE.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(int, rename, (const char *oldpath, const char *newpath)) {
int ret;
rpc::Client::Port port = rpc::client.open<RPC_RENAME>();
port.send_n(oldpath, internal::string_length(oldpath) + 1);
port.send_n(newpath, internal::string_length(newpath) + 1);
port.recv(
[&](rpc::Buffer *buffer) { ret = static_cast<int>(buffer->data[0]); });
port.close();

return ret;
}

} // namespace LIBC_NAMESPACE_DECL
18 changes: 18 additions & 0 deletions libc/utils/gpu/server/rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,24 @@ rpc_status_t handle_server_impl(
});
break;
}
case RPC_RENAME: {
uint64_t oldsizes[lane_size] = {0};
uint64_t newsizes[lane_size] = {0};
void *oldpath[lane_size] = {nullptr};
void *newpath[lane_size] = {nullptr};
port->recv_n(oldpath, oldsizes,
[&](uint64_t size) { return new char[size]; });
port->recv_n(newpath, newsizes,
[&](uint64_t size) { return new char[size]; });
port->send([&](rpc::Buffer *buffer, uint32_t id) {
buffer->data[0] = static_cast<uint64_t>(
rename(reinterpret_cast<const char *>(oldpath[id]),
reinterpret_cast<const char *>(newpath[id])));
delete[] reinterpret_cast<uint8_t *>(oldpath[id]);
delete[] reinterpret_cast<uint8_t *>(newpath[id]);
});
break;
}
case RPC_SYSTEM: {
uint64_t sizes[lane_size] = {0};
void *args[lane_size] = {nullptr};
Expand Down
Loading