<commit_before>/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*            <NAME>, <NAME>, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  Automatique.  Distributed only by permission.                      */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include <signal.h>
#include <stdio.h>
#include "alloc.h"
#include "memory.h"
#include "minor_gc.h"
#include "misc.h"
#include "mlvalues.h"
#include "fail.h"
#include "signals.h"

Volatile int async_signal_mode = 0;
Volatile int pending_signal = 0;
Volatile int force_major_slice = 0;
value signal_handlers = 0;
extern char * caml_last_return_address;

/* Call the handler for the given signal */

static void execute_signal(signal_number)
     int signal_number;
{
  Assert (!async_signal_mode);
  callback(Field(signal_handlers, signal_number), Val_int(signal_number));
}

/* This routine is the common entry point for garbage collection
   and signal handling */

void garbage_collection()
{
  int sig;

  if (young_ptr < young_start || force_major_slice) minor_collection();
  /* If a signal arrives between the following two instructions,
     it will be lost. */
  sig = pending_signal;
  pending_signal = 0;
  if (sig) execute_signal(sig);
  young_limit = young_start;
}

/* Trigger a garbage collection as soon as possible */

void urge_major_slice ()
{
  force_major_slice = 1;
  young_limit = young_end;
  /* This is only moderately effective on ports that cache young_limit
     in a register, since modify() is called directly, not through
     caml_c_call, so it may take a while before the register is reloaded
     from young_limit. */
}

void enter_blocking_section()
{
  int sig;

  while (1){
    Assert (!async_signal_mode);
    /* If a signal arrives between the next two instructions,
       it will be lost. */
    sig = pending_signal;
    pending_signal = 0;
    if (sig) execute_signal(sig);
    async_signal_mode = 1;
    if (!pending_signal) break;
    async_signal_mode = 0;
  }
}

/* This function may be called from outside a blocking section. */
void leave_blocking_section()
{
  async_signal_mode = 0;
}

#if defined(TARGET_alpha) || defined(TARGET_mips) || defined(TARGET_power)
void handle_signal(sig, code, context)
     int sig, code;
     struct sigcontext * context;
#else
void handle_signal(sig)
     int sig;
#endif
{
#ifndef POSIX_SIGNALS
#ifndef BSD_SIGNALS
  signal(sig, handle_signal);
#endif
#endif
  if (async_signal_mode) {
    /* We are interrupting a C function blocked on I/O.
       Callback the Caml code immediately. */
    leave_blocking_section();
    callback(Field(signal_handlers, sig), Val_int(sig));
    enter_blocking_section();
  } else {
    /* We can't execute the signal code immediately.
       Instead, we remember the signal and play with the allocation limit
       so that the next allocation will trigger a garbage collection. */
    pending_signal = sig;
    young_limit = young_end;
    /* Some ports cache young_limit in a register.
       Use the signal context to modify that register too, but not if
       we are inside C code (i.e. caml_last_return_address != NULL). */
#ifdef TARGET_alpha
    /* Cached in register $14 */
    if (caml_last_return_address == NULL)
      context->sc_regs[14] = (long) young_limit;
#endif
#ifdef TARGET_mips
      /* Cached in register $23 */
      if (caml_last_return_address == NULL)
        context->sc_regs[23] = (int) young_limit;
#endif
#ifdef TARGET_power
      /* Cached in register 31 */
#ifdef _AIX
      if (caml_last_return_address == NULL)
        context->sc_jmpbuf.jmp_context.gpr[31] = (ulong_t) young_limit;
#endif
#endif
  }<commit_msg>Signaux pour le PowerPC sous Linux<commit_after>/***********************************************************************/
/*                                                                     */
/*                           Objective Caml                            */
/*                                                                     */
/*            <NAME>, <NAME>, INRIA Rocquencourt         */
/*                                                                     */
/*  Copyright 1996 Institut National de Recherche en Informatique et   */
/*  Automatique.  Distributed only by permission.                      */
/*                                                                     */
/***********************************************************************/

/* $Id$ */

#include <signal.h>
#include <stdio.h>
#ifdef __linux
#include <asm/sigcontext.h>
#endif
#include "alloc.h"
#include "memory.h"
#include "minor_gc.h"
#include "misc.h"
#include "mlvalues.h"
#include "fail.h"
#include "signals.h"

Volatile int async_signal_mode = 0;
Volatile int pending_signal = 0;
Volatile int force_major_slice = 0;
value signal_handlers = 0;
extern char * caml_last_return_address;

/* Call the handler for the given signal */

static void execute_signal(signal_number)
     int signal_number;
{
  Assert (!async_signal_mode);
  callback(Field(signal_handlers, signal_number), Val_int(signal_number));
}

/* This routine is the common entry point for garbage collection
   and signal handling */

void garbage_collection()
{
  int sig;

  if (young_ptr < young_start || force_major_slice) minor_collection();
  /* If a signal arrives between the following two instructions,
     it will be lost. */
  sig = pending_signal;
  pending_signal = 0;
  if (sig) execute_signal(sig);
  young_limit = young_start;
}

/* Trigger a garbage collection as soon as possible */

void urge_major_slice ()
{
  force_major_slice = 1;
  young_limit = young_end;
  /* This is only moderately effective on ports that cache young_limit
     in a register, since modify() is called directly, not through
     caml_c_call, so it may take a while before the register is reloaded
     from young_limit. */
}

void enter_blocking_section()
{
  int sig;

  while (1){
    Assert (!async_signal_mode);
    /* If a signal arrives between the next two instructions,
       it will be lost. */
    sig = pending_signal;
    pending_signal = 0;
    if (sig) execute_signal(sig);
    async_signal_mode = 1;
    if (!pending_signal) break;
    async_signal_mode = 0;
  }
}

/* This function may be called from outside a blocking section. */
void leave_blocking_section()
{
  async_signal_mode = 0;
}

#if defined(TARGET_alpha) || defined(TARGET_mips) || \
    (defined(TARGET_power) && defined(_AIX))
void handle_signal(sig, code, context)
     int sig, code;
     struct sigcontext * context;
#elif defined(TARGET_power) && defined(__linux)
void handle_signal(sig, context)
     int sig;
     struct pt_regs * context;
#else
void handle_signal(sig)
     int sig;
#endif
{
#ifndef POSIX_SIGNALS
#ifndef BSD_SIGNALS
  signal(sig, handle_signal);
#endif
#endif
  if (async_signal_mode) {
    /* We are interrupting a C function blocked on I/O.
       Callback the Caml code immediately. */
    leave_blocking_section();
    callback(Field(signal_handlers, sig), Val_int(sig));
    enter_blocking_section();
  } else {
    /* We can't execute the signal code immediately.
       Instead, we remember the signal and play with the allocation limit
       so that the next allocation will trigger a garbage collection. */
    pending_signal = sig;
    young_limit = young_end;
    /* Some ports cache young_limit in a register.
       Use the signal context to modify that register too, but not if
       we are inside C code (i.e. caml_last_return_address != NULL). */
#ifdef TARGET_alpha
    /* Cached in register $14 */
    if (caml_last_return_address == NULL)
      context->sc_regs[14] = (long) young_limit;
#endif
#ifdef TARGET_mips
      /* Cached in register $23 */
      if (caml_last_return_address == NULL)
        context->sc_regs[23] = (int) young_limit;
#endif
#ifdef TARGET_power
      /* Cached in register 31 */
#ifdef _AIX
      if (caml_last_return_address == NULL)
        context->sc_jmpbuf.jmp_context.gpr[31] = (ulong_t) young_limit;
#endif
#ifdef __linux
      if (caml_last_return_address == NULL)
        context->gpr[31] = (unsigned long) young_limit;
#endif
#endif
  }
{'fraction_non_alphanumeric': 0.12406803355079217, 'fraction_numerical': 0.0065237651444548, 'mean_word_length': 2.5875470121186797, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3898947', 'n_tokens_mistral': 2501, 'n_tokens_neox': 2414, 'n_words': 766}