Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include <pthread.h> |
| 30 | |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 31 | #include <inttypes.h> |
| 32 | #include <stdio.h> |
Elliott Hughes | 9253757 | 2020-06-08 08:33:54 -0700 | [diff] [blame] | 33 | #include <string.h> |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 34 | #include <sys/resource.h> |
Elliott Hughes | 9afb2f2 | 2014-10-09 14:01:47 -0700 | [diff] [blame] | 35 | #include <unistd.h> |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 36 | |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 37 | #include <async_safe/log.h> |
| 38 | |
Peter Collingbourne | bb11ee6 | 2022-05-02 12:26:16 -0700 | [diff] [blame^] | 39 | #include "platform/bionic/page.h" |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 40 | #include "private/ErrnoRestorer.h" |
Peter Collingbourne | bb11ee6 | 2022-05-02 12:26:16 -0700 | [diff] [blame^] | 41 | #include "private/bionic_defs.h" |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 42 | #include "pthread_internal.h" |
| 43 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 44 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 45 | int pthread_attr_init(pthread_attr_t* attr) { |
Elliott Hughes | 6d33918 | 2013-02-12 16:36:04 -0800 | [diff] [blame] | 46 | attr->flags = 0; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 47 | attr->stack_base = nullptr; |
Brian Carlstrom | 50af69e | 2013-09-13 16:34:43 -0700 | [diff] [blame] | 48 | attr->stack_size = PTHREAD_STACK_SIZE_DEFAULT; |
Elliott Hughes | d6c678c | 2017-06-27 17:01:57 -0700 | [diff] [blame] | 49 | attr->guard_size = PTHREAD_GUARD_SIZE; |
Elliott Hughes | 6d33918 | 2013-02-12 16:36:04 -0800 | [diff] [blame] | 50 | attr->sched_policy = SCHED_NORMAL; |
| 51 | attr->sched_priority = 0; |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 52 | return 0; |
| 53 | } |
| 54 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 55 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 56 | int pthread_attr_destroy(pthread_attr_t* attr) { |
| 57 | memset(attr, 0x42, sizeof(pthread_attr_t)); |
| 58 | return 0; |
| 59 | } |
| 60 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 61 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 8aecba7 | 2017-10-17 15:34:41 -0700 | [diff] [blame] | 62 | int pthread_attr_setinheritsched(pthread_attr_t* attr, int flag) { |
| 63 | if (flag == PTHREAD_EXPLICIT_SCHED) { |
| 64 | attr->flags &= ~PTHREAD_ATTR_FLAG_INHERIT; |
Elliott Hughes | 38f01e0 | 2017-10-27 15:28:54 -0700 | [diff] [blame] | 65 | attr->flags |= PTHREAD_ATTR_FLAG_EXPLICIT; |
Elliott Hughes | 8aecba7 | 2017-10-17 15:34:41 -0700 | [diff] [blame] | 66 | } else if (flag == PTHREAD_INHERIT_SCHED) { |
| 67 | attr->flags |= PTHREAD_ATTR_FLAG_INHERIT; |
Elliott Hughes | 38f01e0 | 2017-10-27 15:28:54 -0700 | [diff] [blame] | 68 | attr->flags &= ~PTHREAD_ATTR_FLAG_EXPLICIT; |
Elliott Hughes | 8aecba7 | 2017-10-17 15:34:41 -0700 | [diff] [blame] | 69 | } else { |
| 70 | return EINVAL; |
| 71 | } |
| 72 | return 0; |
| 73 | } |
| 74 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 75 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 8aecba7 | 2017-10-17 15:34:41 -0700 | [diff] [blame] | 76 | int pthread_attr_getinheritsched(const pthread_attr_t* attr, int* flag) { |
Elliott Hughes | 38f01e0 | 2017-10-27 15:28:54 -0700 | [diff] [blame] | 77 | if ((attr->flags & PTHREAD_ATTR_FLAG_INHERIT) != 0) { |
| 78 | *flag = PTHREAD_INHERIT_SCHED; |
| 79 | } else if ((attr->flags & PTHREAD_ATTR_FLAG_EXPLICIT) != 0) { |
| 80 | *flag = PTHREAD_EXPLICIT_SCHED; |
| 81 | } else { |
| 82 | // Historical behavior before P, when pthread_attr_setinheritsched was added. |
| 83 | *flag = (attr->sched_policy != SCHED_NORMAL) ? PTHREAD_EXPLICIT_SCHED : PTHREAD_INHERIT_SCHED; |
| 84 | } |
Elliott Hughes | 8aecba7 | 2017-10-17 15:34:41 -0700 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 88 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 89 | int pthread_attr_setdetachstate(pthread_attr_t* attr, int state) { |
| 90 | if (state == PTHREAD_CREATE_DETACHED) { |
| 91 | attr->flags |= PTHREAD_ATTR_FLAG_DETACHED; |
| 92 | } else if (state == PTHREAD_CREATE_JOINABLE) { |
| 93 | attr->flags &= ~PTHREAD_ATTR_FLAG_DETACHED; |
| 94 | } else { |
| 95 | return EINVAL; |
| 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 100 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 101 | int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* state) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 102 | *state = (attr->flags & PTHREAD_ATTR_FLAG_DETACHED) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE; |
| 103 | return 0; |
| 104 | } |
| 105 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 106 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 107 | int pthread_attr_setschedpolicy(pthread_attr_t* attr, int policy) { |
| 108 | attr->sched_policy = policy; |
| 109 | return 0; |
| 110 | } |
| 111 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 112 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 113 | int pthread_attr_getschedpolicy(const pthread_attr_t* attr, int* policy) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 114 | *policy = attr->sched_policy; |
| 115 | return 0; |
| 116 | } |
| 117 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 118 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 119 | int pthread_attr_setschedparam(pthread_attr_t* attr, const sched_param* param) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 120 | attr->sched_priority = param->sched_priority; |
| 121 | return 0; |
| 122 | } |
| 123 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 124 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 125 | int pthread_attr_getschedparam(const pthread_attr_t* attr, sched_param* param) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 126 | param->sched_priority = attr->sched_priority; |
| 127 | return 0; |
| 128 | } |
| 129 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 130 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 131 | int pthread_attr_setstacksize(pthread_attr_t* attr, size_t stack_size) { |
Elliott Hughes | b95cf0d | 2013-07-15 14:51:07 -0700 | [diff] [blame] | 132 | if (stack_size < PTHREAD_STACK_MIN) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 133 | return EINVAL; |
| 134 | } |
| 135 | attr->stack_size = stack_size; |
| 136 | return 0; |
| 137 | } |
| 138 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 139 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 140 | int pthread_attr_getstacksize(const pthread_attr_t* attr, size_t* stack_size) { |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 141 | void* unused; |
| 142 | return pthread_attr_getstack(attr, &unused, stack_size); |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 143 | } |
| 144 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 145 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 146 | int pthread_attr_setstack(pthread_attr_t* attr, void* stack_base, size_t stack_size) { |
Peter Collingbourne | bb11ee6 | 2022-05-02 12:26:16 -0700 | [diff] [blame^] | 147 | if ((stack_size & (page_size() - 1) || stack_size < PTHREAD_STACK_MIN)) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 148 | return EINVAL; |
| 149 | } |
Peter Collingbourne | bb11ee6 | 2022-05-02 12:26:16 -0700 | [diff] [blame^] | 150 | if (reinterpret_cast<uintptr_t>(stack_base) & (page_size() - 1)) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 151 | return EINVAL; |
| 152 | } |
| 153 | attr->stack_base = stack_base; |
| 154 | attr->stack_size = stack_size; |
| 155 | return 0; |
| 156 | } |
| 157 | |
Mor-sarid, Nitzan | 5693332 | 2015-09-11 05:31:36 +0000 | [diff] [blame] | 158 | static uintptr_t __get_main_stack_startstack() { |
| 159 | FILE* fp = fopen("/proc/self/stat", "re"); |
| 160 | if (fp == nullptr) { |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 161 | async_safe_fatal("couldn't open /proc/self/stat: %s", strerror(errno)); |
Mor-sarid, Nitzan | 5693332 | 2015-09-11 05:31:36 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | char line[BUFSIZ]; |
| 165 | if (fgets(line, sizeof(line), fp) == nullptr) { |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 166 | async_safe_fatal("couldn't read /proc/self/stat: %s", strerror(errno)); |
Mor-sarid, Nitzan | 5693332 | 2015-09-11 05:31:36 +0000 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | fclose(fp); |
| 170 | |
| 171 | // See man 5 proc. There's no reason comm can't contain ' ' or ')', |
| 172 | // so we search backwards for the end of it. We're looking for this field: |
| 173 | // |
| 174 | // startstack %lu (28) The address of the start (i.e., bottom) of the stack. |
| 175 | uintptr_t startstack = 0; |
| 176 | const char* end_of_comm = strrchr(line, ')'); |
| 177 | if (sscanf(end_of_comm + 1, " %*c " |
| 178 | "%*d %*d %*d %*d %*d " |
| 179 | "%*u %*u %*u %*u %*u %*u %*u " |
| 180 | "%*d %*d %*d %*d %*d %*d " |
| 181 | "%*u %*u %*d %*u %*u %*u %" SCNuPTR, &startstack) != 1) { |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 182 | async_safe_fatal("couldn't parse /proc/self/stat"); |
Mor-sarid, Nitzan | 5693332 | 2015-09-11 05:31:36 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | return startstack; |
| 186 | } |
| 187 | |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 188 | static int __pthread_attr_getstack_main_thread(void** stack_base, size_t* stack_size) { |
| 189 | ErrnoRestorer errno_restorer; |
| 190 | |
Elliott Hughes | 9e4ffa7 | 2014-08-27 15:32:01 -0700 | [diff] [blame] | 191 | rlimit stack_limit; |
| 192 | if (getrlimit(RLIMIT_STACK, &stack_limit) == -1) { |
| 193 | return errno; |
| 194 | } |
| 195 | |
Elliott Hughes | 68ae6ad | 2020-07-21 16:11:30 -0700 | [diff] [blame] | 196 | // If the current RLIMIT_STACK is RLIM_INFINITY, only admit to an 8MiB stack |
| 197 | // in case callers such as ART take infinity too literally. |
Elliott Hughes | 9e4ffa7 | 2014-08-27 15:32:01 -0700 | [diff] [blame] | 198 | if (stack_limit.rlim_cur == RLIM_INFINITY) { |
| 199 | stack_limit.rlim_cur = 8 * 1024 * 1024; |
| 200 | } |
| 201 | |
Mor-sarid, Nitzan | 5693332 | 2015-09-11 05:31:36 +0000 | [diff] [blame] | 202 | // Ask the kernel where our main thread's stack started. |
| 203 | uintptr_t startstack = __get_main_stack_startstack(); |
| 204 | |
| 205 | // Hunt for the region that contains that address. |
| 206 | FILE* fp = fopen("/proc/self/maps", "re"); |
| 207 | if (fp == nullptr) { |
Elliott Hughes | 7b0af7a | 2017-09-15 16:09:22 -0700 | [diff] [blame] | 208 | async_safe_fatal("couldn't open /proc/self/maps: %s", strerror(errno)); |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 209 | } |
| 210 | char line[BUFSIZ]; |
Yi Kong | 32bc0fc | 2018-08-02 17:31:13 -0700 | [diff] [blame] | 211 | while (fgets(line, sizeof(line), fp) != nullptr) { |
Mor-sarid, Nitzan | 5693332 | 2015-09-11 05:31:36 +0000 | [diff] [blame] | 212 | uintptr_t lo, hi; |
| 213 | if (sscanf(line, "%" SCNxPTR "-%" SCNxPTR, &lo, &hi) == 2) { |
| 214 | if (lo <= startstack && startstack <= hi) { |
Elliott Hughes | 9e4ffa7 | 2014-08-27 15:32:01 -0700 | [diff] [blame] | 215 | *stack_size = stack_limit.rlim_cur; |
| 216 | *stack_base = reinterpret_cast<void*>(hi - *stack_size); |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 217 | fclose(fp); |
| 218 | return 0; |
| 219 | } |
| 220 | } |
| 221 | } |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 222 | async_safe_fatal("Stack not found in /proc/self/maps"); |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 223 | } |
| 224 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 225 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 226 | int pthread_attr_getstack(const pthread_attr_t* attr, void** stack_base, size_t* stack_size) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 227 | *stack_base = attr->stack_base; |
| 228 | *stack_size = attr->stack_size; |
| 229 | return 0; |
| 230 | } |
| 231 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 232 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 233 | int pthread_attr_setguardsize(pthread_attr_t* attr, size_t guard_size) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 234 | attr->guard_size = guard_size; |
| 235 | return 0; |
| 236 | } |
| 237 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 238 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 239 | int pthread_attr_getguardsize(const pthread_attr_t* attr, size_t* guard_size) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 240 | *guard_size = attr->guard_size; |
| 241 | return 0; |
| 242 | } |
| 243 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 244 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | 57b7a61 | 2014-08-25 17:26:50 -0700 | [diff] [blame] | 245 | int pthread_getattr_np(pthread_t t, pthread_attr_t* attr) { |
Yabin Cui | 9d0c793 | 2015-03-06 13:48:58 -0800 | [diff] [blame] | 246 | pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(t); |
| 247 | *attr = thread->attr; |
Yabin Cui | 58cf31b | 2015-03-06 17:23:53 -0800 | [diff] [blame] | 248 | // We prefer reading join_state here to setting thread->attr.flags in pthread_detach. |
| 249 | // Because data race exists in the latter case. |
| 250 | if (atomic_load(&thread->join_state) == THREAD_DETACHED) { |
| 251 | attr->flags |= PTHREAD_ATTR_FLAG_DETACHED; |
| 252 | } |
Yabin Cui | 9d0c793 | 2015-03-06 13:48:58 -0800 | [diff] [blame] | 253 | // The main thread's stack information is not stored in thread->attr, and we need to |
| 254 | // collect that at runtime. |
| 255 | if (thread->tid == getpid()) { |
| 256 | return __pthread_attr_getstack_main_thread(&attr->stack_base, &attr->stack_size); |
| 257 | } |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 261 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 262 | int pthread_attr_setscope(pthread_attr_t*, int scope) { |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 263 | if (scope == PTHREAD_SCOPE_SYSTEM) { |
| 264 | return 0; |
| 265 | } |
| 266 | if (scope == PTHREAD_SCOPE_PROCESS) { |
| 267 | return ENOTSUP; |
| 268 | } |
| 269 | return EINVAL; |
| 270 | } |
| 271 | |
dimitry | fa43252 | 2017-10-25 13:07:45 +0200 | [diff] [blame] | 272 | __BIONIC_WEAK_FOR_NATIVE_BRIDGE |
Elliott Hughes | c3f1140 | 2013-10-30 14:40:09 -0700 | [diff] [blame] | 273 | int pthread_attr_getscope(const pthread_attr_t*, int* scope) { |
| 274 | *scope = PTHREAD_SCOPE_SYSTEM; |
| 275 | return 0; |
Elliott Hughes | 3e89847 | 2013-02-12 16:40:24 +0000 | [diff] [blame] | 276 | } |