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 "arccore/common/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
107 bool global_has_color_console =
false;
116 return global_symbolizer_service;
126 global_symbolizer_service = service;
136 return global_online_debugger_service;
146 global_online_debugger_service = service;
156 return global_profiling_service;
166 global_profiling_service = service;
176 return global_processor_affinity_service;
186 global_processor_affinity_service = service;
196 return global_performance_counter_service;
205 auto* old_service = global_performance_counter_service;
206 global_performance_counter_service = service;
225 return MemoryUtils::setAcceleratorHostMemoryAllocator(a);
240extern "C++" ARCANE_UTILS_EXPORT IMemoryRessourceMng*
platform::
243 return MemoryUtils::setDataMemoryResourceMng(mng);
252 return MemoryUtils::getDataMemoryResourceMng();
261 return Arccore::Concurrency::getThreadImplementation();
270 return Arccore::Concurrency::setThreadImplementation(service);
280 struct itimerval time_val;
281 struct itimerval otime_val;
282 time_val.it_value.tv_sec = nb_second;
283 time_val.it_value.tv_usec = 0;
284 time_val.it_interval.tv_sec = 0;
285 time_val.it_interval.tv_usec = 0;
289 int r = setitimer(ITIMER_VIRTUAL,&time_val,&otime_val);
291 cout <<
"** ERROR in setitimer r=" << r <<
'\n';
318template<
typename ByteType>
bool
323 if (file_length == 0) {
328 ios::openmode mode = ios::in;
336 out_bytes.
resize(file_length);
337 ifile.read((
char*)(out_bytes.
data()), file_length);
346 size_t nb_read = ifile.gcount();
347 out_bytes.
resize(nb_read);
359 return _readAllFile(filename,is_binary,out_bytes);
368 return _readAllFile(filename,is_binary,out_bytes);
374static bool global_has_dotnet_runtime =
false;
378 return global_has_dotnet_runtime;
384 global_has_dotnet_runtime = v;
394#if defined(ARCANE_OS_LINUX)
395 char* buf = ::realpath(
"/proc/self/exe",
nullptr);
400#elif defined(ARCANE_OS_WIN32)
402 int r = GetModuleFileNameA(NULL,buf,2000);
406#elif defined(ARCANE_OS_MACOS)
408 uint32_t bufSize = 2000;
409 int r = _NSGetExecutablePath(buf, &bufSize);
414#error "platform::getExeFullPath() not implemented for this platform"
428#if defined(ARCANE_OS_LINUX)
430 std::ifstream ifile(
"/proc/self/maps");
432 String true_name =
"lib" + dll_name +
".so";
433 while (ifile.good()){
436 if (vb.
size()>0 && vb[0]==
'/'){
437 if (v.endsWith(true_name)){
445#elif defined(ARCANE_OS_WIN32)
446 HMODULE hModule = GetModuleHandleA(dll_name.
localstr());
449 TCHAR dllPath[_MAX_PATH];
450 GetModuleFileName(hModule, dllPath, _MAX_PATH);
452#elif defined(ARCANE_OS_MACOS)
454 String true_name =
"lib" + dll_name +
".dylib";
455 uint32_t count = _dyld_image_count();
456 for (uint32_t i = 0; i < count; i++) {
457 const char* image_name = _dyld_get_image_name(i);
459 String image_path(image_name);
460 if (image_path.
endsWith(true_name)) {
461 full_path = image_path;
481#if defined(ARCANE_OS_LINUX)
483 const int BUFSIZE = 1024;
484 char buffer[BUFSIZE + 1];
490 const char* filename =
"/proc/self/cmdline";
491 int fd = open(filename, O_RDONLY);
496 while ((nb_read = read(fd, buffer, BUFSIZE)) > 0) {
497 buffer[BUFSIZE] =
'\0';
503 int size = bytes.
size();
504 const char* ptr = bytes.
data();
505 const char* end = ptr + size;
508 while (*ptr++ && ptr < end)
511#elif defined(ARCANE_OS_WIN32)
512 LPWSTR* w_arg_list =
nullptr;
515 w_arg_list = ::CommandLineToArgvW(GetCommandLineW(), &nb_arg);
517 ARCANE_FATAL(
"Can not get arguments from command line");
519 for (
int i = 0; i < nb_arg; i++) {
520 std::wstring_view wstr_view(w_arg_list[i]);
525 ::LocalFree(w_arg_list);
526#elif defined(ARCANE_OS_MACOS)
527 int argc = *_NSGetArgc();
528 char** argv = *_NSGetArgv();
529 for (
int i = 0; i < argc; i++) {
542 String _getDebuggerStack(
const char* command)
545 long pid = (long)getpid();
546 sprintf(filename,
"errlog.%ld", pid);
547 int ret_value = system(command);
548 if (ret_value != 0) {
561#if defined(ARCANE_OS_LINUX)
562 const size_t cmd_size = 4096;
563 char cmd[cmd_size + 1];
566 long pid = (long)getpid();
567 snprintf(cmd, cmd_size,
"gdb --ex 'set debuginfod enabled off' --ex 'attach %ld' --ex 'info threads' --ex 'thread apply all bt full' --batch", pid);
568 result = _getDebuggerStack(cmd);
580#if defined(ARCANE_OS_LINUX)
581 const size_t cmd_size = 4096;
582 char cmd[cmd_size + 1];
583 long pid = (long)getpid();
586 snprintf(cmd, cmd_size,
"lldb -p %ld -o 'bt' -o 'bt all' -o 'clrthreads' -o 'clrstack' -o 'dumpstack' --batch", pid);
587 result = _getDebuggerStack(cmd);
597void (*global_garbage_collector_delegate)() =
nullptr;
600extern "C" ARCANE_UTILS_EXPORT
void
601_ArcaneSetCallGarbageCollectorDelegate(
void(*f)())
603 global_garbage_collector_delegate = f;
609 if (global_garbage_collector_delegate)
610 (*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 utilitaires sur les chaînes de caractères.
String convertToArcaneString(const std::wstring_view &wstr)
Convertie wstr en une String.
Fonctions de gestion mémoire et des allocateurs.
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 -*-
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.