xref: /llvm-project/libc/src/__support/OSUtil/gpu/exit.cpp (revision a6ef0debb1d60966b5bcc69f7d58a2b75c9c621d)
107bd4394SRoseZhang03 //===------------- GPU implementation of an exit function -------*- C++ -*-===//
207bd4394SRoseZhang03 //
307bd4394SRoseZhang03 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
407bd4394SRoseZhang03 // See https://llvm.org/LICENSE.txt for license information.
507bd4394SRoseZhang03 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
607bd4394SRoseZhang03 //
707bd4394SRoseZhang03 //===----------------------------------------------------------------------===//
807bd4394SRoseZhang03 
907bd4394SRoseZhang03 #include "src/__support/OSUtil/exit.h"
1007bd4394SRoseZhang03 
11197e0125SJoseph Huber #include "src/__support/GPU/utils.h"
1207bd4394SRoseZhang03 #include "src/__support/RPC/rpc_client.h"
135ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
1407bd4394SRoseZhang03 #include "src/__support/macros/properties/architectures.h"
1507bd4394SRoseZhang03 
165ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
175ff3ff33SPetr Hosek namespace internal {
1807bd4394SRoseZhang03 
1907bd4394SRoseZhang03 [[noreturn]] void exit(int status) {
2007bd4394SRoseZhang03   // We want to first make sure the server is listening before we exit.
21*a6ef0debSJoseph Huber   rpc::Client::Port port = rpc::client.open<LIBC_EXIT>();
22be0c67c9SJoseph Huber   port.send_and_recv([](rpc::Buffer *, uint32_t) {},
23be0c67c9SJoseph Huber                      [](rpc::Buffer *, uint32_t) {});
24be0c67c9SJoseph Huber   port.send([&](rpc::Buffer *buffer, uint32_t) {
2507bd4394SRoseZhang03     reinterpret_cast<uint32_t *>(buffer->data)[0] = status;
2607bd4394SRoseZhang03   });
2707bd4394SRoseZhang03   port.close();
2807bd4394SRoseZhang03 
2907bd4394SRoseZhang03   gpu::end_program();
3007bd4394SRoseZhang03 }
3107bd4394SRoseZhang03 
325ff3ff33SPetr Hosek } // namespace internal
335ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
34