code-intelligence.com/cifuzz@v0.40.0/third-party/minijail/dump_constants.cc (about)

     1  /* Copyright 2018 The Chromium OS Authors. All rights reserved.
     2   * Use of this source code is governed by a BSD-style license that can be
     3   * found in the LICENSE file.
     4   */
     5  
     6  // Generate a .json file with all the architecture-specific constants.
     7  
     8  #include <cstdint>
     9  #include <iomanip>
    10  #include <iostream>
    11  #include <string>
    12  
    13  #include "arch.h"
    14  #include "libconstants.h"
    15  #include "libsyscalls.h"
    16  
    17  int main() {
    18    // Numeric values are passed to std::cout via std::to_string() to avoid
    19    // the use of 'bextr' asm instruction (when compiled with -march=bdver4).
    20    std::cout << "{\n";
    21    std::cout << "  \"arch_nr\": " << std::to_string(MINIJAIL_ARCH_NR) << ",\n";
    22    std::cout << "  \"arch_name\": \"" << MINIJAIL_ARCH_NAME << "\",\n";
    23    std::cout << "  \"bits\": " << std::to_string(MINIJAIL_ARCH_BITS) << ",\n";
    24    std::cout << "  \"syscalls\": {\n";
    25    bool first = true;
    26    for (const struct syscall_entry* entry = syscall_table; entry->name;
    27         ++entry) {
    28      if (first)
    29        first = false;
    30      else
    31        std::cout << ",\n";
    32      std::cout << "    \"" << entry->name << "\": " << std::to_string(entry->nr);
    33    }
    34    std::cout << "\n  },\n";
    35    std::cout << "  \"constants\": {\n";
    36    first = true;
    37    for (const struct constant_entry* entry = constant_table; entry->name;
    38         ++entry) {
    39      if (first)
    40        first = false;
    41      else
    42        std::cout << ",\n";
    43      std::cout << "    \"" << entry->name << "\": "
    44  	      << std::to_string(entry->value);
    45    }
    46    std::cout << "\n  }\n";
    47    std::cout << "}\n";
    48  
    49    return 0;
    50  }