hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame sysdeps/unix/sysv/linux/riscv/flush-icache.c

Packit 6c4009
/* RISC-V instruction cache flushing VDSO calls
Packit 6c4009
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit 6c4009
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public License as
Packit 6c4009
   published by the Free Software Foundation; either version 2.1 of the
Packit 6c4009
   License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <dl-vdso.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include <atomic.h>
Packit 6c4009
#include <sys/cachectl.h>
Packit 6c4009
#include <asm/syscalls.h>
Packit 6c4009
Packit 6c4009
typedef int (*func_type) (void *, void *, unsigned long int);
Packit 6c4009
Packit 6c4009
static int
Packit 6c4009
__riscv_flush_icache_syscall (void *start, void *end, unsigned long int flags)
Packit 6c4009
{
Packit 6c4009
  return INLINE_SYSCALL (riscv_flush_icache, 3, start, end, flags);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
static func_type
Packit 6c4009
__lookup_riscv_flush_icache (void)
Packit 6c4009
{
Packit 6c4009
  PREPARE_VERSION_KNOWN (linux_version, LINUX_4_15);
Packit 6c4009
Packit 6c4009
  func_type func = _dl_vdso_vsym ("__vdso_flush_icache", &linux_version);
Packit 6c4009
Packit 6c4009
  /* If there is no vDSO entry then call the system call directly.  All Linux
Packit 6c4009
     versions provide the vDSO entry, but QEMU's user-mode emulation doesn't
Packit 6c4009
     provide a vDSO.  */
Packit 6c4009
  if (!func)
Packit 6c4009
    func = &__riscv_flush_icache_syscall;
Packit 6c4009
Packit 6c4009
  return func;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#ifdef SHARED
Packit 6c4009
Packit 6c4009
# define INIT_ARCH()
Packit 6c4009
libc_ifunc (__riscv_flush_icache, __lookup_riscv_flush_icache ())
Packit 6c4009
Packit 6c4009
#else
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
__riscv_flush_icache (void *start, void *end, unsigned long int flags)
Packit 6c4009
{
Packit 6c4009
  static volatile func_type cached_func;
Packit 6c4009
Packit 6c4009
  func_type func = atomic_load_relaxed (&cached_func);
Packit 6c4009
Packit 6c4009
  if (!func)
Packit 6c4009
    {
Packit 6c4009
      func = __lookup_riscv_flush_icache ();
Packit 6c4009
      atomic_store_relaxed (&cached_func, func);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return func (start, end, flags);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif