Siva Chandra Reddy | 0258f56 | 2022-04-08 08:07:22 +0000 | [diff] [blame] | 1 | //===-- Implementation of the pthread_attr_setstacksize -----------------===// |
| 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 "pthread_attr_setstacksize.h" |
| 10 | |
| 11 | #include "src/__support/common.h" |
Petr Hosek | 5ff3ff3 | 2024-07-12 09:28:41 -0700 | [diff] [blame] | 12 | #include "src/__support/macros/config.h" |
Job Henandez Lara | 46944b0 | 2024-10-05 16:31:36 -0700 | [diff] [blame] | 13 | #include "src/errno/libc_errno.h" |
Siva Chandra Reddy | 0258f56 | 2022-04-08 08:07:22 +0000 | [diff] [blame] | 14 | |
Siva Chandra Reddy | 0258f56 | 2022-04-08 08:07:22 +0000 | [diff] [blame] | 15 | #include <pthread.h> |
| 16 | |
Petr Hosek | 5ff3ff3 | 2024-07-12 09:28:41 -0700 | [diff] [blame] | 17 | namespace LIBC_NAMESPACE_DECL { |
Siva Chandra Reddy | 0258f56 | 2022-04-08 08:07:22 +0000 | [diff] [blame] | 18 | |
| 19 | LLVM_LIBC_FUNCTION(int, pthread_attr_setstacksize, |
| 20 | (pthread_attr_t *__restrict attr, size_t stacksize)) { |
Noah Goldstein | 6a18571 | 2023-04-20 15:05:04 -0500 | [diff] [blame] | 21 | // TODO: Should we also ensure stacksize % EXEC_PAGESIZE == 0? |
Siva Chandra Reddy | 0258f56 | 2022-04-08 08:07:22 +0000 | [diff] [blame] | 22 | if (stacksize < PTHREAD_STACK_MIN) |
| 23 | return EINVAL; |
| 24 | attr->__stack = nullptr; |
| 25 | attr->__stacksize = stacksize; |
| 26 | return 0; |
| 27 | } |
| 28 | |
Petr Hosek | 5ff3ff3 | 2024-07-12 09:28:41 -0700 | [diff] [blame] | 29 | } // namespace LIBC_NAMESPACE_DECL |