1 | //===-- GPU Implementation of fopen ---------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/stdio/fopen.h" |
10 | |
11 | #include "hdr/types/FILE.h" |
12 | #include "src/__support/common.h" |
13 | #include "src/stdio/gpu/file.h" |
14 | #include "src/string/memory_utils/inline_memcpy.h" |
15 | #include "src/string/string_utils.h" |
16 | |
17 | namespace LIBC_NAMESPACE_DECL { |
18 | |
19 | LLVM_LIBC_FUNCTION(::FILE *, fopen, |
20 | (const char *__restrict path, const char *__restrict mode)) { |
21 | uintptr_t file; |
22 | rpc::Client::Port port = rpc::client.open<LIBC_OPEN_FILE>(); |
23 | port.send_n(path, internal::string_length(path) + 1); |
24 | port.send_and_recv( |
25 | [=](rpc::Buffer *buffer, uint32_t) { |
26 | inline_memcpy(buffer->data, mode, internal::string_length(mode) + 1); |
27 | }, |
28 | [&](rpc::Buffer *buffer, uint32_t) { file = buffer->data[0]; }); |
29 | port.close(); |
30 | |
31 | return reinterpret_cast<FILE *>(file); |
32 | } |
33 | |
34 | } // namespace LIBC_NAMESPACE_DECL |
35 | |