[libc++][Android] Allow testing libc++ with clang-r536225 (#116149)
[llvm-project.git] / libc / src / gpu / rpc_host_call.cpp
blob1181e9554d16e23c4cc8732fd54575bceb531df1
1 //===---------- GPU implementation of the external RPC call function ------===//
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 //===----------------------------------------------------------------------===//
9 #include "src/gpu/rpc_host_call.h"
11 #include "src/__support/GPU/utils.h"
12 #include "src/__support/RPC/rpc_client.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
16 namespace LIBC_NAMESPACE_DECL {
18 // This calls the associated function pointer on the RPC server with the given
19 // arguments. We expect that the pointer here is a valid pointer on the server.
20 LLVM_LIBC_FUNCTION(unsigned long long, rpc_host_call,
21 (void *fn, void *data, size_t size)) {
22 rpc::Client::Port port = rpc::client.open<RPC_HOST_CALL>();
23 port.send_n(data, size);
24 port.send([=](rpc::Buffer *buffer, uint32_t) {
25 buffer->data[0] = reinterpret_cast<uintptr_t>(fn);
26 });
27 unsigned long long ret;
28 port.recv([&](rpc::Buffer *buffer, uint32_t) {
29 ret = static_cast<unsigned long long>(buffer->data[0]);
30 });
31 port.close();
32 return ret;
35 } // namespace LIBC_NAMESPACE_DECL