From 1ebc07facd7bac4f8a53a5b9749a820b41552dc8 Mon Sep 17 00:00:00 2001 From: haotuo Date: Thu, 13 Oct 2022 09:54:10 +0800 Subject: [PATCH] Add ohos ident flag for x86_64 library compile and fix x86 compile error fixed 3a9781c from https://gitee.com/shawshank506/third_party_musl/pulls/572 fixed x86 compile from :https://gitee.com/openharmony/third_party_musl/pulls/667 Change-Id: Ib980b4d783087a48cd1d8e008726dbcc5db7e317 Signed-off-by: haotuo --- musl_src.gni | 2 + porting/linux/user/crt/x86_64/crti.s | 11 ++++ porting/linux/user/src/linux/cache.c | 65 +++++++++++++++++++++ porting/linux/user/src/sched/sched_getcpu.c | 57 ++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 porting/linux/user/crt/x86_64/crti.s create mode 100644 porting/linux/user/src/linux/cache.c create mode 100644 porting/linux/user/src/sched/sched_getcpu.c diff --git a/musl_src.gni b/musl_src.gni index fa7e37f2..908356ee 100644 --- a/musl_src.gni +++ b/musl_src.gni @@ -2131,6 +2131,8 @@ musl_src_porting_file = [ "src/time/gettimeofday.c", "src/time/time.c", "src/stdio/__fdopen.c", + "src/linux/cache.c", + "src/sched/sched_getcpu.c", ] musl_inc_hook_files = [ diff --git a/porting/linux/user/crt/x86_64/crti.s b/porting/linux/user/crt/x86_64/crti.s new file mode 100644 index 00000000..104d9183 --- /dev/null +++ b/porting/linux/user/crt/x86_64/crti.s @@ -0,0 +1,11 @@ +.include "crtbrand.s" + +.section .init +.global _init +_init: + push %rax + +.section .fini +.global _fini +_fini: + push %rax diff --git a/porting/linux/user/src/linux/cache.c b/porting/linux/user/src/linux/cache.c new file mode 100644 index 00000000..c2782025 --- /dev/null +++ b/porting/linux/user/src/linux/cache.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "syscall.h" +#include "atomic.h" + +#ifdef SYS_cacheflush +int _flush_cache(void *addr, int len, int op) +{ + return syscall(SYS_cacheflush, addr, len, op); +} +weak_alias(_flush_cache, cacheflush); +#endif + +#ifdef SYS_cachectl +int __cachectl(void *addr, int len, int op) +{ + return syscall(SYS_cachectl, addr, len, op); +} +weak_alias(__cachectl, cachectl); +#endif + +#ifdef SYS_riscv_flush_icache + +#define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache" +#define VDSO_FLUSH_ICACHE_VER "LINUX_4.5" + +static void *volatile vdso_func; + +static int flush_icache_init(void *start, void *end, unsigned long int flags) +{ + __get_vdso_info(); + void *p = __get_vdso_addr(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM); + int (*f)(void *, void *, unsigned long int) = + (int (*)(void *, void *, unsigned long int))p; + a_cas_p(&vdso_func, (void *)flush_icache_init, p); + return f ? f(start, end, flags) : -ENOSYS; +} + +static void *volatile vdso_func = (void *)flush_icache_init; + +int __riscv_flush_icache(void *start, void *end, unsigned long int flags) +{ + int (*f)(void *, void *, unsigned long int) = + (int (*)(void *, void *, unsigned long int))vdso_func; + if (f) { + int r = f(start, end, flags); + if (!r) return r; + if (r != -ENOSYS) return __syscall_ret(r); + } +} +weak_alias(__riscv_flush_icache, riscv_flush_icache); +#endif diff --git a/porting/linux/user/src/sched/sched_getcpu.c b/porting/linux/user/src/sched/sched_getcpu.c new file mode 100644 index 00000000..72597b2d --- /dev/null +++ b/porting/linux/user/src/sched/sched_getcpu.c @@ -0,0 +1,57 @@ +/* Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include +#include +#include "syscall.h" +#include "atomic.h" + +#ifdef VDSO_GETCPU_SYM + +static void *volatile vdso_func; + +typedef long (*getcpu_f)(unsigned *, unsigned *, void *); + +static long getcpu_init(unsigned *cpu, unsigned *node, void *unused) +{ + __get_vdso_info(); + void *p = __get_vdso_addr(VDSO_GETCPU_VER, VDSO_GETCPU_SYM); + getcpu_f f = (getcpu_f)p; + a_cas_p(&vdso_func, (void *)getcpu_init, p); + return f ? f(cpu, node, unused) : -ENOSYS; +} + +static void *volatile vdso_func = (void *)getcpu_init; + +#endif + +int sched_getcpu(void) +{ + int r; + unsigned cpu; + +#ifdef VDSO_GETCPU_SYM + getcpu_f f = (getcpu_f)vdso_func; + if (f) { + r = f(&cpu, 0, 0); + if (!r) return cpu; + if (r != -ENOSYS) return __syscall_ret(r); + } +#endif + + r = __syscall(SYS_getcpu, &cpu, 0, 0); + if (!r) return cpu; + return __syscall_ret(r); +} -- GitLab