xref: /llvm-project/libc/src/pthread/pthread_attr_getstack.cpp (revision 5ff3ff33ff930e4ec49da7910612d8a41eb068cb)
10258f566SSiva Chandra Reddy //===-- Implementation of the pthread_attr_getstack -----------------===//
20258f566SSiva Chandra Reddy //
30258f566SSiva Chandra Reddy // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40258f566SSiva Chandra Reddy // See https://llvm.org/LICENSE.txt for license information.
50258f566SSiva Chandra Reddy // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60258f566SSiva Chandra Reddy //
70258f566SSiva Chandra Reddy //===----------------------------------------------------------------------===//
80258f566SSiva Chandra Reddy 
90258f566SSiva Chandra Reddy #include "pthread_attr_getstack.h"
106a185718SNoah Goldstein #include "pthread_attr_getstacksize.h"
110258f566SSiva Chandra Reddy 
120258f566SSiva Chandra Reddy #include "src/__support/common.h"
13*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h"
146a185718SNoah Goldstein #include "src/__support/macros/optimization.h"
150258f566SSiva Chandra Reddy 
160258f566SSiva Chandra Reddy #include <pthread.h>
170258f566SSiva Chandra Reddy 
18*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL {
190258f566SSiva Chandra Reddy 
200258f566SSiva Chandra Reddy LLVM_LIBC_FUNCTION(int, pthread_attr_getstack,
210258f566SSiva Chandra Reddy                    (const pthread_attr_t *__restrict attr,
220258f566SSiva Chandra Reddy                     void **__restrict stack, size_t *__restrict stacksize)) {
236a185718SNoah Goldstein   // As of writing this `pthread_attr_getstacksize` can never fail.
24b6bc9d72SGuillaume Chatelet   int result = LIBC_NAMESPACE::pthread_attr_getstacksize(attr, stacksize);
256a185718SNoah Goldstein   if (LIBC_UNLIKELY(result != 0))
266a185718SNoah Goldstein     return result;
270258f566SSiva Chandra Reddy   *stack = attr->__stack;
280258f566SSiva Chandra Reddy   return 0;
290258f566SSiva Chandra Reddy }
300258f566SSiva Chandra Reddy 
31*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL
32