14#include "arcane/utils/PlatformUtils.h" 
   15#include "arcane/utils/String.h" 
   16#include "arcane/utils/StdHeader.h" 
   17#include "arcane/utils/StackTrace.h" 
   18#include "arcane/utils/IStackTraceService.h" 
   19#include "arcane/utils/IOnlineDebuggerService.h" 
   20#include "arcane/utils/Iostream.h" 
   21#include "arcane/utils/StringBuilder.h" 
   22#include "arcane/utils/NotSupportedException.h" 
   23#include "arcane/utils/NotImplementedException.h" 
   24#include "arcane/utils/FatalErrorException.h" 
   25#include "arcane/utils/Array.h" 
   26#include "arcane/utils/StringList.h" 
   28#include "arcane/utils/CheckedConvert.h" 
   29#include "arcane/utils/internal/MemoryUtilsInternal.h" 
   35#ifndef ARCANE_OS_WIN32 
   51#include <sys/resource.h> 
   61#include <mach-o/dyld.h> 
   62#include <crt_externs.h> 
   68#if !defined(ARCANE_OS_CYGWIN) && !defined(ARCANE_OS_WIN32) 
   70#define ARCANE_HAS_I386_FPU_CONTROL_H 
   71#include <fpu_control.h> 
   75#ifndef ARCANE_OS_WIN32 
   86#if defined(ARCANE_OS_LINUX) && defined(__USE_GNU) 
   88#  define ARCANE_GLIBC_FENV 
  108  bool global_has_color_console = 
false;
 
 
  117  return global_symbolizer_service;
 
 
  127  global_symbolizer_service = service;
 
 
  137  return global_online_debugger_service;
 
 
  147  global_online_debugger_service = service;
 
 
  157  return global_profiling_service;
 
 
  167  global_profiling_service = service;
 
 
  177  return global_dynamic_library_loader;
 
 
  187  global_dynamic_library_loader = idll;
 
 
  197  return global_processor_affinity_service;
 
 
  207  global_processor_affinity_service = service;
 
 
  217  return global_performance_counter_service;
 
 
  226  auto* old_service = global_performance_counter_service;
 
  227  global_performance_counter_service = service;
 
 
  246  return MemoryUtils::setAcceleratorHostMemoryAllocator(a);
 
 
  261extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng* 
platform:: 
  264  return MemoryUtils::setDataMemoryResourceMng(mng);
 
 
  273  return MemoryUtils::getDataMemoryResourceMng();
 
 
  282  return Arccore::Concurrency::getThreadImplementation();
 
 
  291  return Arccore::Concurrency::setThreadImplementation(service);
 
 
  301  struct itimerval time_val;
 
  302  struct itimerval otime_val;
 
  303  time_val.it_value.tv_sec     = nb_second;
 
  304  time_val.it_value.tv_usec    = 0;
 
  305  time_val.it_interval.tv_sec  = 0;
 
  306  time_val.it_interval.tv_usec = 0;
 
  310  int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
 
  312    cout << 
"** ERROR in setitimer r=" << r << 
'\n';
 
 
  339template<
typename ByteType> 
bool 
  344  if (file_length == 0) {
 
  349  ios::openmode mode = ios::in;
 
  357  out_bytes.
resize(file_length);
 
  358  ifile.read((
char*)(out_bytes.
data()), file_length);
 
  367  size_t nb_read = ifile.gcount();
 
  368  out_bytes.
resize(nb_read);
 
  380  return _readAllFile(filename,is_binary,out_bytes);
 
 
  389  return _readAllFile(filename,is_binary,out_bytes);
 
 
  395static bool global_has_dotnet_runtime = 
false;
 
  399  return global_has_dotnet_runtime;
 
 
  405  global_has_dotnet_runtime = v;
 
 
  415#if defined(ARCANE_OS_LINUX) 
  416  char* buf = ::realpath(
"/proc/self/exe",
nullptr);
 
  421#elif defined(ARCANE_OS_WIN32) 
  423  int r = GetModuleFileNameA(NULL,buf,2000);
 
  427#elif defined(ARCANE_OS_MACOS) 
  429  uint32_t bufSize = 2000;
 
  430  int r = _NSGetExecutablePath(buf, &bufSize);
 
  435#error "platform::getExeFullPath() not implemented for this platform" 
 
  449#if defined(ARCANE_OS_LINUX) 
  451    std::ifstream ifile(
"/proc/self/maps");
 
  453    String true_name = 
"lib" + dll_name + 
".so";
 
  454    while (ifile.good()){
 
  457      if (vb.
size()>0 && vb[0]==
'/'){
 
  458        if (v.endsWith(true_name)){
 
  466#elif defined(ARCANE_OS_WIN32) 
  467  HMODULE hModule = GetModuleHandleA(dll_name.
localstr());
 
  470  TCHAR dllPath[_MAX_PATH];
 
  471  GetModuleFileName(hModule, dllPath, _MAX_PATH);
 
  473#elif defined(ARCANE_OS_MACOS) 
  475    String true_name = 
"lib" + dll_name + 
".dylib";
 
  476    uint32_t count = _dyld_image_count();
 
  477    for (uint32_t i = 0; i < count; i++) {
 
  478      const char* image_name = _dyld_get_image_name(i);
 
  480        String image_path(image_name);
 
  481        if (image_path.
endsWith(true_name)) {
 
  482          full_path = image_path;
 
 
  502#if defined(ARCANE_OS_LINUX) 
  504  const int BUFSIZE = 1024;
 
  505  char buffer[BUFSIZE + 1];
 
  511    const char* filename = 
"/proc/self/cmdline";
 
  512    int fd = open(filename, O_RDONLY);
 
  517    while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
 
  518      buffer[BUFSIZE] = 
'\0';
 
  524  int size = bytes.
size();
 
  525  const char* ptr = bytes.
data();
 
  526  const char* end = ptr + size;
 
  529    while (*ptr++ && ptr < end)
 
  532#elif defined(ARCANE_OS_WIN32) 
  533  LPWSTR* w_arg_list = 
nullptr;
 
  536  w_arg_list = ::CommandLineToArgvW(GetCommandLineW(), &nb_arg);
 
  538    ARCANE_FATAL(
"Can not get arguments from command line");
 
  540  for (
int i = 0; i < nb_arg; i++) {
 
  541    std::wstring_view wstr_view(w_arg_list[i]);
 
  546  ::LocalFree(w_arg_list);
 
  547#elif defined(ARCANE_OS_MACOS) 
  548  int argc = *_NSGetArgc();
 
  549  char** argv = *_NSGetArgv();
 
  550  for (
int i = 0; i < argc; i++) {
 
 
  564#if defined(ARCCORE_OS_WIN32) 
  567  return si.dwPageSize;
 
  568#elif defined(ARCANE_OS_LINUX) 
  569  return ::sysconf(_SC_PAGESIZE);
 
  571#warning "getPageSize() not implemented for your platform. Default is 4096" 
  572  Int64 page_size = 4096;
 
 
  582  String _getDebuggerStack(
const char* command)
 
  585    long pid = (long)getpid();
 
  586    sprintf(filename, 
"errlog.%ld", pid);
 
  587    int ret_value = system(command);
 
  588    if (ret_value != 0) {
 
  601#if defined(ARCANE_OS_LINUX) 
  602  const size_t cmd_size = 4096;
 
  603  char cmd[cmd_size + 1];
 
  606  long pid = (long)getpid();
 
  607  snprintf(cmd, cmd_size, 
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
 
  608  result = _getDebuggerStack(cmd);
 
 
  620#if defined(ARCANE_OS_LINUX) 
  621  const size_t cmd_size = 4096;
 
  622  char cmd[cmd_size + 1];
 
  623  long pid = (long)getpid();
 
  626  snprintf(cmd, cmd_size, 
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
 
  627  result = _getDebuggerStack(cmd);
 
 
  637void (*global_garbage_collector_delegate)() = 
nullptr;
 
  640extern "C" ARCANE_UTILS_EXPORT 
void 
  641_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
 
  643  global_garbage_collector_delegate = f;
 
  649  if (global_garbage_collector_delegate)
 
  650    (*global_garbage_collector_delegate)();
 
 
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
Fonctions utilitaires sur les chaînes de caractères.
ARCCORE_BASE_EXPORT String convertToArcaneString(const std::wstring_view &wstr)
Convertie wstr en une String.
Integer size() const
Nombre d'éléments du vecteur.
Classe de base des vecteurs 1D de données.
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
const T * data() const
Accès à la racine du tableau hors toute protection.
void reserve(Int64 new_capacity)
Réserve le mémoire pour new_capacity éléments.
void clear()
Supprime tous les éléments de la collection.
Interface d'un allocateur pour la mémoire.
Interface d'un service de récupération des symboles du code source.
Interface d'un service implémentant le support des threads.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Vue d'un tableau d'éléments de type T.
Vue sur une chaîne de caractères UTF-8.
std::string_view toStdStringView() const ARCCORE_NOEXCEPT
Retourne une vue de la STL de la vue actuelle.
Chaîne de caractères unicode.
bool null() const
Retourne true si la chaîne est nulle.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
bool endsWith(const String &s) const
Indique si la chaîne se termine par les caractères de s.
Vecteur 1D de données avec sémantique par valeur (style STL).
IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.
IMemoryAllocator * getAcceleratorHostMemoryAllocator()
Allocateur spécifique pour les accélérateurs.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
Array< Byte > ByteArray
Tableau dynamique à une dimension de caractères.
List< String > StringList
Tableau de chaînes de caractères unicode.