1 //===------------- GPU implementation of an exit function -------*- C++ -*-===// 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/__support/OSUtil/exit.h" 10 11 #include "src/__support/GPU/utils.h" 12 #include "src/__support/RPC/rpc_client.h" 13 #include "src/__support/macros/config.h" 14 #include "src/__support/macros/properties/architectures.h" 15 16 namespace LIBC_NAMESPACE_DECL { 17 namespace internal { 18 exit(int status)19[[noreturn]] void exit(int status) { 20 // We want to first make sure the server is listening before we exit. 21 rpc::Client::Port port = rpc::client.open<RPC_EXIT>(); 22 port.send_and_recv([](rpc::Buffer *, uint32_t) {}, 23 [](rpc::Buffer *, uint32_t) {}); 24 port.send([&](rpc::Buffer *buffer, uint32_t) { 25 reinterpret_cast<uint32_t *>(buffer->data)[0] = status; 26 }); 27 port.close(); 28 29 gpu::end_program(); 30 } 31 32 } // namespace internal 33 } // namespace LIBC_NAMESPACE_DECL 34