paul@622 | 1 | /* |
paul@622 | 2 | * Thread-related utilities. |
paul@622 | 3 | * |
paul@622 | 4 | * Copyright (C) 2024 Paul Boddie <paul@boddie.org.uk> |
paul@622 | 5 | * |
paul@622 | 6 | * This program is free software; you can redistribute it and/or |
paul@622 | 7 | * modify it under the terms of the GNU General Public License as |
paul@622 | 8 | * published by the Free Software Foundation; either version 2 of |
paul@622 | 9 | * the License, or (at your option) any later version. |
paul@622 | 10 | * |
paul@622 | 11 | * This program is distributed in the hope that it will be useful, |
paul@622 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
paul@622 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
paul@622 | 14 | * GNU General Public License for more details. |
paul@622 | 15 | * |
paul@622 | 16 | * You should have received a copy of the GNU General Public License |
paul@622 | 17 | * along with this program; if not, write to the Free Software |
paul@622 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
paul@622 | 19 | * Boston, MA 02110-1301, USA |
paul@622 | 20 | */ |
paul@622 | 21 | |
paul@622 | 22 | #include <l4/re/env.h> |
paul@622 | 23 | |
paul@622 | 24 | #include <pthread-l4.h> |
paul@622 | 25 | #include <pthread.h> |
paul@622 | 26 | |
paul@622 | 27 | #include "thread.h" |
paul@622 | 28 | |
paul@622 | 29 | |
paul@622 | 30 | |
paul@636 | 31 | l4_cap_idx_t get_current_thread(void) |
paul@622 | 32 | { |
paul@622 | 33 | l4_cap_idx_t thread = pthread_l4_cap(pthread_self()); |
paul@622 | 34 | |
paul@622 | 35 | /* NOTE: On MIPS32, at least, in a payload started by libexec, the main thread |
paul@622 | 36 | is not necessarily returned correctly. */ |
paul@622 | 37 | |
paul@622 | 38 | if (l4_is_invalid_cap(thread)) |
paul@622 | 39 | return l4re_env()->main_thread; |
paul@622 | 40 | |
paul@622 | 41 | return thread; |
paul@622 | 42 | } |