1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <errno.h> 17#include "stdarg.h" 18#include "stdbool.h" 19#include "pthread_impl.h" 20 21struct user_param { 22 unsigned long user_area; 23 unsigned long user_sp; 24 unsigned long map_base; 25 unsigned int map_size; 26}; 27 28int __thread_clone(int (*func)(void *), int flags, struct pthread *thread, unsigned char *sp) 29{ 30 int ret; 31 bool join_flag = false; 32 struct user_param param; 33 34 if (thread->detach_state == DT_JOINABLE) { 35 join_flag = true; 36 } 37 38 param.user_area = TP_ADJ(thread); 39 param.user_sp = sp; 40 param.map_base = thread->map_base; 41 param.map_size = thread->map_size; 42 ret = __syscall(SYS_create_user_thread, func, ¶m, join_flag); 43 if (ret < 0) { 44 return ret; 45 } 46 47 thread->tid = (unsigned long)ret; 48 return 0; 49} 50