<commit_before>//===-- ipcopt.c ----------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// IPC Optimization Central Runtime Management
//
//===----------------------------------------------------------------------===//

#include "debug.h"
#include "ipcd.h"
#include "ipcopt.h"
#include "ipcreg_internal.h"
#include "real.h"
#include "shm.h"

#include <assert.h>
#include <stdio.h>
#include <unistd.h>

// TODO: This table is presently not used thread-safe at all!
libipc_state state = {{}, {}, {}};

void invalidateEPMap() {
  // Set all endpoint identifiers to 'invalid'
  for (unsigned i = 0; i < TABLE_SIZE; ++i)
    state.FDMap[i].EP = EP_INVALID;
}

void __ipcopt_init() {
  invalidateEPMap();
  shm_state_restore();
}

void __attribute__((destructor)) ipcopt_fini() {
  for (unsigned i = 0; i < TABLE_SIZE; ++i)<commit_msg>libipc: Unregister fd's marked close-on-exec on initialization.<commit_after>//===-- ipcopt.c ----------------------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// IPC Optimization Central Runtime Management
//
//===----------------------------------------------------------------------===//

#include "debug.h"
#include "ipcd.h"
#include "ipcopt.h"
#include "ipcreg_internal.h"
#include "real.h"
#include "shm.h"

#include <assert.h>
#include <stdio.h>
#include <unistd.h>

// TODO: This table is presently not used thread-safe at all!
libipc_state state = {{}, {}, {}};

void invalidateEPMap() {
  // Set all endpoint identifiers to 'invalid'
  for (unsigned i = 0; i < TABLE_SIZE; ++i)
    state.FDMap[i].EP = EP_INVALID;
}

void scan_for_cloexec() {
  for (unsigned i = 0; i < TABLE_SIZE; ++i) {
    fd_info &f = getFDInfo(i);
    if (valid_ep(f.EP) && f.close_on_exec) {
      // This fd is actually already closed!

      // Unregister it, closing localfd as needed...
      unregister_inet_socket(i);
    }
  }
}

void __ipcopt_init() {
  invalidateEPMap();
  shm_state_restore();
  scan_for_cloexec();
}

void __attribute__((destructor)) ipcopt_fini() {
  for (unsigned i = 0; i < TABLE_SIZE; ++i)
{'fraction_non_alphanumeric': 0.295906432748538, 'fraction_numerical': 0.001949317738791423, 'mean_word_length': 1.8259911894273129, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '64067', 'n_tokens_mistral': 792, 'n_tokens_neox': 769, 'n_words': 210}