<commit_before>//===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Implementation of the runtime dynamic memory manager base class.
//
//===----------------------------------------------------------------------===//

#include "llvm/Config/config.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include <cstdlib>

#ifdef __linux__
  // These includes used by RTDyldMemoryManager::getPointerToNamedFunction()
  // for Glibc trickery. See comments in this function for more information.
  #ifdef HAVE_SYS_STAT_H
    #include <sys/stat.h>
  #endif
  #include <fcntl.h>
  #include <unistd.h>
#endif

namespace llvm {

RTDyldMemoryManager::~RTDyldMemoryManager() {}

// Determine whether we can register EH tables.
#if (defined(__GNUC__) && !defined(__ARM_EABI__) && !defined(__ia64__) && \
     !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__))
#define HAVE_EHTABLE_SUPPORT 1
#else
#define HAVE_EHTABLE_SUPPORT 0
#endif

#if HAVE_EHTABLE_SUPPORT
extern "C" void __register_frame(void *);
extern "C" void __deregister_frame(void *);
#else
// The building compiler does not have __(de)register_frame but
// it may be found at runtime in a dynamically-loaded library.
// For example, this happens when building LLVM with Visual C++
// but using the MingW runtime.
void __register_frame(void *p) {
  static bool Searched = false;
  static void((*rf)(void *)) = 0;

  if (!Searched) {
    Searched = true;
    *(void **)&rf =
        llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("__register_frame");
  }
  if (rf)
    rf(p);
}

void __deregister_frame(void *p) {
  static bool Searched = false;
  static void((*df)(void *)) = 0;

  if (!Searched) {
    Searched = true;
    *(void **)&df = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(
        "__deregister_frame");
  }
  if (df)
    df(p);
}
#endif

#ifdef __APPLE__

static const char *processFDE(const char *Entry, bool isDeregister) {
  const char *P = Entry;
  uint32_t Length = *((const uint32_t *)P);
  P += 4;
  uint32_t Offset = *((const uint32_t *)P);
  if (Offset != 0) {
    if (isDeregister)
      __deregister_frame(const_cast<char *>(Entry));
    else
      __register_frame(const_cast<char *>(Entry));
  }
  return P + Length;
}

// This implementation handles frame registration for local targets.
// Memory managers for remote targets should re-implement this function
// and use the LoadAddr parameter.
void RTDyldMemoryManager::registerEHFramesInProcess(uint8_t *Addr,
                                                    size_t Size) {
  // On OS X OS X __register_frame takes a single FDE as an argument.
  // See http://lists.llvm.org/pipermail/llvm-dev/2013-April/061768.html
  const char *P = (const char *)Addr;
  const char *End = P + Size;
  do  {
    P = processFDE(P, false);<commit_msg>Update mailing list post URL and add libunwind reference<commit_after>//===-- RTDyldMemoryManager.cpp - Memory manager for MC-JIT -----*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Implementation of the runtime dynamic memory manager base class.
//
//===----------------------------------------------------------------------===//

#include "llvm/Config/config.h"
#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ErrorHandling.h"
#include <cstdlib>

#ifdef __linux__
  // These includes used by RTDyldMemoryManager::getPointerToNamedFunction()
  // for Glibc trickery. See comments in this function for more information.
  #ifdef HAVE_SYS_STAT_H
    #include <sys/stat.h>
  #endif
  #include <fcntl.h>
  #include <unistd.h>
#endif

namespace llvm {

RTDyldMemoryManager::~RTDyldMemoryManager() {}

// Determine whether we can register EH tables.
#if (defined(__GNUC__) && !defined(__ARM_EABI__) && !defined(__ia64__) && \
     !defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__))
#define HAVE_EHTABLE_SUPPORT 1
#else
#define HAVE_EHTABLE_SUPPORT 0
#endif

#if HAVE_EHTABLE_SUPPORT
extern "C" void __register_frame(void *);
extern "C" void __deregister_frame(void *);
#else
// The building compiler does not have __(de)register_frame but
// it may be found at runtime in a dynamically-loaded library.
// For example, this happens when building LLVM with Visual C++
// but using the MingW runtime.
void __register_frame(void *p) {
  static bool Searched = false;
  static void((*rf)(void *)) = 0;

  if (!Searched) {
    Searched = true;
    *(void **)&rf =
        llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("__register_frame");
  }
  if (rf)
    rf(p);
}

void __deregister_frame(void *p) {
  static bool Searched = false;
  static void((*df)(void *)) = 0;

  if (!Searched) {
    Searched = true;
    *(void **)&df = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(
        "__deregister_frame");
  }
  if (df)
    df(p);
}
#endif

#ifdef __APPLE__

static const char *processFDE(const char *Entry, bool isDeregister) {
  const char *P = Entry;
  uint32_t Length = *((const uint32_t *)P);
  P += 4;
  uint32_t Offset = *((const uint32_t *)P);
  if (Offset != 0) {
    if (isDeregister)
      __deregister_frame(const_cast<char *>(Entry));
    else
      __register_frame(const_cast<char *>(Entry));
  }
  return P + Length;
}

// This implementation handles frame registration for local targets.
// Memory managers for remote targets should re-implement this function
// and use the LoadAddr parameter.
void RTDyldMemoryManager::registerEHFramesInProcess(uint8_t *Addr,
                                                    size_t Size) {
  // On OS X OS X __register_frame takes a single FDE as an argument.
  // See http://lists.llvm.org/pipermail/llvm-dev/2013-April/061737.html
  // and projects/libunwind/src/UnwindLevel1-gcc-ext.c.
  const char *P = (const char *)Addr;
  const char *End = P + Size;
  do  {
    P = processFDE(P, false);
{'fraction_non_alphanumeric': 0.16848745960917064, 'fraction_numerical': 0.008462840436990306, 'mean_word_length': 2.9274924471299095, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2010233', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2011, 'n_words': 573}