<commit_before>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
// and <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <os.hpp>
#include <kernel.hpp>
#include <kernel/rng.hpp>
#include <service>
#include <cstdio>
#include <cinttypes>
#include <util/fixed_vector.hpp>
#include <system_log>
#define MYINFO(X,...) INFO("Kernel", X, ##__VA_ARGS__)

//#define ENABLE_PROFILERS
#ifdef ENABLE_PROFILERS
#include <profile>
#define PROFILE(name)  ScopedProfiler __CONCAT(sp, __COUNTER__){name};
#else
#define PROFILE(name) /* name */
#endif

using namespace util;

extern char _start;
extern char _end;
extern char _ELF_START_;
extern char _TEXT_START_;
extern char _LOAD_START_;
extern char _ELF_END_;

//uintptr_t OS::liveupdate_loc_   = 0;

kernel::State __kern_state;

kernel::State& kernel::state() noexcept {
  return __kern_state;
}

util::KHz os::cpu_freq() {
  return kernel::cpu_freq();
}

const uintptr_t elf_binary_size_ {(uintptr_t)&_ELF_END_ - (uintptr_t)&_ELF_START_};

// stdout redirection
using Print_vec = Fixed_vector<os::print_func, 8>;
static Print_vec os_print_handlers(Fixedvector_Init::UNINIT);

// Plugins
struct Plugin_desc {
  Plugin_desc(os::Plugin f, const char* n) : func{f}, name{n} {}

  os::Plugin  func;
  const char* name;
};
static Fixed_vector<Plugin_desc, 16> plugins(Fixedvector_Init::UNINIT);


__attribute__((weak))
size_t kernel::liveupdate_phys_size(size_t /*phys_max*/) noexcept {
  return 4096;
};

__attribute__((weak))
size_t kernel::liveupdate_phys_loc(size_t phys_max) noexcept {
  return phys_max - liveupdate_phys_size(phys_max);
};

__attribute__((weak))
void kernel::setup_liveupdate(uintptr_t)
{
  // without LiveUpdate: storage location is at the last page?
  kernel::state().liveupdate_loc = kernel::heap_max() & ~(uintptr_t) 0xFFF;
}

const char* os::cmdline_args() noexcept {
  return kernel::cmdline();
}

extern kernel::ctor_t __plugin_ctors_start;
extern kernel::ctor_t __plugin_ctors_end;
extern kernel::ctor_t __service_ctors_start;
extern kernel::ctor_t __service_ctors_end;

void os::register_plugin(Plugin delg, const char* name){
  MYINFO("Registering plugin %s", name);
  plugins.emplace_back(delg, name);
}

extern void __arch_reboot();
void os::reboot() noexcept
{
  __arch_reboot();
}
void os::shutdown() noexcept
{
  kernel::state().running = false;
}

void kernel::post_start()
{
  // Enable timestamps (if present)
  kernel::state().timestamps_ready = true;

  // LiveUpdate needs some initialization, although only if present
  kernel::setup_liveupdate();

  // Initialize the system log if plugin is present.
  // Dependent on the liveupdate location being set
  SystemLog::initialize();

  MYINFO("Initializing RNG");
  PROFILE("RNG init");
  RNG::get().init();

  // Seed rand with 32 bits from RNG
  srand(rng_extract_uint32());

  // Custom initialization functions
  MYINFO("Initializing plugins");
  kernel::run_ctors(&__plugin_ctors_start, &__plugin_ctors_end);<commit_msg>kernel: Disable plugin construction on MacOS<commit_after>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
// and <NAME>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <os.hpp>
#include <kernel.hpp>
#include <kernel/rng.hpp>
#include <service>
#include <cstdio>
#include <cinttypes>
#include <util/fixed_vector.hpp>
#include <system_log>
#define MYINFO(X,...) INFO("Kernel", X, ##__VA_ARGS__)

//#define ENABLE_PROFILERS
#ifdef ENABLE_PROFILERS
#include <profile>
#define PROFILE(name)  ScopedProfiler __CONCAT(sp, __COUNTER__){name};
#else
#define PROFILE(name) /* name */
#endif

using namespace util;

extern char _start;
extern char _end;
extern char _ELF_START_;
extern char _TEXT_START_;
extern char _LOAD_START_;
extern char _ELF_END_;

//uintptr_t OS::liveupdate_loc_   = 0;

kernel::State __kern_state;

kernel::State& kernel::state() noexcept {
  return __kern_state;
}

util::KHz os::cpu_freq() {
  return kernel::cpu_freq();
}

const uintptr_t elf_binary_size_ {(uintptr_t)&_ELF_END_ - (uintptr_t)&_ELF_START_};

// stdout redirection
using Print_vec = Fixed_vector<os::print_func, 8>;
static Print_vec os_print_handlers(Fixedvector_Init::UNINIT);

// Plugins
struct Plugin_desc {
  Plugin_desc(os::Plugin f, const char* n) : func{f}, name{n} {}

  os::Plugin  func;
  const char* name;
};
static Fixed_vector<Plugin_desc, 16> plugins(Fixedvector_Init::UNINIT);


__attribute__((weak))
size_t kernel::liveupdate_phys_size(size_t /*phys_max*/) noexcept {
  return 4096;
};

__attribute__((weak))
size_t kernel::liveupdate_phys_loc(size_t phys_max) noexcept {
  return phys_max - liveupdate_phys_size(phys_max);
};

__attribute__((weak))
void kernel::setup_liveupdate(uintptr_t)
{
  // without LiveUpdate: storage location is at the last page?
  kernel::state().liveupdate_loc = kernel::heap_max() & ~(uintptr_t) 0xFFF;
}

const char* os::cmdline_args() noexcept {
  return kernel::cmdline();
}

extern kernel::ctor_t __plugin_ctors_start;
extern kernel::ctor_t __plugin_ctors_end;
extern kernel::ctor_t __service_ctors_start;
extern kernel::ctor_t __service_ctors_end;

void os::register_plugin(Plugin delg, const char* name){
  MYINFO("Registering plugin %s", name);
  plugins.emplace_back(delg, name);
}

extern void __arch_reboot();
void os::reboot() noexcept
{
  __arch_reboot();
}
void os::shutdown() noexcept
{
  kernel::state().running = false;
}

void kernel::post_start()
{
  // Enable timestamps (if present)
  kernel::state().timestamps_ready = true;

  // LiveUpdate needs some initialization, although only if present
  kernel::setup_liveupdate();

  // Initialize the system log if plugin is present.
  // Dependent on the liveupdate location being set
  SystemLog::initialize();

  MYINFO("Initializing RNG");
  PROFILE("RNG init");
  RNG::get().init();

  // Seed rand with 32 bits from RNG
  srand(rng_extract_uint32());

#ifndef __MACH__
  // Custom initialization functions
  MYINFO("Initializing plugins");
  kernel::run_ctors(&__plugin_ctors_start, &__plugin_ctors_end);
#endif
{'fraction_non_alphanumeric': 0.12047691667821989, 'fraction_numerical': 0.006931928462498267, 'mean_word_length': 5.267593397046047, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6776286', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2337, 'n_words': 671}