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 #include "src/__support/CPP/string_view.h" 11 #include "src/stdio/gpu/file.h" 12 13 #include <stdio.h> 14 15 namespace LIBC_NAMESPACE { 16 17 LLVM_LIBC_FUNCTION(::FILE *, fopen, 18 (const char *__restrict path, const char *__restrict mode)) { 19 uintptr_t file; 20 rpc::Client::Port port = rpc::client.open<RPC_OPEN_FILE>(); 21 port.send_n(path, internal::string_length(path) + 1); 22 port.send_and_recv( __anon9b99db030102(rpc::Buffer *buffer) 23 [=](rpc::Buffer *buffer) { 24 inline_memcpy(buffer->data, mode, internal::string_length(mode) + 1); 25 }, __anon9b99db030202(rpc::Buffer *buffer) 26 [&](rpc::Buffer *buffer) { file = buffer->data[0]; }); 27 port.close(); 28 29 return reinterpret_cast<FILE *>(file); 30 } 31 32 } // namespace LIBC_NAMESPACE 33