diff --git a/.gitignore b/.gitignore index 81c7fc6..166d4bd 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,10 @@ artifacts dist cbxp-* *egg-info/ +cbxp/mappings/*.hpp +cbxp/schemas/*.hpp +*.DS_Store +*.txt # CMake CMakeLists.txt.user @@ -50,6 +54,7 @@ compile_commands.json CTestTestfile.cmake _deps CMakeUserPresets.json +DartConfiguration.tcl # Virtual Environment env/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 7573888..e5843f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,9 @@ file( GLOB CBXP_SRC_LIB "cbxp/*.cpp" "cbxp/control_blocks/*.cpp" + "cbxp/traversal/*.cpp" + "cbxp/util/*.cpp" + "externals/json-schema-validator/*.cpp" ) file( @@ -63,6 +66,55 @@ file( # ============================================================================ # Build '/lib/libcbxp.a' # ============================================================================ +# ============================================================================ +# Generate schema header from cbxp/schemas/control_block.json +# ============================================================================ +set(CBXP_SCHEMAS_GENERATED_DIR "${CMAKE_BINARY_DIR}/cbxp/schemas") +file(MAKE_DIRECTORY "${CBXP_SCHEMAS_GENERATED_DIR}") + +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/cbxp/schemas/control_block.json" CBXP_SCHEMA_JSON) + +file(WRITE "${CBXP_SCHEMAS_GENERATED_DIR}/control_block.hpp" +"#ifndef CBXP_SCHEMA_CONTROL_BLOCK_V1_JSON_HPP\n\ +#define CBXP_SCHEMA_CONTROL_BLOCK_V1_JSON_HPP\n\ +\n\ +#define CBXP_SCHEMA_JSON R\"JSON(${CBXP_SCHEMA_JSON})JSON\"\n\ +\n\ +#endif // CBXP_SCHEMA_CONTROL_BLOCK_V1_JSON_HPP\n" +) + +# ============================================================================ +# Generate mapping headers from JSON files in cbxp/mappings/ +# ============================================================================ +set(CBXP_MAPPINGS_GENERATED_DIR "${CMAKE_BINARY_DIR}/cbxp/mappings") +file(MAKE_DIRECTORY "${CBXP_MAPPINGS_GENERATED_DIR}") + +file(GLOB CBXP_MAPPING_JSON_FILES "${CMAKE_CURRENT_SOURCE_DIR}/cbxp/mappings/*.json") + +set(CBXP_MAPPING_FORCED_INCLUDES "") + +foreach(MAPPING_JSON_FILE ${CBXP_MAPPING_JSON_FILES}) + get_filename_component(MAPPING_NAME "${MAPPING_JSON_FILE}" NAME_WE) + string(TOUPPER "${MAPPING_NAME}" MAPPING_NAME_UPPER) + + file(READ "${MAPPING_JSON_FILE}" MAPPING_JSON) + + set(MAPPING_GUARD "${MAPPING_NAME_UPPER}_JSON_HPP") + set(MAPPING_MACRO "${MAPPING_NAME_UPPER}_JSON") + set(MAPPING_HEADER_PATH "${CBXP_MAPPINGS_GENERATED_DIR}/${MAPPING_NAME}.hpp") + + file(WRITE "${MAPPING_HEADER_PATH}" +"#ifndef ${MAPPING_GUARD}\n\ +#define ${MAPPING_GUARD}\n\ +\n\ +#define ${MAPPING_MACRO} R\"JSON(${MAPPING_JSON})JSON\"\n\ +\n\ +#endif // ${MAPPING_GUARD}\n" + ) + + list(APPEND CBXP_MAPPING_FORCED_INCLUDES "--include=${MAPPING_HEADER_PATH}") +endforeach() + add_library(libcbxp STATIC ${CBXP_SRC_LIB}) set_target_properties(libcbxp PROPERTIES OUTPUT_NAME "cbxp") @@ -70,11 +122,17 @@ target_include_directories( libcbxp PUBLIC cbxp cbxp/control_blocks - externals + externals/json + externals/json-schema-validator /usr/include/zos ) -target_compile_options(libcbxp PUBLIC ${COMPILE_OPTIONS}) +target_compile_options( + libcbxp PUBLIC + ${COMPILE_OPTIONS} + "--include=${CBXP_SCHEMAS_GENERATED_DIR}/control_block_v1.hpp" + ${CBXP_MAPPING_FORCED_INCLUDES} +) target_link_options(libcbxp PUBLIC ${LINK_OPTIONS}) # ============================================================================ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f622852..c29eb26 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,7 +76,7 @@ If you fix a bug, open a GitHub pull request against the `dev` branch with the f ### Testing -CBXP is tested using automated functional tests. Test cases for new functionality and bug fixes should be added to [`tests/test.py`](tests/test.py) and [`tests/test.sh`](tests/test.sh). +CBXP is tested using automated functional tests. Test cases for new functionality and bug fixes should be added to [`tests/test.py`](tests/test.py) and [`tests/CMakeLists.txt`](tests/CMakeLists.txt). #### Python Interface Testing 1. Add new test cases to [`tests/test.py`](tests/test.py). @@ -98,7 +98,7 @@ CBXP is tested using automated functional tests. Test cases for new functionalit ``` #### CLI Interface Testing -1. Add new tests cases to [`tests/test.sh`](tests/test.sh). +1. Add new test cases to [`tests/CMakeLists.txt`](tests/CMakeLists.txt) or as a shared fixture under `tests/fixtures/cbxppath/`. 2. Run the test suite using `cmake` and `gmake`. ```shell diff --git a/cbxp/cbxp.cpp b/cbxp/cbxp.cpp index 2ae70e0..3557967 100644 --- a/cbxp/cbxp.cpp +++ b/cbxp/cbxp.cpp @@ -3,7 +3,8 @@ #include #include "control_block_explorer.hpp" -#include "logger.hpp" +#include "util/control_block_error.hpp" +#include "util/logger.hpp" cbxp_result_t* cbxp_extract(const char* control_block_name, const size_t control_block_name_length, @@ -31,11 +32,14 @@ cbxp_result_t* cbxp_extract(const char* control_block_name, CBXP::Logger::getInstance().debugAllocate(p_cbxp_result, 64, sizeof(cbxp_result_t)); - CBXP::ControlBlockExplorer explorer = - CBXP::ControlBlockExplorer(p_cbxp_result); - - explorer.extractControlBlock(control_block_name_string, - includes_string_string, filters_string_string); + try { + CBXP::ControlBlockExplorer explorer = + CBXP::ControlBlockExplorer(p_cbxp_result); + explorer.extractControlBlock(control_block_name_string, + includes_string_string, filters_string_string); + } catch (const CBXP::CBXPError& e) { + p_cbxp_result->return_code = e.getErrorCode(); + } return p_cbxp_result; } @@ -57,23 +61,26 @@ cbxp_result_t* cbxp_format(const char* control_block_name, CBXP::Logger::getInstance().debugAllocate(p_cbxp_result, 64, sizeof(cbxp_result_t)); - CBXP::ControlBlockExplorer explorer = - CBXP::ControlBlockExplorer(p_cbxp_result); - - explorer.formatControlBlock(control_block_name_string, data, data_length); + try { + CBXP::ControlBlockExplorer explorer = + CBXP::ControlBlockExplorer(p_cbxp_result); + explorer.formatControlBlock(control_block_name_string, data, data_length); + } catch (const CBXP::CBXPError& e) { + p_cbxp_result->return_code = e.getErrorCode(); + } return p_cbxp_result; } -void cbxp_free(cbxp_result_t* cbxp_result, bool debug) { +void cbxp_free(cbxp_result_t* p_cbxp_result, bool debug) { CBXP::Logger::getInstance().setDebug(debug); - if (cbxp_result != nullptr) { - if (cbxp_result->result_json != nullptr) { - CBXP::Logger::getInstance().debugFree(cbxp_result->result_json); - delete cbxp_result->result_json; + if (p_cbxp_result != nullptr) { + if (p_cbxp_result->result_json != nullptr) { + CBXP::Logger::getInstance().debugFree(p_cbxp_result->result_json); + delete p_cbxp_result->result_json; } - CBXP::Logger::getInstance().debugFree(cbxp_result); - delete cbxp_result; + CBXP::Logger::getInstance().debugFree(p_cbxp_result); + delete p_cbxp_result; } } diff --git a/cbxp/cbxp.h b/cbxp/cbxp.h index 359c16b..54a95fb 100644 --- a/cbxp/cbxp.h +++ b/cbxp/cbxp.h @@ -26,7 +26,7 @@ cbxp_result_t* cbxp_format(const char* control_block_name, const void* data, const size_t data_length, bool debug); -void cbxp_free(cbxp_result_t* cbxp_result, bool debug); +void cbxp_free(cbxp_result_t* p_cbxp_result, bool debug); #ifdef __cplusplus } diff --git a/cbxp/cbxp_types.hpp b/cbxp/cbxp_types.hpp new file mode 100644 index 0000000..7a13cab --- /dev/null +++ b/cbxp/cbxp_types.hpp @@ -0,0 +1,17 @@ +#ifndef __CBXP_TYPES_H_ +#define __CBXP_TYPES_H_ + +#include +#include + +namespace CBXP { + +typedef struct { + std::vector include_patterns; + std::vector filters; + bool skip_buffer_length_check; +} cbxp_options_t; + +} // namespace CBXP + +#endif diff --git a/cbxp/cli/command_processor.cpp b/cbxp/cli/command_processor.cpp index 75725f4..1386abd 100644 --- a/cbxp/cli/command_processor.cpp +++ b/cbxp/cli/command_processor.cpp @@ -12,7 +12,7 @@ #include #include "cbxp.h" -#include "control_block_error.hpp" +#include "util/control_block_error.hpp" namespace CBXP { @@ -409,16 +409,16 @@ bool CommandProcessor::checkForComma(const std::string& string) { } void CommandProcessor::run() { - cbxp_result_t* cbxp_result; + cbxp_result_t* p_cbxp_result; if (command_ == "extract") { - cbxp_result = cbxp_extract( + p_cbxp_result = cbxp_extract( control_block_name_.c_str(), control_block_name_.length(), extract_options_.include.c_str(), extract_options_.include.length(), extract_options_.filter.c_str(), extract_options_.filter.length(), global_options_.debug); } else { - cbxp_result = + p_cbxp_result = cbxp_format(control_block_name_.c_str(), control_block_name_.length(), static_cast(format_options_.data_buffer.data() + format_options_.offset), @@ -426,13 +426,13 @@ void CommandProcessor::run() { global_options_.debug); } - unsigned int return_code = cbxp_result->return_code; + unsigned int return_code = p_cbxp_result->return_code; if (return_code == 0) { - std::cout << cbxp_result->result_json << std::endl; + std::cout << p_cbxp_result->result_json << std::endl; } - cbxp_free(cbxp_result, global_options_.debug); + cbxp_free(p_cbxp_result, global_options_.debug); switch (return_code) { case 0: @@ -450,8 +450,24 @@ void CommandProcessor::run() { case CBXP::Error::DataTooSmall: std::cerr << ERROR_DATA_TOO_SMALL_ << control_block_name_ << std::endl; throw CLIExitFailure(); + case CBXP::Error::BadCbxpPath: + std::cerr << ERROR_BAD_CBXP_ENV_PATH_ << std::endl; + throw CLIExitFailure(); + case CBXP::Error::BlockUnreachable: + std::cerr << ERROR_CANT_REACH_BLOCK_ << std::endl; + throw CLIExitFailure(); + case CBXP::Error::JsonFailParse: + std::cerr << ERROR_PARSE_JSON_FILE_ << std::endl; + throw CLIExitFailure(); + case CBXP::Error::JsonFailSchema: + std::cerr << ERROR_VALIDATE_JSON_FILE_ << std::endl; + throw CLIExitFailure(); + case CBXP::Error::JsonBadValue: + std::cerr << ERROR_JSON_FILE_VALUES_ << std::endl; + throw CLIExitFailure(); default: - std::cerr << ERROR_UNKNOWN_ERROR_ << control_block_name_ << std::endl; + std::cerr << ERROR_UNKNOWN_ERROR_ << " " << control_block_name_ + << std::endl; throw CLIExitFailure(); } throw CLIExitSuccess(); diff --git a/cbxp/cli/command_processor.hpp b/cbxp/cli/command_processor.hpp index 32ba26e..88b854a 100644 --- a/cbxp/cli/command_processor.hpp +++ b/cbxp/cli/command_processor.hpp @@ -38,6 +38,13 @@ class CommandProcessor { const std::string ERROR_CONTROL_BLOCK_EXPECTED_ = "Positional argument expected"; const std::string ERROR_UNKNOWN_ERROR_ = "An unknown error occurred"; + const std::string ERROR_BAD_CBXP_ENV_PATH_ = + "Error with your CBXPPATH environment variable"; + const std::string ERROR_CANT_REACH_BLOCK_ = "Cannot reach control block"; + const std::string ERROR_PARSE_JSON_FILE_ = "Could not parse a JSON file"; + const std::string ERROR_VALIDATE_JSON_FILE_ = + "Could not validate a JSON file"; + const std::string ERROR_JSON_FILE_VALUES_ = "Could not load a JSON file"; // Format const std::string ERROR_OFFSET_MUST_BE_A_POSITIVE_INTEGER_ = "Offset must be a positive integer"; diff --git a/cbxp/control_block_error.hpp b/cbxp/control_block_error.hpp deleted file mode 100644 index 09f8d3a..0000000 --- a/cbxp/control_block_error.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef __CONTROL_BLOCK_ERROR_H_ -#define __CONTROL_BLOCK_ERROR_H_ - -namespace CBXP { -enum Error { - BadControlBlock = 1, - BadInclude = 2, - BadFilter = 3, - DataTooSmall = 4, - NullDataPtr = 5 -}; - -class CBXPError : public std::exception { - private: - Error error_code_; - - public: - explicit CBXPError(const Error& rc) : error_code_(rc) {} - const unsigned int getErrorCode() const { return error_code_; } -}; - -class ControlBlockError : public CBXPError { - public: - ControlBlockError() : CBXPError(Error::BadControlBlock) {} -}; - -class IncludeError : public CBXPError { - public: - IncludeError() : CBXPError(Error::BadInclude) {} -}; - -class FilterError : public CBXPError { - public: - FilterError() : CBXPError(Error::BadFilter) {} -}; - -class DataLengthError : public CBXPError { - public: - DataLengthError() : CBXPError(Error::DataTooSmall) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_block_explorer.cpp b/cbxp/control_block_explorer.cpp index 548bd42..5b3b958 100644 --- a/cbxp/control_block_explorer.cpp +++ b/cbxp/control_block_explorer.cpp @@ -1,25 +1,203 @@ #include "control_block_explorer.hpp" #include +#include #include -#include +#include +#include #include +#include #include "cbxp.h" -#include "control_block_error.hpp" -#include "control_blocks/ascb.hpp" -#include "control_blocks/assb.hpp" -#include "control_blocks/asvt.hpp" #include "control_blocks/control_block.hpp" -#include "control_blocks/cvt.hpp" -#include "control_blocks/ecvt.hpp" -#include "control_blocks/ldax.hpp" -#include "control_blocks/oucb.hpp" -#include "control_blocks/psa.hpp" -#include "logger.hpp" +#include "traversal/traversal_engine.hpp" +#include "util/control_block_error.hpp" +#include "util/logger.hpp" namespace CBXP { +std::unordered_map +ControlBlockExplorer::loadCustomControlBlocks( + const nlohmann::json_schema::json_validator& cbxp_schema_validator, + const std::filesystem::path& path) { + std::unordered_map new_maps = {}; + if (!std::filesystem::exists(path) || !std::filesystem::is_directory(path)) { + throw CbxpPathError(); + } + for (const auto& file : std::filesystem::directory_iterator(path)) { + if (file.path().extension() != ".json") { + continue; + } + try { + std::ifstream ifs(file.path()); + nlohmann::json json_data = nlohmann::json::parse(ifs); + // Validate before reading "name", as the schema guarantees it exists. + cbxp_schema_validator.validate(json_data); + // Control blocks are keyed by the "name" in the mapping, not the file + // name. + std::string name = json_data["name"].get(); + Logger::getInstance().debug("Adding '" + name + "' control block from '" + + file.path().string() + "'."); + new_maps.insert_or_assign(name, + ControlBlock(cbxp_schema_validator, json_data)); + } catch (const CBXPError&) { + throw; + } catch (const nlohmann::json::parse_error& e) { + // The file is not well formed JSON at all. + Logger::getInstance().debug("Could not parse '" + file.path().string() + + "': " + std::string(e.what())); + throw CbxpJsonParseError(); + } catch (const std::invalid_argument& e) { + // The validator throws std::invalid_argument when the JSON does not + // conform to the schema. + Logger::getInstance().debug("Could not validate '" + + file.path().string() + + "': " + std::string(e.what())); + throw CbxpSchemaValidationError(); + } + } + return new_maps; +} + +std::vector ControlBlockExplorer::splitCbxpPath( + const std::string& cbxp_path) { + std::vector paths; + std::stringstream stream(cbxp_path); + std::string path; + while (std::getline(stream, path, ':')) { + if (!path.empty()) { + paths.push_back(path); + } + } + return paths; +} + +void ControlBlockExplorer::validateControlBlockReferences( + const std::unordered_map& control_blocks) { + auto to_lower = [](std::string str) { + std::transform(str.begin(), str.end(), str.begin(), + [](unsigned char c) { return std::tolower(c); }); + return str; + }; + for (const auto& [name, control_block] : control_blocks) { + const auto& parents = control_block.getPointedToBy(); + auto unknown_parent = std::find_if( + parents.begin(), parents.end(), [&](const std::string& parent) { + return control_blocks.find(parent) == control_blocks.end(); + }); + if (unknown_parent != parents.end()) { + Logger::getInstance().debug("The '" + name + "' control block is " + + "pointed to by unknown control block '" + + *unknown_parent + "'."); + throw CbxpJsonValueError(); + } + for (const auto& [field_name, field] : control_block.getMap()) { + if (!field.repeated) { + continue; + } + const std::string count = to_lower(field.count); + const bool count_exists = std::any_of( + control_block.getMap().begin(), control_block.getMap().end(), + [&](const auto& entry) { return to_lower(entry.first) == count; }); + if (!count_exists) { + Logger::getInstance().debug( + "The repeated field '" + field_name + "' of the '" + name + + "' control block has an unknown count field '" + field.count + + "'."); + throw CbxpJsonValueError(); + } + } + } +} + +std::string ControlBlockExplorer::mapToString( + const std::unordered_map& map) { + std::string map_as_string = ""; + if (map.empty()) { + return map_as_string; + } + map_as_string = "["; + + bool first_entry = true; + for (const auto& [key, value] : map) { + if (!first_entry) { + map_as_string += ", "; + } else { + first_entry = false; + } + map_as_string += key; + } + + map_as_string += "]"; + return map_as_string; +} + +const std::unordered_map& +ControlBlockExplorer::getControlBlocks() { + nlohmann::json_schema::json_validator cbxp_schema_validator; + cbxp_schema_validator.set_root_schema( + nlohmann::json::parse(CBXP_SCHEMA_JSON)); + + // Magic static: initialized on first call, after main() and the logger are + // ready, so any parse/construction errors are visible in debug output. + static std::unordered_map control_blocks = [&]() { + std::unordered_map map; + try { + map = { + { "psa", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(PSA_JSON)) }, + { "cvt", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(CVT_JSON)) }, + {"ecvt", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(ECVT_JSON))}, + {"asvt", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(ASVT_JSON))}, + {"ascb", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(ASCB_JSON))}, + {"assb", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(ASSB_JSON))}, + {"oucb", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(OUCB_JSON))}, + {"ldax", ControlBlock(cbxp_schema_validator, + nlohmann::json::parse(LDAX_JSON))}, + }; + } catch (const std::exception& e) { + Logger::getInstance().debug("Initialization of JSON mappings failed: " + + std::string(e.what())); + return map; + } + + // Load custom control blocks + const char* p_cbxp_path_env = std::getenv("CBXPPATH"); + if (p_cbxp_path_env == nullptr) { + return map; + } + std::string env_p(p_cbxp_path_env); + if (env_p.empty()) { + return map; + } + // CBXPPATH is a colon separated list of directories. Custom mappings + // overwrite any control block of the same name that was already loaded. + for (const auto& path : ControlBlockExplorer::splitCbxpPath(env_p)) { + std::unordered_map custom_control_blocks = + ControlBlockExplorer::loadCustomControlBlocks(cbxp_schema_validator, + path); + if (!custom_control_blocks.empty()) { + Logger::getInstance().debug( + "Added the following custom control blocks from path '" + path + + "': " + ControlBlockExplorer::mapToString(custom_control_blocks)); + for (auto& [name, control_block] : custom_control_blocks) { + map.insert_or_assign(name, std::move(control_block)); + } + } + } + ControlBlockExplorer::validateControlBlockReferences(map); + return map; + }(); + + return control_blocks; +} + std::vector ControlBlockExplorer::createOptionsList( const std::string& comma_separated_string) { if (comma_separated_string == "") { @@ -92,31 +270,18 @@ void ControlBlockExplorer::processControlBlock( nlohmann::json control_block_json = {}; try { - if (control_block_name == "psa") { - control_block_json = - PSA(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "cvt") { - control_block_json = - CVT(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "ecvt") { - control_block_json = - ECVT(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "ascb") { - control_block_json = - ASCB(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "asvt") { - control_block_json = - ASVT(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "assb") { - control_block_json = - ASSB(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "oucb") { - control_block_json = - OUCB(cbxp_options_).get(p_control_block_, control_block_data_length_); - } else if (control_block_name == "ldax") { + const auto& control_blocks = ControlBlockExplorer::getControlBlocks(); + if (control_blocks.empty()) { + // We would only have this if incompatible control blocks overwrote our + // core control blocks + throw CbxpJsonValueError(); + } + if (control_blocks.find(control_block_name) != control_blocks.end()) { + TraversalEngine engine(control_blocks, + cbxp_options_.skip_buffer_length_check); control_block_json = - LDAX(cbxp_options_).get(p_control_block_, control_block_data_length_); - + engine.run(control_block_name, cbxp_options_, p_control_block_, + control_block_data_length_); } else { throw ControlBlockError(); } diff --git a/cbxp/control_block_explorer.hpp b/cbxp/control_block_explorer.hpp index ba1cf8f..8fb049c 100644 --- a/cbxp/control_block_explorer.hpp +++ b/cbxp/control_block_explorer.hpp @@ -4,17 +4,29 @@ #include #include "cbxp.h" +#include "cbxp_types.hpp" #include "control_blocks/control_block.hpp" namespace CBXP { class ControlBlockExplorer { private: + cbxp_options_t cbxp_options_ = {{}, {}, false}; cbxp_result_t* p_result_; - cbxp_options_t cbxp_options_ = {{}, {}, false}; const void* p_control_block_ = nullptr; size_t control_block_data_length_ = 0; std::string control_block_operation_ = ""; + + static std::string mapToString( + const std::unordered_map& map); + static std::unordered_map loadCustomControlBlocks( + const nlohmann::json_schema::json_validator& cbxp_schema_validator, + const std::filesystem::path& path); + static std::vector splitCbxpPath(const std::string& cbxp_path); + static void validateControlBlockReferences( + const std::unordered_map& control_blocks); + static const std::unordered_map& + getControlBlocks(); static std::vector createOptionsList( const std::string& comma_separated_string); diff --git a/cbxp/control_blocks/ascb.cpp b/cbxp/control_blocks/ascb.cpp deleted file mode 100644 index cef0b7a..0000000 --- a/cbxp/control_blocks/ascb.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "ascb.hpp" - -#include -#include - -#include -#include -#include -#include - -#include "assb.hpp" -#include "asvt.hpp" -#include "logger.hpp" -#include "oucb.hpp" - -namespace CBXP { -nlohmann::json ASCB::get(const void* p_control_block, - const size_t buffer_length) { - ASCB::checkDataLength(buffer_length); - nlohmann::json ascb_json = {}; - const ascb* p_ascb; - - if (p_control_block == nullptr) { - // PSA starts at address 0 - const struct psa* __ptr32 p_psa = 0; - - const struct cvtmap* __ptr32 p_cvtmap = - // 'nullPointer' is a false positive because the PSA starts at address 0 - // cppcheck-suppress nullPointer - static_cast(p_psa->flccvt); - asvt_t* __ptr32 p_asvt = static_cast(p_cvtmap->cvtasvt); - - ascb_json["ascbs"] = std::vector(); - std::vector& ascbs = - ascb_json["ascbs"].get_ref&>(); - ascbs.reserve(p_asvt->asvtmaxu); - - uint32_t* __ptr32 p_ascb_addr = - reinterpret_cast(&p_asvt->asvtenty); - for (int i = 0; i < p_asvt->asvtmaxu; i++) { - if (0x80000000 & *p_ascb_addr) { - Logger::getInstance().debug(formatter_.getHex(p_ascb_addr) + - " is not a valid ASCB address"); - p_ascb_addr++; - continue; - } - nlohmann::json next_ascb = - ASCB::get(reinterpret_cast(*p_ascb_addr)); - if (!next_ascb.is_null()) { - ascbs.push_back(next_ascb); - } - p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes. - } - return ascbs; - } else { - p_ascb = static_cast(p_control_block); - } - - ascb_json["ascbassb"] = formatter_.getHex(&(p_ascb->ascbassb)); - ascb_json["ascboucb"] = formatter_.getHex(&(p_ascb->ascboucb)); - - for (const auto& [include, cbxp_options] : options_map_) { - if (include == "assb") { - ascb_json["ascbassb"] = CBXP::ASSB(cbxp_options).get(p_ascb->ascbassb); - if (ascb_json["ascbassb"].is_null()) { - return {}; - } - } else if (include == "oucb") { - ascb_json["ascboucb"] = CBXP::OUCB(cbxp_options).get(p_ascb->ascboucb); - if (ascb_json["ascboucb"].is_null()) { - return {}; - } - } - } - - Logger::getInstance().debug("ASCB hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_ascb), - sizeof(struct ascb)); - - ascb_json["ascbascb"] = formatter_.getString(p_ascb->ascbascb, 4); - ascb_json["ascbasid"] = p_ascb->ascbasn; - ascb_json["ascbasxb"] = formatter_.getHex(&(p_ascb->ascbasxb)); - ascb_json["ascbdcti"] = p_ascb->ascbdcti; - ascb_json["ascbejst"] = formatter_.getBitmap( - reinterpret_cast(&p_ascb->ascbejst)); - ascb_json["ascbflg3"] = formatter_.getBitmap(p_ascb->ascbflg3); - ascb_json["ascbfw3"] = formatter_.getBitmap( - reinterpret_cast(&p_ascb->ascbfw3)); - ascb_json["ascbjbni"] = formatter_.getHex(&(p_ascb->ascbjbni)); - ascb_json["ascbjbns"] = formatter_.getHex(&(p_ascb->ascbjbns)); - ascb_json["ascblsqe"] = p_ascb->ascblsqe; - ascb_json["ascblsqt"] = p_ascb->ascblsqt; - ascb_json["ascbnoft"] = formatter_.getBitmap(p_ascb->ascbnoft); - ascb_json["ascbouxb"] = formatter_.getHex(&(p_ascb->ascbouxb)); - ascb_json["ascbpo1m"] = formatter_.getBitmap(p_ascb->ascbpo1m); - ascb_json["ascbp1m0"] = formatter_.getBitmap(p_ascb->ascbp1m0); - ascb_json["ascbrsme"] = formatter_.getHex(&(p_ascb->ascbrsme)); - ascb_json["ascbsdbf"] = formatter_.getBitmap(p_ascb->ascbsdbf); - ascb_json["ascbsrbt"] = formatter_.getBitmap( - reinterpret_cast(&p_ascb->ascbsrbt)); - ascb_json["ascbtcbe"] = formatter_.getBitmap(p_ascb->ascbtcbe); - ascb_json["ascbtcbs"] = p_ascb->ascbtcbs; - ascb_json["ascbxtcb"] = formatter_.getHex(&(p_ascb->ascbxtcb)); - ascb_json["ascbzcx"] = formatter_.getBitmap(p_ascb->ascbzcx); - - if (ASCB::matchFilter(ascb_json)) { - return ascb_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/ascb.hpp b/cbxp/control_blocks/ascb.hpp deleted file mode 100644 index b858800..0000000 --- a/cbxp/control_blocks/ascb.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __ASCB_H_ -#define __ASCB_H_ - -#include - -#include "control_block.hpp" - -namespace CBXP { - -class ASCB : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit ASCB(const cbxp_options_t& cbxp_options) - : ControlBlock("ascb", {"assb", "oucb"}, cbxp_options, - sizeof(struct ascb)) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_blocks/assb.cpp b/cbxp/control_blocks/assb.cpp deleted file mode 100644 index c261b73..0000000 --- a/cbxp/control_blocks/assb.cpp +++ /dev/null @@ -1,221 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "ascb.hpp" -#include "asvt.hpp" -#include "ldax.hpp" -#include "logger.hpp" - -namespace CBXP { -nlohmann::json ASSB::get(const void* p_control_block, - const size_t buffer_length) { - ASSB::checkDataLength(buffer_length); - const assb* p_assb; - nlohmann::json assb_json = {}; - if (p_control_block == nullptr) { - // PSA starts at address 0 - const struct psa* __ptr32 p_psa = 0; - - const struct cvtmap* __ptr32 p_cvtmap = - // 'nullPointer' is a false positive because the PSA starts at address 0 - // cppcheck-suppress nullPointer - static_cast(p_psa->flccvt); - const asvt_t* __ptr32 p_asvt = - static_cast(p_cvtmap->cvtasvt); - - assb_json["assbs"] = std::vector(); - std::vector& assbs = - assb_json["assbs"].get_ref&>(); - assbs.reserve(p_asvt->asvtmaxu); - - const uint32_t* __ptr32 p_ascb_addr = - reinterpret_cast(&p_asvt->asvtenty); - for (int i = 0; i < p_asvt->asvtmaxu; i++) { - if (0x80000000 & *p_ascb_addr) { - Logger::getInstance().debug(formatter_.getHex(p_ascb_addr) + - " is not a valid ASCB address"); - p_ascb_addr++; - continue; - } - // cast ascb addr into ascb pointer a - // - const struct ascb* __ptr32 p_ascb = - reinterpret_cast(*p_ascb_addr); - nlohmann::json next_assb = - ASSB::get(reinterpret_cast(p_ascb->ascbassb)); - if (!next_assb.is_null()) { - assbs.push_back(next_assb); - } - p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes. - } - return assbs; - } else { - p_assb = static_cast(p_control_block); - } - - Logger::getInstance().debug("assb hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_assb), - sizeof(struct assb)); - - assb_json["assbldax"] = formatter_.getHex(&(p_assb->assbldax)); - - for (const auto& [include, cbxp_options] : options_map_) { - if (include == "ldax") { - assb_json["assbldax"] = - CBXP::LDAX(cbxp_options) - .get(*reinterpret_cast(p_assb->assbldax)); - if (assb_json["assbldax"].is_null()) { - return {}; - } - } - } - - assb_json["assb_cms_lockinst_addr"] = - formatter_.getHex(&(p_assb->assb_cms_lockinst_addr)); - assb_json["assb_enqdeq_cms_lockinst_addr"] = - formatter_.getHex(&(p_assb->assb_enqdeq_cms_lockinst_addr)); - assb_json["assb_latch_cms_lockinst_addr"] = - formatter_.getHex(&(p_assb->assb_latch_cms_lockinst_addr)); - assb_json["assb_local_lockinst_addr"] = - formatter_.getHex(&(p_assb->assb_local_lockinst_addr)); - assb_json["assb_smfcms_lockinst_addr"] = - formatter_.getHex(&(p_assb->assb_smfcms_lockinst_addr)); - assb_json["assbdlcb"] = formatter_.getHex(&(p_assb->assbdlcb)); - assb_json["assbmqma"] = formatter_.getHex(&(p_assb->assbmqma)); - assb_json["assboasb"] = formatter_.getHex(&(p_assb->assboasb)); - assb_json["assbtasb"] = formatter_.getHex(&(p_assb->assbtasb)); - assb_json["assbvab"] = formatter_.getHex(&(p_assb->assbvab)); - assb_json["assbisqn"] = p_assb->assbisqn; - assb_json["assbjbni"] = formatter_.getString(p_assb->assbjbni, 8); - assb_json["assbjbns"] = formatter_.getString(p_assb->assbjbns, 8); - assb_json["assb_asst_time_on_cp"] = - formatter_.uint(p_assb->assb_asst_time_on_cp); - assb_json["assb_asst_time_on_zcbp"] = - formatter_.uint(p_assb->assb_asst_time_on_zcbp); - assb_json["assb_enct"] = formatter_.uint(p_assb->assb_enct); - assb_json["assb_enct_prezos11"] = - formatter_.uint(p_assb->assb_enct_prezos11); - assb_json["assb_ifa_enct"] = formatter_.uint(p_assb->assb_ifa_enct); - assb_json["assb_ifa_enct_prezos11"] = - formatter_.uint(p_assb->assb_ifa_enct_prezos11); - assb_json["assb_ifa_on_cp_enct"] = - formatter_.uint(p_assb->assb_ifa_on_cp_enct); - assb_json["assb_ifa_phtm"] = formatter_.uint(p_assb->assb_ifa_phtm); - assb_json["assb_srb_time_on_cp"] = - formatter_.uint(p_assb->assb_srb_time_on_cp); - assb_json["assb_srb_time_on_zcbp"] = - formatter_.uint(p_assb->assb_srb_time_on_zcbp); - assb_json["assb_sup_on_cp_enct"] = - formatter_.uint(p_assb->assb_sup_on_cp_enct); - assb_json["assb_task_time_on_cp"] = - formatter_.uint(p_assb->assb_task_time_on_cp); - assb_json["assb_time_ifa_on_cp"] = - formatter_.uint(p_assb->assb_time_ifa_on_cp); - assb_json["assb_time_java_on_cp"] = - formatter_.uint(p_assb->assb_time_java_on_cp); - assb_json["assb_time_java_on_ziip"] = - formatter_.uint(p_assb->assb_time_java_on_ziip); - assb_json["assb_time_on_ifa"] = - formatter_.uint(p_assb->assb_time_on_ifa); - assb_json["assb_time_on_zaap"] = - formatter_.uint(p_assb->assb_time_on_zaap); - assb_json["assb_time_on_zcbp"] = - formatter_.uint(p_assb->assb_time_on_zcbp); - assb_json["assb_time_on_ziip"] = - formatter_.uint(p_assb->assb_time_on_ziip); - assb_json["assb_time_zcbp_on_cp"] = - formatter_.uint(p_assb->assb_time_zcbp_on_cp); - assb_json["assb_time_ziip_on_cp"] = - formatter_.uint(p_assb->assb_time_ziip_on_cp); - assb_json["assb_zaap_enct"] = - formatter_.uint(p_assb->assb_zaap_enct); - assb_json["assb_zaap_phtm"] = - formatter_.uint(p_assb->assb_zaap_phtm); - assb_json["assb_zcbp_base_phtm"] = - formatter_.uint(p_assb->assb_zcbp_base_phtm); - assb_json["assb_zcbp_enct"] = - formatter_.uint(p_assb->assb_zcbp_enct); - assb_json["assb_zcbp_on_cp_enct"] = - formatter_.uint(p_assb->assb_zcbp_on_cp_enct); - assb_json["assb_zcbp_phtm"] = - formatter_.uint(p_assb->assb_zcbp_phtm); - assb_json["assb_ziip_enct"] = - formatter_.uint(p_assb->assb_ziip_enct); - assb_json["assb_ziip_on_cp_enct"] = - formatter_.uint(p_assb->assb_ziip_on_cp_enct); - assb_json["assb_ziip_phtm"] = - formatter_.uint(p_assb->assb_ziip_phtm); - assb_json["assb_ziip_phtm_base"] = - formatter_.uint(p_assb->assb_ziip_phtm_base); - assb_json["assbasst"] = formatter_.uint(p_assb->assbasst); - assb_json["assbphtm"] = formatter_.uint(p_assb->assbphtm); - assb_json["assbphtm_base"] = formatter_.uint(p_assb->assbphtm_base); - assb_json["assbstkn"] = formatter_.uint(p_assb->assbstkn); - assb_json["assbhst"] = formatter_.uint(p_assb->assbhst); - assb_json["assbiipt"] = formatter_.uint(p_assb->assbiipt); - assb_json["assblasb"] = formatter_.uint(p_assb->assblasb); - assb_json["assb_time_on_cp"] = - formatter_.uint(p_assb->assb_time_on_cp); - assb_json["assb_base_phtm"] = - formatter_.uint(p_assb->assb_base_phtm); - assb_json["assb_ifa_base_phtm"] = - formatter_.uint(p_assb->assb_ifa_base_phtm); - assb_json["assb_base_enct"] = - formatter_.uint(p_assb->assb_base_enct); - assb_json["assb_zcbp_base_enct"] = - formatter_.uint(p_assb->assb_zcbp_base_enct); - assb_json["assb_ifa_base_enct"] = - formatter_.uint(p_assb->assb_ifa_base_enct); - assb_json["assb_time_on_sup"] = - formatter_.uint(p_assb->assb_time_on_sup); - assb_json["assb_time_sup_on_cp"] = - formatter_.uint(p_assb->assb_time_sup_on_cp); - assb_json["assb_sup_phtm"] = formatter_.uint(p_assb->assb_sup_phtm); - assb_json["assb_sup_enct"] = formatter_.uint(p_assb->assb_sup_enct); - assb_json["assb_zcbp_on_cp_base_enct"] = - formatter_.uint(p_assb->assb_zcbp_on_cp_base_enct); - assb_json["assb_ifa_on_cp_base_enct"] = - formatter_.uint(p_assb->assb_ifa_on_cp_base_enct); - assb_json["assb_time_at_pdp"] = - formatter_.uint(p_assb->assb_time_at_pdp); - assb_json["assb_srbt_base"] = - formatter_.uint(p_assb->assb_srbt_base); - assb_json["assb_switch_to_zaapziip_count"] = - formatter_.uint(p_assb->assb_switch_to_zaapziip_count); - assb_json["assbasab"] = formatter_.uint(p_assb->assbasab); - assb_json["assb_ziip_base_enct"] = - formatter_.uint(p_assb->assb_ziip_base_enct); - assb_json["assb_sup_base_enct"] = - formatter_.uint(p_assb->assb_sup_base_enct); - assb_json["assb_ziip_on_cp_base_enct"] = - formatter_.uint(p_assb->assb_ziip_on_cp_base_enct); - assb_json["assb_sup_on_cp_base_enct"] = - formatter_.uint(p_assb->assb_sup_on_cp_base_enct); - assb_json["assb_hdlockpromotion_time_at_pdp"] = - formatter_.uint(p_assb->assb_hdlockpromotion_time_at_pdp); - assb_json["assb_enct_hdlockpromote_time"] = - formatter_.uint(p_assb->assb_enct_hdlockpromote_time); - assb_json["assbsupc"] = formatter_.uint(p_assb->assbsupc); - assb_json["assb_vartime_at_pdp"] = - formatter_.uint(p_assb->assb_vartime_at_pdp); - assb_json["assb_varweighted_time_at_pdp"] = - formatter_.uint(p_assb->assb_varweighted_time_at_pdp); - assb_json["assb_scmbc"] = formatter_.uint(p_assb->assb_scmbc); - assb_json["assbinitiatorjobid"] = - formatter_.uint(p_assb->assbinitiatorjobid); - assb_json["assbend"] = formatter_.uint(p_assb->assbend); - - if (ASSB::matchFilter(assb_json)) { - return assb_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/assb.hpp b/cbxp/control_blocks/assb.hpp deleted file mode 100644 index 9f0c720..0000000 --- a/cbxp/control_blocks/assb.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __ASSB_H_ -#define __ASSB_H_ - -#include - -#include "control_block.hpp" - -namespace CBXP { - -class ASSB : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit ASSB(const cbxp_options_t& cbxp_options) - : ControlBlock("assb", {"ldax"}, cbxp_options, sizeof(struct assb)) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_blocks/asvt.cpp b/cbxp/control_blocks/asvt.cpp deleted file mode 100644 index 0316177..0000000 --- a/cbxp/control_blocks/asvt.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include "asvt.hpp" - -#include -#include - -#include -#include -#include -#include - -#include "ascb.hpp" -#include "logger.hpp" - -namespace CBXP { -nlohmann::json ASVT::get(const void* p_control_block, - const size_t buffer_length) { - ASVT::checkDataLength(buffer_length); - const asvt_t* p_asvt; - nlohmann::json asvt_json = {}; - - if (p_control_block == nullptr) { - const struct psa* __ptr32 p_psa = 0; - const struct cvtmap* __ptr32 p_cvtmap = - // 'nullPointer' is a false positive because the PSA starts at address 0 - // cppcheck-suppress nullPointer - static_cast(p_psa->flccvt); - p_asvt = static_cast(p_cvtmap->cvtasvt); - } else { - p_asvt = static_cast(p_control_block); - } - - Logger::getInstance().debug("ASCB pointers:"); - Logger::getInstance().hexDump( - reinterpret_cast(&p_asvt->asvtenty), p_asvt->asvtmaxu * 4); - - std::vector ascbs; - ascbs.reserve(p_asvt->asvtmaxu); - const uint32_t* p_ascb = const_cast( - reinterpret_cast(&p_asvt->asvtenty)); - - for (int i = 0; i < p_asvt->asvtmaxu; i++) { - ascbs.push_back(formatter_.getHex(p_ascb)); - p_ascb++; // This SHOULD increment the pointer by 4 bytes. - } - - asvt_json["asvtenty"] = ascbs; - - Logger::getInstance().debug("ASVT hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_asvt), - sizeof(asvt_t)); - for (const auto& [include, cbxp_options] : options_map_) { - if (include == "ascb") { - nlohmann::json ascbs_json; - CBXP::ASCB ascb(cbxp_options); - uint32_t const* __ptr32 p_ascb_addr = const_cast( - reinterpret_cast(&p_asvt->asvtenty)); - for (int i = 0; i < p_asvt->asvtmaxu; i++) { - if (0x80000000 & *p_ascb_addr) { - Logger::getInstance().debug(formatter_.getHex(p_ascb_addr) + - " is not a valid ASCB address"); - p_ascb_addr++; - continue; - } - nlohmann::json ascb_json = - ascb.get(reinterpret_cast(*p_ascb_addr)); - if (!ascb_json.is_null()) { - ascbs_json.push_back(ascb_json); - } - p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes. - } - asvt_json["asvtenty"] = ascbs_json; - if (asvt_json["asvtenty"].is_null()) { - return {}; - } - } - } - - // Get fields - asvt_json["asvthwmasid"] = p_asvt->asvthwmasid; - asvt_json["asvtcurhighasid"] = p_asvt->asvtcurhighasid; - asvt_json["asvtreua"] = formatter_.getHex(p_asvt->asvtreua); - asvt_json["asvtravl"] = formatter_.getHex(p_asvt->asvtravl); - asvt_json["asvtaav"] = p_asvt->asvtaav; - asvt_json["asvtast"] = p_asvt->asvtast; - asvt_json["asvtanr"] = p_asvt->asvtanr; - asvt_json["asvtstrt"] = p_asvt->asvtstrt; - asvt_json["asvtnonr"] = p_asvt->asvtnonr; - asvt_json["asvtmaxi"] = p_asvt->asvtmaxi; - asvt_json["asvtasvt"] = formatter_.getString(p_asvt->asvtasvt, 4); - asvt_json["asvtmaxu"] = p_asvt->asvtmaxu; - asvt_json["asvtmdsc"] = p_asvt->asvtmdsc; - asvt_json["asvtfrst"] = formatter_.getHex(p_asvt->asvtfrst); - - if (ASVT::matchFilter(asvt_json)) { - return asvt_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/asvt.hpp b/cbxp/control_blocks/asvt.hpp deleted file mode 100644 index 16c15c0..0000000 --- a/cbxp/control_blocks/asvt.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef __ASVT_H_ -#define __ASVT_H_ - -#include "control_block.hpp" - -#pragma pack(push, 1) // Don't byte align structure members. -typedef struct { - char esvtprfx[464]; - int32_t asvthwmasid; - int32_t asvtcurhighasid; - char* __ptr32 asvtreua; - char* __ptr32 asvtravl; - int32_t asvtaav; - int32_t asvtast; - int32_t asvtanr; - int32_t asvtstrt; - int32_t asvtnonr; - int32_t asvtmaxi; - uint64_t reserved1; - char asvtasvt[4]; - int32_t asvtmaxu; - int32_t asvtmdsc; - char* __ptr32 asvtfrst; - // skipped this single bit - char* __ptr32 asvtenty; - - // skipped ASVTAVAL ---> to bottom -} asvt_t; -#pragma pack(pop) // Restore default structure packing options. - -namespace CBXP { - -class ASVT : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit ASVT(const cbxp_options_t& cbxp_options) - : ControlBlock("asvt", {"ascb"}, cbxp_options, sizeof(asvt_t)) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_blocks/control_block.cpp b/cbxp/control_blocks/control_block.cpp index eaf2783..a2387fe 100644 --- a/cbxp/control_blocks/control_block.cpp +++ b/cbxp/control_blocks/control_block.cpp @@ -2,302 +2,140 @@ #include +#include #include -#include "control_block_error.hpp" -#include "logger.hpp" +#include "util/control_block_error.hpp" +#include "util/logger.hpp" +#include "zos_subpools.hpp" namespace CBXP { -void ControlBlock::createOptionsMap(const std::vector& includes, - const std::vector& filters) { - // createFilterLists depends on the construction of the "includes" portion - // of the options_map_ structure and must be called after createIncludeLists - ControlBlock::createIncludeLists(includes); - ControlBlock::createFilterLists(filters); - for (auto it = options_map_.begin(); it != options_map_.end(); ++it) { - options_map_[it->first].skip_buffer_length_check = - skip_buffer_length_check_; - } -} -void ControlBlock::createIncludeLists( - const std::vector& includes) { - Logger::getInstance().debug( - "Creating include lists for child control blocks to include with the '" + - control_block_name_ + "' control block..."); - for (std::string include : includes) { - if (include == "**") { - Logger::getInstance().debug("Processing '**' include..."); - ControlBlock::processDoubleAsteriskInclude(); - return; - } else if (include == "*") { - Logger::getInstance().debug("Processing '*' include..."); - ControlBlock::processAsteriskInclude(); - } else { - Logger::getInstance().debug("Processing '" + include + "' include..."); - ControlBlock::processExplicitInclude(include); - } +FieldType ControlBlock::stringToType(const std::string& type_str) { + if (type_str == "string") { + return STRING; } - Logger::getInstance().debug( - "Include lists for child control blocks to include with the '" + - control_block_name_ + "' control block have been created"); -} - -void ControlBlock::processDoubleAsteriskInclude() { - // Any existing entries in the hash map are redundant, so clear them - options_map_.clear(); - for (const std::string& includable : includables_) { - // Build a map of all includables_ but with "**" at the next level - Logger::getInstance().debug( - "Initializing and adding '**' to the include list for the '" + - includable + "' control block..."); - options_map_[includable].include_patterns = {"**"}; + if (type_str == "signed-integer") { + return SIGNED_INT; } -} - -void ControlBlock::processAsteriskInclude() { - if (options_map_.empty()) { - for (const std::string& includable : includables_) { - // Build a map of all includables_ - Logger::getInstance().debug("Initializing include list for the '" + - includable + "' control block..."); - options_map_[includable].include_patterns = {}; - } + if (type_str == "unsigned-integer") { + return UNSIGNED_INT; } - for (const std::string& includable : includables_) { - if (options_map_.find(includable) != options_map_.end()) { - Logger::getInstance().debug("Include list already exists for the '" + - includable + "' control block"); - continue; - } - // Add all includables_ not already present to the map - Logger::getInstance().debug("Initializing include list for the '" + - includable + "' control block..."); - options_map_[includable].include_patterns = {}; + if (type_str == "hex") { + return HEX; } -} - -void ControlBlock::processExplicitInclude(std::string& include) { - // Default case; have to validate against an includable - const std::string del = "."; - std::string include_includes = ""; - size_t del_pos = include.find(del); - if (del_pos != std::string::npos) { - // If there's a "." then separate include into the include and its - // includes - include_includes = include.substr(del_pos + 1); - include.resize(del_pos); + if (type_str == "address") { + return ADDRESS; } - if (std::find(includables_.begin(), includables_.end(), include) == - includables_.end()) { - Logger::getInstance().debug( - "'" + include + - "' is not a known child control block that can be included with the '" + - control_block_name_ + "' control block"); - throw IncludeError(); + if (type_str == "bitstring") { + return BITSTRING; } - if (options_map_.find(include) == options_map_.end()) { - // If we don't already have this include in our map, add it with its - // includes - if (include_includes == "") { - Logger::getInstance().debug("Initializing include list for the '" + - include + "' control block..."); - options_map_[include].include_patterns = {}; - } else { - Logger::getInstance().debug("Adding '" + include_includes + - "' to the include list for the '" + include + - "' control block..."); - options_map_[include].include_patterns = {include_includes}; - } - } else { - // If we DO already have this in our map, then we should add its - // includes if they are useful or new - if (std::find(options_map_[include].include_patterns.begin(), - options_map_[include].include_patterns.end(), - include_includes) != - options_map_[include].include_patterns.end()) { - return; - } - if (include_includes == "") { - return; - } - Logger::getInstance().debug("Adding '" + include_includes + - "' to the include list for the '" + include + - "' control block..."); - options_map_[include].include_patterns.push_back(include_includes); + if (type_str == "triplet") { + return HEX; } + return UNSIGNED_INT; } -void ControlBlock::createFilterLists(const std::vector& filters) { - Logger::getInstance().debug( - "Creating filter lists for the '" + control_block_name_ + - "' control block and included child control blocks..."); - for (const std::string& filter : filters) { - // Only case; specific non-generic filter - const std::string del = "."; - size_t del_pos = filter.find(del); - if (del_pos != std::string::npos) { - // If there's a "." then separate filter into the control_block - // and its filter - std::string control_block_filter = filter.substr(del_pos + 1); - std::string control_block = filter.substr(0, del_pos); - - // Check to make sure we are including the specified control block - auto it = options_map_.find(control_block); - if (it == options_map_.end()) { - Logger::getInstance().debug( - "A filter that requires the '" + control_block + - "' control block was provided, but the '" + control_block + - "' control block was not included"); - throw FilterError(); - } - Logger::getInstance().debug("Adding '" + control_block_filter + - "' to the filter list for the '" + - control_block + "' control block..."); - options_map_[control_block].filters.push_back(control_block_filter); - } else { - ControlBlock::addCurrentFilter(filter); - } - } - Logger::getInstance().debug( - "Filter lists for the '" + control_block_name_ + - "' control block and included child control blocks have been created"); -} - -void ControlBlock::addCurrentFilter(const std::string& filter) { - std::vector operations = {"<=", ">=", "<", ">", "="}; - for (std::string operation : operations) { - size_t operation_pos = filter.find(operation); - if (operation_pos != std::string::npos) { - // If there's a delimeter then separate include into the key and its value - std::string filter_value = - filter.substr(operation_pos + operation.length()); - std::string filter_key = filter.substr(0, operation_pos); - cbxp_filter_t filter_data = {operation, filter_value}; - Logger::getInstance().debug("Adding '" + filter_key + operation + - filter_value + - "' to the current filters list for the '" + - control_block_name_ + "' control block..."); - current_filters_[filter_key].push_back(filter_data); - return; - } - } - Logger::getInstance().debug( - "Filters must be key-value pairs (e.g., 'key=value')"); - throw FilterError(); -} - -bool ControlBlock::compare(const nlohmann::json& json_value, - const std::string& filter_value, - const std::string& operation) { - std::string value_str = ""; - bool value_is_string = false; - uint64_t value_uint; - - if (json_value.is_number()) { - value_uint = json_value.get(); - } else { - value_str = json_value.get(); - value_is_string = true; - if (value_str.substr(0, 2) == "0x") { - value_uint = std::stoull(value_str, nullptr, 0); - value_is_string = false; +ControlBlock::ControlBlock( + const nlohmann::json_schema::json_validator& cbxp_schema_validator, + const nlohmann::json& control_block_map) { + // Validate before reading any attribute, as the schema guarantees the + // fields read below exist and have the right type. + try { + cbxp_schema_validator.validate(control_block_map); + } catch (const std::invalid_argument& e) { + Logger::getInstance().debug("Control block failed validation: " + + std::string(e.what())); + throw CbxpSchemaValidationError(); + } + + storage_attributes_.key = + control_block_map["storageAttributes"]["key"].get(); + control_block_name_ = control_block_map["name"].get(); + + for (auto it = control_block_map["storageAttributes"]["subpools"].begin(); + it != control_block_map["storageAttributes"]["subpools"].end(); ++it) { + // Subpool entries may be integers or strings (e.g. "nucleus"); skip + // strings. + if (!(*it).is_number_integer()) { + storage_attributes_.is_common = true; + storage_attributes_.is_protected = false; + continue; } - } - if (value_is_string) { - // Filter is testing strings - if (operation == "=") { - Logger::getInstance().debug("\"" + value_str + "\" = \"" + filter_value + - "\" ?"); - return (fnmatch(filter_value.c_str(), value_str.c_str(), 0) == 0); + unsigned char subpool = (*it).get(); + const zos::SubpoolInfo* p_info = zos::getSubpoolInfo(subpool); + if (p_info == nullptr) { + // If subpool information isn't there, we try to get the control block + storage_attributes_.is_common = true; + storage_attributes_.is_protected = false; } else { - Logger::getInstance().debug( - "<, <=, >, and >= cannot be used with string filter values"); - throw FilterError(); - } - } // Filter is testing non-strings - else { - uint64_t filter_uint; - try { - filter_uint = std::stoull(filter_value, nullptr, 0); - } catch (...) { - Logger::getInstance().debug("'" + filter_value + - "' cannot be compared to a numeric value"); - throw FilterError(); - } - Logger::getInstance().debug(std::to_string(value_uint) + " " + operation + - " " + std::to_string(filter_uint) + " ?"); - if (operation == "=") { - return value_uint == filter_uint; - } else if (operation == ">") { - return value_uint > filter_uint; - } else if (operation == "<") { - return value_uint < filter_uint; - } else if (operation == ">=") { - return value_uint >= filter_uint; - } else if (operation == "<=") { - return value_uint <= filter_uint; + storage_attributes_.is_common = zos::isCommon(p_info->location); + storage_attributes_.is_protected = p_info->fetch_protected; } } - // We should never get here, so it would be good to say "no match" just in - // case - return false; -} -bool ControlBlock::matchFilter(nlohmann::json& control_block_json) { - Logger::getInstance().debug("Applying filters to the '" + - control_block_name_ + "' control block..."); - if (current_filters_.empty()) { - // If the filter map is empty then we want to return the control block - Logger::getInstance().debug("No filters were provided for the '" + - control_block_name_ + "' control block"); - return true; - } - for (const auto& [filter_key, filter_list] : current_filters_) { - if (!control_block_json.contains(filter_key)) { - Logger::getInstance().debug( - "The filter key '" + filter_key + - "' does not correspond to any control block field in the '" + - control_block_name_ + "' control block"); - throw FilterError(); - } - // cppcheck-suppress useStlAlgorithm - for (const cbxp_filter_t& filter_data : filter_list) { - // would require capturing structured bindings to use all_of or none_of - Logger::getInstance().debug("Applying filter '" + filter_key + - filter_data.operation + filter_data.value + - "'..."); - if (!ControlBlock::compare(control_block_json[filter_key], - filter_data.value, filter_data.operation)) { - Logger::getInstance().debug("The filter '" + filter_key + - filter_data.operation + filter_data.value + - "' did not match"); - return false; + for (auto it = control_block_map["pointedToBy"].begin(); + it != control_block_map["pointedToBy"].end(); ++it) { + std::string pointed_to_by = (*it).get(); + pointed_to_by_.push_back(pointed_to_by); + } + + for (auto section_it = control_block_map["sections"].begin(); + section_it != control_block_map["sections"].end(); ++section_it) { + for (auto it = (*section_it)["fields"].begin(); + it != (*section_it)["fields"].end(); ++it) { + std::string name = (*it)["name"].get(); + ptrdiff_t offset = (*it)["offset"].get(); + size_t length = (*it)["length"].get(); + bool end_of_control_block = (*it).contains("endOfControlBlock") && + (*it)["endOfControlBlock"].get(); + // endOfControlBlock fields mark the boundary address only — do not + // count their length toward the control block size. + if (end_of_control_block) { + if (offset > max_offset_) { + max_offset_ = offset; + } + } else if (offset + static_cast(length) > max_offset_) { + max_offset_ = offset + static_cast(length); + } + std::string points_to = ""; + if ((*it).contains("pointsTo")) { + // Also build inclusion MAP + points_to = (*it)["pointsTo"].get(); + includables_.push_back(points_to); + } + std::string type_str = (*it)["type"].get(); + FieldType type = ControlBlock::stringToType(type_str); + bool repeated = false; + std::string count = ""; + std::string ignore_mask = ""; + if ((*it).contains("repeated")) { + repeated = (*it)["repeated"].get(); + } + if (repeated and (*it).contains("count")) { + count = (*it)["count"].get(); + } + if (repeated and (*it).contains("ignoreMask")) { + ignore_mask = (*it)["ignoreMask"].get(); } + if ((*it).contains("eyecatcher") && (*it)["eyecatcher"].get() && + (*it).contains("init")) { + const auto& init_arr = (*it)["init"]; + auto str_item = std::find_if( + init_arr.begin(), init_arr.end(), [](const nlohmann::json& item) { + return item["type"].get() == "string"; + }); + if (str_item != init_arr.end()) { + eyecatcher_field_ = {offset, length, + (*str_item)["value"].get()}; + } + } + control_block_field_t field = {name, offset, length, + type, points_to, repeated, + count, ignore_mask, end_of_control_block}; + control_block_map_[name] = field; } } - // If we didn't have a reason to return false, we return true - Logger::getInstance().debug("All filters for the '" + control_block_name_ + - "' control block matched"); - return true; -} - -void ControlBlock::checkDataLength(const size_t buffer_length) const { - if (skip_buffer_length_check_) { - // Data length check is only done when formatting - // user provided control block data. - // This check is skipped when extracting and formatting - // control block data from live memory. - return; - } - Logger::getInstance().debug( - "Checking if specified buffer (" + std::to_string(buffer_length) + - " bytes) too small to contain the '" + control_block_name_ + - "' control block (requires " + std::to_string(control_block_length_) + - " bytes)..."); - if (buffer_length < control_block_length_) { - throw DataLengthError(); - } } } // namespace CBXP diff --git a/cbxp/control_blocks/control_block.hpp b/cbxp/control_blocks/control_block.hpp index e7c8989..8eb55b1 100644 --- a/cbxp/control_blocks/control_block.hpp +++ b/cbxp/control_blocks/control_block.hpp @@ -1,62 +1,76 @@ #ifndef __CONTROL_BLOCK_H_ #define __CONTROL_BLOCK_H_ +#include #include #include "control_block_field_formatter.hpp" namespace CBXP { +enum FieldType { STRING, SIGNED_INT, UNSIGNED_INT, HEX, ADDRESS, BITSTRING }; + +typedef struct { + std::string name; + ptrdiff_t offset; + size_t length; + FieldType type; + std::string points_to; + bool repeated; + std::string count; + std::string ignore_mask; + bool end_of_control_block; +} control_block_field_t; + typedef struct { - std::string operation; - std::string value; -} cbxp_filter_t; + ptrdiff_t offset; + size_t length; + std::string expected; // ASCII string; empty means no validation +} eyecatcher_field_t; typedef struct { - std::vector include_patterns; - std::vector filters; - bool skip_buffer_length_check; -} cbxp_options_t; + bool is_common; + bool is_protected; + unsigned char key; +} storage_attributes_t; class ControlBlock { private: - const std::string control_block_name_; - const std::vector includables_; - size_t control_block_length_ = 0; - void createIncludeLists(const std::vector& includes); - void processDoubleAsteriskInclude(); - void processAsteriskInclude(); - void processExplicitInclude(std::string& include); - void createFilterLists(const std::vector& filters); - void addCurrentFilter(const std::string& filter); - bool compare(const nlohmann::json& json_value, - const std::string& filter_value, const std::string& operation); - - protected: - ControlBlockFieldFormatter formatter_; - std::unordered_map options_map_; - std::unordered_map> current_filters_; - void createOptionsMap(const std::vector& includes, - const std::vector& filters); - bool matchFilter(nlohmann::json& control_block_json); - bool skip_buffer_length_check_ = false; + std::unordered_map control_block_map_ = + {}; + // Defaults; the constructor overrides them from the mapping and subpool. + storage_attributes_t storage_attributes_ = {true, false, 8}; + std::string control_block_name_; + std::vector includables_ = {}; + std::vector pointed_to_by_ = {}; + ptrdiff_t max_offset_ = 0; + void* p_fixed_address_ = nullptr; + eyecatcher_field_t eyecatcher_field_ = {0, 0, ""}; + static FieldType stringToType(const std::string& type_str); public: - void checkDataLength(const size_t buffer_length) const; - virtual nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) = 0; - explicit ControlBlock(const std::string& name, - const std::vector& includables, - const cbxp_options_t& cbxp_options, - size_t control_block_length) - : control_block_name_(name), - includables_(includables), - control_block_length_(control_block_length), - skip_buffer_length_check_(cbxp_options.skip_buffer_length_check) { - ControlBlock::createOptionsMap(cbxp_options.include_patterns, - cbxp_options.filters); + ControlBlockFieldFormatter formatter_; + const std::unordered_map& getMap() const { + return control_block_map_; + } + const storage_attributes_t& getStorageAttributes() const { + return storage_attributes_; + } + const std::string& getName() const { return control_block_name_; } + const std::vector& getIncludables() const { + return includables_; + } + const std::vector& getPointedToBy() const { + return pointed_to_by_; + } + ptrdiff_t getMaxOffset() const { return max_offset_; } + const void* getFixedAddress() const { return p_fixed_address_; } + const eyecatcher_field_t& getEyecatcherField() const { + return eyecatcher_field_; } - virtual ~ControlBlock() = default; + explicit ControlBlock( + const nlohmann::json_schema::json_validator& cbxp_schema_validator, + const nlohmann::json& control_block_map); }; } // namespace CBXP diff --git a/cbxp/control_blocks/control_block_field_formatter.hpp b/cbxp/control_blocks/control_block_field_formatter.hpp index f8eac6a..94b61b1 100644 --- a/cbxp/control_blocks/control_block_field_formatter.hpp +++ b/cbxp/control_blocks/control_block_field_formatter.hpp @@ -3,24 +3,41 @@ #include +#include #include +#include #include #include #include +#include + +#include "util/control_block_error.hpp" +#include "util/safe_read.hpp" namespace CBXP { class ControlBlockFieldFormatter { public: + // Every read of live storage goes through safeMemCopy(), so an unreadable + // address (e.g. fetch-protected) raises CbxpBlockUnreachableError instead of + // abending with S0C4. template static T uint(const void* p_field) { T uint_field; - std::memcpy(reinterpret_cast(&uint_field), p_field, sizeof(T)); + ControlBlockFieldFormatter::safeMemCopy(&uint_field, p_field, sizeof(T)); return uint_field; } + template + static T sint(const void* p_field) { + T sint_field; + ControlBlockFieldFormatter::safeMemCopy(&sint_field, p_field, sizeof(T)); + return sint_field; + } + static const std::string getString(const void* p_field, int length) { std::vector ascii_field_tmp(length, 0); - std::memcpy(ascii_field_tmp.data(), p_field, length); + ControlBlockFieldFormatter::safeMemCopy(ascii_field_tmp.data(), p_field, + length); __e2a_l(ascii_field_tmp.data(), length); std::string ascii_field(ascii_field_tmp.begin(), ascii_field_tmp.end()); size_t last_non_space = @@ -49,21 +66,12 @@ class ControlBlockFieldFormatter { oss << std::bitset{field}; return oss.str(); } - static const std::string getPswSmall(const unsigned char* p_field) { - std::ostringstream oss; - oss << getBitmap(p_field); - oss << " | "; - oss << getHex(p_field + 4); - return oss.str(); - } - // Do we plan on using this??? - // cppcheck-suppress unusedFunction - static const std::string getPswBig(const unsigned char* p_field) { - std::ostringstream oss; - oss << getBitmap(p_field); - oss << " | "; - oss << getHex(p_field + 8); - return oss.str(); + + private: + static void safeMemCopy(void* p_dest, const void* p_src, size_t length) { + if (!safeCopy(p_dest, p_src, length)) { + throw CbxpBlockUnreachableError(); + } } }; } // namespace CBXP diff --git a/cbxp/control_blocks/cvt.cpp b/cbxp/control_blocks/cvt.cpp deleted file mode 100644 index 92daa9e..0000000 --- a/cbxp/control_blocks/cvt.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "cvt.hpp" - -#include - -#include -#include -#include - -#include "asvt.hpp" -#include "ecvt.hpp" -#include "logger.hpp" - -namespace CBXP { -nlohmann::json CVT::get(const void* p_control_block, - const size_t buffer_length) { - CVT::checkDataLength(buffer_length); - const struct cvtmap* p_cvtmap; - const struct cvtfix* p_cvtfix; - const struct cvtxtnt2* p_cvtxtnt2; - const struct cvtvstgx* p_cvtvstgx; - nlohmann::json cvt_json = {}; - - if (p_control_block == nullptr) { - // PSA starts at address 0 - const struct psa* __ptr32 p_psa = 0; - // 'nullPointer' is a false positive because the PSA starts at address 0 - // cppcheck-suppress-begin nullPointer - p_cvtmap = static_cast(p_psa->flccvt); - } else { - p_cvtmap = static_cast(p_control_block); - } - p_cvtfix = const_cast( - reinterpret_cast(p_cvtmap)); - p_cvtxtnt2 = const_cast( - reinterpret_cast(p_cvtmap)); - p_cvtvstgx = const_cast( - reinterpret_cast(p_cvtmap)); - // cppcheck-suppress-end nullPointer - - Logger::getInstance().debug("CVT hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_cvtmap), - sizeof(struct cvtmap)); - - cvt_json["cvtasvt"] = formatter_.getHex(&(p_cvtmap->cvtasvt)); - cvt_json["cvtecvt"] = formatter_.getHex(&(p_cvtmap->cvtecvt)); - - for (const auto& [include, cbxp_options] : options_map_) { - if (include == "asvt") { - cvt_json["cvtasvt"] = CBXP::ASVT(cbxp_options).get(p_cvtmap->cvtasvt); - if (cvt_json["cvtasvt"].is_null()) { - return {}; - } - } else if (include == "ecvt") { - cvt_json["cvtecvt"] = CBXP::ECVT(cbxp_options).get(p_cvtmap->cvtecvt); - if (cvt_json["cvtecvt"].is_null()) { - return {}; - } - } - } - - // Get fields - - cvt_json["cvtabend"] = formatter_.getHex(&(p_cvtmap->cvtabend)); - cvt_json["cvtamff"] = formatter_.getHex(&(p_cvtmap->cvtamff)); - cvt_json["cvtasmvt"] = formatter_.getHex(&(p_cvtmap->cvtasmvt)); - cvt_json["cvtbret"] = formatter_.getHex(p_cvtmap->cvtbret); - cvt_json["cvtbsm0f"] = formatter_.getHex(p_cvtmap->cvtbsm0f); - cvt_json["cvtcsd"] = formatter_.getHex(&(p_cvtmap->cvtcsd)); - cvt_json["cvtctlfg"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtctlfg)); - cvt_json["cvtdcb"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtdcb)); - // Read bitfields directly to avoid read-modify-write corruption - cvt_json["cvtdcpa"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 3); - cvt_json["cvtdfa"] = formatter_.getHex(p_cvtmap->cvtdfa); - cvt_json["cvtedat2"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 3); - cvt_json["cvteplps"] = formatter_.getHex(&(p_cvtvstgx->cvteplps)); - cvt_json["cvtexit"] = formatter_.getHex(p_cvtmap->cvtexit); - cvt_json["cvtexp1"] = formatter_.getHex(&(p_cvtmap->cvtexp1)); - // Read bitfields directly to avoid read-modify-write corruption - cvt_json["cvtflag2"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 1); - cvt_json["cvtflag3"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 2); - cvt_json["cvtflag4"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 3); - cvt_json["cvtflag5"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtaqavt) + 4); - cvt_json["cvtflag6"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtaqavt) + 5); - cvt_json["cvtflag7"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtaqavt) + 6); - cvt_json["cvtflag9"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflag9)); - // Read cvtflgbt byte directly to avoid bitfield read-modify-write corruption - // cvtflgbt is at offset 5 in cvtxtnt2 (4 bytes cvt2r000 + 1 byte cvtnucls) - const unsigned char* p_cvtflgbt = - reinterpret_cast(p_cvtxtnt2) + 5; - cvt_json["cvtflgbt"] = formatter_.getBitmap(p_cvtflgbt); - cvt_json["cvtgda"] = formatter_.getHex(&(p_cvtmap->cvtgda)); - // Read bitfield directly to avoid read-modify-write corruption - cvt_json["cvtgrsst"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtppgmx) + 4); - cvt_json["cvtgvt"] = formatter_.getHex(&(p_cvtmap->cvtgvt)); - cvt_json["cvthid"] = formatter_.getHex(&(p_cvtmap->cvthid)); - cvt_json["cvtixavl"] = formatter_.getHex(&(p_cvtmap->cvtixavl)); - cvt_json["cvtjesct"] = formatter_.getHex(&(p_cvtmap->cvtjesct)); - cvt_json["cvtlccat"] = formatter_.getHex(&(p_cvtmap->cvtlccat)); - cvt_json["cvtldto"] = formatter_.getHex(p_cvtxtnt2->cvtldto); - cvt_json["cvtlink"] = formatter_.getHex(&(p_cvtmap->cvtlink)); - cvt_json["cvtlso"] = formatter_.getHex(p_cvtxtnt2->cvtlso); - cvt_json["cvtmaxmp"] = p_cvtmap->cvtmaxmp; - cvt_json["cvtmdl"] = formatter_.getHex(p_cvtfix->cvtmdl); - cvt_json["cvtmser"] = formatter_.getHex(&(p_cvtmap->cvtmser)); - cvt_json["cvtopctp"] = formatter_.getHex(&(p_cvtmap->cvtopctp)); - cvt_json["cvtoslvl"] = formatter_.getHex(p_cvtmap->cvtoslvl) + - formatter_.getHex(p_cvtmap->cvtoslvl + 8); - // Read bitfield directly to avoid read-modify-write corruption - cvt_json["cvtover"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags)); - cvt_json["cvtpccat"] = formatter_.getHex(&(p_cvtmap->cvtpccat)); - cvt_json["cvtpcnvt"] = formatter_.getHex(&(p_cvtmap->cvtpcnvt)); - cvt_json["cvtprltv"] = formatter_.getHex(&(p_cvtmap->cvtprltv)); - cvt_json["cvtprod"] = formatter_.getHex(p_cvtfix->cvtprod) + - formatter_.getHex(p_cvtfix->cvtprod + 8); - cvt_json["cvtpsxm"] = formatter_.getHex(&(p_cvtmap->cvtpsxm)); - cvt_json["cvtpvtp"] = formatter_.getHex(&(p_cvtmap->cvtpvtp)); - cvt_json["cvtqtd00"] = formatter_.getHex(&(p_cvtmap->cvtqtd00)); - cvt_json["cvtqte00"] = formatter_.getHex(&(p_cvtmap->cvtqte00)); - cvt_json["cvtrac"] = formatter_.getHex(&(p_cvtmap->cvtrac)); - cvt_json["cvtrcep"] = formatter_.getHex(&(p_cvtmap->cvtrcep)); - cvt_json["cvtrczrt"] = formatter_.getHex(&(p_cvtmap->cvtrczrt)); - cvt_json["cvtrelno"] = formatter_.getHex(p_cvtfix->cvtrelno); - // Read bitfield directly to avoid read-modify-write corruption - cvt_json["cvtri"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 3); - cvt_json["cvtrtmct"] = formatter_.getHex(&(p_cvtmap->cvtrtmct)); - cvt_json["cvtsaf"] = formatter_.getHex(&(p_cvtmap->cvtsaf)); - cvt_json["cvtscpin"] = formatter_.getHex(&(p_cvtmap->cvtscpin)); - // cvt_json["cvtsdbf"] = formatter_.getBitmap(p_cvtmap->cvtsdbf); - // Read bitfields directly to avoid read-modify-write corruption - cvt_json["cvtsdump"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtdmsr)); - cvt_json["cvtsmca"] = formatter_.getHex(&(p_cvtmap->cvtsmca)); - cvt_json["cvtsname"] = formatter_.getString(p_cvtmap->cvtsname, 8); - cvt_json["cvtsubsp"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags)); - cvt_json["cvtsvt"] = formatter_.getHex(&(p_cvtmap->cvtsvt)); - cvt_json["cvtsysad"] = formatter_.getHex(&(p_cvtmap->cvtsysad)); - cvt_json["cvttpc"] = formatter_.getHex(&(p_cvtmap->cvttpc)); - cvt_json["cvttvt"] = formatter_.getHex(&(p_cvtmap->cvttvt)); - // Read bitfields directly to avoid read-modify-write corruption - cvt_json["cvttx"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 3); - cvt_json["cvttxc"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtflags) + 3); - cvt_json["cvttxte"] = formatter_.getBitmap( - reinterpret_cast(&p_cvtmap->cvtctlfg)); - ; - cvt_json["cvttz"] = p_cvtmap->cvttz; - cvt_json["cvtucbsc"] = formatter_.getHex(&(p_cvtmap->cvtucbsc)); - // Read cvtundvm bit directly to avoid bitfield read-modify-write corruption - // cvtundvm is bit 3 of the byte at offset 5 in cvtxtnt2 (same byte as - // cvtflgbt) - const unsigned char* p_cvtundvm = - reinterpret_cast(p_cvtxtnt2) + 5; - cvt_json["cvtundvm"] = formatter_.getBitmap(p_cvtundvm); - cvt_json["cvtuser"] = formatter_.getHex(&(p_cvtmap->cvtuser)); - cvt_json["cvtverid"] = formatter_.getHex(p_cvtfix->cvtverid); - cvt_json["cvtvfget"] = formatter_.getHex(&(p_cvtmap->cvtvfget)); - cvt_json["cvtvfind"] = formatter_.getHex(&(p_cvtmap->cvtvfind)); - cvt_json["cvtvpsib"] = formatter_.getHex(&(p_cvtmap->cvtvpsib)); - cvt_json["cvtvwait"] = formatter_.getHex(&(p_cvtmap->cvtvwait)); - cvt_json["cvt0ef00"] = formatter_.getHex(&(p_cvtmap->cvt0ef00)); - cvt_json["cvt0pt0e"] = formatter_.getHex(&(p_cvtmap->cvt0pt0e)); - cvt_json["cvt0pt02"] = formatter_.getHex(&(p_cvtmap->cvt0pt02)); - cvt_json["cvt0pt03"] = formatter_.getHex(&(p_cvtmap->cvt0pt03)); - cvt_json["cvt0scr1"] = formatter_.getHex(&(p_cvtmap->cvt0scr1)); - - if (CVT::matchFilter(cvt_json)) { - return cvt_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/cvt.hpp b/cbxp/control_blocks/cvt.hpp deleted file mode 100644 index 51ff892..0000000 --- a/cbxp/control_blocks/cvt.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __CVT_H_ -#define __CVT_H_ - -#include - -#include "control_block.hpp" - -namespace CBXP { - -class CVT : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit CVT(const cbxp_options_t& cbxp_options) - : ControlBlock("cvt", {"ecvt", "asvt"}, cbxp_options, - sizeof(struct cvtmap)) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_blocks/ecvt.cpp b/cbxp/control_blocks/ecvt.cpp deleted file mode 100644 index 9735ba3..0000000 --- a/cbxp/control_blocks/ecvt.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include "ecvt.hpp" - -#include -#include -#include - -#include -#include -#include - -#include "logger.hpp" - -namespace CBXP { -nlohmann::json ECVT::get(const void* p_control_block, - const size_t buffer_length) { - ECVT::checkDataLength(buffer_length); - const struct ecvt* p_ecvt; - nlohmann::json ecvt_json = {}; - - if (p_control_block == nullptr) { - // PSA starts at address 0 - const struct psa* __ptr32 p_psa = 0; - // Get the address of the CVT from the PSA - const struct cvtmap* __ptr32 p_cvt = - // 'nullPointer' is a false positive because the PSA starts at address 0 - // cppcheck-suppress nullPointer - static_cast(p_psa->flccvt); - // Get the address of the EVCT from the CVT - p_ecvt = static_cast(p_cvt->cvtecvt); - } else { - p_ecvt = static_cast(p_control_block); - } - - Logger::getInstance().debug("ECVT hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_ecvt), - sizeof(struct ecvt)); - - // Get Fields - - ecvt_json["ecvt_boostinfo"] = - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo + 8)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo + 16)); - - ecvt_json["ecvt_boostinfo_v1"] = - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v1)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v1 + 8)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v1 + 16)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v1 + 24)); - - ecvt_json["ecvt_boostinfo_v2"] = - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v2)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v2 + 8)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v2 + 16)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_boostinfo_v2 + 24)); - - ecvt_json["ecvt_cms_lockinst_addr"] = - formatter_.getHex(p_ecvt->ecvt_cms_lockinst_addr); - ecvt_json["ecvt_customer_area_addr"] = - formatter_.getHex(p_ecvt->ecvt_customer_area_addr); - ecvt_json["ecvt_enqdeq_cms_lockinst_addr"] = - formatter_.getHex(p_ecvt->ecvt_enqdeq_cms_lockinst_addr); - ecvt_json["ecvt_getsrbidtoken"] = - formatter_.getHex(p_ecvt->ecvt_getsrbidtoken); - ecvt_json["ecvt_installed_core_at_ipl"] = p_ecvt->ecvt_installed_core_at_ipl; - ecvt_json["ecvt_installed_core_hwm"] = p_ecvt->ecvt_installed_core_hwm; - ecvt_json["ecvt_installed_cpu_at_ipl"] = p_ecvt->ecvt_installed_cpu_at_ipl; - ecvt_json["ecvt_installed_cpu_hwm"] = p_ecvt->ecvt_installed_cpu_hwm; - ecvt_json["ecvt_latch_cms_lockinst_addr"] = - formatter_.getHex(p_ecvt->ecvt_latch_cms_lockinst_addr); - // ecvt_json["ECVT_MAX_CPUMASKSIZEINBITS"] = ECVT_MAX_CPUMASKSIZEINBITS; - // ecvt_json["ECVT_MAX_CPUMASKSIZEINBYTES"] = ECVT_MAX_CPUMASKSIZEINBYTES; - // ecvt_json["ECVT_MAX_HIGHESTCPUID"] = ECVT_MAX_HIGHESTCPUID; - ecvt_json["ecvt_osprotect"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_osprotect)); - ecvt_json["ecvt_osprotect_whensystem"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvt_osprotect_whensystem)); - ecvt_json["ecvt_smf_cms_lockinst_addr"] = - formatter_.getHex(p_ecvt->ecvt_smf_cms_lockinst_addr); - ecvt_json["ecvt_ziipboostcoresaddr"] = - formatter_.getHex(p_ecvt->ecvtr430 + 4); - // ecvt_json["ECVT_ZOSR11_CPUMASKSIZEINBITS"] = ECVT_ZOSR11_CPUMASKSIZEINBITS; - // ecvt_json["ECVT_ZOSR11_CPUMASKSIZEINBYTES"] = - // ECVT_ZOSR11_CPUMASKSIZEINBYTES; ecvt_json["ECVT_ZOSR11_HIGHESTCPUID"] = - // ECVT_ZOSR11_HIGHESTCPUID; ecvt_json["ECVT_ZOSV2R1_CPUMASKSIZEINBITS"] = - // ECVT_ZOSV2R1_CPUMASKSIZEINBITS; - // ecvt_json["ECVT_ZOSV2R1_CPUMASKSIZEINBYTES"] = - // ECVT_ZOSV2R1_CPUMASKSIZEINBYTES; ecvt_json["ECVT_ZOSV2R1_HIGHESTCPUID"] = - // ECVT_ZOSV2R1_HIGHESTCPUID; - ecvt_json["ecvtalck"] = formatter_.getHex(p_ecvt->ecvtalck); - ecvt_json["ecvtappc"] = formatter_.getHex(p_ecvt->ecvtappc); - ecvt_json["ecvtappflags"] = - formatter_.getBitmap(p_ecvt->ecvtappflags); - ecvt_json["ecvtcachelinesize"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtcachelinesize)); - ecvt_json["ecvtcachelinestartbdy"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtcachelinestartbdy)); - ecvt_json["ecvtclnu"] = formatter_.getBitmap(p_ecvt->ecvtclnu); - ecvt_json["ecvtclon"] = formatter_.getString(p_ecvt->ecvtclon, 2); - ecvt_json["ecvtcrdt"] = formatter_.getHex(p_ecvt->ecvtcrdt); - ecvt_json["ecvtcsm"] = formatter_.getHex(p_ecvt->ecvtcsm); - ecvt_json["ecvtcsvn"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtcsvn)); - ecvt_json["ecvtctbl"] = formatter_.getHex(p_ecvt->ecvtctbl); - ecvt_json["ecvtctb2"] = formatter_.getHex(p_ecvt->ecvtctb2); - ecvt_json["ecvtdgnb"] = formatter_.getHex(p_ecvt->ecvtdgnb); - ecvt_json["ecvtdlpf"] = formatter_.getHex(p_ecvt->ecvtdlpf); - ecvt_json["ecvtdlpl"] = formatter_.getHex(p_ecvt->ecvtdlpl); - // ecvt_json["ecvtdpqh"] = formatter_.getHex(p_ecvt->ecvtdpqh); ---> - // Protection Exception - ecvt_json["ecvtducu"] = formatter_.getHex(p_ecvt->ecvtducu); - ecvt_json["ecvtfacl"] = formatter_.getHex(p_ecvt->ecvtfacl); - ecvt_json["ecvtflg1"] = formatter_.getBitmap(p_ecvt->ecvtflg1); - ecvt_json["ecvtgmod"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtgmod)); - ecvt_json["ecvthdnm"] = formatter_.getString(p_ecvt->ecvthdnm, 8); - ecvt_json["ecvtipa"] = formatter_.getHex(p_ecvt->ecvtipa); - ecvt_json["ecvtjaof"] = formatter_.getHex(p_ecvt->ecvtjaof); - ecvt_json["ecvtldto"] = - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtldto)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtldto + 8)); - ecvt_json["ecvtlogicaltophysicalmask"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtlogicaltophysicalmask)); - ecvt_json["ecvtlpdelen"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtlpdelen)); - ecvt_json["ecvtlpnm"] = formatter_.getString(p_ecvt->ecvtlpnm, 8); - ecvt_json["ecvtlsab"] = formatter_.getHex(p_ecvt->ecvtlsab); - ecvt_json["ecvtlsen"] = formatter_.getHex(p_ecvt->ecvtlsen); - ecvt_json["ecvtlso"] = - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtlso)) + - formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtlso + 8)); - ecvt_json["ecvtmaxcoreid"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtmaxcoreid)); - ecvt_json["ecvtmaxmpnumbytesinmask"] = p_ecvt->ecvtmaxmpnumbytesinmask; - ecvt_json["ecvtnumcpuidsincore"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtnumcpuidsincore)); - ecvt_json["ecvtocvt"] = formatter_.getHex(p_ecvt->ecvtocvt); - ecvt_json["ecvtoext"] = formatter_.getHex(p_ecvt->ecvtoext); - ecvt_json["ecvtomvs"] = formatter_.getBitmap(p_ecvt->ecvtomvs); - ecvt_json["ecvtpdvl"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtpdvl)); - ecvt_json["ecvtphysicaltologicalmask"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtphysicaltologicalmask)); - ecvt_json["ecvtpidn"] = formatter_.getString(p_ecvt->ecvtpidn, 8); - ecvt_json["ecvtpmod"] = formatter_.getString(p_ecvt->ecvtpmod, 2); - ecvt_json["ecvtpnam"] = formatter_.getString(p_ecvt->ecvtpnam, 16); - ecvt_json["ecvtpown"] = formatter_.getString(p_ecvt->ecvtpown, 16); - ecvt_json["ecvtprel"] = formatter_.getString(p_ecvt->ecvtprel, 2); - ecvt_json["ecvtpseq"] = p_ecvt->ecvtpseq; - ecvt_json["ecvtpver"] = formatter_.getString(p_ecvt->ecvtpver, 2); - ecvt_json["ecvtslid"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtslid)); - ecvt_json["ecvtsplx"] = formatter_.getString(p_ecvt->ecvtsplx, 8); - ecvt_json["ecvtsrbj"] = formatter_.getHex(p_ecvt->ecvtsrbj); - ecvt_json["ecvtsrbl"] = formatter_.getHex(p_ecvt->ecvtsrbl); - ecvt_json["ecvtsxmp"] = formatter_.getHex(p_ecvt->ecvtsxmp); - ecvt_json["ecvtsymt"] = formatter_.getHex(p_ecvt->ecvtsymt); - ecvt_json["ecvttcp"] = formatter_.getHex(p_ecvt->ecvttcp); - ecvt_json["ecvtvmnm"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtvmnm)); - ecvt_json["ecvtvser"] = formatter_.getBitmap( - reinterpret_cast(&p_ecvt->ecvtvser)); - ecvt_json["ecvtxtsw"] = formatter_.getHex(p_ecvt->ecvtxtsw); - - if (ECVT::matchFilter(ecvt_json)) { - return ecvt_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/ecvt.hpp b/cbxp/control_blocks/ecvt.hpp deleted file mode 100644 index a8183a7..0000000 --- a/cbxp/control_blocks/ecvt.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __ECVT_H_ -#define __ECVT_H_ - -#include - -#include "control_block.hpp" - -namespace CBXP { - -class ECVT : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit ECVT(const cbxp_options_t& cbxp_options) - : ControlBlock("ecvt", {}, cbxp_options, sizeof(struct ecvt)) {} -}; -} // namespace CBXP -#endif diff --git a/cbxp/control_blocks/ldax.cpp b/cbxp/control_blocks/ldax.cpp deleted file mode 100644 index 45f30a9..0000000 --- a/cbxp/control_blocks/ldax.cpp +++ /dev/null @@ -1,130 +0,0 @@ -#include "ldax.hpp" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "asvt.hpp" -#include "logger.hpp" - -namespace CBXP { - -nlohmann::json LDAX::get(const void* p_control_block, - const size_t buffer_length) { - LDAX::checkDataLength(buffer_length); - const struct ldax* p_ldax; - nlohmann::json ldax_json = {}; - if (p_control_block == nullptr) { - // PSA starts at address 0 - const struct psa* __ptr32 p_psa = 0; - - const struct cvtmap* __ptr32 p_cvtmap = - // cppcheck-suppress nullPointer - static_cast(p_psa->flccvt); - - const asvt_t* __ptr32 p_asvt = - static_cast(p_cvtmap->cvtasvt); - - ldax_json["ldaxs"] = std::vector(); - std::vector& ldaxs = - ldax_json["ldaxs"].get_ref&>(); - - ldaxs.reserve(p_asvt->asvtmaxu); - - const uint32_t* __ptr32 p_ascb_addr = - reinterpret_cast(&(p_asvt->asvtenty)); - - for (int i = 0; i < p_asvt->asvtmaxu; i++) { - if (0x80000000 & *p_ascb_addr) { - Logger::getInstance().debug(formatter_.getHex(p_ascb_addr) + - " is not a valid ASCB address"); - p_ascb_addr++; - continue; - } - - // Cast ASCB address into ASCB pointer - const struct ascb* __ptr32 p_ascb = - reinterpret_cast(*p_ascb_addr); - - // Get ASSB from ASCB - const struct assb* __ptr32 p_assb = - reinterpret_cast(p_ascb->ascbassb); - - nlohmann::json next_ldax = - LDAX::get(*reinterpret_cast(p_assb->assbldax)); - if (!next_ldax.is_null()) { - ldaxs.push_back(next_ldax); - } - - p_ascb_addr++; - } - - return ldaxs; - } else { - p_ldax = static_cast(p_control_block); - } - - Logger::getInstance().debug("ldax hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_ldax), - sizeof(struct ldax)); - - ldax_json["ldax_id"] = formatter_.getString(p_ldax->ldax_id, 4); - ldax_json["ldax_version"] = - formatter_.getBitmap(p_ldax->ldax_version); - ldax_json["ldax_ldaascb"] = - formatter_.getHex(&(p_ldax->ldax_ldaascb)); - ldax_json["ldax_ldastrta"] = - formatter_.getHex(&(p_ldax->ldax_ldastrta)); - ldax_json["ldax_ldasiza"] = p_ldax->ldax_ldasiza; - ldax_json["ldax_ldaestra"] = - formatter_.getHex(&(p_ldax->ldax_ldaestra)); - ldax_json["ldax_ldaesiza"] = p_ldax->ldax_ldaesiza; - ldax_json["ldax_ldacrgtp"] = - formatter_.getHex(&(p_ldax->ldax_ldacrgtp)); - ldax_json["ldax_ldaergtp"] = - formatter_.getHex(&(p_ldax->ldax_ldaergtp)); - ldax_json["ldax_ldalimit"] = - formatter_.getHex(&(p_ldax->ldax_ldalimit)); - ldax_json["ldax_ldavvrg"] = - formatter_.getHex(&(p_ldax->ldax_ldavvrg)); - ldax_json["ldax_ldaelim"] = - formatter_.getHex(&(p_ldax->ldax_ldaelim)); - ldax_json["ldax_ldaevvrg"] = - formatter_.getHex(&(p_ldax->ldax_ldaevvrg)); - ldax_json["ldax_ldaloal"] = - formatter_.getBitmap(p_ldax->ldax_ldaloal); - ldax_json["ldax_ldahial"] = - formatter_.getBitmap(p_ldax->ldax_ldahial); - ldax_json["ldax_ldaeloal"] = - formatter_.getBitmap(p_ldax->ldax_ldaeloal); - ldax_json["ldax_ldaehial"] = - formatter_.getBitmap(p_ldax->ldax_ldaehial); - ldax_json["ldax_tcthwm"] = p_ldax->ldax_tcthwm; - ldax_json["ldax_tctlwm"] = p_ldax->ldax_tctlwm; - ldax_json["ldax_tctehwm"] = p_ldax->ldax_tctehwm; - ldax_json["ldax_tctelwm"] = p_ldax->ldax_tctelwm; - ldax_json["ldax_curhighbot"] = - formatter_.getHex(&(p_ldax->ldax_curhighbot)); - ldax_json["ldax_curehighbot"] = - formatter_.getHex(&(p_ldax->ldax_curehighbot)); - ldax_json["ldax_ldasmad"] = - formatter_.getHex(&(p_ldax->ldax_ldasmad)); - ldax_json["ldax_ldasmsz"] = - formatter_.getHex(&(p_ldax->ldax_ldasmsz)); - ldax_json["ldax_obtainshomespace"] = p_ldax->ldax_obtainshomespace; - - if (LDAX::matchFilter(ldax_json)) { - return ldax_json; - } else { - return {}; - } -} - -} // namespace CBXP diff --git a/cbxp/control_blocks/ldax.hpp b/cbxp/control_blocks/ldax.hpp deleted file mode 100644 index 0878206..0000000 --- a/cbxp/control_blocks/ldax.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __LDAX_H_ -#define __LDAX_H_ - -#include - -#include "control_block.hpp" - -namespace CBXP { - -class LDAX : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit LDAX(const cbxp_options_t& cbxp_options) - : ControlBlock("ldax", {}, cbxp_options, sizeof(struct ldax)) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_blocks/oucb.cpp b/cbxp/control_blocks/oucb.cpp deleted file mode 100644 index 954a3e4..0000000 --- a/cbxp/control_blocks/oucb.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include "oucb.hpp" - -#include -#include -#include - -#include -#include -#include -#include - -#include "asvt.hpp" -#include "logger.hpp" - -namespace CBXP { -nlohmann::json OUCB::get(const void* p_control_block, - const size_t buffer_length) { - OUCB::checkDataLength(buffer_length); - const oucb_t* p_oucb; - nlohmann::json oucb_json = {}; - if (p_control_block == nullptr) { - // PSA starts at address 0 - const struct psa* __ptr32 p_psa = 0; - - const struct cvtmap* __ptr32 p_cvtmap = - // 'nullPointer' is a false positive because the PSA starts at address - // cppcheck-suppress nullPointer - static_cast(p_psa->flccvt); - const asvt_t* __ptr32 p_asvt = - static_cast(p_cvtmap->cvtasvt); - - oucb_json["oucbs"] = std::vector(); - std::vector& oucbs = - oucb_json["oucbs"].get_ref&>(); - oucbs.reserve(p_asvt->asvtmaxu); - - const uint32_t* __ptr32 p_ascb_addr = - reinterpret_cast(&p_asvt->asvtenty); - for (int i = 0; i < p_asvt->asvtmaxu; i++) { - if (0x80000000 & *p_ascb_addr) { - Logger::getInstance().debug(formatter_.getHex(p_ascb_addr) + - " is not a valid ASCB address"); - p_ascb_addr++; - continue; - } - // cast ascb addr into ascb pointer a - // - const struct ascb* __ptr32 p_ascb = - reinterpret_cast(*p_ascb_addr); - nlohmann::json next_oucb = - OUCB::get(reinterpret_cast(p_ascb->ascboucb)); - if (!next_oucb.is_null()) { - oucbs.push_back(next_oucb); - } - p_ascb_addr++; // This SHOULD increment the pointer by 4 bytes. - } - return oucbs; - } else { - p_oucb = static_cast(p_control_block); - } - - Logger::getInstance().debug("oucb hex dump:"); - Logger::getInstance().hexDump(reinterpret_cast(p_oucb), - sizeof(oucb_t)); - - oucb_json["oucbname"] = formatter_.getString(p_oucb->oucbname, 4); - oucb_json["oucbfwd"] = formatter_.getHex(&(p_oucb->oucbfwd)); - oucb_json["oucbbck"] = formatter_.getHex(&(p_oucb->oucbbck)); - oucb_json["oucbtma"] = p_oucb->oucbtma; - oucb_json["oucbqfl"] = formatter_.getBitmap(p_oucb->oucbqfl); - oucb_json["oucbsfl"] = formatter_.getBitmap(p_oucb->oucbsfl); - oucb_json["oucbyfl"] = formatter_.getBitmap(p_oucb->oucbyfl); - oucb_json["oucbafl"] = formatter_.getBitmap(p_oucb->oucbafl); - oucb_json["oucbtfl"] = formatter_.getBitmap(p_oucb->oucbtfl); - oucb_json["oucbefl"] = formatter_.getBitmap(p_oucb->oucbefl); - oucb_json["oucbasstatus"] = - formatter_.getBitmap(p_oucb->oucbasstatus); - oucb_json["oucbufl"] = formatter_.getBitmap(p_oucb->oucbufl); - oucb_json["oucblfl"] = formatter_.getBitmap(p_oucb->oucblfl); - oucb_json["oucbrfl"] = formatter_.getBitmap(p_oucb->oucbrfl); - oucb_json["oucbndp"] = formatter_.getBitmap(p_oucb->oucbndp); - oucb_json["oucbtndp"] = formatter_.getBitmap(p_oucb->oucbtndp); - oucb_json["oucbmfl"] = formatter_.getBitmap(p_oucb->oucbmfl); - oucb_json["oucbiac"] = p_oucb->oucbiac; - oucb_json["oucbrsv1"] = p_oucb->oucbrsv1; - oucb_json["oucbpgp"] = p_oucb->oucbpgp; - oucb_json["oucbwsci"] = p_oucb->oucbwsci; - oucb_json["oucbwrci"] = p_oucb->oucbwrci; - oucb_json["oucbmfl2"] = formatter_.getBitmap(p_oucb->oucbmfl2); - oucb_json["oucbmfl3"] = formatter_.getBitmap(p_oucb->oucbmfl3); - oucb_json["oucbdmo"] = p_oucb->oucbdmo; - oucb_json["oucbdmn"] = p_oucb->oucbdmn; - oucb_json["oucbsrc"] = p_oucb->oucbsrc; - oucb_json["oucbswc"] = p_oucb->oucbswc; - oucb_json["oucbtmw"] = p_oucb->oucbtmw; - oucb_json["oucbwms"] = p_oucb->oucbwms; - oucb_json["oucbcpu"] = p_oucb->oucbcpu; - oucb_json["oucbioc"] = p_oucb->oucbioc; - oucb_json["oucbmso"] = p_oucb->oucbmso; - oucb_json["oucbtms"] = p_oucb->oucbtms; - oucb_json["oucbtmo"] = p_oucb->oucbtmo; - oucb_json["oucbdrfr"] = p_oucb->oucbdrfr; - // Union - oucb_json["oucbcsw"] = p_oucb->oucbcsw; - oucb_json["oucbacn"] = formatter_.getBitmap(p_oucb->oucbacn); - oucb_json["oucbcfl"] = formatter_.getBitmap(p_oucb->oucbcfl); - oucb_json["oucbcsbt"] = formatter_.getBitmap(p_oucb->oucbcsbt); - oucb_json["oucbcmrv"] = p_oucb->oucbcmrv; - oucb_json["oucbwmrl"] = p_oucb->oucbwmrl; - oucb_json["oucbval"] = p_oucb->oucbval; - oucb_json["oucbpfl"] = formatter_.getBitmap(p_oucb->oucbpfl); - oucb_json["oucbactl"] = p_oucb->oucbactl; - oucb_json["oucbiocl"] = p_oucb->oucbiocl; - oucb_json["oucbdspc"] = formatter_.getBitmap(p_oucb->oucbdspc); - oucb_json["oucbdspn"] = formatter_.getBitmap(p_oucb->oucbdspn); - oucb_json["oucbntsp"] = p_oucb->oucbntsp; - oucb_json["oucbps1"] = p_oucb->oucbps1; - oucb_json["oucbps2"] = p_oucb->oucbps2; - oucb_json["oucbpst"] = p_oucb->oucbpst; - oucb_json["oucbrct"] = p_oucb->oucbrct; - oucb_json["oucbiit"] = p_oucb->oucbiit; - oucb_json["oucbnds"] = p_oucb->oucbnds; - oucb_json["oucbntsg"] = formatter_.getBitmap(p_oucb->oucbntsg); - oucb_json["oucbrsv2"] = p_oucb->oucbrsv2; - oucb_json["oucbtme"] = p_oucb->oucbtme; - oucb_json["oucbtml"] = p_oucb->oucbtml; - oucb_json["oucbdwms"] = p_oucb->oucbdwms; - oucb_json["oucbsrb"] = p_oucb->oucbsrb; - oucb_json["oucbtwss"] = p_oucb->oucbtwss; - oucb_json["oucbtmp"] = p_oucb->oucbtmp; - oucb_json["oucbdlyt"] = p_oucb->oucbdlyt; - oucb_json["oucbhst"] = p_oucb->oucbhst; - oucb_json["oucbcfs"] = p_oucb->oucbcfs; - oucb_json["oucbrpg"] = p_oucb->oucbrpg; - oucb_json["oucbspg"] = p_oucb->oucbspg; - oucb_json["oucbnpg"] = p_oucb->oucbnpg; - oucb_json["oucbsrpg"] = p_oucb->oucbsrpg; - oucb_json["oucbnrpg"] = p_oucb->oucbnrpg; - oucb_json["oucburpg"] = p_oucb->oucburpg; - oucb_json["oucbcrpg"] = p_oucb->oucbcrpg; - oucb_json["oucbarpg"] = p_oucb->oucbarpg; - oucb_json["oucbdrfp"] = p_oucb->oucbdrfp; - oucb_json["oucbtrxn"] = formatter_.getString(p_oucb->oucbtrxn, 8); - oucb_json["oucbusrd"] = formatter_.getString(p_oucb->oucbusrd, 8); - oucb_json["oucbcls"] = formatter_.getString(p_oucb->oucbcls, 8); - oucb_json["oucbtrs"] = p_oucb->oucbtrs; - oucb_json["oucbtrr"] = p_oucb->oucbtrr; - oucb_json["oucbswss"] = p_oucb->oucbswss; - oucb_json["oucbpsum"] = p_oucb->oucbpsum; - oucb_json["oucbfixb"] = p_oucb->oucbfixb; - oucb_json["oucbaplv"] = formatter_.getBitmap(p_oucb->oucbaplv); - oucb_json["oucbesap"] = formatter_.getBitmap(p_oucb->oucbesap); - oucb_json["oucbrst1"] = p_oucb->oucbrst1; - oucb_json["oucbrst2"] = p_oucb->oucbrst2; - oucb_json["oucbx1_0"] = p_oucb->oucbx1_0; - - if (OUCB::matchFilter(oucb_json)) { - return oucb_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/oucb.hpp b/cbxp/control_blocks/oucb.hpp deleted file mode 100644 index a5cff84..0000000 --- a/cbxp/control_blocks/oucb.hpp +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef __OUCB_H_ -#define __OUCB_H_ - -#include "control_block.hpp" - -#pragma pack(push, 1) // Don't byte align structure members. -typedef struct { - char oucbname[4]; - char* __ptr32 oucbfwd; - char* __ptr32 oucbbck; - int32_t oucbtma; - uint8_t oucbqfl; - uint8_t oucbsfl; - uint8_t oucbyfl; - uint8_t oucbafl; - uint8_t oucbtfl; - uint8_t oucbefl; - uint8_t oucbasstatus; - uint8_t oucbufl; - uint8_t oucblfl; - uint8_t oucbrfl; - uint8_t oucbndp; - uint8_t oucbtndp; - uint8_t oucbmfl; - int8_t oucbiac; - int8_t oucbrsv1; - int8_t oucbpgp; - int16_t oucbwsci; - int16_t oucbwrci; - uint8_t oucbmfl2; - uint8_t oucbmfl3; - int16_t oucbdmo; - int8_t oucbdmn; - int8_t oucbsrc; - int16_t oucbswc; - char* __ptr32 oucbascb; - char* __ptr32 oucbpagp; - int32_t oucbtmw; - int32_t oucbwms; - int32_t oucbcpu; - int32_t oucbioc; - int32_t oucbmso; - int32_t oucbtms; - int32_t oucbtmo; - int32_t oucbdrfr; - char* __ptr32 oucbact; - union { - uint32_t oucbcsw; - struct { - uint16_t oucbacn; - uint8_t oucbcfl; - uint8_t oucbcsbt; - }; - }; - int32_t oucbcmrv; - int32_t oucbwmrl; - int16_t oucbval; - uint8_t oucbpfl; - int8_t oucbactl; - int64_t oucbiocl; - uint8_t oucbdspc; - uint8_t oucbdspn; - int16_t oucbntsp; - int32_t oucbps1; - int32_t oucbps2; - int32_t oucbpst; - int32_t oucbrct; - int32_t oucbiit; - int16_t oucbnds; - uint8_t oucbntsg; - int8_t oucbrsv2; - int32_t oucbtme; - int32_t oucbtml; - int32_t oucbdwms; - int32_t oucbsrb; - int32_t oucbtwss; - int32_t oucbtmp; - int32_t oucbdlyt; - int32_t oucbhst; - int32_t oucbcfs; - char oucbsubn[4]; - int16_t oucbrpg; - int16_t oucbspg; - int16_t oucbnpg; - int16_t oucbsrpg; - int16_t oucbnrpg; - int16_t oucburpg; - int16_t oucbcrpg; - int16_t oucbarpg; - int32_t oucbdrfp; - char oucbtrxn[8]; - char oucbusrd[8]; - char oucbcls[8]; - int32_t oucbtrs; - int32_t oucbtrr; - int32_t oucbactp; - int32_t oucbswss; - int32_t oucbpsum; - int16_t oucbfixb; - uint8_t oucbaplv; - uint8_t oucbesap; - int32_t oucbrst1; - int32_t oucbrst2; - int32_t oucbx1_0; -} oucb_t; -#pragma pack(pop) // Restore default structure packing options. - -namespace CBXP { - -class OUCB : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit OUCB(const cbxp_options_t& cbxp_options) - : ControlBlock("oucb", {}, cbxp_options, sizeof(oucb_t)) {} -}; - -} // namespace CBXP - -#endif diff --git a/cbxp/control_blocks/psa.cpp b/cbxp/control_blocks/psa.cpp deleted file mode 100644 index 9824383..0000000 --- a/cbxp/control_blocks/psa.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "psa.hpp" - -#include -#include -#include - -#include "cvt.hpp" -#include "logger.hpp" - -namespace CBXP { -nlohmann::json PSA::get(const void* p_control_block, - const size_t buffer_length) { - PSA::checkDataLength(buffer_length); - const struct psa* p_psa; - nlohmann::json psa_json = {}; - - if (p_control_block == nullptr) { - // PSA starts at address 0 - p_psa = 0; - } else { - p_psa = static_cast(p_control_block); - } - - Logger::getInstance().debug("PSA hex dump:"); - Logger::getInstance().hexDump( - reinterpret_cast(p_psa), sizeof(struct psa) / 2, - true); // Only the first "page" of the PSA is not fetch-protected - - psa_json["flccvt"] = formatter_.getHex(&p_psa->flccvt); - - for (const auto& [include, cbxp_options] : options_map_) { - if (include == "cvt") { - psa_json["flccvt"] = CBXP::CVT(cbxp_options).get(p_psa->flccvt); - if (psa_json["flccvt"].is_null()) { - return {}; - } - } - } - - // Get fields - psa_json["psapsa"] = formatter_.getString(p_psa->psapsa, 4); - psa_json["flcsvilc"] = static_cast(p_psa->flcsvilc); - psa_json["flcrnpsw_bitstring"] = - formatter_.getBitmap(p_psa->flcrnpsw); - psa_json["flcrnpsw_hex"] = formatter_.getHex(p_psa->flcrnpsw + 4); - psa_json["flcsopsw"] = formatter_.getPswSmall(p_psa->flcsopsw); - psa_json["flcarch"] = formatter_.getBitmap( - reinterpret_cast(&p_psa->flcarch)); - psa_json["flccvt64"] = formatter_.getHex(p_psa->flccvt64); - psa_json["flcfacl"] = formatter_.getBitmap(p_psa->flcfacl) + - formatter_.getBitmap(p_psa->flcfacl + 8); - psa_json["flcfacle"] = formatter_.getBitmap(p_psa->flcfacle) + - formatter_.getBitmap(p_psa->flcfacle + 8); - psa_json["psaaold"] = formatter_.getHex(p_psa->psaaold); - psa_json["psaecvt"] = formatter_.getHex(p_psa->psaecvt); - psa_json["psaflags"] = formatter_.getBitmap( - reinterpret_cast(&p_psa->psaflags)); - psa_json["psafpfl"] = formatter_.getBitmap( - reinterpret_cast(&p_psa->psafpfl)); - psa_json["psalaa"] = formatter_.getHex(p_psa->psalaa); - psa_json["psalccav"] = formatter_.getHex(&p_psa->psalccav); - psa_json["psatold"] = formatter_.getHex(p_psa->psatold); - psa_json["psatrvt"] = formatter_.getHex(p_psa->psatrvt); - psa_json["psaval"] = formatter_.getBitmap(p_psa->psaval); - psa_json["psaxcvt"] = formatter_.getHex(p_psa->psaxcvt); - - if (PSA::matchFilter(psa_json)) { - return psa_json; - } else { - return {}; - } -} -} // namespace CBXP diff --git a/cbxp/control_blocks/psa.hpp b/cbxp/control_blocks/psa.hpp deleted file mode 100644 index 92db78a..0000000 --- a/cbxp/control_blocks/psa.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __PSA_H_ -#define __PSA_H_ - -#include - -#include "control_block.hpp" - -namespace CBXP { - -class PSA : public ControlBlock { - public: - nlohmann::json get(const void* p_control_block = nullptr, - const size_t buffer_length = 0) override; - explicit PSA(const cbxp_options_t& cbxp_options) - : ControlBlock("psa", {"cvt"}, cbxp_options, sizeof(struct psa) / 2) {} -}; -} // namespace CBXP -#endif diff --git a/cbxp/control_blocks/zos_subpools.hpp b/cbxp/control_blocks/zos_subpools.hpp new file mode 100644 index 0000000..2a09036 --- /dev/null +++ b/cbxp/control_blocks/zos_subpools.hpp @@ -0,0 +1,206 @@ +#pragma once + +#include +#include + +// IBM z/OS Storage Subpool attributes +// Source: https://www.ibm.com/docs/en/zos/3.1.0?topic=summary-storage-subpools +// Columns captured: Subpool number, Location (Common vs Private), Fetch +// Protection + +namespace zos { + +// --------------------------------------------------------------------------- +// Whether the subpool belongs to the Common or Private address space. +// --------------------------------------------------------------------------- +enum class SubpoolOwnership : uint8_t { + Private, + Common, +}; + +// --------------------------------------------------------------------------- +// The named storage region within the owning address space. +// +// Low = below the 16 MB line (private only) +// High = above the 16 MB line (private only) +// LSQA = Local System Queue Area (private only) +// SQA = System Queue Area (common only) +// CSA = Common Service Area (common only) +// --------------------------------------------------------------------------- +enum class SubpoolRegion : uint8_t { + Low, // Private: below 16 MB line + High, // Private: above 16 MB line + LSQA, // Private: Local System Queue Area + SQA, // Common: System Queue Area + CSA, // Common: Common Service Area +}; + +// --------------------------------------------------------------------------- +// Whether the subpool spans only the base (non-extended) region, only the +// Extended region (above 2 GB bar), or Both. +// +// Base – traditional 31-bit region only (e.g. "SQA" / "LSQA") +// Extended – 64-bit extended region only (e.g. "ESQA" / "ELSQA") +// Both – subpool covers base AND extended (e.g. "SQA/ESQA", "LSQA/ELSQA") +// --------------------------------------------------------------------------- +enum class SubpoolExtent : uint8_t { + Base, + Extended, + Both, +}; + +// --------------------------------------------------------------------------- +// Full descriptor for a subpool entry. +// --------------------------------------------------------------------------- +struct SubpoolLocation { + SubpoolOwnership ownership; + SubpoolRegion region; + SubpoolExtent extent; +}; + +struct SubpoolInfo { + SubpoolLocation location; + bool fetch_protected; +}; + +// --------------------------------------------------------------------------- +// Convenience construction aliases — keeps the map readable. +// --------------------------------------------------------------------------- +namespace detail { +using O = SubpoolOwnership; +using R = SubpoolRegion; +using E = SubpoolExtent; + +// Private shorthands +static constexpr SubpoolLocation PrivLowBase{O::Private, R::Low, E::Base}; +static constexpr SubpoolLocation PrivHighBase{O::Private, R::High, E::Base}; +static constexpr SubpoolLocation PrivLSQABase{O::Private, R::LSQA, E::Base}; +static constexpr SubpoolLocation PrivLSQAExt{O::Private, R::LSQA, E::Extended}; +static constexpr SubpoolLocation PrivLSQABoth{O::Private, R::LSQA, E::Both}; + +// Common shorthands +static constexpr SubpoolLocation CommSQABoth{O::Common, R::SQA, E::Both}; +static constexpr SubpoolLocation CommSQAExt{O::Common, R::SQA, E::Extended}; +static constexpr SubpoolLocation CommCSABoth{O::Common, R::CSA, E::Both}; +static constexpr SubpoolLocation CommCSAExt{O::Common, R::CSA, E::Extended}; +} // namespace detail + +// --------------------------------------------------------------------------- +// Map from subpool decimal number → SubpoolInfo. +// Subpools 0–127 are handled as a range in getSubpoolInfo(); they are NOT +// stored individually here. +// --------------------------------------------------------------------------- +// clang-format off +inline const std::unordered_map kSubpoolMap = { + // SP │ location (ownership, region, extent) │ fetch_protected + // ────┼────────────────────────────────────────┼──────────────── + + // ── 129–134 ───────────────────────────────────────────────────────────── + // IBM table: "Private (low)" — standard 31-bit private storage. + // Notes 24 on 133/134 indicate possible ELPA-range behavior but the + // table still lists them as Private low. + { 129, { detail::PrivLowBase, true } }, // 0x81 + { 130, { detail::PrivLowBase, false } }, // 0x82 + { 131, { detail::PrivLowBase, true } }, // 0x83 + { 132, { detail::PrivLowBase, false } }, // 0x84 + { 133, { detail::PrivLowBase, true } }, // 0x85 (see IBM note 24) + { 134, { detail::PrivLowBase, false } }, // 0x86 (see IBM note 24) + + // ── 203–205 ───────────────────────────────────────────────────────────── + // IBM table: "Private ELSQA" — Extended LSQA only, no base counterpart. + { 203, { detail::PrivLSQAExt, false } }, // 0xCB + { 204, { detail::PrivLSQAExt, false } }, // 0xCC + { 205, { detail::PrivLSQAExt, false } }, // 0xCD + + // ── 213–215 ───────────────────────────────────────────────────────────── + { 213, { detail::PrivLSQAExt, true } }, // 0xD5 + { 214, { detail::PrivLSQAExt, true } }, // 0xD6 + { 215, { detail::PrivLSQAExt, true } }, // 0xD7 + + // ── 223–225 ───────────────────────────────────────────────────────────── + { 223, { detail::PrivLSQAExt, true } }, // 0xDF + { 224, { detail::PrivLSQAExt, true } }, // 0xE0 + { 225, { detail::PrivLSQAExt, true } }, // 0xE1 + + // ── 226–231 ───────────────────────────────────────────────────────────── + // IBM table "SQA/ESQA" → Common SQA, Both extents. + // IBM table "CSA/ECSA" → Common CSA, Both extents. + { 226, { detail::CommSQABoth, false } }, // 0xE2 SQA/ESQA + { 227, { detail::CommCSABoth, true } }, // 0xE3 CSA/ECSA + { 228, { detail::CommCSABoth, false } }, // 0xE4 CSA/ECSA + { 229, { detail::PrivHighBase, true } }, // 0xE5 Private high + { 230, { detail::PrivHighBase, false } }, // 0xE6 Private high + { 231, { detail::CommCSABoth, true } }, // 0xE7 CSA/ECSA + + // ── 233–237 ───────────────────────────────────────────────────────────── + // IBM table "LSQA/ELSQA" → Private LSQA, Both extents. + { 233, { detail::PrivLSQABoth, false } }, // 0xE9 LSQA/ELSQA + { 234, { detail::PrivLSQABoth, false } }, // 0xEA LSQA/ELSQA + { 235, { detail::PrivLSQABoth, false } }, // 0xEB LSQA/ELSQA + { 236, { detail::PrivHighBase, false } }, // 0xEC Private high + { 237, { detail::PrivHighBase, false } }, // 0xED Private high + + // ── 239 ───────────────────────────────────────────────────────────────── + { 239, { detail::CommSQABoth, true } }, // 0xEF SQA/ESQA + + // ── 240–255 ───────────────────────────────────────────────────────────── + { 240, { detail::PrivLowBase, true } }, // 0xF0 + { 241, { detail::CommCSABoth, false } }, // 0xF1 CSA/ECSA + { 242, { detail::CommCSABoth, false } }, // 0xF2 CSA/ECSA [change marker] + { 243, { detail::CommCSABoth, false } }, // 0xF3 CSA/ECSA [change marker] + { 244, { detail::PrivLowBase, false } }, // 0xF4 + { 245, { detail::CommSQABoth, false } }, // 0xF5 SQA/ESQA + { 246, { detail::PrivLowBase, false } }, // 0xF6 [change marker] + // IBM table "ESQA" (no base SQA) → Common SQA, Extended only. + { 247, { detail::CommSQAExt, true } }, // 0xF7 ESQA only + { 248, { detail::CommSQAExt, false } }, // 0xF8 ESQA only + { 249, { detail::PrivHighBase, false } }, // 0xF9 Private high + { 250, { detail::PrivLowBase, true } }, // 0xFA + { 251, { detail::PrivLowBase, true } }, // 0xFB + { 252, { detail::PrivLowBase, false } }, // 0xFC + { 253, { detail::PrivLSQABoth, false } }, // 0xFD LSQA/ELSQA + { 254, { detail::PrivLSQABoth, false } }, // 0xFE LSQA/ELSQA + { 255, { detail::PrivLSQABoth, false } }, // 0xFF LSQA/ELSQA +}; +// clang-format on + +// --------------------------------------------------------------------------- +// Predicates +// --------------------------------------------------------------------------- +[[nodiscard]] inline bool isCommon(const SubpoolLocation& loc) noexcept { + return loc.ownership == SubpoolOwnership::Common; +} + +// cppcheck-suppress unusedFunction +[[nodiscard]] inline bool isPrivate(const SubpoolLocation& loc) noexcept { + return loc.ownership == SubpoolOwnership::Private; +} + +// cppcheck-suppress unusedFunction +[[nodiscard]] inline bool isExtended(const SubpoolLocation& loc) noexcept { + return loc.extent == SubpoolExtent::Extended || + loc.extent == SubpoolExtent::Both; +} + +// cppcheck-suppress unusedFunction +[[nodiscard]] inline bool isBase(const SubpoolLocation& loc) noexcept { + return loc.extent == SubpoolExtent::Base; +} + +// --------------------------------------------------------------------------- +// Primary lookup. Handles the 0–127 range inline (all: Private Low Base, +// fetch-protected). Returns nullptr for any subpool not in the IBM table. +// --------------------------------------------------------------------------- +[[nodiscard]] inline const SubpoolInfo* getSubpoolInfo(uint32_t sp) noexcept { + static constexpr SubpoolInfo k0to127{detail::PrivLowBase, true}; + if (sp <= 127) { + return &k0to127; + } + auto it = kSubpoolMap.find(sp); + if (it == kSubpoolMap.end()) { + return nullptr; + } + return &it->second; +} + +} // namespace zos diff --git a/cbxp/mappings/ascb.json b/cbxp/mappings/ascb.json new file mode 100644 index 0000000..ff0b232 --- /dev/null +++ b/cbxp/mappings/ascb.json @@ -0,0 +1,225 @@ +{ + "version": 1, + "name": "ascb", + "commonName": "ADDRESS SPACE CONTROL BLOCK", + "macroId": "ihaascb", + "description": "Contain information and pointers needed for Address Space Control. The ASCB is non-swappable.", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "asvt" + ], + "storageAttributes": { + "subpools": [ + 245 + ], + "key": 0, + "residency": 24 + }, + "sections": [ + { + "name": "ascb", + "description": "", + "fields": [ + { + "name": "ASCBASCB", + "description": "ACRONYM IN EBCDIC -ASCB-", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "ASCB" + } + ], + "eyecatcher": true + }, + { + "name": "ASCBASID", + "description": "ADDRESS SPACE IDENTIFIER FOR THE ASCB", + "offset": 36, + "length": 2, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBTCBE", + "description": "Count of ready tcbs in the space that are in an enclave. Ownership: Task Management Serialization: Compare and Swap and WEB Lock of TCB for which this count is being manipulated.", + "offset": 44, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBFLG3", + "description": "Flags needing no serialization. byte is a programming interface only for bit ASCBzCX", + "offset": 53, + "length": 1, + "type": "bitstring", + "bitmasks": { + "ASCBCNIP": { + "description": "Address space created during NIP", + "offset": 0, + "length": 1 + }, + "ASCBREUS": { + "description": "This is a reusable ASID. It may be given out only to a reusable ASID requestor", + "offset": 1, + "length": 1 + }, + "ASCBM881": { + "description": "This address space went through IEEMB881", + "offset": 2, + "length": 1 + }, + "ASCBSingleStepStartedTask": { + "description": "This address space is a single step started task", + "offset": 3, + "length": 1 + }, + "ASCBzCX": { + "description": "This address space is a zCX address space", + "offset": 4, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "ASCBEJST", + "description": "Accumulated job step CPU time. Non-enclave TCB time only. Unsigned 64-bit binary number", + "offset": 64, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBASXB", + "description": "POINTER TO ADDRESS SPACE EXTENSION CONTROL BLOCK (ASXB)", + "offset": 108, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASCBOUCB", + "description": "SYSTEM RESOURCES MANAGER (SRM) USER CONTROL BLOCK POINTER", + "offset": 144, + "length": 4, + "type": "address", + "programmingInterface": true, + "pointsTo": "oucb" + }, + { + "name": "ASCBOUXB", + "description": "SYSTEM RESOURCES MANAGER (SRM) USER EXTENSION BLOCK POINTER", + "offset": 148, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASCBJBNI", + "description": "POINTER TO JOBNAME FIELD FOR INITIATED PROGRAMS OR ZERO", + "offset": 172, + "length": 4, + "type": "address", + "pointsTo": "jobname", + "programmingInterface": true + }, + { + "name": "ASCBJBNS", + "description": "POINTER TO JOBNAME FIELD FOR START/MOUNT/LOGON OR ZERO", + "offset": 176, + "length": 4, + "type": "address", + "pointsTo": "jobname", + "programmingInterface": true + }, + { + "name": "ASCBSRBT", + "description": "ACCUMULATED SRB TIME", + "offset": 200, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBTCBS", + "description": "NUMBER OF READY TCB'S. THE ACTUAL NUMBER OF READY TCBS IS ASCBTCBS-ASCBLSQT. SERIALIZATION: CS OWNERSHIP: TASK MANAGEMENT", + "offset": 216, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBLSQT", + "description": "NUMBER OF TCBS ON A LOCAL LOCK SUSPEND QUEUE. SERIALIZATION: CS OWNERSHIP: TASK MANAGEMENT", + "offset": 220, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBXTCB", + "description": "ADDRESS OF THE JOB STEP TASK TCB WHICH OWNS THE CROSS MEMORY RESOURCES IN THIS ADDRESS SPACE. SERIALIZATION - LOCAL LOCK. OWNERSHIP - SUPERVISOR.", + "offset": 284, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASCBFW3", + "description": "Fullword label to address bits in this word. Serialization - CS. This word is a programming interface only for bits ASCBSDBF, ASCBNOFT, ASCBPO1M, ASCBP1M0", + "offset": 288, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBASSB", + "description": "POINTER TO ADDRESS SPACE SECONDARY BLOCK (ASSB).", + "offset": 336, + "length": 4, + "type": "address", + "pointsTo": "assb", + "programmingInterface": true + }, + { + "name": "ASCBLSQE", + "description": "Number of Enclave TCBs that are on a Local Lock Suspend Queue. Ownership: Task Management Serialization: Compare and Swap", + "offset": 348, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBRSME", + "description": "POINTER TO RSM ADDRESS SPACE BLOCK EXTENSION. SERIALIZATION: RSMAD LOCK OWNERSHIP: RSM", + "offset": 364, + "length": 4, + "type": "address", + "pointsTo": "rsm", + "programmingInterface": true + }, + { + "name": "ASCBDCTI", + "description": "ACCUMULATED CHANNEL CONNECT TIME INCURRED BY THIS MEMORY", + "offset": 380, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASCBEND", + "description": "END OF ASCB", + "offset": 384, + "length": 8, + "type": "signed-integer", + "endOfControlBlock": true + } + ] + } + ] +} diff --git a/cbxp/mappings/assb.json b/cbxp/mappings/assb.json new file mode 100644 index 0000000..515ab00 --- /dev/null +++ b/cbxp/mappings/assb.json @@ -0,0 +1,443 @@ +{ + "version": 1, + "name": "assb", + "commonName": "Address Space Secondary Block", + "macroId": "ihaassb", + "description": "Allows address space related information to be maintained above 16 megabytes.", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "ascb" + ], + "storageAttributes": { + "subpools": [ + 245 + ], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "assb", + "description": "", + "fields": [ + { + "name": "ASSBASSB", + "description": "ACRONYM IN EBCDIC - ASSB.", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "ASSB" + } + ], + "eyecatcher": true + }, + { + "name": "ASSBSTKN", + "description": "STOKEN. OWNERSHIP: SUPERVISOR CONTROL. SERIALIZATION: NONE. As with other ASCB/ASSB fields, serialization may be required when accessing something other than your address space's data.", + "offset": 48, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSBISQN", + "description": "Initial address space sequence number / instance number. It can be used with ASCBASID for the SSAIR instruction", + "offset": 52, + "length": 4, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSBMQMA", + "description": "CONTROL BLOCK ANCHOR FOR MQM MVS/ESA. SERIALIZATION: NONE. OWNERSHIP: MQSERIES", + "offset": 148, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSBLDAX", + "description": "Address of LDAX for this space", + "offset": 176, + "length": 8, + "type": "address", + "programmingInterface": true, + "pointsTo": "ldax" + }, + { + "name": "ASSBOASB", + "description": "OpenMVS ADDRESS SPACE BLOCK. SERIALIZATION: ENQ MAJOR=SYSZBPX MINOR=PROCESS_INIT. OWNERSHIP: OpenMVS.", + "offset": 228, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSBDLCB", + "description": "Contains the address of the Dynamic LNKLST Control Block (DLCB) mapped by CSVDLCB. Ownership: CSV Serialization: ENQ", + "offset": 236, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSBVAB", + "description": "ADDRESS OF VSM ADDRESS SPACE BLOCK (VAB), WHICH ANCHORS SOME OF THE VSM CONTROL BLOCKS THAT DESCRIBE COMMON STORAGE. SERIALIZATION: NONE. OWNERSHIP: VIRTUAL STORAGE MANAGER.", + "offset": 240, + "length": 4, + "type": "address", + "pointsTo": "vsm", + "programmingInterface": true + }, + { + "name": "ASSBTASB", + "description": "TCPIP ASSB Extension Ownership: TCPIP Serialization: Compare and Swap when first TCPIP client is initialized in this space.", + "offset": 264, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSBJBNI", + "description": "Jobname for the Initiated Program that is associated with this Address Space. If the first byte is x'00', none is associated. OWNERSHIP: Initiator. SERIALIZATION: None.", + "offset": 336, + "length": 8, + "type": "string", + "programmingInterface": true + }, + { + "name": "ASSBJBNS", + "description": "Jobname for the START/MOUNT/ LOGON that is associated with this Address Space. If the first byte is x'00', none is associated. OWNERSHIP: Console Services. SERIALIZATION: None.", + "offset": 344, + "length": 8, + "type": "string", + "programmingInterface": true + }, + { + "name": "ASSBASST", + "description": "Additional SRB Service Time. CPU time is accumulated here for this address space's non-Enclave Preemptable SRBs and for Client Related SRBs for which this address space is the client. Format: TOD Clock Format Ownership: Supervisor Control Serialization: CS", + "offset": 352, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSBPHTM", + "description": "Preemptable-class Time. The CPU time for all types of preemptable SRBs (PSRB, CSRB, ESRB) executing with this address space as their home space and enclave tasks is accumulated here. This value is not used in SMF or SRM calculations. This value is not reset at step/job start.", + "offset": 360, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_zCBP_ON_CP", + "description": "", + "offset": 472, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_IFA_ON_CP", + "description": "", + "offset": 472, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_ON_zCBP", + "description": "zCBP time. Enclave time not included", + "offset": 480, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_ON_zAAP", + "description": "zAAP time. Enclave time not included", + "offset": 480, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_ON_IFA", + "description": "", + "offset": 480, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TASK_TIME_ON_CP", + "description": "Time on CP in task mode for this space. Valid only when zCBPs, zAAPs or zIIPs are installed", + "offset": 488, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSBPHTM_BASE", + "description": "Value in ASSBPHTM at the end of the previous jobstep. Serialization: none", + "offset": 504, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zCBP_PHTM", + "description": "zCBP-only equivalent of ASSBPHTM This is \"normalized\" time", + "offset": 520, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zAAP_PHTM", + "description": "zAAP-only equivalent of ASSBPHTM This is \"normalized\" time This value is not reset at step/job start.", + "offset": 520, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_IFA_PHTM", + "description": "", + "offset": 520, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_ENCT_PREZOS11", + "description": "Enclave time in an address space on a standard CP Not set as of z/OS 1.11", + "offset": 528, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_IFA_ENCT_PREZOS11", + "description": "Enclave IFA time in an address space. This is \"normalized\" time Not set as of z/OS 1.11", + "offset": 536, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zCBP_Base_PHTM", + "description": "Base value, set by WLM", + "offset": 552, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_ON_zIIP", + "description": "zIIP time. Enclave time not included", + "offset": 592, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_TIME_zIIP_ON_CP", + "description": "zIIP time on CP. Enclave time not included. When zAAPzIIP=YES is in effect, zAAP-eligible work running on a CP is included.", + "offset": 600, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zIIP_PHTM", + "description": "zIIP-only equivalent of ASSBPHTM This is \"normalized\" time This value is not reset at step/job start.", + "offset": 608, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_SRB_TIME_ON_CP", + "description": "Time on CP in SRB mode for this space. Valid only when zAAPs or SUPs are installed", + "offset": 616, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zIIP_ENCT", + "description": "Enclave zIIP time in an address space. This is \"normalized\" time This value is not reset at step/job start.", + "offset": 624, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zCBP_ON_CP_ENCT", + "description": "Enclave time for zCBP on CP in an address space This value is not reset at step/job start.", + "offset": 632, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_IFA_ON_CP_ENCT", + "description": "Enclave time for IFA on CP in an address space This value is not reset at step/job start.", + "offset": 632, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_ASST_TIME_ON_CP", + "description": "Additional SRB Service Time on a standard CP. CPU time is accumulated here for this address space's Preemptable SRBs and for Client Related SRBs for which this address space is the client. Valid only when zAAPs or zIIPs are installed Format: TOD Clock Format Ownership: Supervisor Control", + "offset": 680, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zIIP_ON_CP_ENCT", + "description": "Enclave time for zIIP on CP in an address space. When zAAPzIIP=YES is in effect, zAAP-eligible work running on a CP is included. This value is not reset at step/job start.", + "offset": 712, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_SUP_ON_CP_ENCT", + "description": "See ASSB_zIIP_ON_CP_ENCT", + "offset": 712, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_SMFCMS_LockInst_Addr", + "description": "Address of the SMF CMS instrumentation data for this address space", + "offset": 744, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSB_ENQDEQ_CMS_LockInst_Addr", + "description": "Address of the ENQ/DEQ CMS instrumentation data for this address space", + "offset": 748, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSB_LATCH_CMS_LockInst_Addr", + "description": "Address of the Latch CMS instrumentation data for this address space", + "offset": 752, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSB_CMS_LockInst_Addr", + "description": "Address of the CMS instrumentation data for this address space", + "offset": 756, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSB_Local_LockInst_Addr", + "description": "Address of the local and CML lock instrumentation data for this address space", + "offset": 760, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ASSB_ENCT", + "description": "Enclave time in an address space on a standard CP This value is not reset at step/job start.", + "offset": 1280, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zCBP_ENCT", + "description": "Enclave zCBP time in an address space. This is \"normalized\" time This value is not reset at step/job start.", + "offset": 1536, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zAAP_ENCT", + "description": "Enclave zAAP time in an address space. This is \"normalized\" time This value is not reset at step/job start.", + "offset": 1536, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_IFA_ENCT", + "description": "", + "offset": 1536, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_SRB_TIME_ON_zCBP", + "description": "Non-preemptable SRB time on zCBP", + "offset": 1768, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_ASST_TIME_ON_zCBP", + "description": "non-enclave preemptable SRB time on zCBP", + "offset": 1776, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_zIIP_PHTM_BASE", + "description": "Value in ASSB_zIIP_PHTM at the end x of the previous jobstep.", + "offset": 2336, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_Time_Java_On_zIIP", + "description": "Time Java is zIIP eligible and executing on zIIP engines and not in an enclave. (Unnormalized)", + "offset": 2480, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSB_Time_Java_On_CP", + "description": "Time Java is zIIP eligible and executing on CP engines and not in an enclave", + "offset": 2488, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ASSBEND", + "description": "END OF ASSB.", + "offset": 2496, + "length": 8, + "type": "signed-integer", + "endOfControlBlock": true + } + ] + } + ] +} diff --git a/cbxp/mappings/asvt.json b/cbxp/mappings/asvt.json new file mode 100644 index 0000000..97cedca --- /dev/null +++ b/cbxp/mappings/asvt.json @@ -0,0 +1,176 @@ +{ + "version": 1, + "name": "asvt", + "commonName": "ASVT", + "macroId": "ihaasvt", + "description": "", + "type": "control-block", + "aliases": [], + "pointedToBy": ["cvt"], + "storageAttributes": { + "subpools": [ + 245 + ], + "key": 0, + "residency": 24 + }, + "sections": [ + { + "name": "asvt", + "description": "", + "fields": [ + { + "name": "ASVTPRFX", + "description": "Reserved for future expansion", + "offset": 0, + "length": 464, + "type": "string" + }, + { + "name": "ASVTBEGN", + "description": "BEGINNING OF ASVT", + "offset": 464, + "length": 4, + "type": "hex", + "alignBefore": 8 + }, + { + "name": "AsvtHWMAsid", + "description": "Highest ASID used since IPL", + "offset": 464, + "length": 4, + "type": "signed-integer" + }, + { + "name": "AsvtCurHighAsid", + "description": "Highest ASID currently used", + "offset": 468, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTREUA", + "description": "ADDRESS OF ASVTREUS BITS", + "offset": 472, + "length": 4, + "type": "address", + "pointsTo": "asvtreus" + }, + { + "name": "ASVTRAVL", + "description": "ADDRESS OF FIRST AVAILABLE REUSABLE ASID SLOT", + "offset": 476, + "length": 4, + "type": "address" + }, + { + "name": "ASVTAAV", + "description": "NUMBER OF FREE SLOTS ON THE ASVT AVAILABLE QUEUE.", + "offset": 480, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTAST", + "description": "NUMBER OF FREE SLOTS ON THE START/SASI QUEUE.", + "offset": 484, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTANR", + "description": "NUMBER OF FREE SLOTS ON THE NON-REUSABLE REPLACEMENT QUEUE.", + "offset": 488, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTSTRT", + "description": "ORIGINAL SIZE OF START/SASI QUEUE.", + "offset": 492, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTNONR", + "description": "ORIGINAL SIZE OF NON-REUSABLE REPLACEMENT QUEUE.", + "offset": 496, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTMAXI", + "description": "ORIGINAL MAX USERS COUNT AS INPUT TO IEAVNP09. OWNERSHIP - SUPERVISOR CONTROL SERIALIZATION - NIP RIM PROCESS", + "offset": 500, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTASVT", + "description": "ACRONYM IN EBCDIC -ASVT-", + "offset": 512, + "length": 4, + "type": "string", + "init": [{ "type": "string", "value": "ASVT" }], + "eyecatcher": true + }, + { + "name": "ASVTMAXU", + "description": "MAXIMUM NUMBER OF ADDRESS SPACES", + "offset": 516, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTMDSC", + "description": "MAXUSER DEFICIT SLOT COUNT. ASVTMDSC = ASVTMAXI - ASVTAAV - NUMBER OF ACTIVE A.S. INCREMENTED WHEN WE TRY TO TAKE A REPLACEMENT SLOT BUT THERE AREN'T ANY. DECREMENTED WHEN NON-ZERO AND A NONREUSEABLE ASID BECOMES REUSEABLE AND WE ADD A SLOT TO THE MAXUSER POOL WHEN AN ADDRESS SPACE BECOMES REUSEABLE.", + "offset": 520, + "length": 4, + "type": "signed-integer" + }, + { + "name": "ASVTFRST", + "description": "ADDRESS OF FIRST AVAILABLE ASVT ENTRY", + "offset": 524, + "length": 4, + "type": "address", + "equates": [ + { + "name": "ASVTAVAI", + "value": "X'80'", + "description": "BIT ONE IF ASID IS AVAILABLE AND ZERO IF ASID IS ASSIGNED" + } + ] + }, + { + "name": "ASVTENTY", + "description": "ENTRY FOR EACH POSSIBLE ASID. IF ADDRESS SPACE ASSIGNED, ENTRY CONTAINS ADDRESS OF ASCB. IF NOT ASSIGNED, ENTRY CONTAINS EITHER ADDRESS OF NEXT AVAILABLE ASID OR ZEROS WITH HIGH-ORDER BIT ON IF LAST ENTRY. IF THE ADDRESS SPACE IS MARKED NON-REUSABLE, THE ENTRY CONTAINS THE ADDRESS OF MASTER'S ASVT ENTRY WITH THE HIGH BIT ON.", + "offset": 528, + "length": 4, + "type": "address", + "pointsTo": "ascb", + "equates": [ + { + "name": "ASVTAVAL", + "value": "X'80'", + "description": "BIT ONE IF ASID IS AVAILABLE AND ZERO IF ASID IS ASSIGNED" + }, + { + "name": "ASVTLEN", + "value": "ASVTEND-ASVT", + "description": "ASVT - LENGTH OF ASVT INCLUDING RESERVED FIELDS" + }, + { + "name": "ASVTULEN", + "value": "ASVTEND-ASVTBEGN", + "description": "ASVTBEGN - LENGTH OF USED FIELDS IN ASVT" + } + ], + "repeated": true, + "ignoreMask": "80", + "count": "asvtmaxu" + } + ] + } + ] +} \ No newline at end of file diff --git a/cbxp/mappings/cvt.json b/cbxp/mappings/cvt.json new file mode 100644 index 0000000..c408169 --- /dev/null +++ b/cbxp/mappings/cvt.json @@ -0,0 +1,1333 @@ +{ + "version": 1, + "name": "cvt", + "commonName": "Communications Vector Table", + "macroId": "cvt", + "description": "The CVT provides the means by which non-nucleus-resident routines may refer to information in the nucleus of the control program. It contains addresses of other control blocks and tables used by the control program routines.", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "psa" + ], + "storageAttributes": { + "subpools": [ + "nucleus" + ], + "key": 0, + "residency": 24 + }, + "sections": [ + { + "name": "cvtfix", + "description": "", + "fields": [ + { + "name": "CVTPROD", + "description": "SYSTEM CONTROL PROGRAM PRODUCT LEVEL.", + "offset": -40, + "length": 16, + "type": "string", + "programmingInterface": true + }, + { + "name": "CVTVERID", + "description": "OPTIONAL USER PERSONALIZATION OF SOFTWARE SYSTEM VERSION.", + "offset": -24, + "length": 16, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "CVTMDL", + "description": "CPU NUMBER IN SIGNLESS PACKED DECIMAL, I.E., A 3090 PROCESSOR WOULD APPEAR AS X'3090'", + "offset": -6, + "length": 2, + "type": "string", + "programmingInterface": true + }, + { + "name": "CVTRELNO", + "description": "RELEASE NUMBER (EBCDIC)", + "offset": -4, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "038 " + } + ], + "programmingInterface": true + }, + { + "name": "CVT0EF00", + "description": "ADDRESS OF ROUTINE TO SCHEDULE ASYNCHRONOUS EXITS", + "offset": 4, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEA0EF00" + } + ], + "programmingInterface": true + }, + { + "name": "CVTLINK", + "description": "ADDRESS OF DCB FOR SYS1.LINKLIB DATA SET. UPDATED BY CONTENTS SUPERVISION RIM. OWNERSHIP: CONTENTS SUPERVISION.", + "offset": 8, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEFLINK" + } + ], + "programmingInterface": true + }, + { + "name": "CVTPCNVT", + "description": "ADDRESS OF ENTRY POINT OF THE ROUTINE WHICH CONVERTS A RELATIVE TRACK ADDRESS (TTR) TO AN ABSOLUTE TRACK ADDRESS (MBBCCHHR)", + "offset": 28, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IECPCNVT" + } + ], + "programmingInterface": true + }, + { + "name": "CVTPRLTV", + "description": "ADDRESS OF ENTRY POINT OF THE ROUTINE WHICH CONVERTS AN ABSOLUTE TRACK ADDRESS (MBBCCHHR) TO A RELATIVE TRACK ADDRESS (TTR)", + "offset": 32, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IECPRLTV" + } + ], + "programmingInterface": true + }, + { + "name": "CVTSYSAD", + "description": "UCB ADDRESS FOR THE SYSTEM RESIDENCE VOLUME", + "offset": 48, + "length": 4, + "type": "address", + "pointsTo": "vtrg", + "programmingInterface": true + }, + { + "name": "CVTEXIT", + "description": "An SVC 3 instruction. Exit to dispatcher. This is a programming interface for IRBs only. An IRB may return to the system by branching to this location", + "offset": 80, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "instruction", + "value": "SVC 3" + } + ], + "programmingInterface": true + }, + { + "name": "CVTBRET", + "description": "A BR 14 INSTRUCTION. RETURN TO CALLER (USED BY DATA MANAGEMENT ROUTINES)", + "offset": 82, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "instruction", + "value": "BR 14" + } + ], + "programmingInterface": true + }, + { + "name": "CVTTPC", + "description": "ADDRESS OF THE TIMER SUPERVISOR WORK AREA", + "offset": 88, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEATPC" + } + ], + "pointsTo": "tpc", + "programmingInterface": true + }, + { + "name": "CVTCVT", + "description": "CVT ACRONYM IN EBCDIC (EYE-CATCHER)", + "offset": 96, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": " CVT" + } + ], + "eyecatcher": true + }, + { + "name": "CVTQTE00", + "description": "ADDRESS OF THE TIMER ENQUEUE ROUTINE FOR INTERVAL TIMER", + "offset": 104, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAQTE00" + } + ], + "pointsTo": "qte", + "programmingInterface": true + }, + { + "name": "CVTQTD00", + "description": "ADDRESS OF THE TIMER DEQUEUE ROUTINE FOR INTERVAL TIMER", + "offset": 108, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAQTD00" + } + ], + "pointsTo": "qtd", + "programmingInterface": true + }, + { + "name": "CVTDCB", + "description": "OPERATING SYSTEM FOR S/370-XA MODE EXECUTION, CVTMVSE, CVT4MS1, CVTOSEXT, CVT6DAT, AND CVTMVS2 ARE SET ON AT CVT CREATION", + "offset": 116, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "9B" + } + ], + "bitmasks": { + "CVTMVSE": { + "description": "S/370-XA MODE EXECUTION", + "offset": 0, + "length": 1 + }, + "CVT1SSS": { + "description": "OPTION 1 (PCP) SSS. ALSO, LANGUAGE COMPILERS MAY USE THIS BIT TO DETERMINE IF THEY ARE RUNNING UNDER OS OR VM (WILL BE 0 FOR OS).", + "offset": 1, + "length": 1 + }, + "CVT2SPS": { + "description": "OPTION 2 (MFT) SPS, OS/VS1, VSE", + "offset": 2, + "length": 1 + }, + "CVT4MS1": { + "description": "OPTION 4 (MVT) MS1, OS/VS2", + "offset": 3, + "length": 1 + }, + "CVTOSEXT": { + "description": "INDICATOR THAT THE CVTOSLVL AREA IS PRESENT AND MAY BE REFERENCED. This bit is on for all releases starting with MVS/SP3.1.0.", + "offset": 4, + "length": 1 + }, + "CVT4MPS": { + "description": "MODEL 65 MULTIPROCESSING", + "offset": 5, + "length": 1 + }, + "CVT6DAT": { + "description": "DYNAMIC ADDRESS TRANSLATION BY CPU (OS/VS1, OS/VS2)", + "offset": 6, + "length": 1 + }, + "CVTMVS2": { + "description": "MULTIPLE MEMORY OPTION OF OS/VS2 IS PRESENT", + "offset": 7, + "length": 1 + } + }, + "equates": [ + { + "name": "CVT8AOS2", + "value": "CVT4MS1+CVT6DAT", + "description": "+CVT6DAT - OS/VS2 SYSTEM" + } + ], + "programmingInterface": true + }, + { + "name": "CVTIXAVL", + "description": "ADDRESS OF THE I/O SUPERVISOR'S FREELIST POINTER WHICH CONTAINS THE ADDRESS OF THE NEXT REQUEST ELEMENT (OS/VS1) ADDRESS OF THE I/O SUPERVISOR'S COMMUNICATION AREA (IOCOM) (OS/VS2)", + "offset": 124, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IECIXAVL" + } + ], + "programmingInterface": true + }, + { + "name": "CVTECVT", + "description": "POINTER TO THE EXTENDED CVT", + "offset": 140, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAECVT" + } + ], + "pointsTo": "ecvt", + "programmingInterface": true + }, + { + "name": "CVTMSER", + "description": "ADDRESS OF DATA AREA OF MASTER SCHEDULER RESIDENT DATA AREA", + "offset": 148, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEEMSER" + } + ], + "programmingInterface": true + }, + { + "name": "CVTTVT", + "description": "ADDRESS OF TSO VECTOR TABLE", + "offset": 156, + "length": 4, + "type": "address", + "pointsTo": "tso", + "programmingInterface": true + }, + { + "name": "CVTSMCA", + "description": "ADDRESS OF THE SYSTEM MANAGEMENT CONTROL AREA (SMCA) IF THE SYSTEM MANAGEMENT FACILITIES (SMF) OPTION IS PRESENT IN THE SYSTEM. OTHERWISE, ZERO.", + "offset": 196, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "CVTABEND", + "description": "ADDRESS OF SECONDARY CVT FOR ABEND IN EOT (OS/VS2)", + "offset": 200, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEABEND" + } + ], + "programmingInterface": true + }, + { + "name": "CVTUSER", + "description": "A WORD AVAILABLE TO THE USER", + "offset": 204, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "CVT0SCR1", + "description": "ADDRESS OF THE SECTOR CALCULATION ROUTINE FOR ROTATIONAL POSITION SENSING (RPS)", + "offset": 232, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEC0SCR1" + } + ], + "programmingInterface": true + }, + { + "name": "CVTFLAG5", + "description": "Flags, refreshed upon error, set during NIP and never changed", + "offset": 244, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "40" + } + ], + "bitmasks": { + "CVTVEF": { + "description": "Vector Extension Facility", + "offset": 0, + "length": 1 + }, + "CVTZ1": { + "description": "Z1", + "offset": 0, + "length": 1 + }, + "CVTEEC": { + "description": "EEC", + "offset": 1, + "length": 1 + }, + "CVTNNPAF": { + "description": "NNPA facility", + "offset": 2, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTFLAG6", + "description": "More flags", + "offset": 245, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "CVTSOLED": { + "description": "Solution Edition", + "offset": 0, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTFLAG7", + "description": "More flags", + "offset": 246, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "CvtSysplexZaapOnline": { + "description": "The sysplex has one or more zAAP processors currently online", + "offset": 0, + "length": 1 + }, + "CvtSysplexZcbpOnline": { + "description": "The sysplex has one or more zCBP processors currently online", + "offset": 1, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTSAF", + "description": "ADDRESS OF ROUTER VECTOR TABLE.", + "offset": 248, + "length": 4, + "type": "address", + "pointsTo": "vmsgs", + "programmingInterface": true + }, + { + "name": "CVTAMFF", + "description": "RESERVED FOR ACCESS METHOD FLAGS", + "offset": 264, + "length": 4, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "pointsTo": "vmsgs", + "programmingInterface": true + }, + { + "name": "CVTJESCT", + "description": "ADDRESS OF JOB ENTRY SUBSYSTEM (JES) CONTROL TABLE", + "offset": 296, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEFJESCT" + } + ], + "programmingInterface": true + }, + { + "name": "CVTTZ", + "description": "Difference between local time and UTC (Coordinated Universal Time) in binary units of 1.048576 seconds. Contains the same value as CVTLDTOL. CVTLDTO (which contains CVTLDTOL) has this difference to a finer degree of accuracy.", + "offset": 304, + "length": 4, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "00000000" + } + ], + "programmingInterface": true + }, + { + "name": "CVTSNAME", + "description": "SYSTEM NAME FOR CURRENT SYSTEM. OWNERSHIP: IPL/NIP. SERIALIZATION: NONE.", + "offset": 340, + "length": 8, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "CVTPVTP", + "description": "ADDRESS OF PAGE VECTOR TABLE", + "offset": 356, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IARMPVT" + } + ], + "programmingInterface": true + }, + { + "name": "CVTFLAG2", + "description": "FLAG BYTE", + "offset": 377, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "80" + } + ], + "bitmasks": { + "CVTCMPSC": { + "description": "IF ONE, INDICATES PRESENCE OF MVS COMPRESSION/EXPANSION SERVICE. INITIALIZED ON. OWNERSHIP: CALLABLE SERVICES. SERIALIZATION: NONE.", + "offset": 0, + "length": 1 + }, + "CVTCMPSH": { + "description": "IF ONE, INDICATES PRESENCE OF CMPSC COMPRESSION/EXPANSION HARDWARE INSTRUCTION SET BY NIP. OWNERSHIP: CALLABLE SERVICES. SERIALIZATION: NONE (UNCHANGED AFTER NIP).", + "offset": 1, + "length": 1 + }, + "CVTSOPF": { + "description": "IF ONE, INDICATES PRESENCE OF THE SUPPRESSION-ON-PROTECTION HARDWARE FACILITY. SET BY NIP. OWNERSHIP: SUPERVISOR CONTROL SERIALIZATION: NONE (UNCHANGED AFTER NIP).", + "offset": 2, + "length": 1 + }, + "CVTBFPH": { + "description": "If one, indicates presence of BFP hardware instruction set. Set by NIP. Ownership: Supervisor. Serialization: None (unchanged after NIP).", + "offset": 3, + "length": 1 + }, + "CVTPER2": { + "description": "If one, indicates presence of PER2 hardware on all CPUs Set by NIP. Ownership: Supervisor. Serialization: None (unchanged after NIP).", + "offset": 4, + "length": 1 + }, + "CVTIQD": { + "description": "If one, indicates that Internal Queued Direct Communications is supported. Set by IOS during NIP. Ownership: IOS Serialization: None (unchanged after NIP).", + "offset": 5, + "length": 1 + }, + "CVTALR": { + "description": "If one, indicates ASN and LX Reuse Architecture is enabled. Set by NIP. Ownership: Supervisor. Serialization: None (unchanged after NIP).", + "offset": 6, + "length": 1 + }, + "CVTEDAT": { + "description": "If one, indicates that the Enhanced DAT Architecture is available Set by NIP. Ownership: Supervisor. Serialization: None (unchanged after NIP).", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTFLAG3", + "description": "FLAG BYTE refreshed upon error, set during NIP and never changed", + "offset": 378, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "CVTESAME": { + "description": "cvtesame", + "offset": 0, + "length": 1 + }, + "CVTZARCH": { + "description": "If one, indicates presence of z/Architecture hardware. Note that it is often simpler to check if PSA field FLCARCH is non-zero to determine this. Set by NIP. Ownership: Supervisor. Serialization: None (unchanged after NIP).", + "offset": 0, + "length": 1 + }, + "CvtProcAsCore": { + "description": "A processor resource is viewed as a CPU Core", + "offset": 1, + "length": 1 + }, + "CvtMultiCpusPerCore": { + "description": "When CvtProcAsCore is on, this indicates there are multiple CPUs defined within a CPU Core (On MT hardware). When CvtProcAsCore is off, this is always off", + "offset": 2, + "length": 1 + }, + "CvtCpuAsAliasToCore": { + "description": "When CvtProcAsCore is on, the term \"CPU\" is treated as an alias to \"CORE\" for D M and CF system commands. When CvtProcAsCore is off, this is always off", + "offset": 3, + "length": 1 + }, + "CvtFlag3Diag": { + "description": "Diagnostic data for IBM use only", + "offset": 4, + "length": 1 + }, + "CvtFlag3Rsvd": { + "description": "Reserved for IBM use", + "offset": 5, + "length": 1 + }, + "CvtzCBP": { + "description": "When bit is on, system fields with zCBP names and and aliases with corresponding zAAP names contain data about zCBP processors.", + "offset": 6, + "length": 1 + }, + "CvtGsf": { + "description": "GSF is available", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTFLAG4", + "description": "Flag byte This is an interface for CA CVTZNALC, CVTDCPA, CVTTX, CVTTXC, CVTEDAT2 only", + "offset": 379, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "80" + } + ], + "bitmasks": { + "CVTP001I": { + "description": "If one, indicates that P001 support is installed", + "offset": 0, + "length": 1 + }, + "CVTP001A": { + "description": "If one, indicates that the system is in P001_Active mode Ownership: IPL/NIP Serialization: SALLOC", + "offset": 1, + "length": 1 + }, + "CVTZNALC": { + "description": "zNALC", + "offset": 2, + "length": 1 + }, + "CVTDCPA": { + "description": "Dynamic CPU Addition is enabled", + "offset": 3, + "length": 1 + }, + "CVTTX": { + "description": "TX support is enabled", + "offset": 4, + "length": 1 + }, + "CVTP002": { + "description": "P002 support is enabled", + "offset": 4, + "length": 1 + }, + "CVTTXC": { + "description": "TXC support is enabled", + "offset": 5, + "length": 1 + }, + "CVTP002C": { + "description": "P002C support is enabled", + "offset": 5, + "length": 1 + }, + "CVTRI": { + "description": "RI support is enabled", + "offset": 6, + "length": 1 + }, + "CVTEDAT2": { + "description": "EDAT2 is enabled", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTCTLFG", + "description": "SYSTEM CONTROL FLAGS", + "offset": 398, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "10" + } + ], + "bitmasks": { + "CVTTXTE": { + "description": "A Transactional Execution test is available. When only such a test environment exists, you should not use Transactional Execution in product code. In this test environment, the limited diagnostic data available upon such failures as program interrupts may well be inadequate to debug programs", + "offset": 0, + "length": 1 + }, + "CVTTXJ": { + "description": "Not a programming interface", + "offset": 0, + "length": 1 + }, + "CVTCTLFGDiag": { + "description": "Diagnostic data for IBM use only", + "offset": 1, + "length": 2 + }, + "CVTDSTAT": { + "description": "DEVSTAT OPTION IN EFFECT. DEVICE ADDRESS FOR 2319, 3330, 2314, 3330-1, 3340 CAN VARY ACROSS SYSTEMS. Not a programming interface.", + "offset": 3, + "length": 1 + }, + "CVTDRMOD": { + "description": "Set on when DRMODE=YES was specified.", + "offset": 4, + "length": 1 + }, + "CVTNOMP": { + "description": "MULTIPROCESSING CODE IS NOT IN THE SYSTEM. Not a programming interface.", + "offset": 5, + "length": 1 + }, + "CVTGTRCE": { + "description": "GENERALIZED TRACE FACILITY (GTF) HAS SUPPRESSED SUPERVISOR TRACE. Not a programming interface.", + "offset": 6, + "length": 1 + }, + "CVTSDTRC": { + "description": "SVC DUMP HAS SUPPRESSED SUPERVISOR TRACE. Not a programming interface.", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTGRSST", + "description": "GRS status. SERIALIZATION: None.", + "offset": 428, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "CVTE51GN": { + "description": "When on, global resource contention data normally reported via ENF event code 51 to listeners on this system is unavailable or incomplete.", + "offset": 0, + "length": 1 + }, + "CVTE51LN": { + "description": "When on, local resource contention data normally reported via ENF event code 51 to listeners on this system is unavailable or incomplete.", + "offset": 1, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTFLAG9", + "description": "Function-available flags", + "offset": 429, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "41" + } + ], + "bitmasks": { + "CVT_LLACOPY_DEBLOCKEXCLOK": { + "description": "LLACOPY supports DEBLOCKEXCLOK=YES", + "offset": 1, + "length": 1 + }, + "CVTIFAWICAvailable": { + "description": "IFAWIC service is available for use", + "offset": 6, + "length": 1 + }, + "CVTIFAWICInstalled": { + "description": "IFAWIC service is installed", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTBSM0F", + "description": "Return via reg 15, BSM 0,15", + "offset": 430, + "length": 2, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "0B0F" + } + ], + "programmingInterface": true + }, + { + "name": "CVTGVT", + "description": "ADDRESS OF THE GRS VECTOR TABLE", + "offset": 432, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "GVT" + } + ], + "pointsTo": "pdsrt", + "programmingInterface": true + }, + { + "name": "CVTMAXMP", + "description": "Maximum CPU address available for this IPL", + "offset": 476, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0001" + } + ], + "programmingInterface": true + }, + { + "name": "CVTASVT", + "description": "POINTER TO ADDRESS SPACE VECTOR TABLE (ASVT)", + "offset": 556, + "length": 4, + "type": "address", + "pointsTo": "asvt", + "programmingInterface": true + }, + { + "name": "CVTGDA", + "description": "POINTER TO GLOBAL DATA AREA (GDA) IN SQA", + "offset": 560, + "length": 4, + "type": "address", + "pointsTo": "mascb", + "programmingInterface": true + }, + { + "name": "CVTRTMCT", + "description": "POINTER TO RECOVERY/TERMINATION CONTROL TABLE", + "offset": 572, + "length": 4, + "type": "address", + "pointsTo": "vstag", + "programmingInterface": true + }, + { + "name": "CVTSDBF", + "description": "Address of 4K SQA buffer used by SVC Dump. High-order bit of this CVT word is used as lock to indicate buffer is in use. See related bit ASCBSDBF in macro IHAASCB.", + "offset": 588, + "length": 4, + "type": "address", + "init": [ + { + "type": "hex", + "value": "80000000" + } + ], + "programmingInterface": true + }, + { + "name": "CVTOPCTP", + "description": "ADDRESS OF SYSTEM RESOURCES MANAGER (SRM) CONTROL TABLE", + "offset": 604, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IRARMCNS" + } + ], + "pointsTo": "vexpr", + "programmingInterface": true + }, + { + "name": "CVTVWAIT", + "description": "ADDRESS OF WAIT ROUTINE", + "offset": 624, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVWAIT" + } + ], + "pointsTo": "vwait", + "programmingInterface": true + }, + { + "name": "CVTCSD", + "description": "VIRTUAL ADDRESS OF COMMON SYSTEM DATA AREA (CSD). INITIALIZED BY NIP.", + "offset": 660, + "length": 4, + "type": "address", + "pointsTo": "dqiqe", + "programmingInterface": true + }, + { + "name": "CVTASMVT", + "description": "POINTER TO AUXILIARY STORAGE MANAGEMENT VECTOR TABLE (AMVT)", + "offset": 704, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "ASMVT" + } + ], + "pointsTo": "spost", + "programmingInterface": true + }, + { + "name": "CVTPCCAT", + "description": "POINTER TO PHYSICAL CCA VECTOR TABLE", + "offset": 764, + "length": 4, + "type": "address", + "pointsTo": "vxsft", + "programmingInterface": true + }, + { + "name": "CVTLCCAT", + "description": "POINTER TO LOGICAL CCA VECTOR TABLE", + "offset": 768, + "length": 4, + "type": "address", + "pointsTo": "vxsft", + "programmingInterface": true + }, + { + "name": "CVTVPSIB", + "description": "BRANCH ENTRY TO PAGE SERVICES", + "offset": 804, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IARPSIV" + } + ], + "programmingInterface": true + }, + { + "name": "CVTSCPIN", + "description": "ADDRESS OF IPL-TIME SCPINFO DATA BLOCK (ECVTSCPIN has address of \"current\"). Mapped by IHASCCB", + "offset": 832, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "CVTSVT", + "description": "ADDRESS POINTER FOR FETCH PROTECTED PSASVT.", + "offset": 868, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVESVT" + } + ], + "pointsTo": "vesvt", + "programmingInterface": true + }, + { + "name": "CVT0PT02", + "description": "ADDRESS OF POST ENTRY POINT IEA0PT02.", + "offset": 880, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEA0PT02" + } + ], + "pointsTo": "post", + "programmingInterface": true + }, + { + "name": "CVTEXP1", + "description": "ADDRESS OF EXIT PROLOGUE WHICH RETURNS TO THE DISPATCHER.", + "offset": 920, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVEXP1" + } + ], + "pointsTo": "vexp", + "programmingInterface": true + }, + { + "name": "CVTRAC", + "description": "ADDRESS OF ACCESS CONTROL CVT.", + "offset": 992, + "length": 4, + "type": "address", + "pointsTo": "access", + "programmingInterface": true + }, + { + "name": "CVT0PT0E", + "description": "ENTRY POINT TO IDENTIFY POST EXIT ROUTINES.", + "offset": 1004, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEA0PT0E" + } + ], + "pointsTo": "tso", + "programmingInterface": true + }, + { + "name": "CVT0PT03", + "description": "POST REINVOCATION ENTRY POINT FROM POST EXIT ROUTINES.", + "offset": 1008, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEA0PT03" + } + ], + "pointsTo": "tso", + "programmingInterface": true + }, + { + "name": "CVTHID", + "description": "ADDRESS OF SCP HOST ID.", + "offset": 1068, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IOSVHID" + } + ], + "pointsTo": "scp", + "programmingInterface": true + }, + { + "name": "CVTPSXM", + "description": "ADDRESS OF CROSS MEMORY PAGE FIX AND PAGE FREE.", + "offset": 1072, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IARPSXM" + } + ], + "pointsTo": "cross", + "programmingInterface": true + }, + { + "name": "CVTUCBSC", + "description": "ADDRESS OF UCB SCAN SERVICE.", + "offset": 1076, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IOSVSUCB" + } + ], + "pointsTo": "ucb", + "programmingInterface": true + }, + { + "name": "CVTVFIND", + "description": "THE POINTER TO VIRTUAL FETCH BUILD AND FIND ROUTINE.", + "offset": 1100, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CSVVFIND" + } + ], + "pointsTo": "virtual", + "programmingInterface": true + }, + { + "name": "CVTVFGET", + "description": "THE POINTER TO VIRTUAL FETCH GET ROUTINE.", + "offset": 1104, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CSVVFGET" + } + ], + "pointsTo": "virtual", + "programmingInterface": true + }, + { + "name": "CVTRCEP", + "description": "ADDRESS OF THE RSM CONTROL AND ENUMERATION AREA.", + "offset": 1168, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IARMRRCE" + } + ], + "programmingInterface": true + }, + { + "name": "CVTRCZRT", + "description": "", + "offset": 1188, + "length": 4, + "type": "signed-integer", + "init": [ + { + "type": "instruction", + "value": "SR 15,15" + } + ], + "programmingInterface": true + }, + { + "name": "CVTDFA", + "description": "ADDRESS OF DFP ID TABLE, MAPPED BY THE DFA. OWNERSHIP: DFP.", + "offset": 1216, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "DFAIDTAB" + } + ], + "pointsTo": "vnvt", + "programmingInterface": true + }, + { + "name": "CVTOSLVL", + "description": "SYSTEM LEVEL INDICATORS The presence of certain hardware functions is indicated within the SCCB (mapped by macro IHASCCB, pointed to by CVTSCPIN and/or ECVTSCPIN). The presence of other hardware functions can be found within CVT field CVTFLAGS2.", + "offset": 1264, + "length": 16, + "type": "hex", + "programmingInterface": true + } + ] + }, + { + "name": "cvtvstgx", + "description": "", + "fields": [ + { + "name": "CVTEPLPS", + "description": "Starting virtual address of extended PLPA. This is an interface for accessing the LPAT only.", + "offset": -200, + "length": 4, + "type": "address", + "programmingInterface": true + } + ] + }, + { + "name": "cvtxtnt2", + "description": "", + "fields": [ + { + "name": "CVTFLGBT", + "description": "Flag byte. This byte is an interface only for bits CVTUNDzVM (CVTUNDVM), CVTzPDT CVTUNDAltVM, CVTzPDT & CVTVMENV", + "offset": -251, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "CVTNPE": { + "description": "INDICATES NON-PAGING ENVIRONMENT (VM HANDSHAKING) (OS/VS1)", + "offset": 0, + "length": 1 + }, + "CVTVME": { + "description": "INDICATES MACHINE IS OPERATING IN VM ENVIRONMENT (OS/VS1)", + "offset": 1, + "length": 1 + }, + "CVTBAH": { + "description": "INDICATES THAT THE VM/370 - OS/VS1 BTAM AUTOPOLL HANDSHAKE IS OPERATIONAL (OS/VS1)", + "offset": 2, + "length": 1 + }, + "CVTUNDZVM": { + "description": "Running under z/VM (this is not the same as running under VICOM) Bit is set to 0 when CVTUNDAltVM is 1.", + "offset": 3, + "length": 1 + }, + "CVTUNDVM": { + "description": "Same as CVTUNDzVM", + "offset": 3, + "length": 1 + }, + "CVTVICOM": { + "description": "Running under VICOM", + "offset": 4, + "length": 1 + }, + "CVTZPDT": { + "description": "Running on zPDT (includes running on zD&T)", + "offset": 5, + "length": 1 + }, + "CVTUNDAltVM": { + "description": "Running under an alternate virtual machine environment. To determine which alternate virtual machine, the STSI output will list the control program identifier in field SI22V3DBCPIdentifier mapped by CSRSIIDF and can be obtained by the CSRSI service. Bit is set to 0 when CVTUNDzVM is 1", + "offset": 6, + "length": 1 + }, + "CVTVMENV": { + "description": "Running as a virtual machine environment. Bit is set to 1 when CVTUNDzVM or CVTUNDAltVM is set to 1", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "CVTLDTO", + "description": "LOCAL TIME/DATE OFFSET", + "offset": -203, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "CVTLSO", + "description": "LEAP SECOND OFFSET IN TOD FORMAT", + "offset": -179, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + } + ] + } + ], + "constants": [ + { + "name": "CVTPTR", + "value": 16, + "description": "ABSOLUTE ADDRESS OF POINTER TO CVT" + } + ] +} diff --git a/cbxp/mappings/ecvt.json b/cbxp/mappings/ecvt.json new file mode 100644 index 0000000..fc3e45d --- /dev/null +++ b/cbxp/mappings/ecvt.json @@ -0,0 +1,1075 @@ +{ + "version": 1, + "name": "ecvt", + "commonName": "Extended Communications Vector Table", + "macroId": "ihaecvt", + "description": "", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "cvt", + "psa" + ], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "ecvt", + "description": "", + "fields": [ + { + "name": "ECVTECVT", + "description": "ECVT ACRONYM", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "ECVT" + } + ], + "eyecatcher": true + }, + { + "name": "ECVTSPLX", + "description": "SYSPLEX NAME USED FOR DEBUGGING. OWNERSHIP: XCF. SERIALIZATION: N/A.", + "offset": 8, + "length": 8, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTAPPC", + "description": "ANCHOR FOR APPC DATA STRUCTURES OWNERSHIP: MVS/APPC SERIALIZATION: NONE", + "offset": 40, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTCSVN", + "description": "Counter Second Version Number for CPU counter facility", + "offset": 56, + "length": 2, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_Customer_Area_Addr", + "description": "Customer Area Address. - Address of a 128-byte area in - page-fixed, key 0, common - storage above 16M, below 2G. This - field is owned by the customer that - owns this system. No program should - modify this without the permission - of the owner. Non-zero as of - z/OS 2.2. Prior to z/OS 2.2, the - owning customer may take the steps - to allocate an area of storage and -", + "offset": 88, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVECAA" + } + ], + "pointsTo": "vecaa", + "equates": [ + { + "name": "ECVTCAA", + "value": "ECVT_Customer_Area_Addr" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTDPQH", + "description": "Queue of DU-AL Pools (DPHs) Ownership: PC Auth Serialization: Disp lock", + "offset": 96, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTSRBJ", + "description": "SRB-mode enclave join - A value of 0 in ECVTSRBJ means that the function is not available - Caller must be AMODE 31 or 64, key 0, supervisor state, enabled for I/O and external interrupts, holding no locks - SRB mode (preemptible non-Client SRB only) - Primary ASC mode - Any P, Any S, Any H - Set GR 1 to the below-2G address of the 8-byte enclave token. Bits 0-31 of 64-bit", + "offset": 144, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVJOIN" + } + ], + "pointsTo": "vjoin", + "programmingInterface": true + }, + { + "name": "ECVTSRBL", + "description": "SRB-mode enclave leave - A value of 0 in ECVTSRBL means that the function is not available - Caller must be AMODE 31 or 64, key 0, supervisor state, enabled for I/O and external interrupts, holding no locks - SRB mode - Primary ASC mode - Any P, Any S, Any H - Set GR 1 to the below-2G address of the 8-byte enclave token. Bits 0-31 of 64-bit", + "offset": 148, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVLEAV" + } + ], + "pointsTo": "vleav", + "programmingInterface": true + }, + { + "name": "ECVTTCP", + "description": "Token used by TCP/IP OWNERSHIP: TCPIP SERIALIZATION: Compare and Swap during TCPIP initialization", + "offset": 176, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTCSM", + "description": "Pointer to Communication Storage Manager control structure OWNERSHIP: VTAM (Communications Storage Manager(CSM)) SERIALIZATION: ENQUEUE/DEQUEUE", + "offset": 200, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTCTBL", + "description": "Customer anchor table. Slots assigned by IBM. Ownership: Callable Services. Serialization: None", + "offset": 204, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CSRCTABL" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTSLID", + "description": "CONTAINS THE SLIP PER TRAP ID OR BINARY ZEROS. OWNERSHIP: SLIP SERIALIZATION: NONE.", + "offset": 224, + "length": 4, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "pointsTo": "vexpm", + "programmingInterface": true + }, + { + "name": "ECVTOCVT", + "description": "ANCHOR FOR OpenMVS COMMUNICATION VECTOR TABLE. OWNERSHIP: OpenMVS. SERIALIZATION: COMPARE AND SWAP DURING OpenMVS INITIALIZATION.", + "offset": 240, + "length": 4, + "type": "address", + "equates": [ + { + "name": "ECVTOMVS", + "value": "X'80'", + "description": "If on, OpenMVS is up and available." + } + ], + "programmingInterface": true + }, + { + "name": "ECVTOEXT", + "description": "ANCHOR FOR OpenMVS EXTERNAL DATA THAT NEEDS TO BE ACCESSED BY NON-MVS CODE. OWNERSHIP: OpenMVS. SERIALIZATION: COMPARE AND SWAP DURING OpenMVS INITIALIZATION. (NEVER CHANGED AFTER INITIALIZATION)", + "offset": 244, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTCLON", + "description": "1 or 2 character value used to identify a system within a sysplex. Valid values are A-Z, 0-9, $, @, #. Not valid if blank. Serialization: None. Ownership: Supervisor Control.", + "offset": 264, + "length": 2, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTGMOD", + "description": "GRS mode of operation OWNERSHIP: GRS. SERIALIZATION: None.", + "offset": 266, + "length": 1, + "type": "hex", + "equates": [ + { + "name": "ECVTGNON", + "value": "0", + "description": "GRS operating with option NONE." + }, + { + "name": "ECVTGRNG", + "value": "1", + "description": "GRS operating in ring mode." + }, + { + "name": "ECVTGSTA", + "value": "2", + "description": "GRS operating in star mode." + } + ], + "programmingInterface": true + }, + { + "name": "ECVTLPDELEN", + "description": "Length of LPDE", + "offset": 267, + "length": 1, + "type": "hex", + "programmingInterface": true + }, + { + "name": "ECVTDUCU", + "description": "DUCT update", + "offset": 268, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVDUCU" + } + ], + "pointsTo": "vducu", + "programmingInterface": true + }, + { + "name": "ECVTALCK", + "description": "ALIAS check", + "offset": 272, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVALCK" + } + ], + "pointsTo": "valck", + "programmingInterface": true + }, + { + "name": "ECVTSXMP", + "description": "IEAMSXMP target. This field is an interface only for determining if IEAMSXMP may be used. When this field is 0, IEAMSXMP may not be used, otherwise it may be.", + "offset": 276, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVSXMP" + } + ], + "pointsTo": "vsxmp", + "programmingInterface": true + }, + { + "name": "ECVTLSAB", + "description": "Pointer to Logger Services Anchor Block. Mapped by IXGPLSAB macro. OWNERSHIP: IXG. SERIALIZATION: None.", + "offset": 288, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IXGLSAB" + } + ], + "pointsTo": "logger", + "programmingInterface": true + }, + { + "name": "ECVTSYMT", + "description": "Address of the system static symbol table. The system static symbol table is mapped by dsect SYMBT within ASASYMBP. The table is preceded by an area mapped by dsect SYMBTH within ASASYMBP. Serialization: None. Ownership: NIP", + "offset": 296, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTFLG1", + "description": "First miscellaneous flag Serialization: None. Ownership: NIP", + "offset": 304, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "ECVTCLNU": { + "description": "When set, this flag indicates that the system static symbol &SYSCLONE value defined in an IEASYMxx member used for this IPL must be unique in the SYSPLEX. Serialization: None. Ownership: NIP", + "offset": 0, + "length": 1 + }, + "ECVTPMAC": { + "description": "Serialization: None. Ownership: NIP", + "offset": 1, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "ECVTVSER", + "description": "Reserved for use by VSE Ownership: VSE Serialization: none", + "offset": 324, + "length": 4, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "00000000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTLSEN", + "description": "Address of module IEAVLSEN", + "offset": 328, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVLSEN" + } + ], + "pointsTo": "vlsen", + "programmingInterface": true + }, + { + "name": "ECVTDGNB", + "description": "Address of DGNB Serialization: None. Ownership: VSM", + "offset": 332, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IGVDGNBT" + } + ], + "pointsTo": "dgnb", + "programmingInterface": true + }, + { + "name": "ECVTHDNM", + "description": "Hardware name of the processor configuration. Serialization: None. Ownership: NIP", + "offset": 336, + "length": 8, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTLPNM", + "description": "LPAR name of the processor configuration. This field is blanks if processor is not in LPAR mode. Serialization: None. Ownership: NIP", + "offset": 344, + "length": 8, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTVMNM", + "description": "z/VM user id of the virtual machine, of which this z/OS image is a guest. This field is blanks if the processor is not a guest under z/VM (such as running under PR/SM or an alternate VM). Serialization: None. Ownership: NIP", + "offset": 352, + "length": 8, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTIPA", + "description": "Address of the Initialization Parameter Area Serialization: None. Ownership: NIP", + "offset": 392, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTPSEQ", + "description": "Product sequence number. This field will be changed when any new version, release, or modification level is provided. It can be used to determine if the operating system is at a suitable level for a desired function. Its value will always increase from one release/mod level to the next. For z/OS 3.2 (HBB77F0), the value is For z/OS 3.1 (HBB77E0), the value is For z/OS 2.5 (HBB77D0), the value is", + "offset": 476, + "length": 4, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "00000000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPOWN", + "description": "Product owner", + "offset": 480, + "length": 16, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPNAM", + "description": "Product name.", + "offset": 496, + "length": 16, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPVER", + "description": "Product version", + "offset": 512, + "length": 2, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPREL", + "description": "Product release", + "offset": 514, + "length": 2, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPMOD", + "description": "Product mod level", + "offset": 516, + "length": 2, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPDVL", + "description": "Product development level. Note: This field is used for web deliverable for which the Product Modification Level is not changed.", + "offset": 518, + "length": 1, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTDLPF", + "description": "Address of first CDE on dynamic LPA queue. Ownership: CSV Only CSV is allowed to change this. Serialization: CMS Lock", + "offset": 552, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTDLPL", + "description": "Address of last CDE on dynamic LPA queue. It is intended that the CDHAIN field of this CDE point to the CDE pointed to by the word pointed to by CVTQLPAQ Ownership: CSV Only CSV is allowed to change this. Serialization: CMS Lock", + "offset": 556, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVTPIDN", + "description": "PID number", + "offset": 568, + "length": 8, + "type": "string", + "init": [ + { + "type": "string", + "value": " " + } + ], + "programmingInterface": true + }, + { + "name": "ECVTCRDT", + "description": "Entry for RACF to get CDRACDTY bits set", + "offset": 648, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CSVRCDTY" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTCTB2", + "description": "Customer anchor table 2 (8-byte slots) Slots assigned by IBM. Ownership: Callable Services. Serialization: None", + "offset": 652, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CSRCTAB2" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTJAOF", + "description": "Address of IEAVJAOF when not 0. Use this when you must turn off JSCBAUTH. The system might have additional functions to perform when this is done. The JSCBAUTH bit in the JSCB pointed to by the current task's jobstep task's JSCB will be turned off. For system integrity reasons you should not turn JSCBAUTH back on once it has been turned off. - Caller must be AMODE 31 or AMODE 64. - Caller must be supervisor state and key 0", + "offset": 656, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVJAOF" + } + ], + "pointsTo": "vjaof", + "programmingInterface": true + }, + { + "name": "ECVTCACHELINESIZE", + "description": "CPU Cache Line Size", + "offset": 704, + "length": 2, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTCACHELINESTARTBDY", + "description": "CPU Cache Line Start Boundary", + "offset": 706, + "length": 1, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_OSProtect", + "description": "- OSPROTECT system parameter in effect. X'00' indicates OSPROTECT=SYSTEM. See ECVT_OSProtect_WhenSystem. X'01' indicates OSPROTECT=1. X'FF' indicates OSPROTECT=MIN. A value in the range x'01'-x'FE' indicates \"more than minimum\"", + "offset": 707, + "length": 1, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_Installed_CPU_HWM", + "description": "The highest CPU number currently installed within this IPL. Could increase upon dynamic CPU addition", + "offset": 712, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_Installed_CPU_At_IPL", + "description": "The highest CPU number installed at the time of IPL.", + "offset": 714, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTFACL", + "description": "Address of 2048-byte facility area mapped by IHAFACL.", + "offset": 852, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVFACL" + } + ], + "pointsTo": "vfacl", + "programmingInterface": true + }, + { + "name": "ECVTMaxCoreID", + "description": "When CvtProcAsCore is on, the maximum CPU Core Id allowed in the system for this IPL. When CvtProcAsCore is off, this will be set to CVTMAXMP.", + "offset": 856, + "length": 2, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ECVTNumCPUIDsInCore", + "description": "The maximum number of CPUs that can \"fit\" on a CPU Core. This doesn't mean all of them can be active. This can be looked at as how many IDs exist between thread 0 of two contiguous cores. When CvtProcAsCore is off, this will be set to 1.", + "offset": 858, + "length": 2, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "ECVTMaxMPNumBytesInMask", + "description": "Maximum number of bytes a bitmask of CVTMAXMP bits would take up, rounded to a multiple of 8", + "offset": 888, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTPhysicalToLogicalMask", + "description": "\"OR\" this value with a CPUs physical ID to obtain its logical ID", + "offset": 890, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTLogicalToPhysicalMask", + "description": "\"AND\" this value with a CPUs logical ID to obtain its physical ID", + "offset": 892, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "ECVTAppFlags", + "description": "Application-set flags Serialization: CS", + "offset": 894, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "0" + } + ], + "bitmasks": { + "ECVTStcksyncReplaced": { + "description": "A product has replaced system control block fields that contain the entry point addresses for STCKSYNC services. The system is not to reset these fields to their IPL-time values.", + "offset": 0, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "ECVT_OSProtect_WhenSystem", + "description": "As of z/OS 3.1, the OSPROTECT level you get when OSPROTECT=SYSTEM is in effect. Valid only when OSPROTECT=SYSTEM is in effect. Current possible values are: X'01' indicating OSPROTECT=1 (not on zPDT), X'FF' indicating OSPROTECT=MIN (on zPDT) A value in the range x'01'-x'FE' indicates \"more than minimum\"", + "offset": 895, + "length": 1, + "type": "hex", + "programmingInterface": true + }, + { + "name": "ECVT_GetSrbIdToken", + "description": "Address of the routine to return the SrbIdToken of the current preemptible- class SRB - Caller must be running under the preemptible- class SRB for which the SrbIdToken is to be returned. - Caller may be AMODE 31 or 64, must be key 0 Supervisor state. - Caller may hold any locks, none are required. - Primary ASC mode. - Any P, Any S, Any H.", + "offset": 896, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVSCHY" + } + ], + "pointsTo": "vschy", + "programmingInterface": true + }, + { + "name": "ECVTXTSW", + "description": "Address of \"Cross-memory TCB or SRB wait\" routine. - Caller must be AMODE 31, key 0, supervisor state, enabled for I/O and external interrupts, holding no locks. - SRB or task mode. - Primary ASC mode. - Any P, Any S, Any H. - Load this address into GR 15, - Issue BASR 14,15 - 31-bit GRs 2-13, high halves 2-14, and", + "offset": 900, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "ISGXSRBW" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_SMF_CMS_LockInst_Addr", + "description": "Address of the SMF CMS instrumentation data for the system", + "offset": 904, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CMSSMFLP" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_ENQDEQ_CMS_LockInst_Addr", + "description": "Address of the ENQ/DEQ CMS instrumentation data for the system", + "offset": 908, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CMSEDLPP" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_LATCH_CMS_LockInst_Addr", + "description": "Address of the Latch CMS instrumentation data for the system", + "offset": 912, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CMSLATLP" + } + ], + "programmingInterface": true + }, + { + "name": "ECVT_CMS_LockInst_Addr", + "description": "Address of the CMS instrumentation data for the system", + "offset": 916, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "CMSLP" + } + ], + "programmingInterface": true + }, + { + "name": "Ecvt_Installed_Core_HWM", + "description": "The highest core number currently installed. Could increase upon dynamic core/CPU addition.", + "offset": 940, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "Ecvt_Installed_Core_At_IPL", + "description": "The highest core number installed at the time of IPL.", + "offset": 942, + "length": 2, + "type": "signed-integer", + "init": [ + { + "type": "hex", + "value": "0000" + } + ], + "programmingInterface": true + }, + { + "name": "EcvtLSO", + "description": "Leap second value in STCKE format. Bytes 1-8 (0 origin) have same value as CVTLSO", + "offset": 944, + "length": 16, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "EcvtLDTO", + "description": "Local time/date offset in STCKE format. Bytes 1-8 (0-origin) have same value as CVTLDTO. Byte 0 is sign extended from bit 0 of byte 1", + "offset": 960, + "length": 16, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "Ecvt_BoostInfo", + "description": "Valid only when CVTBoost is on", + "offset": 992, + "length": 24, + "type": "hex", + "programmingInterface": true + }, + { + "name": "Ecvt_BoostInfo_V1", + "description": "Recovery process boost support. Valid when Ecvt_BoostLevel is at least Ecvt_BoostLevel_V1", + "offset": 1016, + "length": 32, + "type": "hex", + "programmingInterface": true + }, + { + "name": "ECVT_BoostInfo_V2", + "description": "", + "offset": 1048, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "Ecvt_zIIPBoostCoresAddr", + "description": "When not 0, the address of an area that is a bit string of which cores were config'd online for a boost. Each bit corresponds to a core (bit 0 is core 0, bit 1 is core 1, etc). When bit n is on, core n is considered a zIIP boost core", + "offset": 1076, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "Ecvt_IFunc_Addr", + "description": "Address of area mapped by IHAIFUNC indicating which function codes of such instructions as PRNO, KIMD, KLMD are available.", + "offset": 1080, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "ECVT_MaxTOD", + "description": "A value that will not be reached by the clock comparator for this IPL. That is x'FFFFFFFF_FFFFFFFF' when a signed CC is not used, x'7FFFFFFF_FFFFFFFF' when a signed CC is used", + "offset": 1088, + "length": 8, + "type": "bitstring", + "equates": [ + { + "name": "ECVT_max_highestCPUID", + "value": "ECVT_zOSV2R1_highestCPUID", + "description": "The highest physical CPU ID allowed in a z/OS system. If you use this equate, you must be prepared to reassemble if this value changes in a new release. IBM recommends using CVTMAXMP at runtime." + }, + { + "name": "ECVT_max_CPUMaskSizeInBits", + "value": "ECVT_zOSV2R1_CPUMaskSizeInBits", + "description": "The maximum number of bits needed to allocate storage at assemble time to guarantee enough storage to hold a full CPU mask of any current or prior release. If you use this equate, you must be prepared to reassemble if this value changes in a new release. IBM recommends using CVTMAXMP at runtime." + }, + { + "name": "ECVT_max_CPUMaskSizeInBytes", + "value": "ECVT_max_CPUMaskSizeInBits/8", + "description": "/8 The maximum number of bytes needed to allocate storage at assemble time to guarantee enough storage to hold a full CPU mask of of any current or prior release. If you use this equate, you must be prepared to reassemble if this value changes in a new release. IBM recommends using ECVTMaxMPNumBytesInMask at runtime." + }, + { + "name": "ECVT_zOSV2R1_highestCPUID", + "value": "255", + "description": "The highest physical CPU ID allowed in a z/OS system up to and including z/OS V2R1. This constant will never change. IBM recommends using CVTMAXMP at runtime." + }, + { + "name": "ECVT_zOSV2R1_CPUMaskSizeInBits", + "value": "256", + "description": "The number of bits needed to allocate storage at assemble time to guarantee enough storage to hold a full CPU mask up to and including release z/OS V2R1. This constant will never change. IBM recommends using CVTMAXMP at runtime." + }, + { + "name": "ECVT_zOSV2R1_CPUMaskSizeInBytes", + "value": "ECVT_zOSV2R1_CPUMaskSizeInBits/8", + "description": "/8 Number of bytes needed to allocate storage at assemble time to guarantee enough storage to hold a full CPU mask up to and including release z/OS V2R1. This constant will never change. IBM recommends using ECVTMaxMPNumBytesInMask at runtime." + }, + { + "name": "ECVT_zOSR11_highestCPUID", + "value": "99", + "description": "The highest physical CPU ID allowed in a z/OS system up to and including z/OS V1R11. This constant will never change. IBM recommends using CVTMAXMP at runtime." + }, + { + "name": "ECVT_zOSR11_CPUMaskSizeInBits", + "value": "128", + "description": "The number of bits needed to allocate storage at assemble time to guarantee enough storage to hold a full CPU mask up to and including release z/OS V1R11. This constant will never change. IBM recommends using CVTMAXMP at runtime." + }, + { + "name": "ECVT_zOSR11_CPUMaskSizeInBytes", + "value": "ECVT_zOSR11_CPUMaskSizeInBits/8", + "description": "/8 The number of bytes needed to allocate storage at assemble time to guarantee enough storage to hold a full CPU mask up to and including release z/OS V1R11. This constant will never change. IBM recommends using ECVTMaxMPNumBytesInMask at runtime." + }, + { + "name": "Ecvt_RPBReq_Not_Identified", + "value": "0" + }, + { + "name": "Ecvt_RPBReq_Sysplex_Partitioning", + "value": "1" + }, + { + "name": "Ecvt_RPBReq_CF_Structure_Recov", + "value": "2" + }, + { + "name": "Ecvt_RPBReq_CF_Datasharing_Member_Recov", + "value": "3" + }, + { + "name": "Ecvt_RPBReq_Hyperswap", + "value": "4" + }, + { + "name": "Ecvt_RPBReq_SVCDump", + "value": "5" + }, + { + "name": "Ecvt_RPBReq_Middleware_Region_Startup", + "value": "6" + }, + { + "name": "Ecvt_RPBReq_Hyperswap_Config_Load", + "value": "7" + }, + { + "name": "Ecvt_RPBReq_Dynamic_IO_Activate", + "value": "8" + } + ], + "bitmasks": { + "Ecvt_BoostClass_Mask": { + "description": "ecvt_boostclass_mask", + "offset": 61, + "length": 3 + }, + "Ecvt_BoostClass_IPL": { + "description": "ecvt_boostclass_ipl", + "offset": 63, + "length": 1 + }, + "Ecvt_BoostClass_ShutDown": { + "description": "ecvt_boostclass_shutdown", + "offset": 62, + "length": 1 + }, + "Ecvt_BoostClass_RP": { + "description": "ecvt_boostclass_rp", + "offset": 62, + "length": 2 + } + }, + "programmingInterface": true + } + ] + } + ] +} diff --git a/cbxp/mappings/ldax.json b/cbxp/mappings/ldax.json new file mode 100644 index 0000000..a78c80a --- /dev/null +++ b/cbxp/mappings/ldax.json @@ -0,0 +1,223 @@ +{ + "version": 1, + "name": "ldax", + "commonName": "VSM Local Data Area Extension", + "macroId": "ihaldax", + "description": "The LDAX (Local Data Area Extension) contains information about address space related virtual storage. Owned by Virtual Storage Manager (SC1CH). Size: X'0080' bytes (128 bytes). Created by IEAMSWCB and IEAVEMRQ.", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "assb" + ], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "ldax", + "description": "", + "fields": [ + { + "name": "LDAX_HEADER", + "description": "Header area (eye-catcher + version)", + "offset": 0, + "length": 8, + "type": "string" + }, + { + "name": "LDAX_ID", + "description": "Eye-catcher ID - 'LDAX'", + "offset": 0, + "length": 4, + "type": "string" + }, + { + "name": "LDAX_VERSION", + "description": "Version byte", + "offset": 4, + "length": 1, + "type": "bitstring" + }, + { + "name": "LDAX_LDAASCB", + "description": "Address of ASCB for this address space", + "offset": 8, + "length": 4, + "type": "address", + "pointsTo": "ascb" + }, + { + "name": "LDAX_LDASTRTA", + "description": "Low address of Region (below 16M)", + "offset": 12, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDASIZA", + "description": "Size of Region (below 16M)", + "offset": 16, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_LDAESTRA", + "description": "Low address of extended Region (above 16M)", + "offset": 20, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDAESIZA", + "description": "Size of extended Region (above 16M)", + "offset": 24, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_LDACRGTP", + "description": "Current high address of PRIVATE AREA Region (below 16M)", + "offset": 28, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDAERGTP", + "description": "Current high address of EXTENDED PRIVATE AREA Region (above 16M)", + "offset": 32, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDALIMIT", + "description": "Below 16M V=V Region limit value", + "offset": 36, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDAVVRG", + "description": "Below 16M V=V Region high value", + "offset": 40, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDAELIM", + "description": "Above 16M V=V Region limit value", + "offset": 44, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDAEVVRG", + "description": "Above 16M V=V Region high value", + "offset": 48, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDALOAL", + "description": "Below 16M USER Region alloc value", + "offset": 52, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_LDAHIAL", + "description": "Below 16M AUTH Region alloc value", + "offset": 56, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_LDAELOAL", + "description": "Above 16M USER Region alloc value", + "offset": 60, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_LDAEHIAL", + "description": "Above 16M AUTH Region alloc value", + "offset": 64, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_TCTVALUS", + "description": "TCT water marks (overlays LDAX_TCTHWM through LDAX_TCTELWM)", + "offset": 68, + "length": 16, + "type": "hex" + }, + { + "name": "LDAX_TCTHWM", + "description": "Below 16M max virtual storage in SWA and LSQA", + "offset": 68, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_TCTLWM", + "description": "Below 16M max virtual storage in user subpools", + "offset": 72, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_TCTEHWM", + "description": "Above 16M max virtual storage in SWA and LSQA", + "offset": 76, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_TCTELWM", + "description": "Above 16M max virtual storage in user subpools", + "offset": 80, + "length": 4, + "type": "signed-integer" + }, + { + "name": "LDAX_CURHIGHBOT", + "description": "Below 16M current bottom of AUTH area", + "offset": 84, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_CUREHIGHBOT", + "description": "Above 16M current bottom of extended AUTH area", + "offset": 88, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDASMAD", + "description": "Storage Management Area address", + "offset": 92, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_LDASMSZ", + "description": "Storage Management Size", + "offset": 96, + "length": 4, + "type": "address" + }, + { + "name": "LDAX_END", + "description": "End of LDAX / reserved", + "offset": 128, + "length": 1, + "type": "hex", + "endOfControlBlock": true + } + ] + } + ] +} diff --git a/cbxp/mappings/oucb.json b/cbxp/mappings/oucb.json new file mode 100644 index 0000000..67214f4 --- /dev/null +++ b/cbxp/mappings/oucb.json @@ -0,0 +1,1348 @@ +{ + "version": 1, + "name": "oucb", + "commonName": "Resources Manager User Control Block", + "macroId": "iraoucb", + "description": "The OUCB describes the status of the associated memory (user) to the system resources manager. It contains resource usage information needed to decide when to swap-in the memory. The OUCB is positioned on transitional system resources manager chains to indicate actions to be taken for that memory. Owned by Systems Resource Manager (SC1CX). Subpool 245, ESQA, key 0, above 16M line. Size: 2048 bytes (X'800'). Created by IRAEVMEM and IRARMERR.", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "ascb" + ], + "storageAttributes": { + "subpools": [ + 245 + ], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "oucb", + "description": "First 256 bytes of OUCB (first two cache lines)", + "fields": [ + { + "name": "OUCBNAME", + "description": "Block identification eye-catcher - 'OUCB'", + "offset": 0, + "length": 4, + "type": "string" + }, + { + "name": "OUCBFWD", + "description": "Swap chain forward pointer", + "offset": 4, + "length": 4, + "type": "address", + "pointsTo": "oucb" + }, + { + "name": "OUCBBCK", + "description": "Swap chain backward pointer", + "offset": 8, + "length": 4, + "type": "address", + "pointsTo": "oucb" + }, + { + "name": "OUCBTMA", + "description": "Time of last analysis", + "offset": 12, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBQFL", + "description": "Swappability transition flags", + "offset": 16, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBGOO": { + "description": "Address space is being swapped out or logically swapped", + "offset": 0, + "length": 1 + }, + "OUCBGOI": { + "description": "Transitioning into core", + "offset": 1, + "length": 1 + }, + "OUCBGOB": { + "description": "Transitioning between states", + "offset": 2, + "length": 1 + }, + "OUCBQSFL": { + "description": "QSCEFL recursion flag", + "offset": 3, + "length": 1 + }, + "OUCBOFF": { + "description": "Requesting enter wait state", + "offset": 4, + "length": 1 + }, + "OUCBOUT": { + "description": "Requesting enter out state", + "offset": 5, + "length": 1 + }, + "OUCBLSW": { + "description": "Logically swapped", + "offset": 6, + "length": 1 + }, + "OUCBDLYB": { + "description": "Delayed by RTO on out queue", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBSFL", + "description": "Swapout continuation flags", + "offset": 17, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBNSW": { + "description": "Non-swappable status", + "offset": 0, + "length": 1 + }, + "OUCBCTI": { + "description": "CTL inhibits quiesce", + "offset": 1, + "length": 1 + }, + "OUCBBIB": { + "description": "Bring in for cancel", + "offset": 2, + "length": 1 + }, + "OUCBINV": { + "description": "OUCB is invalid", + "offset": 3, + "length": 1 + }, + "OUCBNSWI": { + "description": "Prevent swap in", + "offset": 4, + "length": 1 + }, + "OUCBPVL": { + "description": "Privileged program running", + "offset": 5, + "length": 1 + }, + "OUCBENQ": { + "description": "ENQ resident status", + "offset": 6, + "length": 1 + }, + "OUCBSCN": { + "description": "Swap chain termination mark", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBYFL", + "description": "User type flags", + "offset": 18, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBPSTE": { + "description": "Post error", + "offset": 0, + "length": 1 + }, + "OUCBSTT": { + "description": "START created user", + "offset": 1, + "length": 1 + }, + "OUCBLOG": { + "description": "Logon created user", + "offset": 2, + "length": 1 + }, + "OUCBMNT": { + "description": "Mount created user", + "offset": 3, + "length": 1 + }, + "OUCBRSFL": { + "description": "Restore fail", + "offset": 4, + "length": 1 + }, + "OUCBAXS": { + "description": "Aux shortage forced swap", + "offset": 5, + "length": 1 + }, + "OUCBDTA": { + "description": "Data accumulation impacted", + "offset": 6, + "length": 1 + }, + "OUCBFXS": { + "description": "Fixed storage forced swap", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBAFL", + "description": "Algorithm status flags", + "offset": 19, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBIRSW": { + "description": "RealSwap in pending", + "offset": 0, + "length": 1 + }, + "OUCBAPG": { + "description": "APG algorithm applicable", + "offset": 1, + "length": 1 + }, + "OUCBREPT": { + "description": "RPGNs are present", + "offset": 2, + "length": 1 + }, + "OUCBENQI": { + "description": "OUCBENQ was on at some point during the policy adjustment interval (goal mode only)", + "offset": 3, + "length": 1 + }, + "OUCBJSR": { + "description": "JobSelect received", + "offset": 4, + "length": 1 + }, + "OUCBMXS": { + "description": "Memory pool shortage forced swap", + "offset": 5, + "length": 1 + }, + "OUCBNWT": { + "description": "MSO detected nonswappable wait", + "offset": 6, + "length": 1 + }, + "OUCBASW": { + "description": "Authorized for dontswap", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBTFL", + "description": "Transaction status flags", + "offset": 20, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBATR": { + "description": "Transaction in existence", + "offset": 0, + "length": 1 + }, + "OUCBSTR": { + "description": "Transaction start pending", + "offset": 1, + "length": 1 + }, + "OUCBNTR": { + "description": "Transaction stop pending", + "offset": 2, + "length": 1 + }, + "OUCBRTR": { + "description": "Transaction resume pending", + "offset": 3, + "length": 1 + }, + "OUCBPCH": { + "description": "Performance group period change pending", + "offset": 4, + "length": 1 + }, + "OUCBMAR": { + "description": "Activity recording subtract flag", + "offset": 5, + "length": 1 + }, + "OUCBINP": { + "description": "Initiator attach pending", + "offset": 6, + "length": 1 + }, + "OUCBINC": { + "description": "Initiator attach current", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBEFL", + "description": "Event status flags", + "offset": 21, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBLWT": { + "description": "Long wait status", + "offset": 0, + "length": 1 + }, + "OUCBQSFLP2": { + "description": "QSCEFL swap-out phase 2", + "offset": 2, + "length": 1 + }, + "OUCBQSC": { + "description": "QSCECMP event processed", + "offset": 6, + "length": 1 + }, + "OUCBMWT": { + "description": "MSO detected wait status", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBASSTATUS", + "description": "Address space status flags", + "offset": 22, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBASINIT": { + "description": "Address space initialization done", + "offset": 0, + "length": 1 + }, + "OUCBASTERM": { + "description": "Address space termination started", + "offset": 1, + "length": 1 + }, + "OUCBASSINIT": { + "description": "Address space step initialization done", + "offset": 2, + "length": 1 + }, + "OUCBASSTERM": { + "description": "Address space step termination done", + "offset": 3, + "length": 1 + }, + "OUCBASRSV4": { + "description": "Reserved", + "offset": 4, + "length": 1 + }, + "OUCBASRSV5": { + "description": "Reserved", + "offset": 5, + "length": 1 + }, + "OUCBASRSV6": { + "description": "Reserved", + "offset": 6, + "length": 1 + }, + "OUCBASRSV7": { + "description": "Reserved", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBUFL", + "description": "User type flags", + "offset": 23, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBJSFS": { + "description": "Job select delayed", + "offset": 0, + "length": 1 + }, + "OUCBJSAS": { + "description": "Job select delayed (alternate)", + "offset": 1, + "length": 1 + }, + "OUCBNSWDP": { + "description": "NSW address space currently non-dispatchable", + "offset": 2, + "length": 1 + }, + "OUCBTSWP": { + "description": "TransSwap in progress", + "offset": 3, + "length": 1 + }, + "OUCBTSWC": { + "description": "TransSwap complete", + "offset": 4, + "length": 1 + }, + "OUCBSI": { + "description": "Storage isolation control active", + "offset": 5, + "length": 1 + }, + "OUCBENQR": { + "description": "OUCBENQ on during RA interval", + "offset": 6, + "length": 1 + }, + "OUCBSIFX": { + "description": "Fixed target working set size for GRS storage isolation", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBLFL", + "description": "Algorithm status flags", + "offset": 24, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBEAS": { + "description": "Early address space that has not been through InitAtt yet", + "offset": 0, + "length": 1 + }, + "OUCBQSRV": { + "description": "Space was managed as a server when it was quiesced", + "offset": 1, + "length": 1 + }, + "OUCBRQSC": { + "description": "Quiesced by reset command", + "offset": 2, + "length": 1 + }, + "OUCBFWA": { + "description": "Fast workload acceptance application", + "offset": 3, + "length": 1 + }, + "OUCBTET": { + "description": "TransSwap expiration timer", + "offset": 4, + "length": 1 + }, + "OUCBREDP": { + "description": "Reduced preemption required", + "offset": 5, + "length": 1 + }, + "OUCBPRF": { + "description": "Previous resource failure", + "offset": 6, + "length": 1 + }, + "OUCBSTGI": { + "description": "Address space has been recognized initializing storage", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBRFL", + "description": "More user flags", + "offset": 25, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBCSFS": { + "description": "Swap in fail defer bit - user on wait queue", + "offset": 0, + "length": 1 + }, + "OUCBCSFM": { + "description": "Swap in message required", + "offset": 1, + "length": 1 + }, + "OUCBEASI": { + "description": "Early address space", + "offset": 2, + "length": 1 + }, + "OUCBHIDP": { + "description": "Early address space needs high priority", + "offset": 3, + "length": 1 + }, + "OUCBBJOB": { + "description": "Address space is running a batch job", + "offset": 4, + "length": 1 + }, + "OUCBSTFX": { + "description": "Fixed below frames are stealable indicator", + "offset": 5, + "length": 1 + }, + "OUCBDFSW": { + "description": "Swap in fail special processing - real thresholds raised on behalf of the address space's primary working set", + "offset": 6, + "length": 1 + }, + "OUCBLLSW": { + "description": "Last swap was logical", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBNDP", + "description": "New ASCB dispatching priority", + "offset": 26, + "length": 1, + "type": "bitstring" + }, + { + "name": "OUCBTNDP", + "description": "New TS dispatching priority", + "offset": 27, + "length": 1, + "type": "bitstring" + }, + { + "name": "OUCBMFL", + "description": "Miscellaneous flags", + "offset": 28, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBSBT": { + "description": "Stole below threshold", + "offset": 0, + "length": 1 + }, + "OUCBAFAP": { + "description": "Auxiliary swap-in frame allocation is pending for primary working set (MCVCAPWS was raised)", + "offset": 1, + "length": 1 + }, + "OUCBDFS2": { + "description": "Thresholds raised by secondary working set size", + "offset": 2, + "length": 1 + }, + "OUCBMGSW": { + "description": "Selected for migration swap (ESA mode only, do not use in z/OS)", + "offset": 3, + "length": 1 + }, + "OUCBDISC": { + "description": "Frames are included in the logical swap discretionary count (ESA mode only, do not use in z/OS)", + "offset": 4, + "length": 1 + }, + "OUCBASAP": { + "description": "Secondary working set allocation pending", + "offset": 5, + "length": 1 + }, + "OUCBMPUR": { + "description": "Selected for migration purge (ESA mode only, do not use in z/OS)", + "offset": 6, + "length": 1 + }, + "OUCBACNT": { + "description": "Account number specified on job", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBIAC", + "description": "Initiator attach count", + "offset": 29, + "length": 1, + "type": "signed-integer" + }, + { + "name": "OUCBRSV1", + "description": "Reserved", + "offset": 30, + "length": 1, + "type": "hex" + }, + { + "name": "OUCBPGP", + "description": "Current WPGP offset in WPGD; goal mode: period number", + "offset": 31, + "length": 1, + "type": "signed-integer" + }, + { + "name": "OUCBWSCI", + "description": "Goal mode: service class index", + "offset": 32, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBWRCI", + "description": "Goal mode: report class index", + "offset": 34, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBMFL2", + "description": "More miscellaneous flags, serialized by SRM lock", + "offset": 36, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBVFMG": { + "description": "Message issued on behalf of address space swapped out due to vector wait", + "offset": 0, + "length": 1 + }, + "OUCBMGIN": { + "description": "SRM has requested that RSM inhibit migration of DREF pages (ESA mode only)", + "offset": 1, + "length": 1 + }, + "OUCBAFPD": { + "description": "Auxiliary swap-in frame allocation is pending for swap-in of DREF pages (MCVCAPWS was raised)", + "offset": 2, + "length": 1 + }, + "OUCBDFDR": { + "description": "Real thresholds were raised on behalf of the DREF pages in the address space", + "offset": 3, + "length": 1 + }, + "OUCBDFDE": { + "description": "Expanded storage thresholds were raised on behalf of the DREF pages (ESA mode only)", + "offset": 4, + "length": 1 + }, + "OUCBMIGP": { + "description": "MIGPURGE indicator: address space has been returned to RSM for this instance of MIGPURGE (ESA mode only)", + "offset": 5, + "length": 1 + }, + "OUCBRPT1": { + "description": "First time of entry into RPT - Raise Processor Threshold (ESA mode only)", + "offset": 6, + "length": 1 + }, + "OUCBERST": { + "description": "Eligible for restart flag", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBMFL3", + "description": "More miscellaneous flags", + "offset": 37, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBAPPC": { + "description": "APPC transaction program", + "offset": 0, + "length": 1 + }, + "OUCBPMON": { + "description": "This address space is being monitored", + "offset": 1, + "length": 1 + }, + "OUCBVALV": { + "description": "Working set management recommendation value is valid", + "offset": 2, + "length": 1 + }, + "OUCBOMVS": { + "description": "OpenMVS transaction program", + "offset": 3, + "length": 1 + }, + "OUCBTBMN": { + "description": "Address space is to be monitored when enough data has been gathered about it", + "offset": 4, + "length": 1 + }, + "OUCBSTTA": { + "description": "OUCBWKTM for this address space has been added to the system transaction time in the workload activity reporting table for the period", + "offset": 5, + "length": 1 + }, + "OUCBGWRK": { + "description": "Initiator started using GETWORK interface", + "offset": 6, + "length": 1 + }, + "OUCBINIT": { + "description": "Started task is an initiator", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBDMO", + "description": "Offset into domain table; valid only in compatibility mode", + "offset": 38, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBDMN", + "description": "Domain number", + "offset": 40, + "length": 1, + "type": "signed-integer" + }, + { + "name": "OUCBSRC", + "description": "Swap out reason code", + "offset": 41, + "length": 1, + "type": "signed-integer" + }, + { + "name": "OUCBSWC", + "description": "Transaction swap count", + "offset": 42, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBTMW", + "description": "WLM interval start time", + "offset": 52, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBWMS", + "description": "Interval service accumulator", + "offset": 56, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBCPU", + "description": "Interval CPU service accumulator", + "offset": 60, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBIOC", + "description": "Deprecated (interval I/O service no longer accumulated)", + "offset": 64, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBMSO", + "description": "Deprecated (interval MSO service no longer accumulated)", + "offset": 68, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTMS", + "description": "Time of last swap action", + "offset": 72, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTMO", + "description": "Transaction start time", + "offset": 76, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBDRFR", + "description": "Count of DREF pages in real storage; updated from values returned from RSM IARXCNTF routine", + "offset": 80, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBCSW", + "description": "Compare and swap field", + "offset": 88, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBACN", + "description": "Deferred action flags (2-byte array at offset 0x58)", + "offset": 88, + "length": 1, + "type": "bitstring" + }, + { + "name": "OUCBCFL", + "description": "Multiprocess condition flags", + "offset": 90, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBRDY": { + "description": "UserRdy event received", + "offset": 0, + "length": 1 + }, + "OUCBRSM": { + "description": "RSM service outstanding", + "offset": 1, + "length": 1 + }, + "OUCBESSS": { + "description": "Suspended for swapout to extended (ESA mode only)", + "offset": 2, + "length": 1 + }, + "OUCBESSW": { + "description": "Has been or will be swapped to extended (ESA mode only)", + "offset": 3, + "length": 1 + }, + "OUCBASSW": { + "description": "Has been or will be swapped to auxiliary", + "offset": 4, + "length": 1 + }, + "OUCBCSMF": { + "description": "SMF needs to be notified that the address space is swapped in", + "offset": 5, + "length": 1 + }, + "OUCBSHBN": { + "description": "Server history block needed", + "offset": 6, + "length": 1 + }, + "OUCBHITR": { + "description": "HIT has run since UserRdy", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBCSBT", + "description": "Compare and swap bits", + "offset": 91, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBTRM": { + "description": "Terminal wait status", + "offset": 0, + "length": 1 + }, + "OUCBOWT": { + "description": "Output terminal wait", + "offset": 1, + "length": 1 + }, + "OUCBCIM": { + "description": "Composite input message", + "offset": 2, + "length": 1 + }, + "OUCBPSTR": { + "description": "If post error, recover", + "offset": 3, + "length": 1 + }, + "OUCBSTA": { + "description": "Swap turn around", + "offset": 4, + "length": 1 + }, + "OUCBQSS": { + "description": "QSCEST event processed", + "offset": 5, + "length": 1 + }, + "OUCBOIW": { + "description": "A detected wait should be treated as an OpenMVS input wait", + "offset": 6, + "length": 1 + }, + "OUCBOOW": { + "description": "An OpenMVS output wait condition is present", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBCMRV", + "description": "Composite recommendation value", + "offset": 92, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBWMRL", + "description": "Workload recommendation value saved at swap-out", + "offset": 96, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBVAL", + "description": "Working set management recommendation value", + "offset": 100, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBPFL", + "description": "Processing flags", + "offset": 102, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBFTDN": { + "description": "Trimming has been completed for this address space", + "offset": 0, + "length": 1 + }, + "OUCBPSD": { + "description": "This address space is a direct physical swap", + "offset": 1, + "length": 1 + }, + "OUCBDPSW": { + "description": "Delayed physical swap", + "offset": 2, + "length": 1 + }, + "OUCBSRP": { + "description": "Steal recently referenced pages on the next steal attempt from the address space", + "offset": 3, + "length": 1 + }, + "OUCBPTDN": { + "description": "Preliminary trimming has been completed for this address space", + "offset": 4, + "length": 1 + }, + "OUCBFTDNNOSWAP": { + "description": "Trimming has been completed for this address space - no swapping will be done", + "offset": 5, + "length": 1 + } + } + }, + { + "name": "OUCBACTL", + "description": "Length of storage allocated to save accounting data", + "offset": 103, + "length": 1, + "type": "signed-integer" + }, + { + "name": "OUCBIOCL", + "description": "Deprecated (I/O service no longer accumulated)", + "offset": 104, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBDSPC", + "description": "Current dispatching control", + "offset": 112, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBMTW": { + "description": "Current control is MTW", + "offset": 0, + "length": 1 + }, + "OUCBTS": { + "description": "Current control is time slicing", + "offset": 2, + "length": 1 + }, + "OUCBTSC3": { + "description": "Workarea for TS", + "offset": 3, + "length": 1 + }, + "OUCBTSC4": { + "description": "Workarea for TS", + "offset": 4, + "length": 1 + }, + "OUCBTSC5": { + "description": "Workarea for TS", + "offset": 5, + "length": 1 + }, + "OUCBTSC6": { + "description": "Workarea for TS", + "offset": 6, + "length": 1 + }, + "OUCBTSC7": { + "description": "Workarea for TS", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBDSPN", + "description": "New dispatching control", + "offset": 113, + "length": 1, + "type": "bitstring", + "bitmasks": { + "OUCBNMTW": { + "description": "New control is MTW", + "offset": 0, + "length": 1 + }, + "OUCBNTS": { + "description": "New control is time slicing", + "offset": 2, + "length": 1 + }, + "OUCBTSN3": { + "description": "Workarea for TS", + "offset": 3, + "length": 1 + }, + "OUCBTSN4": { + "description": "Workarea for TS", + "offset": 4, + "length": 1 + }, + "OUCBTSN5": { + "description": "Workarea for TS", + "offset": 5, + "length": 1 + }, + "OUCBTSN6": { + "description": "Workarea for TS", + "offset": 6, + "length": 1 + }, + "OUCBTSN7": { + "description": "Workarea for TS", + "offset": 7, + "length": 1 + } + } + }, + { + "name": "OUCBNTSP", + "description": "Number of additional TransSwaps pending", + "offset": 114, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBPSS", + "description": "CPU page seconds", + "offset": 116, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBPST", + "description": "Time of last working set change", + "offset": 124, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBRCT", + "description": "Interval RCT service accumulator", + "offset": 128, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBIIT", + "description": "Interval I/O interrupt service accumulator", + "offset": 132, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBNDS", + "description": "Number of outstanding DontSwaps", + "offset": 136, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBNTSG", + "description": "New time slice group number", + "offset": 138, + "length": 1, + "type": "bitstring" + }, + { + "name": "OUCBRSV2", + "description": "Reserved", + "offset": 139, + "length": 1, + "type": "hex" + }, + { + "name": "OUCBTME", + "description": "Last response time", + "offset": 140, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTML", + "description": "Time of last termwait", + "offset": 144, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBDWMS", + "description": "Interval domain service accumulator", + "offset": 148, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBSRB", + "description": "Interval SRB service accumulator", + "offset": 152, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTWSS", + "description": "Target working set size", + "offset": 156, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTMP", + "description": "Performance group period start time", + "offset": 160, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBDLYT", + "description": "RTO delay end time", + "offset": 164, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBHST", + "description": "Interval Hiperspace service accumulator", + "offset": 168, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBCFS", + "description": "Accumulated sample of RAXFMCT for determining average central storage", + "offset": 172, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBRPG", + "description": "Reset performance group number", + "offset": 180, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBSPG", + "description": "Specified performance group number", + "offset": 182, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBNPG", + "description": "New performance group number", + "offset": 184, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBSRPG", + "description": "Subsystem RPGN", + "offset": 186, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBNRPG", + "description": "Transaction name RPGN", + "offset": 188, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBURPG", + "description": "User ID RPGN", + "offset": 190, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBCRPG", + "description": "Transaction class RPGN", + "offset": 192, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBARPG", + "description": "Account number RPGN", + "offset": 194, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBDRFP", + "description": "Count of DREF pages in processor storage (ESA mode only, do not use in z/OS)", + "offset": 196, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTRXN", + "description": "Transaction name", + "offset": 200, + "length": 8, + "type": "string" + }, + { + "name": "OUCBUSRD", + "description": "User ID", + "offset": 208, + "length": 8, + "type": "string" + }, + { + "name": "OUCBCLS", + "description": "Transaction class name", + "offset": 216, + "length": 8, + "type": "string" + }, + { + "name": "OUCBTRS", + "description": "Accumulated transaction service", + "offset": 224, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBTRR", + "description": "Transaction residency time accumulator", + "offset": 228, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBSWSS", + "description": "Secondary working set size", + "offset": 236, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBPSUM", + "description": "Base value for page-in count", + "offset": 240, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBFIXB", + "description": "Count of below frames needed for fixed/LSQA pages", + "offset": 244, + "length": 2, + "type": "signed-integer" + }, + { + "name": "OUCBAPLV", + "description": "APPC optimization level", + "offset": 246, + "length": 1, + "type": "bitstring" + }, + { + "name": "OUCBESAP", + "description": "Individual expanded storage access policy, goal mode only (ESA mode only)", + "offset": 247, + "length": 1, + "type": "bitstring" + }, + { + "name": "OUCBRST", + "description": "Page residency time in 1024 microsecond units", + "offset": 248, + "length": 4, + "type": "signed-integer" + }, + { + "name": "OUCBEND", + "description": "End of OUCB", + "offset": 3072, + "length": 8, + "type": "hex", + "endOfControlBlock": true + } + ] + } + ] +} diff --git a/cbxp/mappings/psa.json b/cbxp/mappings/psa.json new file mode 100644 index 0000000..437838b --- /dev/null +++ b/cbxp/mappings/psa.json @@ -0,0 +1,271 @@ +{ + "version": 1, + "name": "psa", + "commonName": "Prefixed Save Area", + "macroId": "ihapsa", + "description": "Maps fixed hardware and software storage locations for the related processor. The fixed hardware storage locations (all within the first x'200' bytes of the area) are for the ESA/390 architecture. The z/Architecture locations are mapped by macro IHAPSAE.", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [ + 239 + ], + "key": 0, + "residency": 24 + }, + "sections": [ + { + "name": "psa", + "description": "", + "fields": [ + { + "name": "FLCCVT", + "description": "ADDRESS OF CVT (AFTER IPL).", + "offset": 16, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEACVT" + } + ], + "pointsTo": "cvt", + "programmingInterface": true + }, + { + "name": "FLCCVT64", + "description": "8-byte CVT address", + "offset": 72, + "length": 8, + "type": "signed-integer", + "programmingInterface": true + }, + { + "name": "FLCARCH", + "description": "Architecture information", + "offset": 163, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "PSAZARCH": { + "description": "z/Architecture", + "offset": 7, + "length": 1 + }, + "PSAESAME": { + "description": "z/Architecture", + "offset": 7, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "FLCFACL", + "description": "Facilities List. See FaclBytes0To15 in IHAFACL for description", + "offset": 200, + "length": 16, + "type": "hex", + "programmingInterface": true + }, + { + "name": "FLCFACLE", + "description": "Facilities List bytes 16-31. See FaclBytes16To31 in IHAFACL for description", + "offset": 216, + "length": 16, + "type": "hex", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "programmingInterface": true + }, + { + "name": "PSAPSA", + "description": "CONTROL BLOCK ACRONYM IN EBCDIC", + "offset": 512, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "PSA " + } + ], + "eyecatcher": true + }, + { + "name": "PSALCCAV", + "description": "VIRTUAL ADDRESS OF LCCA", + "offset": 528, + "length": 4, + "type": "address", + "pointsTo": "lcca", + "programmingInterface": true + }, + { + "name": "PSATOLD", + "description": "Pointer to current TCB or zero if in SRB mode. e", + "offset": 540, + "length": 4, + "type": "address", + "programmingInterface": true + }, + { + "name": "PSAAOLD", + "description": "Pointer to the home (current) ASCB.", + "offset": 548, + "length": 4, + "type": "address", + "pointsTo": "home", + "programmingInterface": true + }, + { + "name": "PSAFLAGS", + "description": "SYSTEM FLAGS This field is PI for bits PSATX and PSATXC only OWNERSHIP: SUPERVISOR CONTROL SERIALIZATION: DISABLEMENT SERIALIZATION: None for PI bits", + "offset": 576, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "PSAAEIT": { + "description": "ADDRESSING ENVIRONMENT IS IN TRANSITION. INDICATES THAT THE SPACE TYPE (ADDRESS SPACE OR SUBSPACE) ASSOCIATED WITH PASN OR SASN IS UNKNOWN. Was PSAFPAC, PSAFPPE", + "offset": 0, + "length": 1 + }, + "PSATX": { + "description": "Equivalent to CVTTX", + "offset": 4, + "length": 1 + }, + "PSATXC": { + "description": "Equivalent to CVTTXC", + "offset": 5, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "PSAVAL", + "description": "Virtual Architecture Level. Bits 0-11 are the same as IHASCCB field SCCBVAL bits 20-31. Bits 12-15 are not defined.", + "offset": 894, + "length": 2, + "type": "hex", + "programmingInterface": true + }, + { + "name": "PSAFPFL", + "description": "See LCCAFPFL Interface only for PSABFP, PSAVSS", + "offset": 1018, + "length": 1, + "type": "bitstring", + "init": [ + { + "type": "hex", + "value": "00" + } + ], + "bitmasks": { + "PSABFP": { + "description": "Additional FP status is being saved", + "offset": 3, + "length": 1 + }, + "PSAVSS": { + "description": "VRs are being saved", + "offset": 4, + "length": 1 + }, + "PSAGSF": { + "description": "GSF controls are being saved", + "offset": 5, + "length": 1 + } + }, + "programmingInterface": true + }, + { + "name": "PSALAA", + "description": "LE Anchor Area. Owner: LE", + "offset": 1208, + "length": 4, + "type": "address", + "pointsTo": "velt", + "programmingInterface": true + }, + { + "name": "PSAECVT", + "description": "Address of ECVT", + "offset": 1952, + "length": 8, + "type": "address", + "pointsTo": "ecvt", + "programmingInterface": true + }, + { + "name": "PSAXCVT", + "description": "Address of XCVT", + "offset": 1960, + "length": 8, + "type": "address", + "pointsTo": "xcvt", + "programmingInterface": true + }, + { + "name": "PSATRVT", + "description": "ADDRESS OF SYSTEM TRACE VECTOR TABLE.", + "offset": 2040, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVETVT" + } + ], + "pointsTo": "vetvt", + "programmingInterface": true + }, + { + "name": "PSASVTX", + "description": "Address of Supervisor Vector Table extension. SERIALIZATION: None OWNERSHIP: Supervisor Control", + "offset": 2896, + "length": 4, + "type": "address", + "init": [ + { + "type": "address", + "value": "IEAVSVTX" + } + ], + "pointsTo": "vsvtx", + "programmingInterface": true + }, + { + "name": "PSAEND", + "description": "END OF PSA", + "offset": 4096, + "length": 8, + "type": "signed-integer", + "endOfControlBlock": true + } + ] + } + ] +} diff --git a/cbxp/schemas/control_block.json b/cbxp/schemas/control_block.json new file mode 100644 index 0000000..6db7cd9 --- /dev/null +++ b/cbxp/schemas/control_block.json @@ -0,0 +1,551 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "version": "1.1.0", + "title": "Control Block", + "description": "CBXP Control Block Schema", + "type": "object", + "definitions": { + "initItem": { + "description": "A single initialization entry for a control block field", + "type": "object", + "oneOf": [ + { + "description": "Hex literal initialization (DC XL'...')", + "properties": { + "type": { + "const": "hex" + }, + "value": { + "description": "Hex string without surrounding quotes (e.g. '040E0000')", + "type": "string", + "pattern": "^[0-9A-Fa-f]+$" + } + }, + "required": [ + "type", + "value" + ], + "additionalProperties": false + }, + { + "description": "String literal initialization (DC CL'...')", + "properties": { + "type": { + "const": "string" + }, + "value": { + "description": "Character string value as-is (e.g. '038 ')", + "type": "string" + } + }, + "required": [ + "type", + "value" + ], + "additionalProperties": false + }, + { + "description": "Address initialization (DC A(...), DC V(...), DC A(X'80000000'+SYM))", + "properties": { + "type": { + "const": "address" + }, + "value": { + "description": "Symbol name (e.g. 'IEAVRSTR')", + "type": "string", + "minLength": 1 + }, + "bitmask": { + "description": "Optional ORed bitmask applied to the address (e.g. '80000000')", + "type": "string", + "pattern": "^[0-9A-Fa-f]+$" + }, + "wideExternal": { + "description": "True when the address was declared with WXTRN (wide external reference)", + "type": "boolean", + "const": true + } + }, + "required": [ + "type", + "value" + ], + "additionalProperties": false + }, + { + "description": "Machine instruction initialization (e.g. SVC 3, BR 14)", + "properties": { + "type": { + "const": "instruction" + }, + "value": { + "description": "The assembler instruction mnemonic and operands (e.g. 'SVC 3')", + "type": "string", + "minLength": 1 + } + }, + "required": [ + "type", + "value" + ], + "additionalProperties": false + } + ] + }, + "initArray": { + "description": "Ordered list of initialization data items that together fill the field", + "type": "array", + "minItems": 1, + "items": { + "$ref": "#/definitions/initItem" + } + }, + "equatesArray": { + "description": "Standalone EQU constants attached to a field that cannot be represented as bitmasks", + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "minLength": 1 + }, + "value": { + "type": "string", + "minLength": 1 + }, + "description": { + "type": "string" + } + }, + "required": [ + "name", + "value" + ], + "additionalProperties": false + } + }, + "bitmasksDef": { + "description": "Bit definitions within a field, or the name of another field whose bitmask definitions to reuse", + "oneOf": [ + { + "type": "object", + "patternProperties": { + "^[a-zA-Z][a-zA-Z0-9_]*$": { + "type": "object", + "properties": { + "description": { + "description": "Description of what this bit or bit field represents", + "type": "string" + }, + "offset": { + "description": "Bit offset within the field (0-based from MSB/leftmost bit)", + "type": "integer", + "minimum": 0 + }, + "length": { + "description": "Number of bits (typically 1 for single bit flags)", + "type": "integer", + "minimum": 1 + } + }, + "required": [ + "description", + "offset", + "length" + ], + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "string", + "minLength": 1 + } + ] + }, + "fieldCommonProps": { + "description": "Common properties shared by all field variants", + "type": "object", + "properties": { + "name": { + "description": "Name of the control block field", + "type": "string", + "minLength": 1 + }, + "aliases": { + "description": "Alternative names for this field", + "type": "array", + "items": { + "type": "string", + "minLength": 1 + } + }, + "description": { + "description": "Control block field description", + "type": "string" + }, + "offset": { + "description": "Decimal offset to the control block field", + "type": "integer" + }, + "length": { + "description": "Decimal length of the control block field", + "type": "integer" + }, + "repeated": { + "description": "Whether this field is a repeated array entry (prototype). Must be used together with 'count'.", + "type": "boolean", + "const": true + }, + "count": { + "description": "Name of the field in this control block whose value gives the number of repetitions. Must be used together with 'repeated'.", + "type": "string", + "minLength": 1 + }, + "ignoreMask": { + "description": "Hex bitmask indicating which bit(s) mark a repeated entry as invalid/ignored. Only valid on fields with 'repeated: true'. Default '00' means no entries are ignored.", + "type": "string", + "pattern": "^[0-9A-Fa-f]+$", + "default": "00" + }, + "alignBefore": { + "description": "Alignment boundary in bytes that was explicitly enforced before this field in the original source via an unnamed DS 0D (8), DS 0F (4), or DS 0H (2) directive.", + "type": "integer" + }, + "programmingInterface": { + "description": "True when this field is documented as a Programming Interface (PI).", + "type": "boolean", + "const": true + }, + "equates": { + "description": "Standalone EQU constants attached to this field (cannot be represented as bitmasks).", + "$ref": "#/definitions/equatesArray" + }, + "boundary": { + "description": "Memory alignment boundary in bytes", + "type": "integer", + "enum": [1, 2, 4, 8] + } + } + }, + "field": { + "description": "A single control block field", + "type": "object", + "oneOf": [ + { + "description": "Standard field (string, integer, hex, bitstring)", + "properties": { + "name": { "type": "string", "minLength": 1 }, + "aliases": { "type": "array", "items": { "type": "string", "minLength": 1 } }, + "description": { "type": "string" }, + "offset": { "type": "integer" }, + "length": { "type": "integer" }, + "type": { + "description": "Control block field type", + "enum": [ + "string", + "signed-integer", + "unsigned-integer", + "hex", + "address" + ] + }, + "init": { "$ref": "#/definitions/initArray" }, + "eyecatcher": { "type": "boolean", "const": true, + "description": "When true, the field is the control block eyecatcher. The expected ASCII value must be supplied via init[0] (type: string)." }, + "repeated": { "type": "boolean", "const": true }, + "count": { "type": "string", "minLength": 1 }, + "ignoreMask": { "type": "string", "pattern": "^[0-9A-Fa-f]+$", "default": "00" }, + "alignBefore": { "type": "integer" }, + "programmingInterface": { "type": "boolean", "const": true }, + "endOfControlBlock": { "type": "boolean", "const": true }, + "equates": { "$ref": "#/definitions/equatesArray" }, + "bitmasks": { "$ref": "#/definitions/bitmasksDef" }, + "boundary": { "type": "integer", "enum": [1, 2, 4, 8] }, + "children": { + "description": "Child fields nested within this container/structure field", + "type": "array", + "items": { "$ref": "#/definitions/field" } + } + }, + "required": ["name", "offset", "length", "type"], + "dependencies": { + "repeated": ["count"], + "count": ["repeated"], + "ignoreMask": ["repeated"], + "eyecatcher": ["init"] + }, + "additionalProperties": false + }, + { + "description": "Pointer/hex field that points to another control block", + "properties": { + "name": { "type": "string", "minLength": 1 }, + "aliases": { "type": "array", "items": { "type": "string", "minLength": 1 } }, + "description": { "type": "string" }, + "offset": { "type": "integer" }, + "length": { "enum": [4, 8] }, + "type": { "const": "hex" }, + "pointsTo": { + "description": "Control block that this field points to", + "type": "string", + "minLength": 1 + }, + "init": { "$ref": "#/definitions/initArray" }, + "repeated": { "type": "boolean", "const": true }, + "count": { "type": "string", "minLength": 1 }, + "ignoreMask": { "type": "string", "pattern": "^[0-9A-Fa-f]+$", "default": "00" }, + "alignBefore": { "type": "integer" }, + "programmingInterface": { "type": "boolean", "const": true }, + "endOfControlBlock": { "type": "boolean", "const": true }, + "equates": { "$ref": "#/definitions/equatesArray" }, + "boundary": { "type": "integer", "enum": [1, 2, 4, 8] } + }, + "required": ["name", "offset", "length", "type", "pointsTo"], + "dependencies": { + "repeated": ["count"], + "count": ["repeated"], + "ignoreMask": ["repeated"] + }, + "additionalProperties": false + }, + { + "description": "Address pointer field that points to another control block", + "properties": { + "name": { "type": "string", "minLength": 1 }, + "aliases": { "type": "array", "items": { "type": "string", "minLength": 1 } }, + "description": { "type": "string" }, + "offset": { "type": "integer" }, + "length": { "enum": [4, 8] }, + "type": { "const": "address" }, + "pointsTo": { + "description": "Control block that this field points to", + "type": "string", + "minLength": 1 + }, + "init": { "$ref": "#/definitions/initArray" }, + "repeated": { "type": "boolean", "const": true }, + "count": { "type": "string", "minLength": 1 }, + "ignoreMask": { "type": "string", "pattern": "^[0-9A-Fa-f]+$", "default": "00" }, + "alignBefore": { "type": "integer" }, + "programmingInterface": { "type": "boolean", "const": true }, + "endOfControlBlock": { "type": "boolean", "const": true }, + "equates": { "$ref": "#/definitions/equatesArray" }, + "boundary": { "type": "integer", "enum": [1, 2, 4, 8] } + }, + "required": ["name", "offset", "length", "type", "pointsTo"], + "dependencies": { + "repeated": ["count"], + "count": ["repeated"], + "ignoreMask": ["repeated"] + }, + "additionalProperties": false + }, + { + "description": "Bitstring field with bitmask definitions", + "properties": { + "name": { "type": "string", "minLength": 1 }, + "aliases": { "type": "array", "items": { "type": "string", "minLength": 1 } }, + "description": { "type": "string" }, + "offset": { "type": "integer" }, + "length": { "type": "integer" }, + "type": { "const": "bitstring" }, + "init": { "$ref": "#/definitions/initArray" }, + "repeated": { "type": "boolean", "const": true }, + "count": { "type": "string", "minLength": 1 }, + "ignoreMask": { "type": "string", "pattern": "^[0-9A-Fa-f]+$", "default": "00" }, + "bitmasks": { "$ref": "#/definitions/bitmasksDef" }, + "alignBefore": { "type": "integer" }, + "programmingInterface": { "type": "boolean", "const": true }, + "endOfControlBlock": { "type": "boolean", "const": true }, + "equates": { "$ref": "#/definitions/equatesArray" }, + "boundary": { "type": "integer", "enum": [1, 2, 4, 8] } + }, + "required": ["name", "offset", "length", "type"], + "dependencies": { + "repeated": ["count"], + "count": ["repeated"], + "ignoreMask": ["repeated"] + }, + "additionalProperties": false + }, + { + "description": "Triplet field: a container for three child fields representing a triplet (offset, length, count). The triplet type enforces exactly 3 children at fixed relative offsets within the 8-byte parent.", + "properties": { + "name": { "type": "string", "minLength": 1 }, + "description": { "type": "string" }, + "offset": { "type": "integer" }, + "length": { "type": "integer", "const": 8 }, + "type": { "const": "triplet" }, + "children": { + "description": "Exactly 3 child fields: offset (4 bytes), length (2 bytes), count (2 bytes)", + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "$ref": "#/definitions/field" } + } + }, + "required": ["name", "offset", "length", "type", "children"], + "additionalProperties": false + } + ] + }, + "section": { + "description": "A single DSECT or logical grouping of fields within a control block", + "type": "object", + "properties": { + "name": { + "description": "DSECT/section name (lowercase)", + "type": "string", + "minLength": 1 + }, + "description": { + "description": "Optional section description", + "type": "string" + }, + "equ": { + "description": "Optional length equate expression (e.g. '*-SECTIONNAME'). Captures length EQU directives like 'XXXXXXDS_Len EQU *-XXXXXXDS'.", + "type": "string" + }, + "fields": { + "description": "List of fields in this section", + "type": "array", + "items": { "$ref": "#/definitions/field" } + } + }, + "required": ["name", "fields"], + "additionalProperties": false + } + }, + "properties": { + "version": { + "description": "CBXP control block schema version", + "const": 1 + }, + "type": { + "description": "Mapping category: 'control-block' for z/OS control blocks", + "type": "string", + "enum": ["control-block"] + }, + "name": { + "description": "Control block name", + "type": "string", + "minLength": 1, + "maxLength": 8 + }, + "commonName": { + "description": "Full control block name", + "type": "string", + "minLength": 1 + }, + "macroId": { + "description": "Macro invocation name (e.g. ihapsa for the IHAPSA macro)", + "type": "string", + "minLength": 1 + }, + "description": { + "description": "Control block description", + "type": "string" + }, + "aliases": { + "description": "Alternative names for this control block (ACRONYM, EYE-CATCHER, DSECT name, etc.)", + "type": "array", + "items": { + "type": "string", + "minLength": 1, + "maxLength": 8 + } + }, + "pointedToBy": { + "description": "List of control blocks that points to this control block", + "type": "array", + "items": { + "type": "string", + "minLength": 1 + } + }, + "storageAttributes": { + "description": "Storage attributes for this control block", + "type": "object", + "properties": { + "subpools": { + "description": "Subpool numbers this control block resides in. An empty array indicates 'ANY' or unknown subpool. Numeric subpools are integers (0-255); ambiguous named values (e.g. 'Nucleus') are strings.", + "type": "array", + "items": { + "oneOf": [ + { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + { + "type": "string", + "minLength": 1 + } + ] + } + }, + "key": { + "description": "Storage key (0-8)", + "type": "integer", + "minimum": 0, + "maximum": 8 + }, + "residency": { + "description": "RMODE of this control block: 24 = below 16M line (RMODE24), 31 = below 2G bar (RMODE31), 64 = above 2G bar (RMODE64), null = any/unknown (RMODEANY).", + "oneOf": [ + { + "type": "integer", + "enum": [ + 24, + 31, + 64 + ] + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "subpools", + "key", + "residency" + ], + "additionalProperties": false + }, + "constants": { + "description": "Named constants declared with DCL ... Constant(...)", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "description": "Constant name", "type": "string", "minLength": 1 }, + "value": { "description": "Constant value (numeric or string)", "oneOf": [{"type": "number"}, {"type": "string"}] }, + "length": { "description": "Optional explicit length for character constants", "type": "integer", "minimum": 1 }, + "description": { "description": "Optional constant description", "type": "string" } + }, + "required": ["name", "value"], + "additionalProperties": false + } + }, + "sections": { + "description": "List of DSECTs/sections that make up this control block. Single-DSECT control blocks have one entry; multi-DSECT structures have multiple entries.", + "type": "array", + "minItems": 1, + "items": { "$ref": "#/definitions/section" } + } + }, + "required": [ + "version", + "name", + "commonName", + "pointedToBy", + "sections" + ], + "additionalProperties": false +} diff --git a/cbxp/traversal/control_block_node.cpp b/cbxp/traversal/control_block_node.cpp new file mode 100644 index 0000000..ae0ab2c --- /dev/null +++ b/cbxp/traversal/control_block_node.cpp @@ -0,0 +1,357 @@ +#include "traversal/control_block_node.hpp" + +#include +#include +#include +#include + +#include "util/address_util.hpp" +#include "util/control_block_error.hpp" +#include "util/logger.hpp" + +namespace CBXP { + +ControlBlockNode::ControlBlockNode(TraversalContext& ctx, + const cbxp_options_t& options, + const std::string& cb_name, + const void* p_address, size_t buffer_length) + : ctx_(ctx), + cb_(ctx.control_blocks.at(cb_name)), + p_address_(p_address), + buffer_length_(buffer_length) { + // Resolve include patterns into child_options_ for this node. + child_options_ = IncludeResolver::resolve(options.include_patterns, cb_, + ctx_.control_blocks); + // Propagate skip_buffer_length_check into each child option set. + for (auto& [name, child_opt] : child_options_) { + child_opt.skip_buffer_length_check = ctx_.skip_buffer_length_check; + } + // Parse filter strings; child filters are pushed into child_options_. + filter_set_.parse(options.filters, child_options_, cb_name); +} + +// --------------------------------------------------------------------------- +// Public + +NodeParseResult ControlBlockNode::parse() { + NodeParseResult result; + result.filter_passed = true; + result.json = nullptr; + + // Verify the whole block fits in the caller's buffer before reading anything; + // no-op when skip_buffer_length_check is true (live memory). + ControlBlockNode::checkDataLength(ControlBlockNode::getReadableLength()); + + if (!ControlBlockNode::eyecatcherMatches()) { + return result; // json stays null + } + + result.json = ControlBlockNode::parseFields(); + + if (!filter_set_.match(result.json)) { + result.filter_passed = false; + Logger::getInstance().debug( + "Filters rejected '" + cb_.getName() + "' at address " + + addressToString(p_address_) + ": discarding " + + std::to_string(pending_children_.size()) + " pending child(ren)"); + pending_children_.clear(); // rejected: do not load children + return result; + } + + ControlBlockNode::enqueuePendingChildren(); + + return result; +} + +ControlBlockNode ControlBlockNode::withAddress(const void* p_address) const { + ControlBlockNode copy(*this); + copy.p_address_ = p_address; + return copy; +} + +std::unordered_map ControlBlockNode::childFilterMap() const { + std::unordered_map out; + for (const auto& [name, child_opt] : child_options_) { + out[name] = !child_opt.filters.empty(); + } + return out; +} + +// --------------------------------------------------------------------------- +// Private helpers + +bool ControlBlockNode::eyecatcherMatches() const { + const eyecatcher_field_t& ec = cb_.getEyecatcherField(); + if (ec.expected.empty()) { + return true; + } + const char* p_raw = static_cast(p_address_) + ec.offset; + std::string actual = + ControlBlockFieldFormatter::getString(p_raw, static_cast(ec.length)); + std::string expected = ec.expected; + expected.erase(expected.find_last_not_of(" \t\0", std::string::npos, 3) + 1); + if (actual != expected) { + Logger::getInstance().debug( + "Eyecatcher mismatch for '" + cb_.getName() + "' at " + + [&]() { + std::ostringstream oss; + oss << p_address_; + return oss.str(); + }() + + ": expected '" + expected + "', got '" + actual + "' — skipping"); + return false; + } + return true; +} + +void ControlBlockNode::checkDataLength(ptrdiff_t offset) const { + if (ctx_.skip_buffer_length_check) { + return; + } + if (offset < 0) { + return; + } + Logger::getInstance().debug( + "Checking if specified buffer (" + std::to_string(buffer_length_) + + " bytes) too small to contain the '" + cb_.getName() + + "' control block (requires at least " + std::to_string(offset) + + " bytes)..."); + if (static_cast(offset) > buffer_length_) { + throw DataLengthError(); + } +} + +ptrdiff_t ControlBlockNode::getReadableLength() const { + return cb_.getName() == "psa" ? (cb_.getMaxOffset() - 8) / 2 + : cb_.getMaxOffset(); +} + +nlohmann::json ControlBlockNode::fieldToJson(const control_block_field_t& field, + ptrdiff_t extra_offset) { + ptrdiff_t offset = field.offset + extra_offset; + ControlBlockNode::checkDataLength(offset); + + nlohmann::json field_json; + const char* p_base = static_cast(p_address_); + + try { + switch (field.type) { + case STRING: + field_json = cb_.formatter_.getString(p_base + offset, field.length); + break; + case UNSIGNED_INT: + if (field.length == 8) { + field_json = cb_.formatter_.uint(p_base + offset); + } else if (field.length == 2) { + field_json = cb_.formatter_.uint(p_base + offset); + } else if (field.length == 1) { + field_json = cb_.formatter_.uint(p_base + offset); + } else { + field_json = cb_.formatter_.uint(p_base + offset); + } + break; + case SIGNED_INT: + if (field.length == 8) { + field_json = cb_.formatter_.sint(p_base + offset); + } else if (field.length == 2) { + field_json = cb_.formatter_.sint(p_base + offset); + } else if (field.length == 1) { + field_json = cb_.formatter_.sint(p_base + offset); + } else { + field_json = cb_.formatter_.sint(p_base + offset); + } + break; + case BITSTRING: + if (field.length == 8) { + field_json = cb_.formatter_.getBitmap(p_base + offset); + } else if (field.length == 2) { + field_json = cb_.formatter_.getBitmap(p_base + offset); + } else if (field.length == 1) { + field_json = cb_.formatter_.getBitmap(p_base + offset); + } else { + field_json = cb_.formatter_.getBitmap(p_base + offset); + } + break; + case HEX: + case ADDRESS: + if (field.length == 8) { + field_json = cb_.formatter_.getHex(p_base + offset); + } else { + field_json = cb_.formatter_.getHex(p_base + offset); + } + break; + } + } catch (const std::exception& e) { + Logger::getInstance().debug( + "Unexpected error reading field '" + field.name + "' (type " + + std::to_string(static_cast(field.type)) + ", offset " + + std::to_string(offset) + ") of '" + cb_.getName() + "' at address " + + addressToString(p_address_) + ": " + e.what()); + throw CbxpBlockUnreachableError(); + } + + // For an included child pointer field: enqueue the target and return the raw + // pointer hex as a placeholder, which the engine resolves after traversal. + if (!field.points_to.empty() && + child_options_.find(field.points_to) != child_options_.end()) { + const std::string& child_name = field.points_to; + const char* p_raw = p_base + offset; + const void* p_child_addr; + if (field.length == 8) { + p_child_addr = + reinterpret_cast(cb_.formatter_.uint(p_raw)); + } else { + p_child_addr = reinterpret_cast( + cb_.formatter_.uint(p_raw)); + } + + // Reject guard page addresses before enqueueing: the 0C4 fires + // before any C++ catch, so a try/catch can't handle it. + if (isGuardPageAddress(p_child_addr)) { + Logger::getInstance().debug( + "Skipping enqueue of '" + child_name + + "' — address falls in PSA fetch-protected range " + kGuardPageRange); + return field_json; // leave raw hex placeholder in place + } + + // Defer enqueueing until this node's filters are evaluated, so children of + // rejected nodes are never loaded. + pending_children_.push_back({p_child_addr, child_name, + child_options_[child_name], + /*is_root=*/false}); + // Return the raw hex as a placeholder regardless — the engine will + // patch it to the real child JSON once that node finishes processing. + } + + return field_json; +} + +void ControlBlockNode::enqueuePendingChildren() { + size_t enqueued = 0; + for (const PendingNode& child : pending_children_) { + auto visit_key = std::make_pair(child.p_address, child.cb_name); + std::string addr_str = addressToString(child.p_address); + if (ctx_.visited.find(visit_key) == ctx_.visited.end()) { + // Mark in-progress before enqueueing so two parents at the same BFS level + // can't double-enqueue the same child address. + ctx_.visited[visit_key] = false; // sentinel + ctx_.queue.push(child); + ++enqueued; + Logger::getInstance().debug("Enqueued '" + child.cb_name + + "' at address " + addr_str); + } else { + Logger::getInstance().debug("Already visited/enqueued '" + child.cb_name + + "' at address " + addr_str); + } + } + if (!pending_children_.empty()) { + Logger::getInstance().debug( + "'" + cb_.getName() + "' at address " + addressToString(p_address_) + + ": enqueued " + std::to_string(enqueued) + " of " + + std::to_string(pending_children_.size()) + " pending child(ren)"); + } + pending_children_.clear(); +} + +nlohmann::json ControlBlockNode::parseFields() { + nlohmann::json cb_json = {}; + std::unordered_map repeated_fields; + size_t psa_fields_skipped = 0; + + for (const auto& [field_name, field_data] : cb_.getMap()) { + if (field_data.end_of_control_block) { + continue; + } + if (cb_.getName() == "psa" && + field_data.offset >= (cb_.getMaxOffset() - 8) / 2 && + field_data.offset >= 0) { + ++psa_fields_skipped; + continue; + } + + std::string lower_name = field_name; + std::transform(lower_name.begin(), lower_name.end(), lower_name.begin(), + [](unsigned char c) { return std::tolower(c); }); + + if (field_data.repeated) { + repeated_fields[lower_name] = field_data; + continue; + } + + nlohmann::json resolved = ControlBlockNode::fieldToJson(field_data); + + if (resolved.is_object() || resolved.is_array()) { + // Already an expanded child — preserve raw pointer under "_ptr". + const char* p_raw = + static_cast(p_address_) + field_data.offset; + cb_json[lower_name + "_ptr"] = + (field_data.length == 8) + ? nlohmann::json(cb_.formatter_.getHex(p_raw)) + : nlohmann::json(cb_.formatter_.getHex(p_raw)); + } + cb_json[lower_name] = resolved; + } + + if (psa_fields_skipped > 0) { + Logger::getInstance().debug("Skipped " + + std::to_string(psa_fields_skipped) + + " 'psa' field(s) beyond the readable range"); + } + + // --- repeated fields --- + for (const auto& [field_name, field_data] : repeated_fields) { + nlohmann::json field_json = {}; + field_json[field_name + "s"] = {}; + + std::string count_key = field_data.count; + std::transform(count_key.begin(), count_key.end(), count_key.begin(), + [](unsigned char c) { return std::tolower(c); }); + + size_t count = cb_json[count_key].get(); + Logger::getInstance().debug("Repeated field '" + field_name + + "': count_key='" + count_key + + "', count=" + std::to_string(count)); + + size_t entries_ignored = 0; + + for (size_t i = 0; i < count; ++i) { + // ignoreMask matches (e.g. unused slots) are dropped up front, so they + // are neither emitted nor followed. Child filters are applied later by + // TraversalEngine::resolvePlaceholders. + if (!field_data.ignore_mask.empty() && !field_data.points_to.empty() && + child_options_.find(field_data.points_to) != child_options_.end()) { + ControlBlockNode::checkDataLength( + field_data.offset + static_cast(i) * field_data.length); + const char* p_entry_raw = static_cast(p_address_) + + field_data.offset + i * field_data.length; + const uint32_t mask = static_cast(std::stoull( + field_data.ignore_mask, nullptr, 16)) + << 24; + if (cb_.formatter_.uint(p_entry_raw) & mask) { + ++entries_ignored; + continue; + } + } + + nlohmann::json entry = ControlBlockNode::fieldToJson( + field_data, static_cast(i) * field_data.length); + + if (!entry.is_null()) { + field_json[field_name + "s"].push_back(entry); + } + } + + if (entries_ignored > 0) { + Logger::getInstance().debug( + "Repeated field '" + field_name + "': ignored " + + std::to_string(entries_ignored) + " of " + std::to_string(count) + + " entries (ignoreMask)"); + } + + cb_json.merge_patch(field_json); + } + + return cb_json; +} + +} // namespace CBXP diff --git a/cbxp/traversal/control_block_node.hpp b/cbxp/traversal/control_block_node.hpp new file mode 100644 index 0000000..44fcc0f --- /dev/null +++ b/cbxp/traversal/control_block_node.hpp @@ -0,0 +1,71 @@ +#ifndef __CBXP_CONTROL_BLOCK_NODE_H_ +#define __CBXP_CONTROL_BLOCK_NODE_H_ + +#include +#include +#include + +#include "cbxp_types.hpp" +#include "control_blocks/control_block.hpp" +#include "traversal/filter_set.hpp" +#include "traversal/include_resolver.hpp" +#include "traversal/traversal_context.hpp" + +namespace CBXP { + +// Result returned by ControlBlockNode::parse(). +struct NodeParseResult { + // The parsed JSON for this node, or null if the eyecatcher mismatched. + nlohmann::json json; + // True when this node's own filter matched (or there were no filters). + // False when the filter rejected the node. + bool filter_passed; +}; + +// Parses one control block at a known address; included pointer targets are +// queued on ctx.queue as hex placeholders. Never modifies ctx.visited. +class ControlBlockNode { + public: + ControlBlockNode(TraversalContext& ctx, const cbxp_options_t& options, + const std::string& cb_name, const void* p_address, + size_t buffer_length = 0); + + // Returns a copy of this node bound to `address`. The include and filter + // lists are copied, not rebuilt, so nothing is re-parsed or re-logged. + ControlBlockNode withAddress(const void* p_address) const; + + NodeParseResult parse(); + + // Included child control block name -> true if that child has filters. + std::unordered_map childFilterMap() const; + + private: + TraversalContext& ctx_; + const ControlBlock& cb_; + const void* p_address_; + size_t buffer_length_; + std::unordered_map child_options_; + FilterSet filter_set_; + // Children discovered while parsing fields; enqueued only if this node's + // own filters pass. + std::vector pending_children_; + + bool eyecatcherMatches() const; + void checkDataLength(ptrdiff_t offset) const; + ptrdiff_t getReadableLength() const; + + // Reads one field and returns its JSON; included pointer targets are queued + // on ctx_.queue and returned as raw pointer hex placeholders. + nlohmann::json fieldToJson(const control_block_field_t& field, + ptrdiff_t extra_offset = 0); + + // Push pending_children_ onto ctx_.queue (skipping already-visited ones). + void enqueuePendingChildren(); + + // Builds the JSON for this node's fields. + nlohmann::json parseFields(); +}; + +} // namespace CBXP + +#endif diff --git a/cbxp/traversal/filter_set.cpp b/cbxp/traversal/filter_set.cpp new file mode 100644 index 0000000..e90f627 --- /dev/null +++ b/cbxp/traversal/filter_set.cpp @@ -0,0 +1,155 @@ +#include "traversal/filter_set.hpp" + +#include + +#include + +#include "util/control_block_error.hpp" +#include "util/logger.hpp" + +namespace CBXP { + +void FilterSet::parse( + const std::vector& filters, + std::unordered_map& child_options, + const std::string& cb_name) { + Logger::getInstance().debug( + "Creating filter lists for the '" + cb_name + + "' control block and included child control blocks..."); + + for (const std::string& filter : filters) { + const std::string del = "."; + size_t del_pos = filter.find(del); + if (del_pos != std::string::npos) { + std::string child_cb = filter.substr(0, del_pos); + std::string child_filter = filter.substr(del_pos + 1); + auto it = child_options.find(child_cb); + if (it == child_options.end()) { + Logger::getInstance().debug("A filter that requires the '" + child_cb + + "' control block was provided, but the '" + + child_cb + + "' control block was not included"); + throw FilterError(); + } + Logger::getInstance().debug("Adding '" + child_filter + + "' to the filter list for the '" + child_cb + + "' control block..."); + it->second.filters.push_back(child_filter); + } else { + FilterSet::addFilter(filter, cb_name); + } + } + + Logger::getInstance().debug( + "Filter lists for the '" + cb_name + + "' control block and included child control blocks have been created"); +} + +void FilterSet::addFilter(const std::string& filter, + const std::string& cb_name) { + static const std::vector operations = {"<=", ">=", "<", ">", + "="}; + for (const std::string& operation : operations) { + size_t op_pos = filter.find(operation); + if (op_pos != std::string::npos) { + std::string filter_key = filter.substr(0, op_pos); + std::string filter_value = filter.substr(op_pos + operation.length()); + cbxp_filter_t filter_data = {operation, filter_value}; + Logger::getInstance().debug("Adding '" + filter_key + operation + + filter_value + + "' to the current filters list for the '" + + cb_name + "' control block..."); + filters_[filter_key].push_back(filter_data); + return; + } + } + Logger::getInstance().debug( + "Filters must be key-value pairs (e.g., 'key=value')"); + throw FilterError(); +} + +bool FilterSet::compare(const nlohmann::json& json_value, + const std::string& filter_value, + const std::string& operation) { + std::string value_str = ""; + bool value_is_string = false; + uint64_t value_uint = 0; + + if (json_value.is_number()) { + value_uint = json_value.get(); + } else { + value_str = json_value.get(); + value_is_string = true; + if (value_str.substr(0, 2) == "0x") { + value_uint = std::stoull(value_str, nullptr, 0); + value_is_string = false; + } + } + + if (value_is_string) { + if (operation == "=") { + Logger::getInstance().debug("\"" + value_str + "\" = \"" + filter_value + + "\" ?"); + return (fnmatch(filter_value.c_str(), value_str.c_str(), 0) == 0); + } else { + Logger::getInstance().debug( + "<, <=, >, and >= cannot be used with string filter values"); + throw FilterError(); + } + } + + uint64_t filter_uint; + try { + filter_uint = std::stoull(filter_value, nullptr, 0); + } catch (...) { + Logger::getInstance().debug("'" + filter_value + + "' cannot be compared to a numeric value"); + throw FilterError(); + } + Logger::getInstance().debug(std::to_string(value_uint) + " " + operation + + " " + std::to_string(filter_uint) + " ?"); + if (operation == "=") return value_uint == filter_uint; + if (operation == ">") return value_uint > filter_uint; + if (operation == "<") return value_uint < filter_uint; + if (operation == ">=") return value_uint >= filter_uint; + if (operation == "<=") return value_uint <= filter_uint; + return false; +} + +bool FilterSet::match(const nlohmann::json& cb_json) const { + if (filters_.empty()) { + return true; + } + for (const auto& [filter_key, filter_list] : filters_) { + if (!cb_json.contains(filter_key)) { + Logger::getInstance().debug( + "The filter key '" + filter_key + + "' does not correspond to any control block field"); + throw FilterError(); + } + const nlohmann::json& json_field = cb_json[filter_key]; + const std::string ptr_key = filter_key + "_ptr"; + const nlohmann::json& effective_value = + (json_field.is_object() || json_field.is_array()) && + cb_json.contains(ptr_key) + ? cb_json[ptr_key] + : json_field; + // cppcheck-suppress useStlAlgorithm; loop body contains throw and + // debug logging; std::all_of cannot express this pattern. + for (const cbxp_filter_t& filter_data : filter_list) { + Logger::getInstance().debug("Applying filter '" + filter_key + + filter_data.operation + filter_data.value + + "'..."); + if (!FilterSet::compare(effective_value, filter_data.value, + filter_data.operation)) { + Logger::getInstance().debug("The filter '" + filter_key + + filter_data.operation + filter_data.value + + "' did not match"); + return false; + } + } + } + return true; +} + +} // namespace CBXP diff --git a/cbxp/traversal/filter_set.hpp b/cbxp/traversal/filter_set.hpp new file mode 100644 index 0000000..c9818fc --- /dev/null +++ b/cbxp/traversal/filter_set.hpp @@ -0,0 +1,43 @@ +#ifndef __CBXP_FILTER_SET_H_ +#define __CBXP_FILTER_SET_H_ + +#include +#include +#include +#include + +#include "cbxp_types.hpp" + +namespace CBXP { + +typedef struct { + std::string operation; + std::string value; +} cbxp_filter_t; + +// Parses a filter-string list and evaluates them against a JSON object. +class FilterSet { + public: + // Parses `filters`; those targeting child blocks ("ascb.field=value") go into + // `child_options` keyed by child name. + void parse(const std::vector& filters, + std::unordered_map& child_options, + const std::string& cb_name); + + // Returns true if `cb_json` satisfies every filter in this set. + bool match(const nlohmann::json& cb_json) const; + + private: + // field_name → list of (operation, value) pairs + std::unordered_map> filters_; + + void addFilter(const std::string& filter, const std::string& cb_name); + + static bool compare(const nlohmann::json& json_value, + const std::string& filter_value, + const std::string& operation); +}; + +} // namespace CBXP + +#endif diff --git a/cbxp/traversal/include_resolver.cpp b/cbxp/traversal/include_resolver.cpp new file mode 100644 index 0000000..5d6a732 --- /dev/null +++ b/cbxp/traversal/include_resolver.cpp @@ -0,0 +1,146 @@ +#include "traversal/include_resolver.hpp" + +#include + +#include "util/control_block_error.hpp" +#include "util/logger.hpp" + +namespace CBXP { + +std::unordered_map> + IncludeResolver::double_asterisk_cache_ = {}; + +const std::unordered_map& +IncludeResolver::getDoubleAsteriskMap( + const ControlBlock& cb, + const std::unordered_map& all_cbs) { + const std::string& cb_name = cb.getName(); + auto it = double_asterisk_cache_.find(cb_name); + if (it != double_asterisk_cache_.end()) { + Logger::getInstance().debug("Using cached '**' options map for '" + + cb_name + "'"); + return it->second; + } + + Logger::getInstance().debug("Building and caching '**' options map for '" + + cb_name + "'"); + std::unordered_map built_map; + for (const std::string& includable : cb.getIncludables()) { + if (all_cbs.find(includable) == all_cbs.end()) { + Logger::getInstance().debug("Skipping '" + includable + + "' — not a loaded control block"); + continue; + } + Logger::getInstance().debug( + "Initializing and adding '**' to the include list for the '" + + includable + "' control block..."); + built_map[includable].include_patterns = {"**"}; + } + + auto [inserted_it, _] = + double_asterisk_cache_.emplace(cb_name, std::move(built_map)); + return inserted_it->second; +} + +std::unordered_map IncludeResolver::resolve( + const std::vector& include_patterns, const ControlBlock& cb, + const std::unordered_map& all_cbs) { + Logger::getInstance().debug( + "Creating include lists for child control blocks to include with the '" + + cb.getName() + "' control block..."); + + std::unordered_map out; + + for (const std::string& include : include_patterns) { + if (include == "**") { + Logger::getInstance().debug("Processing '**' include..."); + // ** overrides everything: return the cached full-depth map directly. + return IncludeResolver::getDoubleAsteriskMap(cb, all_cbs); + } else if (include == "*") { + Logger::getInstance().debug("Processing '*' include..."); + IncludeResolver::processAsterisk(out, cb, all_cbs); + } else { + Logger::getInstance().debug("Processing '" + include + "' include..."); + IncludeResolver::processExplicit(out, include, cb, all_cbs); + } + } + + Logger::getInstance().debug( + "Include lists for child control blocks to include with the '" + + cb.getName() + "' control block have been created"); + return out; +} + +void IncludeResolver::processAsterisk( + std::unordered_map& out, + const ControlBlock& cb, + const std::unordered_map& all_cbs) { + for (const std::string& includable : cb.getIncludables()) { + if (all_cbs.find(includable) == all_cbs.end()) { + Logger::getInstance().debug("Skipping '" + includable + + "' — not a loaded control block"); + continue; + } + if (out.find(includable) != out.end()) { + Logger::getInstance().debug("Include list already exists for the '" + + includable + "' control block"); + continue; + } + Logger::getInstance().debug("Initializing include list for the '" + + includable + "' control block..."); + out[includable].include_patterns = {}; + } +} + +void IncludeResolver::processExplicit( + std::unordered_map& out, std::string include, + const ControlBlock& cb, + const std::unordered_map& all_cbs) { + const std::string del = "."; + std::string include_includes = ""; + size_t del_pos = include.find(del); + if (del_pos != std::string::npos) { + include_includes = include.substr(del_pos + 1); + include.resize(del_pos); + } + if (std::find(cb.getIncludables().begin(), cb.getIncludables().end(), + include) == cb.getIncludables().end()) { + Logger::getInstance().debug( + "'" + include + + "' is not a known child control block that can be included with the '" + + cb.getName() + "' control block"); + throw IncludeError(); + } + if (all_cbs.find(include) == all_cbs.end()) { + Logger::getInstance().debug("'" + include + + "' is not a loaded control block"); + throw IncludeError(); + } + if (out.find(include) == out.end()) { + if (include_includes.empty()) { + Logger::getInstance().debug("Initializing include list for the '" + + include + "' control block..."); + out[include].include_patterns = {}; + } else { + Logger::getInstance().debug("Adding '" + include_includes + + "' to the include list for the '" + include + + "' control block..."); + out[include].include_patterns = {include_includes}; + } + } else { + if (include_includes.empty()) { + return; + } + if (std::find(out[include].include_patterns.begin(), + out[include].include_patterns.end(), + include_includes) != out[include].include_patterns.end()) { + return; + } + Logger::getInstance().debug("Adding '" + include_includes + + "' to the include list for the '" + include + + "' control block..."); + out[include].include_patterns.push_back(include_includes); + } +} + +} // namespace CBXP diff --git a/cbxp/traversal/include_resolver.hpp b/cbxp/traversal/include_resolver.hpp new file mode 100644 index 0000000..f6956b1 --- /dev/null +++ b/cbxp/traversal/include_resolver.hpp @@ -0,0 +1,48 @@ +#ifndef __CBXP_INCLUDE_RESOLVER_H_ +#define __CBXP_INCLUDE_RESOLVER_H_ + +#include +#include +#include + +#include "cbxp_types.hpp" +#include "control_blocks/control_block.hpp" + +namespace CBXP { + +// Parses an include-pattern list into a per-child options map. +// Pure after construction: resolve() always returns the same result. +class IncludeResolver { + public: + // Returns the cached double-asterisk options map for `cb`, built on first + // call; the cache is keyed by name and shared process-wide. + static const std::unordered_map& + getDoubleAsteriskMap( + const ControlBlock& cb, + const std::unordered_map& all_cbs); + + // Parses `include_patterns` for `cb` and returns child-block-name -> + // cbxp_options_t for every child to follow. + static std::unordered_map resolve( + const std::vector& include_patterns, const ControlBlock& cb, + const std::unordered_map& all_cbs); + + private: + static std::unordered_map> + double_asterisk_cache_; + + static void processAsterisk( + std::unordered_map& out, + const ControlBlock& cb, + const std::unordered_map& all_cbs); + + static void processExplicit( + std::unordered_map& out, std::string include, + const ControlBlock& cb, + const std::unordered_map& all_cbs); +}; + +} // namespace CBXP + +#endif diff --git a/cbxp/traversal/traversal_context.hpp b/cbxp/traversal/traversal_context.hpp new file mode 100644 index 0000000..4d77a9f --- /dev/null +++ b/cbxp/traversal/traversal_context.hpp @@ -0,0 +1,67 @@ +#ifndef __CBXP_TRAVERSAL_CONTEXT_H_ +#define __CBXP_TRAVERSAL_CONTEXT_H_ + +#include +#include +#include +#include +#include +#include +#include + +#include "cbxp_types.hpp" +#include "control_blocks/control_block.hpp" + +namespace CBXP { + +// Hash for (address, cb_name) pairs used as VisitedMap keys. +struct PairHash { + std::size_t operator()( + const std::pair& p) const noexcept { + std::size_t h1 = std::hash{}(p.first); + std::size_t h2 = std::hash{}(p.second); + return h1 ^ (h2 << 32 | h2 >> 32); + } +}; + +// Result JSON per enqueued (address, cb_type): false = in progress (cycle +// break), null = empty/unreachable, object/array = fully resolved. +using VisitKey = std::pair; +using VisitedMap = std::unordered_map; +using VisitKeySet = std::unordered_set; +using VisitKeyMap = std::unordered_map; + +class ControlBlockNode; + +// One item in the BFS work-queue. +struct PendingNode { + const void* p_address; + std::string cb_name; + cbxp_options_t options; + // True for nodes seeded by run() (roots), false for children; traverse uses + // it to decide whether missing filters make the reachability check refuse. + bool is_root = false; + // Roots only: the node run() built while validating options, reused by + // traverse(). Null for children. + std::shared_ptr prepared = nullptr; +}; + +// All shared, mutable traversal state. Passed by reference into every +// ControlBlockNode so nodes never own traversal state themselves. +struct TraversalContext { + const std::unordered_map& control_blocks; + bool skip_buffer_length_check; + VisitedMap visited; + std::queue queue; + // Nodes rejected by their own filters (visited holds null); lets a parent + // tell this apart from inaccessible / eyecatcher mismatch. + VisitKeySet filter_rejected; + // Included child name -> whether it has filters (can reject its parent); + // used by TraversalEngine::resolvePlaceholders. + std::unordered_map, PairHash> + child_filtered; +}; + +} // namespace CBXP + +#endif diff --git a/cbxp/traversal/traversal_engine.cpp b/cbxp/traversal/traversal_engine.cpp new file mode 100644 index 0000000..69ae526 --- /dev/null +++ b/cbxp/traversal/traversal_engine.cpp @@ -0,0 +1,599 @@ +#include "traversal/traversal_engine.hpp" + +#include +#include +#include + +#include "control_blocks/control_block_field_formatter.hpp" +#include "traversal/control_block_node.hpp" +#include "traversal/include_resolver.hpp" +#include "util/address_util.hpp" +#include "util/control_block_error.hpp" +#include "util/logger.hpp" + +namespace CBXP { + +TraversalEngine::TraversalEngine( + const std::unordered_map& control_blocks, + bool skip_buffer_length_check) + : ctx_{control_blocks, skip_buffer_length_check, {}, {}, {}, {}} {} + +// --------------------------------------------------------------------------- +// Public + +nlohmann::json TraversalEngine::run(const std::string& cb_name, + const cbxp_options_t& options, + const void* p_address, + size_t buffer_length) { + const ControlBlock& cb = ctx_.control_blocks.at(cb_name); + // Validate include/filter options against the root block before reading + // storage; the node is kept so traverse() reuses its include/filter lists. + const ControlBlockNode validator(ctx_, options, cb_name, /*address=*/nullptr, + buffer_length); + Logger::getInstance().debug( + "Traversing '" + cb_name + "' (" + + (p_address == nullptr ? "extract" : "format") + + "): " + std::to_string(options.include_patterns.size()) + + " include pattern(s), " + std::to_string(options.filters.size()) + + " filter(s)"); + + // Extract only (address == nullptr): child nodes skip this check because + // their parent already passed it. + if (p_address == nullptr) { + TraversalEngine::checkReachability(cb, !options.filters.empty()); + } + + // Resolve the set of root addresses for this traversal. + std::vector roots; + if (p_address != nullptr) { + roots = {p_address}; + } else { + roots = TraversalEngine::findRootAddresses(cb); + // Deduplicate (e.g. ECVT is pointed to by both CVT and PSA). + std::vector unique_roots; + for (const void* p : roots) { + if (std::find(unique_roots.begin(), unique_roots.end(), p) == + unique_roots.end()) { + unique_roots.push_back(p); + } + } + if (unique_roots.size() != roots.size()) { + Logger::getInstance().debug( + "Dropped " + std::to_string(roots.size() - unique_roots.size()) + + " duplicate root address(es) for '" + cb_name + "'"); + } + roots = std::move(unique_roots); + } + + if (roots.empty()) { + Logger::getInstance().debug("No pointers found for '" + cb_name + + "' control block."); + return {}; + } + Logger::getInstance().debug("Found " + std::to_string(roots.size()) + + " root address(es) for '" + cb_name + "'"); + + // Seed the queue with the roots; is_root=true makes traverse() apply the + // full reachability check (incl. the no-filter guard) to them only. + for (const void* p_root_addr : roots) { + auto visit_key = std::make_pair(p_root_addr, cb_name); + // try_emplace is a no-op when the key already exists, so this + // atomically checks-and-inserts the in-progress sentinel. + if (ctx_.visited.try_emplace(visit_key, false).second) { + ctx_.queue.push({p_root_addr, cb_name, options, /*is_root=*/true, + std::make_shared( + validator.withAddress(p_root_addr))}); + } else { + Logger::getInstance().debug("Root '" + cb_name + "' at address " + + addressToString(p_root_addr) + + " already queued, skipping"); + } + } + + // Process the queue until empty — this is the BFS loop. + TraversalEngine::traverse(); + + // Resolve placeholder hex strings to real child JSON. A root is omitted + // when it (or a filtered descendant) was rejected. + auto resolve_root = [&](const void* p_root_addr, nlohmann::json& resolved) { + const VisitKey visit_key(p_root_addr, cb_name); + const nlohmann::json& v = ctx_.visited.at(visit_key); + const std::string root_desc = + "Root '" + cb_name + "' at address " + addressToString(p_root_addr); + if (v.is_null() || v.is_boolean()) { + Logger::getInstance().debug( + root_desc + " omitted: unreachable or rejected by filters"); + return false; + } + resolved = v; + VisitKeySet expanded; + const VisitKeyMap owners = TraversalEngine::computeOwners(visit_key); + const bool accepted = TraversalEngine::resolvePlaceholders( + resolved, visit_key, expanded, owners); + Logger::getInstance().debug( + root_desc + (accepted ? " included in output" + : " omitted: rejected by child filters")); + return accepted; + }; + + // A single root yields its object (null if rejected); multiple roots yield + // an array of the roots that were not rejected. + nlohmann::json output; + if (roots.size() == 1) { + nlohmann::json resolved; + if (resolve_root(roots[0], resolved)) { + output = std::move(resolved); + } + } else { + output = nlohmann::json::array(); + for (const void* p_root_addr : roots) { + nlohmann::json resolved; + if (resolve_root(p_root_addr, resolved)) { + output.push_back(std::move(resolved)); + } + } + } + + return output; +} + +// --------------------------------------------------------------------------- +// Private + +void TraversalEngine::checkReachability(const ControlBlock& cb, + bool has_filters) { + const storage_attributes_t& attr = cb.getStorageAttributes(); + if (attr.key != 8 && attr.is_protected && cb.getName() != "psa") { + Logger::getInstance().debug( + "The '" + cb.getName() + "' control block is key '" + + std::to_string(attr.key) + + "' and fetch protected, so cbxp cannot access it."); + throw CbxpBlockUnreachableError(); + } + if (!attr.is_common && !has_filters) { + Logger::getInstance().debug( + "The '" + cb.getName() + + "' control block is not in common storage and there are no filters " + "enabled, so cbxp cannot guarantee accuracy."); + throw CbxpBlockUnreachableError(); + } +} + +std::vector TraversalEngine::findRootAddresses( + const ControlBlock& cb) const { + std::vector result; + const std::vector& pointed_to_by = cb.getPointedToBy(); + + if (pointed_to_by.empty()) { + return {cb.getFixedAddress()}; + } + + for (const auto& parent_name : pointed_to_by) { + const ControlBlock& parent_cb = ctx_.control_blocks.at(parent_name); + const std::vector parent_addrs = + TraversalEngine::findRootAddresses(parent_cb); + + // Find the field in parent that points to cb. + std::string pointer_field_name; + ptrdiff_t pointer_offset = 0; + size_t pointer_length = 4; + std::string count_field; + + for (const auto& [fname, fdata] : parent_cb.getMap()) { + if (!fdata.points_to.empty() && fdata.points_to == cb.getName()) { + pointer_field_name = fname; + pointer_offset = fdata.offset; + pointer_length = fdata.length; + count_field = fdata.count; + break; + } + } + + for (const void* p_parent_addr : parent_addrs) { + size_t count = 1; + if (!count_field.empty()) { + std::string count_key = count_field; + std::transform(count_key.begin(), count_key.end(), count_key.begin(), + [](unsigned char c) { return std::toupper(c); }); + const control_block_field_t& count_f = parent_cb.getMap().at(count_key); + const char* p_count = + static_cast(p_parent_addr) + count_f.offset; + if (count_f.type == SIGNED_INT) { + int64_t signed_count = + (count_f.length == 8) + ? ControlBlockFieldFormatter::sint(p_count) + : ControlBlockFieldFormatter::sint(p_count); + count = (signed_count > 0) ? static_cast(signed_count) : 0; + } else { + count = (count_f.length == 8) + ? ControlBlockFieldFormatter::uint(p_count) + : ControlBlockFieldFormatter::uint(p_count); + } + Logger::getInstance().debug( + "Repeated pointer field '" + pointer_field_name + + "' count_field='" + count_key + "' count=" + std::to_string(count)); + } + + for (size_t i = 0; i < count; ++i) { + const char* p_base = static_cast(p_parent_addr) + + i * pointer_length + pointer_offset; + const void* p_resolved; + if (pointer_length == 8) { + p_resolved = reinterpret_cast( + ControlBlockFieldFormatter::uint(p_base)); + } else { + p_resolved = reinterpret_cast( + ControlBlockFieldFormatter::uint(p_base)); + } + + // Skip entries masked by ignoreMask. + const auto& field_map = parent_cb.getMap(); + auto mask_it = field_map.find(pointer_field_name); + if (mask_it != field_map.end() && + !mask_it->second.ignore_mask.empty()) { + uint32_t raw_val = ControlBlockFieldFormatter::uint(p_base); + uint32_t mask = static_cast(std::stoull( + mask_it->second.ignore_mask, nullptr, 16)) + << 24; + if (raw_val & mask) { + Logger::getInstance().debug( + "Skipping '" + cb.getName() + "' entry at index " + + std::to_string(i) + " — ignoreMask bit set (raw=0x" + + [&]() { + std::ostringstream oss; + oss << std::hex << raw_val; + return oss.str(); + }() + + ")"); + continue; + } + } + + Logger::getInstance().debug("Resolved '" + cb.getName() + + "' pointer to address " + [&]() { + std::ostringstream oss; + oss << p_resolved; + return oss.str(); + }()); + result.push_back(p_resolved); + } + } + } + + return result; +} + +void TraversalEngine::traverse() { + size_t processed = 0; + while (!ctx_.queue.empty()) { + PendingNode node = ctx_.queue.front(); + ctx_.queue.pop(); + ++processed; + Logger::getInstance().debug( + "Processing " + std::string(node.is_root ? "root" : "child") + " '" + + node.cb_name + "' at address " + addressToString(node.p_address) + + " (" + std::to_string(ctx_.queue.size()) + " still queued)"); + + const ControlBlock& cb = ctx_.control_blocks.at(node.cb_name); + + // Roots get the full reachability check (incl. refusing non-common storage + // without filters); children only need the key/fetch-protection gate. + auto visit_key = std::make_pair(node.p_address, node.cb_name); + + // Only CbxpBlockUnreachableError is handled per node (recorded as null, so + // the placeholder stays raw hex); other CBXPErrors propagate out of run(). + try { + if (isGuardPageAddress(node.p_address)) { + Logger::getInstance().debug( + "Skipping '" + node.cb_name + + "' — address falls in PSA fetch-protected range " + + kGuardPageRange); + throw CbxpBlockUnreachableError(); + } + if (node.is_root) { + TraversalEngine::checkReachability(cb, !node.options.filters.empty()); + } else { + TraversalEngine::checkReachability(cb, /*has_filters=*/true); + } + + Logger::getInstance().debug(node.cb_name + " hex dump: address=" + [&]() { + std::ostringstream oss; + oss << node.p_address; + return oss.str(); + }() + " length=" + std::to_string(cb.getMaxOffset())); + Logger::getInstance().hexDump( + reinterpret_cast(node.p_address), + static_cast(cb.getName() == "psa" ? (cb.getMaxOffset() - 8) / 2 + : cb.getMaxOffset()), + cb.getName() == "psa"); + + // Root nodes arrive with the node run() built while validating the + // options; children are built here. + std::shared_ptr cb_node = node.prepared; + if (!cb_node) { + cb_node = std::make_shared( + ctx_, node.options, node.cb_name, node.p_address, + 0 /* buffer_length: 0 = live memory */); + } + NodeParseResult result = cb_node->parse(); + + if (result.json.is_null()) { + ctx_.visited[visit_key] = nullptr; + } else if (!result.filter_passed) { + // Remember that this node was rejected by a filter so that its + // parent can tell this apart from an inaccessible node. + Logger::getInstance().debug( + "Rejected '" + node.cb_name + "' at address " + + addressToString(node.p_address) + ": did not pass its filters"); + ctx_.visited[visit_key] = nullptr; + ctx_.filter_rejected.insert(visit_key); + } else { + ctx_.visited[visit_key] = result.json; + ctx_.child_filtered[visit_key] = cb_node->childFilterMap(); + Logger::getInstance().debug( + "Parsed '" + node.cb_name + "' at address " + + addressToString(node.p_address) + ": " + + std::to_string(result.json.size()) + " JSON key(s)"); + } + } catch (const CbxpBlockUnreachableError& e) { + Logger::getInstance().debug( + "Skipping '" + node.cb_name + "' at address " + + addressToString(node.p_address) + " — error code " + + std::to_string(e.getErrorCode())); + ctx_.visited[visit_key] = nullptr; + } + } + Logger::getInstance().debug( + "Traversal complete: " + std::to_string(processed) + + " node(s) processed, " + std::to_string(ctx_.filter_rejected.size()) + + " rejected by filters"); +} + +namespace { + +enum class ChildState { Resolved, Rejected, Unavailable }; + +const void* placeholderToAddress(const std::string& hex_str, + size_t field_length) { + if (field_length == 8) { + return reinterpret_cast(std::stoull(hex_str, nullptr, 0)); + } + return reinterpret_cast( + static_cast(std::stoull(hex_str, nullptr, 0))); +} + +struct ChildField { + std::string name; + size_t length = 4; + bool is_repeated = false; +}; + +// Returns whether JSON `key` of `cb` is a pointer field to an included child, +// matching the field name or its repeated form "s". +bool findChildField(const ControlBlock& cb, const std::string& key, + const std::unordered_map& child_options, + ChildField& out) { + for (const auto& [fname, fdata] : cb.getMap()) { + std::string lower_fname = fname; + std::transform(lower_fname.begin(), lower_fname.end(), lower_fname.begin(), + [](unsigned char c) { return std::tolower(c); }); + const bool exact_match = (lower_fname == key); + const bool repeated_match = (lower_fname + "s" == key) && fdata.repeated; + if ((exact_match || repeated_match) && !fdata.points_to.empty() && + child_options.find(fdata.points_to) != child_options.end()) { + out = {fdata.points_to, fdata.length, repeated_match}; + return true; + } + } + return false; +} + +bool isPtrKey(const std::string& key) { + return key.size() > 4 && key.substr(key.size() - 4) == "_ptr"; +} + +} // namespace + +VisitKeyMap TraversalEngine::computeOwners(const VisitKey& root_key) const { + VisitKeyMap owners; + owners.emplace(root_key, root_key); + std::queue pending; + pending.push(root_key); + + while (!pending.empty()) { + const VisitKey node_key = pending.front(); + pending.pop(); + + auto node_it = ctx_.visited.find(node_key); + auto opts_it = ctx_.child_filtered.find(node_key); + if (node_it == ctx_.visited.end() || opts_it == ctx_.child_filtered.end() || + !node_it->second.is_object()) { + continue; + } + const ControlBlock& cb = ctx_.control_blocks.at(node_key.second); + + auto claim = [&](const nlohmann::json& placeholder, const ChildField& f) { + if (!placeholder.is_string()) { + return; + } + const VisitKey child_key( + placeholderToAddress(placeholder.get(), f.length), + f.name); + if (owners.emplace(child_key, node_key).second) { + pending.push(child_key); + Logger::getInstance().debug( + "Owner of '" + child_key.second + "' at address " + + addressToString(child_key.first) + " is '" + node_key.second + + "' at address " + addressToString(node_key.first)); + } + }; + + for (const auto& [key, value] : node_it->second.items()) { + ChildField field; + if (isPtrKey(key) || !findChildField(cb, key, opts_it->second, field)) { + continue; + } + if (field.is_repeated && value.is_array()) { + for (const auto& elem : value) { + claim(elem, field); + } + } else if (!field.is_repeated) { + claim(value, field); + } + } + } + return owners; +} + +// Stitches child JSON into `json`. Unfiltered children expand once, under their +// shallowest parent: keeps 'asvtenty' entries in place, stays linear on cyclic +// graphs ('**'). Filtered ones resolve first; filters lose a path segment per +// level, so this cannot cycle. Returns false if the node is rejected. +bool TraversalEngine::resolvePlaceholders(nlohmann::json& json, + const VisitKey& node_key, + VisitKeySet& expanded, + const VisitKeyMap& owners) const { + if (!json.is_object()) { + return true; + } + + expanded.insert(node_key); + + const std::string& cb_name = node_key.second; + const ControlBlock& cb = ctx_.control_blocks.at(cb_name); + // Included child name -> whether that child carries filters. + const auto& child_options = ctx_.child_filtered.at(node_key); + const std::string node_desc = + "'" + cb_name + "' at address " + addressToString(node_key.first); + + for (auto& [key, value] : json.items()) { + // Skip the "_ptr" preservation keys. + if (isPtrKey(key)) { + continue; + } + + // Determine whether this key maps to a pointer field with an included + // child. + ChildField child_field; + if (!findChildField(cb, key, child_options, child_field)) { + continue; + } + const std::string& child_name = child_field.name; + const size_t field_length = child_field.length; + const bool is_repeated_key = child_field.is_repeated; + + // Only children that carry filters can reject this node. + const bool child_filtered = child_options.at(child_name); + + // Look up one child placeholder. On Resolved, child_json holds the child + // (for filtered children, with its own filtered descendants stitched in). + auto resolve_child = [&](const std::string& hex_str, + nlohmann::json& child_json) { + const void* p_child_addr = placeholderToAddress(hex_str, field_length); + const VisitKey child_key(p_child_addr, child_name); + + if (!child_filtered) { + // Expand only under the owner (shallowest parent); any other + // reference stays as a pointer placeholder. + auto leave_as_pointer = [&](const std::string& reason) { + Logger::getInstance().debug( + "Leaving '" + child_name + "' at address " + + addressToString(p_child_addr) + " as a pointer under " + + node_desc + ": " + reason); + return ChildState::Unavailable; + }; + auto owner_it = owners.find(child_key); + if (owner_it == owners.end() || owner_it->second != node_key) { + return leave_as_pointer("it is owned by a different parent"); + } + auto it = ctx_.visited.find(child_key); + if (it == ctx_.visited.end() || it->second.is_boolean() || + it->second.is_null()) { + return leave_as_pointer("it is unreachable or was never parsed"); + } + if (expanded.count(child_key) != 0) { + return leave_as_pointer("it was already expanded"); + } + child_json = it->second; + TraversalEngine::resolvePlaceholders(child_json, child_key, expanded, + owners); + return ChildState::Resolved; + } + + ChildState state = ChildState::Unavailable; + if (ctx_.filter_rejected.count(child_key) != 0) { + state = ChildState::Rejected; + } else { + auto it = ctx_.visited.find(child_key); + if (it != ctx_.visited.end() && !it->second.is_boolean() && + !it->second.is_null()) { + child_json = it->second; + state = TraversalEngine::resolvePlaceholders(child_json, child_key, + expanded, owners) + ? ChildState::Resolved + : ChildState::Rejected; + } + } + + const char* p_verdict = state == ChildState::Resolved ? "passed" + : state == ChildState::Rejected + ? "was REJECTED by a filter" + : "is unavailable (treated as rejected)"; + Logger::getInstance().debug( + "Parent " + node_desc + " evaluated filtered child '" + child_name + + "' at address " + addressToString(p_child_addr) + ": " + p_verdict); + return state; + }; + + if (!is_repeated_key) { + if (!value.is_string()) { + continue; + } + nlohmann::json child_json; + ChildState state = resolve_child(value.get(), child_json); + if (state == ChildState::Resolved) { + json[key + "_ptr"] = value; + value = child_json; + } else if (child_filtered) { + Logger::getInstance().debug("Rejecting " + node_desc + ": child via '" + + key + "' did not pass its filters"); + return false; + } + } else if (value.is_array()) { + nlohmann::json kept = nlohmann::json::array(); + size_t rejected = 0; + for (auto& elem : value) { + if (!elem.is_string()) { + kept.push_back(elem); + continue; + } + nlohmann::json child_json; + ChildState state = resolve_child(elem.get(), child_json); + if (state == ChildState::Resolved) { + kept.push_back(child_json); + } else if (child_filtered) { + ++rejected; + } else { + kept.push_back(elem); + } + } + if (rejected > 0) { + Logger::getInstance().debug( + "Parent " + node_desc + " dropped " + std::to_string(rejected) + + " rejected entr" + (rejected == 1 ? "y" : "ies") + " from '" + key + + "' (" + std::to_string(kept.size()) + " kept)"); + } + if (rejected > 0 && kept.empty()) { + Logger::getInstance().debug("Rejecting " + node_desc + + ": every entry in '" + key + + "' was rejected by child filters"); + return false; + } + value = std::move(kept); + } + } + + return true; +} + +} // namespace CBXP diff --git a/cbxp/traversal/traversal_engine.hpp b/cbxp/traversal/traversal_engine.hpp new file mode 100644 index 0000000..14cfe13 --- /dev/null +++ b/cbxp/traversal/traversal_engine.hpp @@ -0,0 +1,59 @@ +#ifndef __CBXP_TRAVERSAL_ENGINE_H_ +#define __CBXP_TRAVERSAL_ENGINE_H_ + +#include +#include +#include +#include + +#include "cbxp_types.hpp" +#include "control_blocks/control_block.hpp" +#include "traversal/traversal_context.hpp" + +namespace CBXP { + +// Drives the BFS traversal of a control block tree. Pass address=nullptr to +// extract from live memory, or a caller-supplied address to format. +class TraversalEngine { + public: + explicit TraversalEngine( + const std::unordered_map& control_blocks, + bool skip_buffer_length_check); + + // Runs the traversal rooted at `cb_name`: returns the root object, an array + // for multiple roots, or null if rejected / no root found. + nlohmann::json run(const std::string& cb_name, const cbxp_options_t& options, + const void* p_address, size_t buffer_length); + + private: + TraversalContext ctx_; + + // Resolves the root address(es) of `cb` by walking its pointedToBy chain + // from a fixed anchor address. + std::vector findRootAddresses(const ControlBlock& cb) const; + + // BFS loop: pops each node, parses it and stores its JSON in ctx_.visited; + // parsing enqueues children, so the queue grows until the graph is visited. + void traverse(); + + // BFS from `root_key` mapping each node to its shallowest parent (its + // owner); the root maps to itself. + VisitKeyMap computeOwners(const VisitKey& root_key) const; + + // Replaces pointer placeholders in `json` with child JSON from ctx_.visited; + // returns false if `node_key` must be rejected by its filters. `owners` and + // `expanded` limit each node to one expansion, under its shallowest parent. + // Rejected entries of a repeated pointer field are dropped; the node is + // rejected only if every entry was. + bool resolvePlaceholders(nlohmann::json& json, const VisitKey& node_key, + VisitKeySet& expanded, + const VisitKeyMap& owners) const; + + // Check storage-attribute reachability for the root control block. + // Throws CbxpBlockUnreachableError if the block cannot be accessed. + static void checkReachability(const ControlBlock& cb, bool has_filters); +}; + +} // namespace CBXP + +#endif diff --git a/cbxp/util/address_util.hpp b/cbxp/util/address_util.hpp new file mode 100644 index 0000000..6f88084 --- /dev/null +++ b/cbxp/util/address_util.hpp @@ -0,0 +1,29 @@ +#ifndef __CBXP_ADDRESS_UTIL_H_ +#define __CBXP_ADDRESS_UTIL_H_ + +#include +#include + +namespace CBXP { + +inline std::string addressToString(const void* p_addr) { + std::ostringstream oss; + oss << p_addr; + return oss.str(); +} + +// The area 0x7FFFF000-0x7FFFFFFF is fetch-protected, so any access +// from a non-zero key causes a 0C4 before C++ exception handling can +// intervene. Pointers into it must be rejected before any memory access. +constexpr uintptr_t kGuardPageStart = 0x7FFFF000u; +constexpr uintptr_t kGuardPageEnd = 0x7FFFFFFFu; +constexpr const char* kGuardPageRange = "0x7FFFF000-0x7FFFFFFF"; + +inline bool isGuardPageAddress(const void* p_addr) { + const uintptr_t p = reinterpret_cast(p_addr); + return p >= kGuardPageStart && p <= kGuardPageEnd; +} + +} // namespace CBXP + +#endif diff --git a/cbxp/util/control_block_error.hpp b/cbxp/util/control_block_error.hpp new file mode 100644 index 0000000..7c28787 --- /dev/null +++ b/cbxp/util/control_block_error.hpp @@ -0,0 +1,74 @@ +#ifndef __CONTROL_BLOCK_ERROR_H_ +#define __CONTROL_BLOCK_ERROR_H_ + +namespace CBXP { +enum Error { + BadControlBlock = 1, + BadInclude = 2, + BadFilter = 3, + DataTooSmall = 4, + NullDataPtr = 5, + BadCbxpPath = 6, + BlockUnreachable = 7, + JsonFailParse = 8, + JsonFailSchema = 9, + JsonBadValue = 10, +}; + +class CBXPError : public std::exception { + private: + Error error_code_; + + public: + explicit CBXPError(const Error& rc) : error_code_(rc) {} + const unsigned int getErrorCode() const { return error_code_; } +}; + +class ControlBlockError : public CBXPError { + public: + ControlBlockError() : CBXPError(Error::BadControlBlock) {} +}; + +class IncludeError : public CBXPError { + public: + IncludeError() : CBXPError(Error::BadInclude) {} +}; + +class FilterError : public CBXPError { + public: + FilterError() : CBXPError(Error::BadFilter) {} +}; + +class DataLengthError : public CBXPError { + public: + DataLengthError() : CBXPError(Error::DataTooSmall) {} +}; + +class CbxpPathError : public CBXPError { + public: + CbxpPathError() : CBXPError(Error::BadCbxpPath) {} +}; + +class CbxpBlockUnreachableError : public CBXPError { + public: + CbxpBlockUnreachableError() : CBXPError(Error::BlockUnreachable) {} +}; + +class CbxpJsonParseError : public CBXPError { + public: + CbxpJsonParseError() : CBXPError(Error::JsonFailParse) {} +}; + +class CbxpSchemaValidationError : public CBXPError { + public: + CbxpSchemaValidationError() : CBXPError(Error::JsonFailSchema) {} +}; + +class CbxpJsonValueError : public CBXPError { + public: + CbxpJsonValueError() : CBXPError(Error::JsonBadValue) {} +}; + +} // namespace CBXP + +#endif diff --git a/cbxp/logger.cpp b/cbxp/util/logger.cpp similarity index 81% rename from cbxp/logger.cpp rename to cbxp/util/logger.cpp index 6fe7c9f..8867119 100644 --- a/cbxp/logger.cpp +++ b/cbxp/util/logger.cpp @@ -1,6 +1,6 @@ #define _POSIX_SOURCE -#include "logger.hpp" +#include "util/logger.hpp" #include @@ -12,6 +12,8 @@ #include #include +#include "util/safe_read.hpp" + namespace CBXP { Logger::Logger() { debug_ = false; } @@ -41,22 +43,23 @@ void Logger::debug(const std::string& message, const std::string& body) const { } } -void Logger::debugAllocate(const void* ptr, int rmode, int byte_count) const { +void Logger::debugAllocate(const void* p_memory, int rmode, + int byte_count) const { if (!debug_) { return; } std::ostringstream oss; oss << "Allocated " << byte_count << " bytes in " << rmode - << "-bit memory at address " << ptr; + << "-bit memory at address " << p_memory; Logger::debug(oss.str()); } -void Logger::debugFree(const void* ptr) const { +void Logger::debugFree(const void* p_memory) const { if (!debug_) { return; } std::ostringstream oss; - oss << "Freeing memory at address " << ptr << " ..."; + oss << "Freeing memory at address " << p_memory << " ..."; Logger::debug(oss.str()); } @@ -71,8 +74,15 @@ void Logger::hexDump(const char* p_buffer, int length, return; } + // Copy the storage once (guarded, so --debug cannot abend on an unreadable + // address); everything below reads from the copies, never from p_buffer. + auto raw_unique_ptr = std::make_unique(length); + if (!safeCopy(raw_unique_ptr.get(), p_buffer, length)) { + std::cout << std::endl << "" << std::endl << std::endl; + return; + } auto decoded_unique_ptr = std::make_unique(length); - std::memcpy(decoded_unique_ptr.get(), p_buffer, length); + std::memcpy(decoded_unique_ptr.get(), raw_unique_ptr.get(), length); __e2a_l(decoded_unique_ptr.get(), length); std::string hex_dump = "\n"; @@ -122,7 +132,7 @@ void Logger::hexDump(const char* p_buffer, int length, } } hex_stream << std::hex << std::setw(2) << std::setfill('0') - << (static_cast(p_buffer[i]) & 0xff); + << (static_cast(raw_unique_ptr.get()[i]) & 0xff); if (isatty(fileno(stdout))) { hex_stream << ansi_reset_; } diff --git a/cbxp/logger.hpp b/cbxp/util/logger.hpp similarity index 85% rename from cbxp/logger.hpp rename to cbxp/util/logger.hpp index 0545fb7..9771837 100644 --- a/cbxp/logger.hpp +++ b/cbxp/util/logger.hpp @@ -20,8 +20,8 @@ class Logger { static Logger& getInstance(); void setDebug(bool debug); void debug(const std::string& message, const std::string& body = "") const; - void debugAllocate(const void* ptr, int rmode, int byte_count) const; - void debugFree(const void* ptr) const; + void debugAllocate(const void* p_memory, int rmode, int byte_count) const; + void debugFree(const void* p_memory) const; void hexDump(const char* p_buffer, int length, bool intended_nullptr = false) const; }; diff --git a/cbxp/util/safe_read.cpp b/cbxp/util/safe_read.cpp new file mode 100644 index 0000000..967dbde --- /dev/null +++ b/cbxp/util/safe_read.cpp @@ -0,0 +1,42 @@ +#include "util/safe_read.hpp" + +#include <__le_api.h> +#include + +#include + +namespace CBXP { + +namespace { + +struct Recovery { + jmp_buf env; +}; + +// Language Environment abends the thread/process if an exception handler +// returns, so this only ever leaves via longjmp. The token is the Recovery +// object of the safeCopy() frame that registered the handler. +void onStorageException(struct __cib*, void* token) { + longjmp(static_cast(token)->env, 1); +} + +} // namespace + +// Keep this frame free of C++ objects: longjmp does not run destructors. +bool safeCopy(void* p_dst, const void* p_src, size_t n) { + Recovery rec; + if (setjmp(rec.env) != 0) { + // The handler is still registered in this frame, so remove it. + __reset_exception_handler(); + return false; + } + if (__set_exception_handler(onStorageException, &rec) != 0) { + // Fail closed: never read without protection in place. + return false; + } + std::memcpy(p_dst, p_src, n); + __reset_exception_handler(); + return true; +} + +} // namespace CBXP diff --git a/cbxp/util/safe_read.hpp b/cbxp/util/safe_read.hpp new file mode 100644 index 0000000..3dbe27f --- /dev/null +++ b/cbxp/util/safe_read.hpp @@ -0,0 +1,16 @@ +#ifndef __CBXP_SAFE_READ_H_ +#define __CBXP_SAFE_READ_H_ + +#include + +namespace CBXP { + +// Copies n bytes from storage that may be unreadable (fetch-protected, +// unmapped, ...). Returns false instead of abending with S0C4 if the copy +// raises a hardware exception. The contents of dst are indeterminate on +// failure. +bool safeCopy(void* p_dst, const void* p_src, size_t n); + +} // namespace CBXP + +#endif diff --git a/externals/json-schema-validator/LICENSE b/externals/json-schema-validator/LICENSE new file mode 100644 index 0000000..f660b34 --- /dev/null +++ b/externals/json-schema-validator/LICENSE @@ -0,0 +1,22 @@ +Modern C++ JSON schema validator is licensed under the MIT License +: + +Copyright (c) 2016 Patrick Boettcher + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/externals/json-schema-validator/json-patch.cpp b/externals/json-schema-validator/json-patch.cpp new file mode 100644 index 0000000..3203543 --- /dev/null +++ b/externals/json-schema-validator/json-patch.cpp @@ -0,0 +1,115 @@ +#include "json-patch.hpp" + +#include + +namespace +{ + +// originally from http://jsonpatch.com/, http://json.schemastore.org/json-patch +// with fixes +const nlohmann::json patch_schema = R"patch({ + "title": "JSON schema for JSONPatch files", + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "array", + + "items": { + "oneOf": [ + { + "additionalProperties": false, + "required": [ "value", "op", "path"], + "properties": { + "path" : { "$ref": "#/definitions/path" }, + "op": { + "description": "The operation to perform.", + "type": "string", + "enum": [ "add", "replace", "test" ] + }, + "value": { + "description": "The value to add, replace or test." + } + } + }, + { + "additionalProperties": false, + "required": [ "op", "path"], + "properties": { + "path" : { "$ref": "#/definitions/path" }, + "op": { + "description": "The operation to perform.", + "type": "string", + "enum": [ "remove" ] + } + } + }, + { + "additionalProperties": false, + "required": [ "from", "op", "path" ], + "properties": { + "path" : { "$ref": "#/definitions/path" }, + "op": { + "description": "The operation to perform.", + "type": "string", + "enum": [ "move", "copy" ] + }, + "from": { + "$ref": "#/definitions/path", + "description": "A JSON Pointer path pointing to the location to move/copy from." + } + } + } + ] + }, + "definitions": { + "path": { + "description": "A JSON Pointer path.", + "type": "string" + } + } +})patch"_json; +} // namespace + +namespace nlohmann +{ + +json_patch::json_patch(json &&patch) + : j_(std::move(patch)) +{ + validateJsonPatch(j_); +} + +json_patch::json_patch(const json &patch) + : j_(std::move(patch)) +{ + validateJsonPatch(j_); +} + +json_patch &json_patch::add(const json::json_pointer &ptr, json value) +{ + j_.push_back(json{{"op", "add"}, {"path", ptr.to_string()}, {"value", std::move(value)}}); + return *this; +} + +json_patch &json_patch::replace(const json::json_pointer &ptr, json value) +{ + j_.push_back(json{{"op", "replace"}, {"path", ptr.to_string()}, {"value", std::move(value)}}); + return *this; +} + +json_patch &json_patch::remove(const json::json_pointer &ptr) +{ + j_.push_back(json{{"op", "remove"}, {"path", ptr.to_string()}}); + return *this; +} + +void json_patch::validateJsonPatch(json const &patch) +{ + // static put here to have it created at the first usage of validateJsonPatch + static nlohmann::json_schema::json_validator patch_validator(patch_schema); + + patch_validator.validate(patch); + + for (auto const &op : patch) + json::json_pointer(op["path"].get()); +} + +} // namespace nlohmann diff --git a/externals/json-schema-validator/json-patch.hpp b/externals/json-schema-validator/json-patch.hpp new file mode 100644 index 0000000..39a579b --- /dev/null +++ b/externals/json-schema-validator/json-patch.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include +#include + +namespace nlohmann +{ +class JsonPatchFormatException : public std::exception +{ +public: + explicit JsonPatchFormatException(std::string msg) + : ex_{std::move(msg)} {} + + inline const char *what() const noexcept override final { return ex_.c_str(); } + +private: + std::string ex_; +}; + +class json_patch +{ +public: + json_patch() = default; + json_patch(json &&patch); + json_patch(const json &patch); + + json_patch &add(const json::json_pointer &, json value); + json_patch &replace(const json::json_pointer &, json value); + json_patch &remove(const json::json_pointer &); + + json &get_json() { return j_; } + const json &get_json() const { return j_; } + + operator json() const { return j_; } + +private: + json j_ = nlohmann::json::array(); + + static void validateJsonPatch(json const &patch); +}; +} // namespace nlohmann diff --git a/externals/json-schema-validator/json-schema-draft7.json.cpp b/externals/json-schema-validator/json-schema-draft7.json.cpp new file mode 100644 index 0000000..b680e2c --- /dev/null +++ b/externals/json-schema-validator/json-schema-draft7.json.cpp @@ -0,0 +1,185 @@ +/* + * JSON schema validator for JSON for modern C++ + * + * Copyright (c) 2016-2019 Patrick Boettcher . + * + * SPDX-License-Identifier: MIT + * + */ +#include + +namespace nlohmann +{ +namespace json_schema +{ + +json draft7_schema_builtin = R"( { + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://json-schema.org/draft-07/schema#", + "title": "Core schema meta-schema", + "definitions": { + "schemaArray": { + "type": "array", + "minItems": 1, + "items": { "$ref": "#" } + }, + "nonNegativeInteger": { + "type": "integer", + "minimum": 0 + }, + "nonNegativeIntegerDefault0": { + "allOf": [ + { "$ref": "#/definitions/nonNegativeInteger" }, + { "default": 0 } + ] + }, + "simpleTypes": { + "enum": [ + "array", + "boolean", + "integer", + "null", + "number", + "object", + "string" + ] + }, + "stringArray": { + "type": "array", + "items": { "type": "string" }, + "uniqueItems": true, + "default": [] + } + }, + "type": ["object", "boolean"], + "properties": { + "$id": { + "type": "string", + "format": "uri-reference" + }, + "$schema": { + "type": "string", + "format": "uri" + }, + "$ref": { + "type": "string", + "format": "uri-reference" + }, + "$comment": { + "type": "string" + }, + "title": { + "type": "string" + }, + "description": { + "type": "string" + }, + "default": true, + "readOnly": { + "type": "boolean", + "default": false + }, + "examples": { + "type": "array", + "items": true + }, + "multipleOf": { + "type": "number", + "exclusiveMinimum": 0 + }, + "maximum": { + "type": "number" + }, + "exclusiveMaximum": { + "type": "number" + }, + "minimum": { + "type": "number" + }, + "exclusiveMinimum": { + "type": "number" + }, + "maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, + "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "pattern": { + "type": "string", + "format": "regex" + }, + "additionalItems": { "$ref": "#" }, + "items": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/schemaArray" } + ], + "default": true + }, + "maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, + "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "uniqueItems": { + "type": "boolean", + "default": false + }, + "contains": { "$ref": "#" }, + "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, + "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, + "required": { "$ref": "#/definitions/stringArray" }, + "additionalProperties": { "$ref": "#" }, + "definitions": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "default": {} + }, + "properties": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "default": {} + }, + "patternProperties": { + "type": "object", + "additionalProperties": { "$ref": "#" }, + "propertyNames": { "format": "regex" }, + "default": {} + }, + "dependencies": { + "type": "object", + "additionalProperties": { + "anyOf": [ + { "$ref": "#" }, + { "$ref": "#/definitions/stringArray" } + ] + } + }, + "propertyNames": { "$ref": "#" }, + "const": true, + "enum": { + "type": "array", + "items": true, + "minItems": 1, + "uniqueItems": true + }, + "type": { + "anyOf": [ + { "$ref": "#/definitions/simpleTypes" }, + { + "type": "array", + "items": { "$ref": "#/definitions/simpleTypes" }, + "minItems": 1, + "uniqueItems": true + } + ] + }, + "format": { "type": "string" }, + "contentMediaType": { "type": "string" }, + "contentEncoding": { "type": "string" }, + "if": { "$ref": "#" }, + "then": { "$ref": "#" }, + "else": { "$ref": "#" }, + "allOf": { "$ref": "#/definitions/schemaArray" }, + "anyOf": { "$ref": "#/definitions/schemaArray" }, + "oneOf": { "$ref": "#/definitions/schemaArray" }, + "not": { "$ref": "#" } + }, + "default": true +} )"_json; +} +} // namespace nlohmann diff --git a/externals/json-schema-validator/json-uri.cpp b/externals/json-schema-validator/json-uri.cpp new file mode 100644 index 0000000..2602556 --- /dev/null +++ b/externals/json-schema-validator/json-uri.cpp @@ -0,0 +1,159 @@ +/* + * JSON schema validator for JSON for modern C++ + * + * Copyright (c) 2016-2019 Patrick Boettcher . + * + * SPDX-License-Identifier: MIT + * + */ +#include + +#include + +namespace nlohmann +{ + +void json_uri::update(const std::string &uri) +{ + std::string pointer = ""; // default pointer is document-root + + // first split the URI into location and pointer + auto pointer_separator = uri.find('#'); + if (pointer_separator != std::string::npos) { // and extract the pointer-string if found + pointer = uri.substr(pointer_separator + 1); // remove # + + // unescape %-values IOW, decode JSON-URI-formatted JSON-pointer + std::size_t pos = pointer.size() - 1; + do { + pos = pointer.rfind('%', pos); + if (pos == std::string::npos) + break; + + if (pos >= pointer.size() - 2) { + pos--; + continue; + } + + std::string hex = pointer.substr(pos + 1, 2); + char ascii = static_cast(std::strtoul(hex.c_str(), nullptr, 16)); + pointer.replace(pos, 3, 1, ascii); + + pos--; + } while (1); + } + + auto location = uri.substr(0, pointer_separator); + + if (location.size()) { // a location part has been found + + // if it is an URN take it as it is + if (location.find("urn:") == 0) { + urn_ = location; + + // and clear URL members + scheme_ = ""; + authority_ = ""; + path_ = ""; + + } else { // it is an URL + + // split URL in protocol, hostname and path + std::size_t pos = 0; + auto proto = location.find("://", pos); + if (proto != std::string::npos) { // extract the protocol + + urn_ = ""; // clear URN-member if URL is parsed + + scheme_ = location.substr(pos, proto - pos); + pos = 3 + proto; // 3 == "://" + + auto authority = location.find("/", pos); + if (authority != std::string::npos) { // and the hostname (no proto without hostname) + authority_ = location.substr(pos, authority - pos); + pos = authority; + } + } + + auto path = location.substr(pos); + + // URNs cannot of have paths + if (urn_.size() && path.size()) + throw std::invalid_argument("Cannot add a path (" + path + ") to an URN URI (" + urn_ + ")"); + + if (path[0] == '/') // if it starts with a / it is root-path + path_ = path; + else if (pos == 0) { // the URL contained only a path and the current path has no / at the end, strip last element until / and append + auto last_slash = path_.rfind('/'); + path_ = path_.substr(0, last_slash) + '/' + path; + } else // otherwise it is a subfolder + path_.append(path); + } + } + + pointer_ = ""_json_pointer; + identifier_ = ""; + + if (pointer[0] == '/') + pointer_ = json::json_pointer(pointer); + else + identifier_ = pointer; +} + +std::string json_uri::location() const +{ + if (urn_.size()) + return urn_; + + std::stringstream s; + + if (scheme_.size() > 0) + s << scheme_ << "://"; + + s << authority_ + << path_; + + return s.str(); +} + +std::string json_uri::to_string() const +{ + std::stringstream s; + + s << location() << " # "; + + if (identifier_ == "") + s << pointer_.to_string(); + else + s << identifier_; + + return s.str(); +} + +std::ostream &operator<<(std::ostream &os, const json_uri &u) +{ + return os << u.to_string(); +} + +std::string json_uri::escape(const std::string &src) +{ + std::vector> chars = { + {"~", "~0"}, + {"/", "~1"}}; + + std::string l = src; + + for (const auto &c : chars) { + std::size_t pos = 0; + do { + pos = l.find(c.first, pos); + if (pos == std::string::npos) + break; + l.replace(pos, 1, c.second); + pos += c.second.size(); + } while (1); + } + + return l; +} + +} // namespace nlohmann diff --git a/externals/json-schema-validator/json-validator.cpp b/externals/json-schema-validator/json-validator.cpp new file mode 100644 index 0000000..62ce97c --- /dev/null +++ b/externals/json-schema-validator/json-validator.cpp @@ -0,0 +1,1520 @@ +/* + * JSON schema validator for JSON for modern C++ + * + * Copyright (c) 2016-2019 Patrick Boettcher . + * + * SPDX-License-Identifier: MIT + * + */ +#include + +#include "json-patch.hpp" + +#include +#include +#include +#include +#include + +using nlohmann::json; +using nlohmann::json_patch; +using nlohmann::json_uri; +using nlohmann::json_schema::root_schema; +using namespace nlohmann::json_schema; + +#ifdef JSON_SCHEMA_BOOST_REGEX +# include +# define REGEX_NAMESPACE boost +#elif defined(JSON_SCHEMA_NO_REGEX) +# define NO_STD_REGEX +#else +# include +# define REGEX_NAMESPACE std +#endif + +namespace +{ + +class schema +{ +protected: + root_schema *root_; + json default_value_ = nullptr; + +protected: + virtual std::shared_ptr make_for_default_( + std::shared_ptr<::schema> & /* sch */, + root_schema * /* root */, + std::vector & /* uris */, + nlohmann::json & /* default_value */) const + { + return nullptr; + }; + +public: + virtual ~schema() = default; + + schema(root_schema *root) + : root_(root) {} + + virtual void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const = 0; + + virtual const json &default_value(const json::json_pointer &, const json &, error_handler &) const + { + return default_value_; + } + + void set_default_value(const json &v) { default_value_ = v; } + + static std::shared_ptr make(json &schema, + root_schema *root, + const std::vector &key, + std::vector uris); +}; + +class schema_ref : public schema +{ + const std::string id_; + std::weak_ptr target_; + std::shared_ptr target_strong_; // for references to references keep also the shared_ptr because + // no one else might use it after resolving + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final + { + auto target = target_.lock(); + + if (target) + target->validate(ptr, instance, patch, e); + else + e.error(ptr, instance, "unresolved or freed schema-reference " + id_); + } + + const json &default_value(const json::json_pointer &ptr, const json &instance, error_handler &e) const override final + { + if (!default_value_.is_null()) + return default_value_; + + auto target = target_.lock(); + if (target) + return target->default_value(ptr, instance, e); + + e.error(ptr, instance, "unresolved or freed schema-reference " + id_); + + return default_value_; + } + +protected: + virtual std::shared_ptr make_for_default_( + std::shared_ptr<::schema> &sch, + root_schema *root, + std::vector &uris, + nlohmann::json &default_value) const override + { + // create a new reference schema using the original reference (which will be resolved later) + // to store this overloaded default value #209 + auto result = std::make_shared(uris[0].to_string(), root); + result->set_target(sch, true); + result->set_default_value(default_value); + return result; + }; + +public: + schema_ref(const std::string &id, root_schema *root) + : schema(root), id_(id) {} + + const std::string &id() const { return id_; } + + void set_target(const std::shared_ptr &target, bool strong = false) + { + target_ = target; + if (strong) + target_strong_ = target; + } +}; + +} // namespace + +namespace nlohmann +{ +namespace json_schema +{ + +class root_schema +{ + schema_loader loader_; + format_checker format_check_; + content_checker content_check_; + + std::shared_ptr root_; + + struct schema_file { + std::map> schemas; + std::map> unresolved; // contains all unresolved references from any other file seen during parsing + json unknown_keywords; + }; + + // location as key + std::map files_; + + schema_file &get_or_create_file(const std::string &loc) + { + auto file = files_.lower_bound(loc); + if (file != files_.end() && !(files_.key_comp()(loc, file->first))) + return file->second; + else + return files_.insert(file, {loc, {}})->second; + } + +public: + root_schema(schema_loader &&loader, + format_checker &&format, + content_checker &&content) + + : loader_(std::move(loader)), + format_check_(std::move(format)), + content_check_(std::move(content)) + { + } + + format_checker &format_check() { return format_check_; } + content_checker &content_check() { return content_check_; } + + void insert(const json_uri &uri, const std::shared_ptr &s) + { + auto &file = get_or_create_file(uri.location()); + auto sch = file.schemas.lower_bound(uri.fragment()); + if (sch != file.schemas.end() && !(file.schemas.key_comp()(uri.fragment(), sch->first))) { + throw std::invalid_argument("schema with " + uri.to_string() + " already inserted"); + return; + } + + file.schemas.insert({uri.fragment(), s}); + + // was someone referencing this newly inserted schema? + auto unresolved = file.unresolved.find(uri.fragment()); + if (unresolved != file.unresolved.end()) { + unresolved->second->set_target(s); + file.unresolved.erase(unresolved); + } + } + + void insert_unknown_keyword(const json_uri &uri, const std::string &key, json &value) + { + auto &file = get_or_create_file(uri.location()); + auto new_uri = uri.append(key); + auto fragment = new_uri.pointer(); + + // is there a reference looking for this unknown-keyword, which is thus no longer a unknown keyword but a schema + auto unresolved = file.unresolved.find(fragment.to_string()); + if (unresolved != file.unresolved.end()) + schema::make(value, this, {}, {{new_uri}}); + else { // no, nothing ref'd it, keep for later + + // need to create an object for each reference-token in the + // JSON-Pointer When not existing, a stringified integer reference + // token (e.g. "123") in the middle of the pointer will be + // interpreted a an array-index and an array will be created. + + // json_pointer's reference_tokens is private - get them + std::deque ref_tokens; + auto uri_pointer = uri.pointer(); + while (!uri_pointer.empty()) { + ref_tokens.push_front(uri_pointer.back()); + uri_pointer.pop_back(); + } + + // for each token create an object, if not already existing + auto unk_kw = &file.unknown_keywords; + for (auto &rt : ref_tokens) { + // create a json_pointer from rt as rt can be an stringified integer doing find on an array won't work + json::json_pointer rt_ptr{"/" + rt}; + if (unk_kw->contains(rt_ptr) == false) + (*unk_kw)[rt] = json::object(); + unk_kw = &(*unk_kw)[rt_ptr]; + } + (*unk_kw)[key] = value; + } + + // recursively add possible subschemas of unknown keywords + if (value.type() == json::value_t::object) + for (auto &subsch : value.items()) + insert_unknown_keyword(new_uri, subsch.key(), subsch.value()); + } + + std::shared_ptr get_or_create_ref(const json_uri &uri) + { + auto &file = get_or_create_file(uri.location()); + + // existing schema + auto sch = file.schemas.find(uri.fragment()); + if (sch != file.schemas.end()) + return sch->second; + + // referencing an unknown keyword, turn it into schema + // + // an unknown keyword can only be referenced by a json-pointer, + // not by a plain name fragment + if (!uri.pointer().to_string().empty()) { + bool contains_pointer = file.unknown_keywords.contains(uri.pointer()); + if (contains_pointer) { + auto &subschema = file.unknown_keywords.at(uri.pointer()); + auto s = schema::make(subschema, this, {}, {{uri}}); + if (s) { // if schema is valid (non-null) + file.unknown_keywords.erase(uri.fragment()); + return s; + } + } + } + + // get or create a schema_ref + auto r = file.unresolved.lower_bound(uri.fragment()); + if (r != file.unresolved.end() && !(file.unresolved.key_comp()(uri.fragment(), r->first))) { + return r->second; // unresolved, already seen previously - use existing reference + } else { + return file.unresolved.insert(r, + {uri.fragment(), std::make_shared(uri.to_string(), this)}) + ->second; // unresolved, create reference + } + } + + void set_root_schema(json sch) + { + files_.clear(); + root_ = schema::make(sch, this, {}, {{"#"}}); + + // load all files which have not yet been loaded + do { + bool new_schema_loaded = false; + + // files_ is modified during parsing, iterators are invalidated + std::vector locations; + for (auto &file : files_) + locations.push_back(file.first); + + for (auto &loc : locations) { + if (files_[loc].schemas.size() == 0) { // nothing has been loaded for this file + if (loader_) { + json loaded_schema; + + loader_(loc, loaded_schema); + + schema::make(loaded_schema, this, {}, {{loc}}); + new_schema_loaded = true; + } else { + throw std::invalid_argument("external schema reference '" + loc + "' needs loading, but no loader callback given"); + } + } + } + + if (!new_schema_loaded) // if no new schema loaded, no need to try again + break; + } while (1); + + for (const auto &file : files_) { + if (file.second.unresolved.size() != 0) { + // Build a representation of the undefined + // references as a list of comma-separated strings. + auto n_urefs = file.second.unresolved.size(); + std::string urefs = "["; + + decltype(n_urefs) counter = 0; + for (const auto &p : file.second.unresolved) { + urefs += p.first; + + if (counter != n_urefs - 1u) { + urefs += ", "; + } + + ++counter; + } + + urefs += "]"; + + throw std::invalid_argument("after all files have been parsed, '" + + (file.first == "" ? "" : file.first) + + "' has still the following undefined references: " + urefs); + } + } + } + + void validate(const json::json_pointer &ptr, + const json &instance, + json_patch &patch, + error_handler &e, + const json_uri &initial) const + { + if (!root_) { + e.error(ptr, "", "no root schema has yet been set for validating an instance"); + return; + } + + auto file_entry = files_.find(initial.location()); + if (file_entry == files_.end()) { + e.error(ptr, "", "no file found serving requested root-URI. " + initial.location()); + return; + } + + auto &file = file_entry->second; + auto sch = file.schemas.find(initial.fragment()); + if (sch == file.schemas.end()) { + e.error(ptr, "", "no schema find for request initial URI: " + initial.to_string()); + return; + } + + sch->second->validate(ptr, instance, patch, e); + } +}; + +} // namespace json_schema +} // namespace nlohmann + +namespace +{ + +class first_error_handler : public error_handler +{ +public: + bool error_{false}; + json::json_pointer ptr_; + json instance_; + std::string message_; + + void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override + { + if (*this) + return; + error_ = true; + ptr_ = ptr; + instance_ = instance; + message_ = message; + } + + operator bool() const { return error_; } +}; + +class logical_not : public schema +{ + std::shared_ptr subschema_; + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final + { + first_error_handler esub; + subschema_->validate(ptr, instance, patch, esub); + + if (!esub) + e.error(ptr, instance, "the subschema has succeeded, but it is required to not validate"); + } + + const json &default_value(const json::json_pointer &ptr, const json &instance, error_handler &e) const override + { + return subschema_->default_value(ptr, instance, e); + } + +public: + logical_not(json &sch, + root_schema *root, + const std::vector &uris) + : schema(root) + { + subschema_ = schema::make(sch, root, {"not"}, uris); + } +}; + +enum logical_combination_types { + allOf, + anyOf, + oneOf +}; + +class logical_combination_error_handler : public error_handler +{ +public: + struct error_entry { + json::json_pointer ptr_; + json instance_; + std::string message_; + }; + + std::vector error_entry_list_; + + void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override + { + error_entry_list_.push_back(error_entry{ptr, instance, message}); + } + + void propagate(error_handler &e, const std::string &prefix) const + { + for (const error_entry &entry : error_entry_list_) + e.error(entry.ptr_, entry.instance_, prefix + entry.message_); + } + + operator bool() const { return !error_entry_list_.empty(); } +}; + +template +class logical_combination : public schema +{ + std::vector> subschemata_; + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const final + { + size_t count = 0; + logical_combination_error_handler error_summary; + + for (std::size_t index = 0; index < subschemata_.size(); ++index) { + const std::shared_ptr &s = subschemata_[index]; + logical_combination_error_handler esub; + auto oldPatchSize = patch.get_json().size(); + s->validate(ptr, instance, patch, esub); + if (!esub) + count++; + else { + patch.get_json().get_ref().resize(oldPatchSize); + esub.propagate(error_summary, "case#" + std::to_string(index) + "] "); + } + + if (is_validate_complete(instance, ptr, e, esub, count, index)) + return; + } + + if (count == 0) { + e.error(ptr, instance, "no subschema has succeeded, but one of them is required to validate. Type: " + key + ", number of failed subschemas: " + std::to_string(subschemata_.size())); + error_summary.propagate(e, "[combination: " + key + " / "); + } + } + + // specialized for each of the logical_combination_types + static const std::string key; + static bool is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t, size_t); + +public: + logical_combination(json &sch, + root_schema *root, + const std::vector &uris) + : schema(root) + { + size_t c = 0; + for (auto &subschema : sch) + subschemata_.push_back(schema::make(subschema, root, {key, std::to_string(c++)}, uris)); + + // value of allOf, anyOf, and oneOf "MUST be a non-empty array" + // TODO error/throw? when subschemata_.empty() + } +}; + +template <> +const std::string logical_combination::key = "allOf"; +template <> +const std::string logical_combination::key = "anyOf"; +template <> +const std::string logical_combination::key = "oneOf"; + +template <> +bool logical_combination::is_validate_complete(const json &, const json::json_pointer &, error_handler &e, const logical_combination_error_handler &esub, size_t, size_t current_schema_index) +{ + if (esub) { + e.error(esub.error_entry_list_.front().ptr_, esub.error_entry_list_.front().instance_, "at least one subschema has failed, but all of them are required to validate - " + esub.error_entry_list_.front().message_); + esub.propagate(e, "[combination: allOf / case#" + std::to_string(current_schema_index) + "] "); + } + return esub; +} + +template <> +bool logical_combination::is_validate_complete(const json &, const json::json_pointer &, error_handler &, const logical_combination_error_handler &, size_t count, size_t) +{ + return count == 1; +} + +template <> +bool logical_combination::is_validate_complete(const json &instance, const json::json_pointer &ptr, error_handler &e, const logical_combination_error_handler &, size_t count, size_t) +{ + if (count > 1) + e.error(ptr, instance, "more than one subschema has succeeded, but exactly one of them is required to validate"); + return count > 1; +} + +class type_schema : public schema +{ + std::vector> type_; + std::pair enum_, const_; + std::vector> logic_; + + static std::shared_ptr make(json &schema, + json::value_t type, + root_schema *, + const std::vector &, + std::set &); + + std::shared_ptr if_, then_, else_; + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const override final + { + // depending on the type of instance run the type specific validator - if present + auto type = type_[static_cast(instance.type())]; + + if (type) + type->validate(ptr, instance, patch, e); + else + e.error(ptr, instance, "unexpected instance type"); + + if (enum_.first) { + bool seen_in_enum = false; + for (auto &v : enum_.second) + if (instance == v) { + seen_in_enum = true; + break; + } + + if (!seen_in_enum) + e.error(ptr, instance, "instance not found in required enum"); + } + + if (const_.first && + const_.second != instance) + e.error(ptr, instance, "instance not const"); + + for (auto l : logic_) + l->validate(ptr, instance, patch, e); + + if (if_) { + first_error_handler err; + + if_->validate(ptr, instance, patch, err); + if (!err) { + if (then_) + then_->validate(ptr, instance, patch, e); + } else { + if (else_) + else_->validate(ptr, instance, patch, e); + } + } + if (instance.is_null()) { + patch.add(nlohmann::json::json_pointer{}, default_value_); + } + } + +protected: + virtual std::shared_ptr make_for_default_( + std::shared_ptr<::schema> & /* sch */, + root_schema * /* root */, + std::vector & /* uris */, + nlohmann::json &default_value) const override + { + auto result = std::make_shared(*this); + result->set_default_value(default_value); + return result; + }; + +public: + type_schema(json &sch, + root_schema *root, + const std::vector &uris) + : schema(root), type_(static_cast(json::value_t::discarded) + 1) + { + // association between JSON-schema-type and NLohmann-types + static const std::vector> schema_types = { + {"null", json::value_t::null}, + {"object", json::value_t::object}, + {"array", json::value_t::array}, + {"string", json::value_t::string}, + {"boolean", json::value_t::boolean}, + {"integer", json::value_t::number_integer}, + {"number", json::value_t::number_float}, + }; + + std::set known_keywords; + + auto attr = sch.find("type"); + if (attr == sch.end()) // no type field means all sub-types possible + for (auto &t : schema_types) + type_[static_cast(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords); + else { + switch (attr.value().type()) { // "type": "type" + + case json::value_t::string: { + auto schema_type = attr.value().get(); + for (auto &t : schema_types) + if (t.first == schema_type) + type_[static_cast(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords); + } break; + + case json::value_t::array: // "type": ["type1", "type2"] + for (auto &array_value : attr.value()) { + auto schema_type = array_value.get(); + for (auto &t : schema_types) + if (t.first == schema_type) + type_[static_cast(t.second)] = type_schema::make(sch, t.second, root, uris, known_keywords); + } + break; + + default: + break; + } + + sch.erase(attr); + } + + attr = sch.find("default"); + if (attr != sch.end()) { + set_default_value(attr.value()); + sch.erase(attr); + } + + for (auto &key : known_keywords) + sch.erase(key); + + // with nlohmann::json float instance (but number in schema-definition) can be seen as unsigned or integer - + // reuse the number-validator for integer values as well, if they have not been specified explicitly + if (type_[static_cast(json::value_t::number_float)] && !type_[static_cast(json::value_t::number_integer)]) + type_[static_cast(json::value_t::number_integer)] = type_[static_cast(json::value_t::number_float)]; + + // #54: JSON-schema does not differentiate between unsigned and signed integer - nlohmann::json does + // we stick with JSON-schema: use the integer-validator if instance-value is unsigned + type_[static_cast(json::value_t::number_unsigned)] = type_[static_cast(json::value_t::number_integer)]; + + // special for binary types + if (type_[static_cast(json::value_t::string)]) { + type_[static_cast(json::value_t::binary)] = type_[static_cast(json::value_t::string)]; + } + + attr = sch.find("enum"); + if (attr != sch.end()) { + enum_ = {true, attr.value()}; + sch.erase(attr); + } + + attr = sch.find("const"); + if (attr != sch.end()) { + const_ = {true, attr.value()}; + sch.erase(attr); + } + + attr = sch.find("not"); + if (attr != sch.end()) { + logic_.push_back(std::make_shared(attr.value(), root, uris)); + sch.erase(attr); + } + + attr = sch.find("allOf"); + if (attr != sch.end()) { + logic_.push_back(std::make_shared>(attr.value(), root, uris)); + sch.erase(attr); + } + + attr = sch.find("anyOf"); + if (attr != sch.end()) { + logic_.push_back(std::make_shared>(attr.value(), root, uris)); + sch.erase(attr); + } + + attr = sch.find("oneOf"); + if (attr != sch.end()) { + logic_.push_back(std::make_shared>(attr.value(), root, uris)); + sch.erase(attr); + } + + attr = sch.find("if"); + if (attr != sch.end()) { + auto attr_then = sch.find("then"); + auto attr_else = sch.find("else"); + + if (attr_then != sch.end() || attr_else != sch.end()) { + if_ = schema::make(attr.value(), root, {"if"}, uris); + + if (attr_then != sch.end()) { + then_ = schema::make(attr_then.value(), root, {"then"}, uris); + sch.erase(attr_then); + } + + if (attr_else != sch.end()) { + else_ = schema::make(attr_else.value(), root, {"else"}, uris); + sch.erase(attr_else); + } + } + sch.erase(attr); + } + } +}; + +class string : public schema +{ + std::pair maxLength_{false, 0}; + std::pair minLength_{false, 0}; + +#ifndef NO_STD_REGEX + std::pair pattern_{false, REGEX_NAMESPACE::regex()}; + std::string patternString_; +#endif + + std::pair format_; + std::tuple content_{false, "", ""}; + + std::size_t utf8_length(const std::string &s) const + { + size_t len = 0; + for (auto c : s) + if ((c & 0xc0) != 0x80) + len++; + return len; + } + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override + { + if (minLength_.first) { + if (utf8_length(instance.get()) < minLength_.second) { + std::ostringstream s; + s << "instance is too short as per minLength:" << minLength_.second; + e.error(ptr, instance, s.str()); + } + } + + if (maxLength_.first) { + if (utf8_length(instance.get()) > maxLength_.second) { + std::ostringstream s; + s << "instance is too long as per maxLength: " << maxLength_.second; + e.error(ptr, instance, s.str()); + } + } + + if (std::get<0>(content_)) { + if (root_->content_check() == nullptr) + e.error(ptr, instance, std::string("a content checker was not provided but a contentEncoding or contentMediaType for this string have been present: '") + std::get<1>(content_) + "' '" + std::get<2>(content_) + "'"); + else { + try { + root_->content_check()(std::get<1>(content_), std::get<2>(content_), instance); + } catch (const std::exception &ex) { + e.error(ptr, instance, std::string("content-checking failed: ") + ex.what()); + } + } + } else if (instance.type() == json::value_t::binary) { + e.error(ptr, instance, "expected string, but get binary data"); + } + + if (instance.type() != json::value_t::string) { + return; // next checks only for strings + } + +#ifndef NO_STD_REGEX + if (pattern_.first && + !REGEX_NAMESPACE::regex_search(instance.get(), pattern_.second)) + e.error(ptr, instance, "instance does not match regex pattern: " + patternString_); +#endif + + if (format_.first) { + if (root_->format_check() == nullptr) + e.error(ptr, instance, std::string("a format checker was not provided but a format keyword for this string is present: ") + format_.second); + else { + try { + root_->format_check()(format_.second, instance.get()); + } catch (const std::exception &ex) { + e.error(ptr, instance, std::string("format-checking failed: ") + ex.what()); + } + } + } + } + +public: + string(json &sch, root_schema *root) + : schema(root) + { + auto attr = sch.find("maxLength"); + if (attr != sch.end()) { + maxLength_ = {true, attr.value().get()}; + sch.erase(attr); + } + + attr = sch.find("minLength"); + if (attr != sch.end()) { + minLength_ = {true, attr.value().get()}; + sch.erase(attr); + } + + attr = sch.find("contentEncoding"); + if (attr != sch.end()) { + std::get<0>(content_) = true; + std::get<1>(content_) = attr.value().get(); + + // special case for nlohmann::json-binary-types + // + // https://github.com/pboettch/json-schema-validator/pull/114 + // + // We cannot use explicitly in a schema: {"type": "binary"} or + // "type": ["binary", "number"] we have to be implicit. For a + // schema where "contentEncoding" is set to "binary", an instance + // of type json::value_t::binary is accepted. If a + // contentEncoding-callback has to be provided and is called + // accordingly. For encoding=binary, no other type validations are done + + sch.erase(attr); + } + + attr = sch.find("contentMediaType"); + if (attr != sch.end()) { + std::get<0>(content_) = true; + std::get<2>(content_) = attr.value().get(); + + sch.erase(attr); + } + + if (std::get<0>(content_) == true && root_->content_check() == nullptr) { + throw std::invalid_argument{"schema contains contentEncoding/contentMediaType but content checker was not set"}; + } + +#ifndef NO_STD_REGEX + attr = sch.find("pattern"); + if (attr != sch.end()) { + patternString_ = attr.value().get(); + pattern_ = {true, REGEX_NAMESPACE::regex(attr.value().get(), + REGEX_NAMESPACE::regex::ECMAScript)}; + sch.erase(attr); + } +#endif + + attr = sch.find("format"); + if (attr != sch.end()) { + if (root_->format_check() == nullptr) + throw std::invalid_argument{"a format checker was not provided but a format keyword for this string is present: " + format_.second}; + + format_ = {true, attr.value().get()}; + sch.erase(attr); + } + } +}; + +template +class numeric : public schema +{ + std::pair maximum_{false, 0}; + std::pair minimum_{false, 0}; + + bool exclusiveMaximum_ = false; + bool exclusiveMinimum_ = false; + + std::pair multipleOf_{false, 0}; + + // multipleOf - if the remainder of the division is 0 -> OK + bool violates_multiple_of(T x) const + { + double res = std::remainder(x, multipleOf_.second); + double multiple = std::fabs(x / multipleOf_.second); + if (multiple > 1) { + res = res / multiple; + } + double eps = std::nextafter(x, 0) - static_cast(x); + + return std::fabs(res) > std::fabs(eps); + } + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override + { + T value = instance; // conversion of json to value_type + + std::ostringstream oss; + + if (multipleOf_.first && value != 0) // zero is multiple of everything + if (violates_multiple_of(value)) + oss << "instance is not a multiple of " << json(multipleOf_.second); + + if (maximum_.first) { + if (exclusiveMaximum_ && value >= maximum_.second) + oss << "instance exceeds or equals maximum of " << json(maximum_.second); + else if (value > maximum_.second) + oss << "instance exceeds maximum of " << json(maximum_.second); + } + + if (minimum_.first) { + if (exclusiveMinimum_ && value <= minimum_.second) + oss << "instance is below or equals minimum of " << json(minimum_.second); + else if (value < minimum_.second) + oss << "instance is below minimum of " << json(minimum_.second); + } + + oss.seekp(0, std::ios::end); + auto size = oss.tellp(); + if (size != 0) { + oss.seekp(0, std::ios::beg); + e.error(ptr, instance, oss.str()); + } + } + +public: + numeric(const json &sch, root_schema *root, std::set &kw) + : schema(root) + { + auto attr = sch.find("maximum"); + if (attr != sch.end()) { + maximum_ = {true, attr.value().get()}; + kw.insert("maximum"); + } + + attr = sch.find("minimum"); + if (attr != sch.end()) { + minimum_ = {true, attr.value().get()}; + kw.insert("minimum"); + } + + attr = sch.find("exclusiveMaximum"); + if (attr != sch.end()) { + exclusiveMaximum_ = true; + maximum_ = {true, attr.value().get()}; + kw.insert("exclusiveMaximum"); + } + + attr = sch.find("exclusiveMinimum"); + if (attr != sch.end()) { + exclusiveMinimum_ = true; + minimum_ = {true, attr.value().get()}; + kw.insert("exclusiveMinimum"); + } + + attr = sch.find("multipleOf"); + if (attr != sch.end()) { + multipleOf_ = {true, attr.value().get()}; + kw.insert("multipleOf"); + } + } +}; + +class null : public schema +{ + void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override + { + if (!instance.is_null()) + e.error(ptr, instance, "expected to be null"); + } + +public: + null(json &, root_schema *root) + : schema(root) {} +}; + +class boolean_type : public schema +{ + void validate(const json::json_pointer &, const json &, json_patch &, error_handler &) const override {} + +public: + boolean_type(json &, root_schema *root) + : schema(root) {} +}; + +class boolean : public schema +{ + bool true_; + void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override + { + if (!true_) { // false schema + // empty array + // switch (instance.type()) { + // case json::value_t::array: + // if (instance.size() != 0) // valid false-schema + // e.error(ptr, instance, "false-schema required empty array"); + // return; + //} + + e.error(ptr, instance, "instance invalid as per false-schema"); + } + } + +public: + boolean(json &sch, root_schema *root) + : schema(root), true_(sch) {} +}; + +class required : public schema +{ + const std::vector required_; + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &, error_handler &e) const override final + { + for (auto &r : required_) + if (instance.find(r) == instance.end()) + e.error(ptr, instance, "required property '" + r + "' not found in object as a dependency"); + } + +public: + required(const std::vector &r, root_schema *root) + : schema(root), required_(r) {} +}; + +class object : public schema +{ + std::pair maxProperties_{false, 0}; + std::pair minProperties_{false, 0}; + std::vector required_; + + std::map> properties_; +#ifndef NO_STD_REGEX + std::vector>> patternProperties_; +#endif + std::shared_ptr additionalProperties_; + + std::map> dependencies_; + + std::shared_ptr propertyNames_; + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const override + { + if (maxProperties_.first && instance.size() > maxProperties_.second) + e.error(ptr, instance, "too many properties"); + + if (minProperties_.first && instance.size() < minProperties_.second) + e.error(ptr, instance, "too few properties"); + + for (auto &r : required_) + if (instance.find(r) == instance.end()) + e.error(ptr, instance, "required property '" + r + "' not found in object"); + + // for each property in instance + for (auto &p : instance.items()) { + if (propertyNames_) + propertyNames_->validate(ptr, p.key(), patch, e); + + bool a_prop_or_pattern_matched = false; + auto schema_p = properties_.find(p.key()); + // check if it is in "properties" + if (schema_p != properties_.end()) { + a_prop_or_pattern_matched = true; + schema_p->second->validate(ptr / p.key(), p.value(), patch, e); + } + +#ifndef NO_STD_REGEX + // check all matching patternProperties + for (auto &schema_pp : patternProperties_) + if (REGEX_NAMESPACE::regex_search(p.key(), schema_pp.first)) { + a_prop_or_pattern_matched = true; + schema_pp.second->validate(ptr / p.key(), p.value(), patch, e); + } +#endif + + // check additionalProperties as a last resort + if (!a_prop_or_pattern_matched && additionalProperties_) { + first_error_handler additional_prop_err; + additionalProperties_->validate(ptr / p.key(), p.value(), patch, additional_prop_err); + if (additional_prop_err) + e.error(ptr, instance, "validation failed for additional property '" + p.key() + "': " + additional_prop_err.message_); + } + } + + // reverse search + for (auto const &prop : properties_) { + const auto finding = instance.find(prop.first); + if (instance.end() == finding) { // if the prop is not in the instance + const auto &default_value = prop.second->default_value(ptr, instance, e); + if (!default_value.is_null()) { // if default value is available + patch.add((ptr / prop.first), default_value); + } + } + } + + for (auto &dep : dependencies_) { + auto prop = instance.find(dep.first); + if (prop != instance.end()) // if dependency-property is present in instance + dep.second->validate(ptr / dep.first, instance, patch, e); // validate + } + } + +public: + object(json &sch, + root_schema *root, + const std::vector &uris) + : schema(root) + { + auto attr = sch.find("maxProperties"); + if (attr != sch.end()) { + maxProperties_ = {true, attr.value().get()}; + sch.erase(attr); + } + + attr = sch.find("minProperties"); + if (attr != sch.end()) { + minProperties_ = {true, attr.value().get()}; + sch.erase(attr); + } + + attr = sch.find("required"); + if (attr != sch.end()) { + required_ = attr.value().get>(); + sch.erase(attr); + } + + attr = sch.find("properties"); + if (attr != sch.end()) { + for (auto prop : attr.value().items()) + properties_.insert( + std::make_pair( + prop.key(), + schema::make(prop.value(), root, {"properties", prop.key()}, uris))); + sch.erase(attr); + } + +#ifndef NO_STD_REGEX + attr = sch.find("patternProperties"); + if (attr != sch.end()) { + for (auto prop : attr.value().items()) + patternProperties_.push_back( + std::make_pair( + REGEX_NAMESPACE::regex(prop.key(), REGEX_NAMESPACE::regex::ECMAScript), + schema::make(prop.value(), root, {prop.key()}, uris))); + sch.erase(attr); + } +#endif + + attr = sch.find("additionalProperties"); + if (attr != sch.end()) { + additionalProperties_ = schema::make(attr.value(), root, {"additionalProperties"}, uris); + sch.erase(attr); + } + + attr = sch.find("dependencies"); + if (attr != sch.end()) { + for (auto &dep : attr.value().items()) + switch (dep.value().type()) { + case json::value_t::array: + dependencies_.emplace(dep.key(), + std::make_shared( + dep.value().get>(), root)); + break; + + default: + dependencies_.emplace(dep.key(), + schema::make(dep.value(), root, {"dependencies", dep.key()}, uris)); + break; + } + sch.erase(attr); + } + + attr = sch.find("propertyNames"); + if (attr != sch.end()) { + propertyNames_ = schema::make(attr.value(), root, {"propertyNames"}, uris); + sch.erase(attr); + } + + attr = sch.find("default"); + if (attr != sch.end()) { + set_default_value(*attr); + } + } +}; + +class array : public schema +{ + std::pair maxItems_{false, 0}; + std::pair minItems_{false, 0}; + bool uniqueItems_ = false; + + std::shared_ptr items_schema_; + + std::vector> items_; + std::shared_ptr additionalItems_; + + std::shared_ptr contains_; + + void validate(const json::json_pointer &ptr, const json &instance, json_patch &patch, error_handler &e) const override + { + if (maxItems_.first && instance.size() > maxItems_.second) + e.error(ptr, instance, "array has too many items"); + + if (minItems_.first && instance.size() < minItems_.second) + e.error(ptr, instance, "array has too few items"); + + if (uniqueItems_) { + for (auto it = instance.cbegin(); it != instance.cend(); ++it) { + auto v = std::find(it + 1, instance.end(), *it); + if (v != instance.end()) + e.error(ptr, instance, "items have to be unique for this array"); + } + } + + size_t index = 0; + if (items_schema_) + for (auto &i : instance) { + items_schema_->validate(ptr / index, i, patch, e); + index++; + } + else { + auto item = items_.cbegin(); + for (auto &i : instance) { + std::shared_ptr item_validator; + if (item == items_.cend()) + item_validator = additionalItems_; + else { + item_validator = *item; + item++; + } + + if (!item_validator) + break; + + item_validator->validate(ptr / index, i, patch, e); + } + } + + if (contains_) { + bool contained = false; + for (auto &item : instance) { + first_error_handler local_e; + contains_->validate(ptr, item, patch, local_e); + if (!local_e) { + contained = true; + break; + } + } + if (!contained) + e.error(ptr, instance, "array does not contain required element as per 'contains'"); + } + } + +public: + array(json &sch, root_schema *root, const std::vector &uris) + : schema(root) + { + auto attr = sch.find("maxItems"); + if (attr != sch.end()) { + maxItems_ = {true, attr.value().get()}; + sch.erase(attr); + } + + attr = sch.find("minItems"); + if (attr != sch.end()) { + minItems_ = {true, attr.value().get()}; + sch.erase(attr); + } + + attr = sch.find("uniqueItems"); + if (attr != sch.end()) { + uniqueItems_ = attr.value().get(); + sch.erase(attr); + } + + attr = sch.find("items"); + if (attr != sch.end()) { + + if (attr.value().type() == json::value_t::array) { + size_t c = 0; + for (auto &subsch : attr.value()) + items_.push_back(schema::make(subsch, root, {"items", std::to_string(c++)}, uris)); + + auto attr_add = sch.find("additionalItems"); + if (attr_add != sch.end()) { + additionalItems_ = schema::make(attr_add.value(), root, {"additionalItems"}, uris); + sch.erase(attr_add); + } + + } else if (attr.value().type() == json::value_t::object || + attr.value().type() == json::value_t::boolean) + items_schema_ = schema::make(attr.value(), root, {"items"}, uris); + + sch.erase(attr); + } + + attr = sch.find("contains"); + if (attr != sch.end()) { + contains_ = schema::make(attr.value(), root, {"contains"}, uris); + sch.erase(attr); + } + } +}; + +std::shared_ptr type_schema::make(json &schema, + json::value_t type, + root_schema *root, + const std::vector &uris, + std::set &kw) +{ + switch (type) { + case json::value_t::null: + return std::make_shared(schema, root); + + case json::value_t::number_unsigned: + case json::value_t::number_integer: + return std::make_shared>(schema, root, kw); + case json::value_t::number_float: + return std::make_shared>(schema, root, kw); + case json::value_t::string: + return std::make_shared(schema, root); + case json::value_t::boolean: + return std::make_shared(schema, root); + case json::value_t::object: + return std::make_shared(schema, root, uris); + case json::value_t::array: + return std::make_shared(schema, root, uris); + + case json::value_t::discarded: // not a real type - silence please + break; + + case json::value_t::binary: + break; + } + return nullptr; +} +} // namespace + +namespace +{ + +std::shared_ptr schema::make(json &schema, + root_schema *root, + const std::vector &keys, + std::vector uris) +{ + // remove URIs which contain plain name identifiers, as sub-schemas cannot be referenced + for (auto uri = uris.begin(); uri != uris.end();) + if (uri->identifier() != "") + uri = uris.erase(uri); + else + uri++; + + // append to all URIs the keys for this sub-schema + for (auto &key : keys) + for (auto &uri : uris) + uri = uri.append(key); + + std::shared_ptr<::schema> sch; + + // boolean schema + if (schema.type() == json::value_t::boolean) + sch = std::make_shared(schema, root); + else if (schema.type() == json::value_t::object) { + + auto attr = schema.find("$id"); // if $id is present, this schema can be referenced by this ID + // as an additional URI + if (attr != schema.end()) { + if (std::find(uris.begin(), + uris.end(), + attr.value().get()) == uris.end()) + uris.push_back(uris.back().derive(attr.value().get())); // so add it to the list if it is not there already + schema.erase(attr); + } + + auto findDefinitions = [&](const std::string &defs) -> bool { + attr = schema.find(defs); + if (attr != schema.end()) { + for (auto &def : attr.value().items()) + schema::make(def.value(), root, {defs, def.key()}, uris); + schema.erase(attr); + return true; + } + return false; + }; + if (!findDefinitions("$defs")) { + findDefinitions("definitions"); + } + + attr = schema.find("$ref"); + if (attr != schema.end()) { // this schema is a reference + // the last one on the uri-stack is the last id seen before coming here, + // so this is the origial URI for this reference, the $ref-value has thus be resolved from it + auto id = uris.back().derive(attr.value().get()); + sch = root->get_or_create_ref(id); + + schema.erase(attr); + + // special case where we break draft-7 and allow overriding of properties when a $ref is used + attr = schema.find("default"); + if (attr != schema.end()) { + // copy the referenced schema depending on the underlying type and modify the default value + if (auto new_sch = sch->make_for_default_(sch, root, uris, attr.value())) { + sch = new_sch; + } + schema.erase(attr); + } + } else { + sch = std::make_shared(schema, root, uris); + } + + schema.erase("$schema"); + schema.erase("title"); + schema.erase("description"); + } else { + throw std::invalid_argument("invalid JSON-type for a schema for " + uris[0].to_string() + ", expected: boolean or object"); + } + + for (auto &uri : uris) { // for all URIs this schema is referenced by + root->insert(uri, sch); + + if (schema.type() == json::value_t::object) + for (auto &u : schema.items()) + root->insert_unknown_keyword(uri, u.key(), u.value()); // insert unknown keywords for later reference + } + return sch; +} + +class throwing_error_handler : public error_handler +{ + void error(const json::json_pointer &ptr, const json &instance, const std::string &message) override + { + throw std::invalid_argument(std::string("At ") + ptr.to_string() + " of " + instance.dump() + " - " + message + "\n"); + } +}; + +} // namespace + +namespace nlohmann +{ +namespace json_schema +{ + +json_validator::json_validator(schema_loader loader, + format_checker format, + content_checker content) + : root_(std::unique_ptr(new root_schema(std::move(loader), + std::move(format), + std::move(content)))) +{ +} + +json_validator::json_validator(const json &schema, + schema_loader loader, + format_checker format, + content_checker content) + : json_validator(std::move(loader), + std::move(format), + std::move(content)) +{ + set_root_schema(schema); +} + +json_validator::json_validator(json &&schema, + schema_loader loader, + format_checker format, + content_checker content) + + : json_validator(std::move(loader), + std::move(format), + std::move(content)) +{ + set_root_schema(std::move(schema)); +} + +// move constructor, destructor and move assignment operator can be defaulted here +// where root_schema is a complete type +json_validator::json_validator(json_validator &&) = default; +json_validator::~json_validator() = default; +json_validator &json_validator::operator=(json_validator &&) = default; + +void json_validator::set_root_schema(const json &schema) +{ + root_->set_root_schema(schema); +} + +void json_validator::set_root_schema(json &&schema) +{ + root_->set_root_schema(std::move(schema)); +} + +json json_validator::validate(const json &instance) const +{ + throwing_error_handler err; + return validate(instance, err); +} + +json json_validator::validate(const json &instance, error_handler &err, const json_uri &initial_uri) const +{ + json::json_pointer ptr; + json_patch patch; + root_->validate(ptr, instance, patch, err, initial_uri); + return patch; +} + +} // namespace json_schema +} // namespace nlohmann diff --git a/externals/json-schema-validator/nlohmann/json-schema.hpp b/externals/json-schema-validator/nlohmann/json-schema.hpp new file mode 100644 index 0000000..07befd3 --- /dev/null +++ b/externals/json-schema-validator/nlohmann/json-schema.hpp @@ -0,0 +1,198 @@ +/* + * JSON schema validator for JSON for modern C++ + * + * Copyright (c) 2016-2019 Patrick Boettcher . + * + * SPDX-License-Identifier: MIT + * + */ +#ifndef NLOHMANN_JSON_SCHEMA_HPP__ +#define NLOHMANN_JSON_SCHEMA_HPP__ + +#ifdef _WIN32 +# if defined(JSON_SCHEMA_VALIDATOR_EXPORTS) +# define JSON_SCHEMA_VALIDATOR_API __declspec(dllexport) +# elif defined(JSON_SCHEMA_VALIDATOR_IMPORTS) +# define JSON_SCHEMA_VALIDATOR_API __declspec(dllimport) +# else +# define JSON_SCHEMA_VALIDATOR_API +# endif +#else +# define JSON_SCHEMA_VALIDATOR_API +#endif + +#include + +#ifdef NLOHMANN_JSON_VERSION_MAJOR +# if (NLOHMANN_JSON_VERSION_MAJOR * 10000 + NLOHMANN_JSON_VERSION_MINOR * 100 + NLOHMANN_JSON_VERSION_PATCH) < 30800 +# error "Please use this library with NLohmann's JSON version 3.8.0 or higher" +# endif +#else +# error "expected existing NLOHMANN_JSON_VERSION_MAJOR preproc variable, please update to NLohmann's JSON 3.8.0" +#endif + +// make yourself a home - welcome to nlohmann's namespace +namespace nlohmann +{ + +// A class representing a JSON-URI for schemas derived from +// section 8 of JSON Schema: A Media Type for Describing JSON Documents +// draft-wright-json-schema-00 +// +// New URIs can be derived from it using the derive()-method. +// This is useful for resolving refs or subschema-IDs in json-schemas. +// +// This is done implement the requirements described in section 8.2. +// +class JSON_SCHEMA_VALIDATOR_API json_uri +{ + std::string urn_; + + std::string scheme_; + std::string authority_; + std::string path_; + + json::json_pointer pointer_; // fragment part if JSON-Pointer + std::string identifier_; // fragment part if Locatation Independent ID + +protected: + // decodes a JSON uri and replaces all or part of the currently stored values + void update(const std::string &uri); + + std::tuple as_tuple() const + { + return std::make_tuple(urn_, scheme_, authority_, path_, identifier_ != "" ? identifier_ : pointer_.to_string()); + } + +public: + json_uri(const std::string &uri) + { + update(uri); + } + + const std::string &scheme() const { return scheme_; } + const std::string &authority() const { return authority_; } + const std::string &path() const { return path_; } + + const json::json_pointer &pointer() const { return pointer_; } + const std::string &identifier() const { return identifier_; } + + std::string fragment() const + { + if (identifier_ == "") + return pointer_.to_string(); + else + return identifier_; + } + + std::string url() const { return location(); } + std::string location() const; + + static std::string escape(const std::string &); + + // create a new json_uri based in this one and the given uri + // resolves relative changes (pathes or pointers) and resets part if proto or hostname changes + json_uri derive(const std::string &uri) const + { + json_uri u = *this; + u.update(uri); + return u; + } + + // append a pointer-field to the pointer-part of this uri + json_uri append(const std::string &field) const + { + if (identifier_ != "") + return *this; + + json_uri u = *this; + u.pointer_ /= field; + return u; + } + + std::string to_string() const; + + friend bool operator<(const json_uri &l, const json_uri &r) + { + return l.as_tuple() < r.as_tuple(); + } + + friend bool operator==(const json_uri &l, const json_uri &r) + { + return l.as_tuple() == r.as_tuple(); + } + + friend std::ostream &operator<<(std::ostream &os, const json_uri &u); +}; + +namespace json_schema +{ + +extern json draft7_schema_builtin; + +typedef std::function schema_loader; +typedef std::function format_checker; +typedef std::function content_checker; + +// Interface for validation error handlers +class JSON_SCHEMA_VALIDATOR_API error_handler +{ +public: + virtual ~error_handler() {} + virtual void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) = 0; +}; + +class JSON_SCHEMA_VALIDATOR_API basic_error_handler : public error_handler +{ + bool error_{false}; + +public: + void error(const json::json_pointer & /*ptr*/, const json & /*instance*/, const std::string & /*message*/) override + { + error_ = true; + } + + virtual void reset() { error_ = false; } + operator bool() const { return error_; } +}; + +/** + * Checks validity of JSON schema built-in string format specifiers like 'date-time', 'ipv4', ... + */ +void JSON_SCHEMA_VALIDATOR_API default_string_format_check(const std::string &format, const std::string &value); + +class root_schema; + +class JSON_SCHEMA_VALIDATOR_API json_validator +{ + std::unique_ptr root_; + +public: + json_validator(schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); + + json_validator(const json &, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); + json_validator(json &&, schema_loader = nullptr, format_checker = nullptr, content_checker = nullptr); + + json_validator(json_validator &&); + json_validator &operator=(json_validator &&); + + json_validator(json_validator const &) = delete; + json_validator &operator=(json_validator const &) = delete; + + ~json_validator(); + + // insert and set the root-schema + void set_root_schema(const json &); + void set_root_schema(json &&); + + // validate a json-document based on the root-schema + json validate(const json &) const; + + // validate a json-document based on the root-schema with a custom error-handler + json validate(const json &, error_handler &, const json_uri &initial_uri = json_uri("#")) const; +}; + +} // namespace json_schema +} // namespace nlohmann + +#endif /* NLOHMANN_JSON_SCHEMA_HPP__ */ diff --git a/externals/json-schema-validator/smtp-address-validator.cpp b/externals/json-schema-validator/smtp-address-validator.cpp new file mode 100644 index 0000000..3b4a461 --- /dev/null +++ b/externals/json-schema-validator/smtp-address-validator.cpp @@ -0,0 +1,792 @@ +/* + +Snarfed from + +: + +Copyright (c) 2021 Gene Hightower + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +#include "smtp-address-validator.hpp" + +static const signed char _address_actions[] = { + 0, 1, 0, 1, 1, 0}; + +static const short _address_key_offsets[] = { + 0, 0, 24, 26, 50, 52, 54, 56, + 58, 60, 62, 86, 103, 105, 107, 109, + 111, 113, 115, 117, 134, 150, 161, 168, + 176, 180, 181, 190, 195, 196, 201, 202, + 207, 210, 213, 219, 222, 225, 228, 234, + 237, 240, 243, 249, 252, 261, 270, 282, + 293, 302, 311, 320, 328, 345, 353, 360, + 367, 368, 375, 382, 389, 396, 397, 404, + 411, 418, 425, 426, 433, 440, 447, 454, + 455, 462, 469, 476, 483, 484, 491, 498, + 505, 512, 513, 523, 531, 538, 545, 546, + 552, 559, 566, 573, 581, 589, 597, 608, + 618, 626, 634, 641, 649, 657, 665, 667, + 673, 681, 689, 697, 699, 705, 713, 721, + 729, 731, 737, 745, 753, 761, 763, 769, + 777, 785, 793, 795, 802, 812, 821, 829, + 837, 839, 848, 857, 865, 873, 875, 884, + 893, 901, 909, 911, 920, 929, 937, 945, + 947, 956, 965, 974, 983, 992, 1004, 1015, + 1024, 1033, 1042, 1051, 1060, 1072, 1083, 1092, + 1101, 1109, 1118, 1127, 1136, 1148, 1159, 1168, + 1177, 1185, 1194, 1203, 1212, 1224, 1235, 1244, + 1253, 1261, 1270, 1279, 1288, 1300, 1311, 1320, + 1329, 1337, 1339, 1353, 1355, 1357, 1359, 1361, + 1363, 1365, 1367, 1368, 1370, 1388, 0}; + +static const signed char _address_trans_keys[] = { + -32, -19, -16, -12, 34, 45, 61, 63, + -62, -33, -31, -17, -15, -13, 33, 39, + 42, 43, 47, 57, 65, 90, 94, 126, + -128, -65, -32, -19, -16, -12, 33, 46, + 61, 64, -62, -33, -31, -17, -15, -13, + 35, 39, 42, 43, 45, 57, 63, 90, + 94, 126, -96, -65, -128, -65, -128, -97, + -112, -65, -128, -65, -128, -113, -32, -19, + -16, -12, 33, 45, 61, 63, -62, -33, + -31, -17, -15, -13, 35, 39, 42, 43, + 47, 57, 65, 90, 94, 126, -32, -19, + -16, -12, 91, -62, -33, -31, -17, -15, + -13, 48, 57, 65, 90, 97, 122, -128, + -65, -96, -65, -128, -65, -128, -97, -112, + -65, -128, -65, -128, -113, -32, -19, -16, + -12, 45, -62, -33, -31, -17, -15, -13, + 48, 57, 65, 90, 97, 122, -32, -19, + -16, -12, -62, -33, -31, -17, -15, -13, + 48, 57, 65, 90, 97, 122, 45, 48, + 49, 50, 73, 51, 57, 65, 90, 97, + 122, 45, 48, 57, 65, 90, 97, 122, + 45, 58, 48, 57, 65, 90, 97, 122, + 33, 90, 94, 126, 93, 45, 46, 58, + 48, 57, 65, 90, 97, 122, 48, 49, + 50, 51, 57, 46, 48, 49, 50, 51, + 57, 46, 48, 49, 50, 51, 57, 93, + 48, 57, 93, 48, 57, 53, 93, 48, + 52, 54, 57, 93, 48, 53, 46, 48, + 57, 46, 48, 57, 46, 53, 48, 52, + 54, 57, 46, 48, 53, 46, 48, 57, + 46, 48, 57, 46, 53, 48, 52, 54, + 57, 46, 48, 53, 45, 46, 58, 48, + 57, 65, 90, 97, 122, 45, 46, 58, + 48, 57, 65, 90, 97, 122, 45, 46, + 53, 58, 48, 52, 54, 57, 65, 90, + 97, 122, 45, 46, 58, 48, 53, 54, + 57, 65, 90, 97, 122, 45, 58, 80, + 48, 57, 65, 90, 97, 122, 45, 58, + 118, 48, 57, 65, 90, 97, 122, 45, + 54, 58, 48, 57, 65, 90, 97, 122, + 45, 58, 48, 57, 65, 90, 97, 122, + 58, 33, 47, 48, 57, 59, 64, 65, + 70, 71, 90, 94, 96, 97, 102, 103, + 126, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 48, 57, 65, 70, 97, 102, + 58, 48, 57, 65, 70, 97, 102, 58, + 58, 48, 57, 65, 70, 97, 102, 58, + 48, 57, 65, 70, 97, 102, 58, 48, + 57, 65, 70, 97, 102, 58, 48, 57, + 65, 70, 97, 102, 58, 58, 48, 57, + 65, 70, 97, 102, 58, 48, 57, 65, + 70, 97, 102, 58, 48, 57, 65, 70, + 97, 102, 58, 48, 57, 65, 70, 97, + 102, 58, 58, 48, 57, 65, 70, 97, + 102, 58, 48, 57, 65, 70, 97, 102, + 58, 48, 57, 65, 70, 97, 102, 58, + 48, 57, 65, 70, 97, 102, 58, 58, + 48, 57, 65, 70, 97, 102, 58, 48, + 57, 65, 70, 97, 102, 58, 48, 57, + 65, 70, 97, 102, 58, 48, 57, 65, + 70, 97, 102, 58, 58, 48, 57, 65, + 70, 97, 102, 58, 48, 57, 65, 70, + 97, 102, 58, 48, 57, 65, 70, 97, + 102, 58, 48, 57, 65, 70, 97, 102, + 58, 48, 49, 50, 58, 51, 57, 65, + 70, 97, 102, 46, 58, 48, 57, 65, + 70, 97, 102, 58, 48, 57, 65, 70, + 97, 102, 58, 48, 57, 65, 70, 97, + 102, 58, 48, 57, 65, 70, 97, 102, + 93, 48, 57, 65, 70, 97, 102, 93, + 48, 57, 65, 70, 97, 102, 93, 48, + 57, 65, 70, 97, 102, 46, 58, 48, + 57, 65, 70, 97, 102, 46, 58, 48, + 57, 65, 70, 97, 102, 46, 58, 48, + 57, 65, 70, 97, 102, 46, 53, 58, + 48, 52, 54, 57, 65, 70, 97, 102, + 46, 58, 48, 53, 54, 57, 65, 70, + 97, 102, 46, 58, 48, 57, 65, 70, + 97, 102, 46, 58, 48, 57, 65, 70, + 97, 102, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 58, 48, 57, 65, 70, + 97, 102, 48, 49, 50, 93, 51, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 49, 50, 51, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 49, 50, 51, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 49, 50, 51, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 49, 50, 51, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 57, 65, 70, 97, 102, 46, 58, 93, + 48, 57, 65, 70, 97, 102, 46, 58, + 93, 48, 57, 65, 70, 97, 102, 46, + 58, 93, 48, 57, 65, 70, 97, 102, + 46, 53, 58, 93, 48, 52, 54, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 53, 54, 57, 65, 70, 97, 102, 46, + 58, 93, 48, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 57, 65, 70, 97, + 102, 46, 58, 93, 48, 57, 65, 70, + 97, 102, 46, 58, 93, 48, 57, 65, + 70, 97, 102, 46, 58, 93, 48, 57, + 65, 70, 97, 102, 46, 53, 58, 93, + 48, 52, 54, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 53, 54, 57, 65, + 70, 97, 102, 46, 58, 93, 48, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 57, 65, 70, 97, 102, 46, 58, 93, + 48, 57, 65, 70, 97, 102, 46, 58, + 93, 48, 57, 65, 70, 97, 102, 46, + 58, 93, 48, 57, 65, 70, 97, 102, + 46, 53, 58, 93, 48, 52, 54, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 53, 54, 57, 65, 70, 97, 102, 46, + 58, 93, 48, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 46, 58, 93, 48, 57, 65, 70, + 97, 102, 46, 58, 93, 48, 57, 65, + 70, 97, 102, 46, 58, 93, 48, 57, + 65, 70, 97, 102, 46, 53, 58, 93, + 48, 52, 54, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 53, 54, 57, 65, + 70, 97, 102, 46, 58, 93, 48, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 57, 65, 70, 97, 102, 58, 93, 48, + 57, 65, 70, 97, 102, 46, 58, 93, + 48, 57, 65, 70, 97, 102, 46, 58, + 93, 48, 57, 65, 70, 97, 102, 46, + 58, 93, 48, 57, 65, 70, 97, 102, + 46, 53, 58, 93, 48, 52, 54, 57, + 65, 70, 97, 102, 46, 58, 93, 48, + 53, 54, 57, 65, 70, 97, 102, 46, + 58, 93, 48, 57, 65, 70, 97, 102, + 46, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, 48, 57, 65, 70, 97, + 102, 58, 93, -32, -19, -16, -12, 34, + 92, -62, -33, -31, -17, -15, -13, 32, + 126, -128, -65, -96, -65, -128, -65, -128, + -97, -112, -65, -128, -65, -128, -113, 64, + 32, 126, -32, -19, -16, -12, 45, 46, + -62, -33, -31, -17, -15, -13, 48, 57, + 65, 90, 97, 122, 0}; + +static const signed char _address_single_lengths[] = { + 0, 8, 0, 8, 0, 0, 0, 0, + 0, 0, 8, 5, 0, 0, 0, 0, + 0, 0, 0, 5, 4, 5, 1, 2, + 0, 1, 3, 3, 1, 3, 1, 3, + 1, 1, 2, 1, 1, 1, 2, 1, + 1, 1, 2, 1, 3, 3, 4, 3, + 3, 3, 3, 2, 1, 2, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 4, 2, 1, 1, 1, 0, + 1, 1, 1, 2, 2, 2, 3, 2, + 2, 2, 1, 2, 2, 2, 2, 0, + 2, 2, 2, 2, 0, 2, 2, 2, + 2, 0, 2, 2, 2, 2, 0, 2, + 2, 2, 2, 1, 4, 3, 2, 2, + 2, 3, 3, 2, 2, 2, 3, 3, + 2, 2, 2, 3, 3, 2, 2, 2, + 3, 3, 3, 3, 3, 4, 3, 3, + 3, 3, 3, 3, 4, 3, 3, 3, + 2, 3, 3, 3, 4, 3, 3, 3, + 2, 3, 3, 3, 4, 3, 3, 3, + 2, 3, 3, 3, 4, 3, 3, 3, + 2, 2, 6, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 6, 0, 0}; + +static const signed char _address_range_lengths[] = { + 0, 8, 1, 8, 1, 1, 1, 1, + 1, 1, 8, 6, 1, 1, 1, 1, + 1, 1, 1, 6, 6, 3, 3, 3, + 2, 0, 3, 1, 0, 1, 0, 1, + 1, 1, 2, 1, 1, 1, 2, 1, + 1, 1, 2, 1, 3, 3, 4, 4, + 3, 3, 3, 3, 8, 3, 3, 3, + 0, 3, 3, 3, 3, 0, 3, 3, + 3, 3, 0, 3, 3, 3, 3, 0, + 3, 3, 3, 3, 0, 3, 3, 3, + 3, 0, 3, 3, 3, 3, 0, 3, + 3, 3, 3, 3, 3, 3, 4, 4, + 3, 3, 3, 3, 3, 3, 0, 3, + 3, 3, 3, 0, 3, 3, 3, 3, + 0, 3, 3, 3, 3, 0, 3, 3, + 3, 3, 0, 3, 3, 3, 3, 3, + 0, 3, 3, 3, 3, 0, 3, 3, + 3, 3, 0, 3, 3, 3, 3, 0, + 3, 3, 3, 3, 3, 4, 4, 3, + 3, 3, 3, 3, 4, 4, 3, 3, + 3, 3, 3, 3, 4, 4, 3, 3, + 3, 3, 3, 3, 4, 4, 3, 3, + 3, 3, 3, 3, 4, 4, 3, 3, + 3, 0, 4, 1, 1, 1, 1, 1, + 1, 1, 0, 1, 6, 0, 0}; + +static const short _address_index_offsets[] = { + 0, 0, 17, 19, 36, 38, 40, 42, + 44, 46, 48, 65, 77, 79, 81, 83, + 85, 87, 89, 91, 103, 114, 123, 128, + 134, 137, 139, 146, 151, 153, 158, 160, + 165, 168, 171, 176, 179, 182, 185, 190, + 193, 196, 199, 204, 207, 214, 221, 230, + 238, 245, 252, 259, 265, 275, 281, 286, + 291, 293, 298, 303, 308, 313, 315, 320, + 325, 330, 335, 337, 342, 347, 352, 357, + 359, 364, 369, 374, 379, 381, 386, 391, + 396, 401, 403, 411, 417, 422, 427, 429, + 433, 438, 443, 448, 454, 460, 466, 474, + 481, 487, 493, 498, 504, 510, 516, 519, + 523, 529, 535, 541, 544, 548, 554, 560, + 566, 569, 573, 579, 585, 591, 594, 598, + 604, 610, 616, 619, 624, 632, 639, 645, + 651, 654, 661, 668, 674, 680, 683, 690, + 697, 703, 709, 712, 719, 726, 732, 738, + 741, 748, 755, 762, 769, 776, 785, 793, + 800, 807, 814, 821, 828, 837, 845, 852, + 859, 865, 872, 879, 886, 895, 903, 910, + 917, 923, 930, 937, 944, 953, 961, 968, + 975, 981, 988, 995, 1002, 1011, 1019, 1026, + 1033, 1039, 1042, 1053, 1055, 1057, 1059, 1061, + 1063, 1065, 1067, 1069, 1071, 1084, 0}; + +static const short _address_cond_targs[] = { + 4, 6, 7, 9, 186, 3, 3, 3, + 2, 5, 8, 3, 3, 3, 3, 3, + 0, 3, 0, 4, 6, 7, 9, 3, + 10, 3, 11, 2, 5, 8, 3, 3, + 3, 3, 3, 0, 2, 0, 2, 0, + 2, 0, 5, 0, 5, 0, 5, 0, + 4, 6, 7, 9, 3, 3, 3, 3, + 2, 5, 8, 3, 3, 3, 3, 3, + 0, 13, 15, 16, 18, 21, 12, 14, + 17, 196, 196, 196, 0, 196, 0, 12, + 0, 12, 0, 12, 0, 14, 0, 14, + 0, 14, 0, 13, 15, 16, 18, 19, + 12, 14, 17, 196, 196, 196, 0, 13, + 15, 16, 18, 12, 14, 17, 196, 196, + 196, 0, 22, 26, 44, 46, 48, 45, + 23, 23, 0, 22, 23, 23, 23, 0, + 22, 24, 23, 23, 23, 0, 25, 25, + 0, 197, 0, 22, 27, 24, 23, 23, + 23, 0, 28, 40, 42, 41, 0, 29, + 0, 30, 36, 38, 37, 0, 31, 0, + 25, 32, 34, 33, 0, 197, 33, 0, + 197, 25, 0, 35, 197, 33, 25, 0, + 197, 25, 0, 31, 37, 0, 31, 30, + 0, 31, 39, 37, 30, 0, 31, 30, + 0, 29, 41, 0, 29, 28, 0, 29, + 43, 41, 28, 0, 29, 28, 0, 22, + 27, 24, 45, 23, 23, 0, 22, 27, + 24, 26, 23, 23, 0, 22, 27, 47, + 24, 45, 26, 23, 23, 0, 22, 27, + 24, 26, 23, 23, 23, 0, 22, 24, + 49, 23, 23, 23, 0, 22, 24, 50, + 23, 23, 23, 0, 22, 51, 24, 23, + 23, 23, 0, 22, 52, 23, 23, 23, + 0, 185, 25, 53, 25, 53, 25, 25, + 53, 25, 0, 57, 197, 54, 54, 54, + 0, 57, 55, 55, 55, 0, 57, 56, + 56, 56, 0, 57, 0, 124, 58, 58, + 58, 0, 62, 59, 59, 59, 0, 62, + 60, 60, 60, 0, 62, 61, 61, 61, + 0, 62, 0, 124, 63, 63, 63, 0, + 67, 64, 64, 64, 0, 67, 65, 65, + 65, 0, 67, 66, 66, 66, 0, 67, + 0, 124, 68, 68, 68, 0, 72, 69, + 69, 69, 0, 72, 70, 70, 70, 0, + 72, 71, 71, 71, 0, 72, 0, 124, + 73, 73, 73, 0, 77, 74, 74, 74, + 0, 77, 75, 75, 75, 0, 77, 76, + 76, 76, 0, 77, 0, 98, 78, 78, + 78, 0, 82, 79, 79, 79, 0, 82, + 80, 80, 80, 0, 82, 81, 81, 81, + 0, 82, 0, 83, 91, 94, 98, 97, + 123, 123, 0, 27, 87, 84, 84, 84, + 0, 87, 85, 85, 85, 0, 87, 86, + 86, 86, 0, 87, 0, 88, 88, 88, + 0, 197, 89, 89, 89, 0, 197, 90, + 90, 90, 0, 197, 25, 25, 25, 0, + 27, 87, 92, 84, 84, 0, 27, 87, + 93, 85, 85, 0, 27, 87, 86, 86, + 86, 0, 27, 95, 87, 92, 96, 84, + 84, 0, 27, 87, 93, 85, 85, 85, + 0, 27, 87, 85, 85, 85, 0, 27, + 87, 96, 84, 84, 0, 197, 99, 99, + 99, 0, 103, 197, 100, 100, 100, 0, + 103, 197, 101, 101, 101, 0, 103, 197, + 102, 102, 102, 0, 103, 197, 0, 104, + 104, 104, 0, 108, 197, 105, 105, 105, + 0, 108, 197, 106, 106, 106, 0, 108, + 197, 107, 107, 107, 0, 108, 197, 0, + 109, 109, 109, 0, 113, 197, 110, 110, + 110, 0, 113, 197, 111, 111, 111, 0, + 113, 197, 112, 112, 112, 0, 113, 197, + 0, 114, 114, 114, 0, 118, 197, 115, + 115, 115, 0, 118, 197, 116, 116, 116, + 0, 118, 197, 117, 117, 117, 0, 118, + 197, 0, 119, 119, 119, 0, 87, 197, + 120, 120, 120, 0, 87, 197, 121, 121, + 121, 0, 87, 197, 122, 122, 122, 0, + 87, 197, 0, 87, 84, 84, 84, 0, + 125, 177, 180, 197, 183, 184, 184, 0, + 27, 129, 197, 126, 126, 126, 0, 129, + 197, 127, 127, 127, 0, 129, 197, 128, + 128, 128, 0, 129, 197, 0, 130, 169, + 172, 175, 176, 176, 0, 27, 134, 197, + 131, 131, 131, 0, 134, 197, 132, 132, + 132, 0, 134, 197, 133, 133, 133, 0, + 134, 197, 0, 135, 161, 164, 167, 168, + 168, 0, 27, 139, 197, 136, 136, 136, + 0, 139, 197, 137, 137, 137, 0, 139, + 197, 138, 138, 138, 0, 139, 197, 0, + 140, 153, 156, 159, 160, 160, 0, 27, + 144, 197, 141, 141, 141, 0, 144, 197, + 142, 142, 142, 0, 144, 197, 143, 143, + 143, 0, 144, 197, 0, 145, 146, 149, + 152, 119, 119, 0, 27, 87, 197, 120, + 120, 120, 0, 27, 87, 197, 147, 120, + 120, 0, 27, 87, 197, 148, 121, 121, + 0, 27, 87, 197, 122, 122, 122, 0, + 27, 150, 87, 197, 147, 151, 120, 120, + 0, 27, 87, 197, 148, 121, 121, 121, + 0, 27, 87, 197, 121, 121, 121, 0, + 27, 87, 197, 151, 120, 120, 0, 27, + 144, 197, 154, 141, 141, 0, 27, 144, + 197, 155, 142, 142, 0, 27, 144, 197, + 143, 143, 143, 0, 27, 157, 144, 197, + 154, 158, 141, 141, 0, 27, 144, 197, + 155, 142, 142, 142, 0, 27, 144, 197, + 142, 142, 142, 0, 27, 144, 197, 158, + 141, 141, 0, 144, 197, 141, 141, 141, + 0, 27, 139, 197, 162, 136, 136, 0, + 27, 139, 197, 163, 137, 137, 0, 27, + 139, 197, 138, 138, 138, 0, 27, 165, + 139, 197, 162, 166, 136, 136, 0, 27, + 139, 197, 163, 137, 137, 137, 0, 27, + 139, 197, 137, 137, 137, 0, 27, 139, + 197, 166, 136, 136, 0, 139, 197, 136, + 136, 136, 0, 27, 134, 197, 170, 131, + 131, 0, 27, 134, 197, 171, 132, 132, + 0, 27, 134, 197, 133, 133, 133, 0, + 27, 173, 134, 197, 170, 174, 131, 131, + 0, 27, 134, 197, 171, 132, 132, 132, + 0, 27, 134, 197, 132, 132, 132, 0, + 27, 134, 197, 174, 131, 131, 0, 134, + 197, 131, 131, 131, 0, 27, 129, 197, + 178, 126, 126, 0, 27, 129, 197, 179, + 127, 127, 0, 27, 129, 197, 128, 128, + 128, 0, 27, 181, 129, 197, 178, 182, + 126, 126, 0, 27, 129, 197, 179, 127, + 127, 127, 0, 27, 129, 197, 127, 127, + 127, 0, 27, 129, 197, 182, 126, 126, + 0, 129, 197, 126, 126, 126, 0, 124, + 197, 0, 188, 190, 191, 193, 194, 195, + 187, 189, 192, 186, 0, 186, 0, 187, + 0, 187, 0, 187, 0, 189, 0, 189, + 0, 189, 0, 11, 0, 186, 0, 13, + 15, 16, 18, 19, 20, 12, 14, 17, + 196, 196, 196, 0, 0, 0, 1, 2, + 3, 4, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, + 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, + 51, 52, 53, 54, 55, 56, 57, 58, + 59, 60, 61, 62, 63, 64, 65, 66, + 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, + 91, 92, 93, 94, 95, 96, 97, 98, + 99, 100, 101, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 119, 120, 121, 122, + 123, 124, 125, 126, 127, 128, 129, 130, + 131, 132, 133, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144, 145, 146, + 147, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, 160, 161, 162, + 163, 164, 165, 166, 167, 168, 169, 170, + 171, 172, 173, 174, 175, 176, 177, 178, + 179, 180, 181, 182, 183, 184, 185, 186, + 187, 188, 189, 190, 191, 192, 193, 194, + 195, 196, 197, 0}; + +static const signed char _address_cond_actions[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 3, 0, 3, 0, 3, + 0, 3, 0, 3, 0, 3, 0, 3, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 3, 1, 3, 0, + 3, 0, 3, 0, 3, 0, 3, 0, + 3, 0, 3, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 3, 0, + 0, 0, 0, 0, 0, 0, 1, 1, + 1, 3, 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 3, + 0, 0, 0, 0, 0, 3, 0, 0, + 3, 1, 3, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 0, 0, 3, 0, + 3, 0, 0, 0, 0, 3, 0, 3, + 0, 0, 0, 0, 3, 1, 0, 3, + 1, 0, 3, 0, 1, 0, 0, 3, + 1, 0, 3, 0, 0, 3, 0, 0, + 3, 0, 0, 0, 0, 3, 0, 0, + 3, 0, 0, 3, 0, 0, 3, 0, + 0, 0, 0, 3, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, + 0, 0, 0, 3, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 3, 0, 3, 0, 0, 0, + 0, 3, 0, 0, 0, 0, 3, 0, + 0, 0, 0, 3, 0, 0, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 3, + 0, 0, 0, 0, 3, 0, 0, 0, + 0, 3, 0, 0, 0, 0, 3, 0, + 3, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 3, + 0, 0, 0, 0, 3, 0, 3, 0, + 0, 0, 0, 3, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 3, 0, 3, 0, 0, 0, + 0, 3, 0, 0, 0, 0, 3, 0, + 0, 0, 0, 3, 0, 0, 0, 0, + 3, 0, 3, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 3, 0, 3, 0, 0, 0, + 3, 1, 0, 0, 0, 3, 1, 0, + 0, 0, 3, 1, 0, 0, 0, 3, + 0, 0, 0, 0, 0, 3, 0, 0, + 0, 0, 0, 3, 0, 0, 0, 0, + 0, 3, 0, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 3, 1, 0, 0, + 0, 3, 0, 1, 0, 0, 0, 3, + 0, 1, 0, 0, 0, 3, 0, 1, + 0, 0, 0, 3, 0, 1, 3, 0, + 0, 0, 3, 0, 1, 0, 0, 0, + 3, 0, 1, 0, 0, 0, 3, 0, + 1, 0, 0, 0, 3, 0, 1, 3, + 0, 0, 0, 3, 0, 1, 0, 0, + 0, 3, 0, 1, 0, 0, 0, 3, + 0, 1, 0, 0, 0, 3, 0, 1, + 3, 0, 0, 0, 3, 0, 1, 0, + 0, 0, 3, 0, 1, 0, 0, 0, + 3, 0, 1, 0, 0, 0, 3, 0, + 1, 3, 0, 0, 0, 3, 0, 1, + 0, 0, 0, 3, 0, 1, 0, 0, + 0, 3, 0, 1, 0, 0, 0, 3, + 0, 1, 3, 0, 0, 0, 0, 3, + 0, 0, 0, 1, 0, 0, 0, 3, + 0, 0, 1, 0, 0, 0, 3, 0, + 1, 0, 0, 0, 3, 0, 1, 0, + 0, 0, 3, 0, 1, 3, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 1, + 0, 0, 0, 3, 0, 1, 0, 0, + 0, 3, 0, 1, 0, 0, 0, 3, + 0, 1, 3, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 1, 0, 0, 0, + 3, 0, 1, 0, 0, 0, 3, 0, + 1, 0, 0, 0, 3, 0, 1, 3, + 0, 0, 0, 0, 0, 0, 3, 0, + 0, 1, 0, 0, 0, 3, 0, 1, + 0, 0, 0, 3, 0, 1, 0, 0, + 0, 3, 0, 1, 3, 0, 0, 0, + 0, 0, 0, 3, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 1, 0, 0, + 0, 3, 0, 0, 1, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 3, + 0, 0, 0, 1, 0, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 3, + 0, 0, 1, 0, 0, 0, 3, 0, + 0, 1, 0, 0, 0, 3, 0, 0, + 1, 0, 0, 0, 3, 0, 0, 1, + 0, 0, 0, 3, 0, 0, 0, 1, + 0, 0, 0, 0, 3, 0, 0, 1, + 0, 0, 0, 0, 3, 0, 0, 1, + 0, 0, 0, 3, 0, 0, 1, 0, + 0, 0, 3, 0, 1, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 3, + 0, 0, 1, 0, 0, 0, 3, 0, + 0, 1, 0, 0, 0, 3, 0, 0, + 0, 1, 0, 0, 0, 0, 3, 0, + 0, 1, 0, 0, 0, 0, 3, 0, + 0, 1, 0, 0, 0, 3, 0, 0, + 1, 0, 0, 0, 3, 0, 1, 0, + 0, 0, 3, 0, 0, 1, 0, 0, + 0, 3, 0, 0, 1, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 3, + 0, 0, 0, 1, 0, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 0, + 3, 0, 0, 1, 0, 0, 0, 3, + 0, 0, 1, 0, 0, 0, 3, 0, + 1, 0, 0, 0, 3, 0, 0, 1, + 0, 0, 0, 3, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 1, 0, 0, + 0, 3, 0, 0, 0, 1, 0, 0, + 0, 0, 3, 0, 0, 1, 0, 0, + 0, 0, 3, 0, 0, 1, 0, 0, + 0, 3, 0, 0, 1, 0, 0, 0, + 3, 0, 1, 0, 0, 0, 3, 0, + 1, 3, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, 3, 0, + 3, 0, 3, 0, 3, 0, 3, 0, + 3, 0, 3, 0, 3, 0, 3, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 3, 3, 0, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, + 3, 0, 0, 0}; + +static const short _address_eof_trans[] = { + 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, + 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, + 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, + 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, + 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, + 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, + 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, + 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, + 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, + 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, + 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, + 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, + 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, + 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, + 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, + 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, + 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, + 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, + 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, + 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, + 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253, + 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, + 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, + 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, + 1278, 1279, 1280, 1281, 1282, 1283, 0}; + +static const int address_start = 1; + +bool is_address(const char *p, const char *pe) +{ + int cs = 0; + + const char *eof = pe; + + bool result = false; + + { + cs = (int) address_start; + } + { + int _klen; + unsigned int _trans = 0; + const signed char *_keys; + const signed char *_acts; + unsigned int _nacts; + _resume: { + } + if (p == pe && p != eof) + goto _out; + if (p == eof) { + if (_address_eof_trans[cs] > 0) { + _trans = (unsigned int) _address_eof_trans[cs] - 1; + } + } else { + _keys = (_address_trans_keys + (_address_key_offsets[cs])); + _trans = (unsigned int) _address_index_offsets[cs]; + + _klen = (int) _address_single_lengths[cs]; + if (_klen > 0) { + const signed char *_lower = _keys; + const signed char *_upper = _keys + _klen - 1; + const signed char *_mid; + while (1) { + if (_upper < _lower) { + _keys += _klen; + _trans += (unsigned int) _klen; + break; + } + + _mid = _lower + ((_upper - _lower) >> 1); + if (((*(p))) < (*(_mid))) + _upper = _mid - 1; + else if (((*(p))) > (*(_mid))) + _lower = _mid + 1; + else { + _trans += (unsigned int) (_mid - _keys); + goto _match; + } + } + } + + _klen = (int) _address_range_lengths[cs]; + if (_klen > 0) { + const signed char *_lower = _keys; + const signed char *_upper = _keys + (_klen << 1) - 2; + const signed char *_mid; + while (1) { + if (_upper < _lower) { + _trans += (unsigned int) _klen; + break; + } + + _mid = _lower + (((_upper - _lower) >> 1) & ~1); + if (((*(p))) < (*(_mid))) + _upper = _mid - 2; + else if (((*(p))) > (*(_mid + 1))) + _lower = _mid + 2; + else { + _trans += (unsigned int) ((_mid - _keys) >> 1); + break; + } + } + } + + _match: { + } + } + cs = (int) _address_cond_targs[_trans]; + + if (_address_cond_actions[_trans] != 0) { + + _acts = (_address_actions + (_address_cond_actions[_trans])); + _nacts = (unsigned int) (*(_acts)); + _acts += 1; + while (_nacts > 0) { + switch ((*(_acts))) { + case 0: { + { + result = true; + } + break; + } + case 1: { + { + result = false; + } + break; + } + } + _nacts -= 1; + _acts += 1; + } + } + + if (p == eof) { + if (cs >= 196) + goto _out; + } else { + if (cs != 0) { + p += 1; + goto _resume; + } + } + _out: { + } + } + return result; +} diff --git a/externals/json-schema-validator/smtp-address-validator.hpp b/externals/json-schema-validator/smtp-address-validator.hpp new file mode 100644 index 0000000..8d3c12b --- /dev/null +++ b/externals/json-schema-validator/smtp-address-validator.hpp @@ -0,0 +1,34 @@ +#ifndef SMTP_ADDRESS_PARSER_HPP_INCLUDED +#define SMTP_ADDRESS_PARSER_HPP_INCLUDED + +/* + +Snarfed from + +: + +Copyright (c) 2021 Gene Hightower + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +bool is_address(const char *p, const char *pe); + +#endif // SMTP_ADDRESS_PARSER_HPP_INCLUDED diff --git a/externals/json-schema-validator/string-format-check.cpp b/externals/json-schema-validator/string-format-check.cpp new file mode 100644 index 0000000..ecc428f --- /dev/null +++ b/externals/json-schema-validator/string-format-check.cpp @@ -0,0 +1,414 @@ +#include + +#include "smtp-address-validator.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef JSON_SCHEMA_BOOST_REGEX +# include +# define REGEX_NAMESPACE boost +#elif defined(JSON_SCHEMA_NO_REGEX) +# define NO_STD_REGEX +#else +# include +# define REGEX_NAMESPACE std +#endif + +/** + * Many of the RegExes are from @see http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + */ + +namespace +{ +template +void range_check(const T value, const T min, const T max) +{ + if (!((value >= min) && (value <= max))) { + std::stringstream out; + out << "Value " << value << " should be in interval [" << min << "," << max << "] but is not!"; + throw std::invalid_argument(out.str()); + } +} + +/** @see date_time_check */ +void rfc3339_date_check(const std::string &value) +{ + const static REGEX_NAMESPACE::regex dateRegex{R"(^([0-9]{4})\-([0-9]{2})\-([0-9]{2})$)"}; + + REGEX_NAMESPACE::smatch matches; + if (!REGEX_NAMESPACE::regex_match(value, matches, dateRegex)) { + throw std::invalid_argument(value + " is not a date string according to RFC 3339."); + } + + const auto year = std::stoi(matches[1].str()); + const auto month = std::stoi(matches[2].str()); + const auto mday = std::stoi(matches[3].str()); + + const auto isLeapYear = (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0)); + + range_check(month, 1, 12); + if (month == 2) { + range_check(mday, 1, isLeapYear ? 29 : 28); + } else if (month <= 7) { + range_check(mday, 1, month % 2 == 0 ? 30 : 31); + } else { + range_check(mday, 1, month % 2 == 0 ? 31 : 30); + } +} + +/** @see date_time_check */ +void rfc3339_time_check(const std::string &value) +{ + const static REGEX_NAMESPACE::regex timeRegex{R"(^([0-9]{2})\:([0-9]{2})\:([0-9]{2})(\.[0-9]+)?(?:[Zz]|((?:\+|\-)[0-9]{2})\:([0-9]{2}))$)"}; + + REGEX_NAMESPACE::smatch matches; + if (!REGEX_NAMESPACE::regex_match(value, matches, timeRegex)) { + throw std::invalid_argument(value + " is not a time string according to RFC 3339."); + } + + auto hour = std::stoi(matches[1].str()); + auto minute = std::stoi(matches[2].str()); + auto second = std::stoi(matches[3].str()); + // const auto secfrac = std::stof( matches[4].str() ); + + range_check(hour, 0, 23); + range_check(minute, 0, 59); + + int offsetHour = 0, + offsetMinute = 0; + + /* don't check the numerical offset if time zone is specified as 'Z' */ + if (!matches[5].str().empty()) { + offsetHour = std::stoi(matches[5].str()); + offsetMinute = std::stoi(matches[6].str()); + + range_check(offsetHour, -23, 23); + range_check(offsetMinute, 0, 59); + if (offsetHour < 0) + offsetMinute *= -1; + } + + /** + * @todo Could be made more exact by querying a leap second database and choosing the + * correct maximum in {58,59,60}. This current solution might match some invalid dates + * but it won't lead to false negatives. This only works if we know the full date, however + */ + + auto day_minutes = hour * 60 + minute - (offsetHour * 60 + offsetMinute); + if (day_minutes < 0) + day_minutes += 60 * 24; + hour = day_minutes % 24; + minute = day_minutes / 24; + + if (hour == 23 && minute == 59) + range_check(second, 0, 60); // possible leap-second + else + range_check(second, 0, 59); +} + +/** + * @see https://tools.ietf.org/html/rfc3339#section-5.6 + * + * @verbatim + * date-fullyear = 4DIGIT + * date-month = 2DIGIT ; 01-12 + * date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on + * ; month/year + * time-hour = 2DIGIT ; 00-23 + * time-minute = 2DIGIT ; 00-59 + * time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second + * ; rules + * time-secfrac = "." 1*DIGIT + * time-numoffset = ("+" / "-") time-hour ":" time-minute + * time-offset = "Z" / time-numoffset + * + * partial-time = time-hour ":" time-minute ":" time-second + * [time-secfrac] + * full-date = date-fullyear "-" date-month "-" date-mday + * full-time = partial-time time-offset + * + * date-time = full-date "T" full-time + * @endverbatim + * NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this + * syntax may alternatively be lower case "t" or "z" respectively. + */ +void rfc3339_date_time_check(const std::string &value) +{ + const static REGEX_NAMESPACE::regex dateTimeRegex{R"(^([0-9]{4}\-[0-9]{2}\-[0-9]{2})[Tt]([0-9]{2}\:[0-9]{2}\:[0-9]{2}(?:\.[0-9]+)?(?:[Zz]|(?:\+|\-)[0-9]{2}\:[0-9]{2}))$)"}; + + REGEX_NAMESPACE::smatch matches; + if (!REGEX_NAMESPACE::regex_match(value, matches, dateTimeRegex)) { + throw std::invalid_argument(value + " is not a date-time string according to RFC 3339."); + } + + rfc3339_date_check(matches[1].str()); + rfc3339_time_check(matches[2].str()); +} + +const std::string decOctet{R"((?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9]))"}; // matches numbers 0-255 +const std::string ipv4Address{"(?:" + decOctet + R"(\.){3})" + decOctet}; +const std::string h16{R"([0-9A-Fa-f]{1,4})"}; +const std::string h16Left{"(?:" + h16 + ":)"}; +const std::string ipv6Address{ + "(?:" + "(?:" + + h16Left + "{6}" + "|::" + + h16Left + "{5}" + "|(?:" + + h16 + ")?::" + h16Left + "{4}" + "|(?:" + + h16Left + "{0,1}" + h16 + ")?::" + h16Left + "{3}" + "|(?:" + + h16Left + "{0,2}" + h16 + ")?::" + h16Left + "{2}" + "|(?:" + + h16Left + "{0,3}" + h16 + ")?::" + h16Left + + "|(?:" + h16Left + "{0,4}" + h16 + ")?::" + ")(?:" + + h16Left + h16 + "|" + ipv4Address + ")" + "|(?:" + + h16Left + "{0,5}" + h16 + ")?::" + h16 + + "|(?:" + h16Left + "{0,6}" + h16 + ")?::" + ")"}; +const std::string ipvFuture{R"([Vv][0-9A-Fa-f]+\.[A-Za-z0-9\-._~!$&'()*+,;=:]+)"}; +const std::string regName{R"((?:[A-Za-z0-9\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*)"}; +const std::string host{ + "(?:" + R"(\[(?:)" + + ipv6Address + "|" + ipvFuture + R"()\])" + + "|" + ipv4Address + + "|" + regName + + ")"}; + +const std::string uuid{R"([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})"}; + +// from http://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address +const std::string hostname{R"(^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$)"}; + +bool is_ascii(std::string const &value) +{ + for (auto ch : value) { + if (ch & 0x80) { + return false; + } + } + return true; +} + +/** + * @see + * + * @verbatim + * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] + * + * hier-part = "//" authority path-abempty + * / path-absolute + * / path-rootless + * / path-empty + * + * URI-reference = URI / relative-ref + * + * absolute-URI = scheme ":" hier-part [ "?" query ] + * + * relative-ref = relative-part [ "?" query ] [ "#" fragment ] + * + * relative-part = "//" authority path-abempty + * / path-absolute + * / path-noscheme + * / path-empty + * + * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) + * + * authority = [ userinfo "@" ] host [ ":" port ] + * userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) + * host = IP-literal / IPv4address / reg-name + * port = *DIGIT + * + * IP-literal = "[" ( IPv6address / IPvFuture ) "]" + * + * IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) + * + * IPv6address = 6( h16 ":" ) ls32 + * / "::" 5( h16 ":" ) ls32 + * / [ h16 ] "::" 4( h16 ":" ) ls32 + * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 + * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 + * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 + * / [ *4( h16 ":" ) h16 ] "::" ls32 + * / [ *5( h16 ":" ) h16 ] "::" h16 + * / [ *6( h16 ":" ) h16 ] "::" + * + * h16 = 1*4HEXDIG + * ls32 = ( h16 ":" h16 ) / IPv4address + * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet + * dec-octet = DIGIT ; 0-9 + * / %x31-39 DIGIT ; 10-99 + * / "1" 2DIGIT ; 100-199 + * / "2" %x30-34 DIGIT ; 200-249 + * / "25" %x30-35 ; 250-255 + * + * reg-name = *( unreserved / pct-encoded / sub-delims ) + * + * path = path-abempty ; begins with "/" or is empty + * / path-absolute ; begins with "/" but not "//" + * / path-noscheme ; begins with a non-colon segment + * / path-rootless ; begins with a segment + * / path-empty ; zero characters + * + * path-abempty = *( "/" segment ) + * path-absolute = "/" [ segment-nz *( "/" segment ) ] + * path-noscheme = segment-nz-nc *( "/" segment ) + * path-rootless = segment-nz *( "/" segment ) + * path-empty = 0 + * + * segment = *pchar + * segment-nz = 1*pchar + * segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) + * ; non-zero-length segment without any colon ":" + * + * pchar = unreserved / pct-encoded / sub-delims / ":" / "@" + * + * query = *( pchar / "/" / "?" ) + * + * fragment = *( pchar / "/" / "?" ) + * + * pct-encoded = "%" HEXDIG HEXDIG + * + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * reserved = gen-delims / sub-delims + * gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + * + * @endverbatim + * @see adapted from: https://github.com/jhermsmeier/uri.regex/blob/master/uri.regex + * + */ +void rfc3986_uri_check(const std::string &value) +{ + const static std::string scheme{R"(([A-Za-z][A-Za-z0-9+\-.]*):)"}; + const static std::string hierPart{ + R"((?:(\/\/)(?:((?:[A-Za-z0-9\-._~!$&'()*+,;=:]|)" + R"(%[0-9A-Fa-f]{2})*)@)?((?:\[(?:(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}|)" + R"(::(?:[0-9A-Fa-f]{1,4}:){5}|)" + R"((?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}|)" + R"((?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}|)" + R"((?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}|)" + R"((?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:|)" + R"((?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::)(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|)" + R"((?:(?:25[0-5]|2[0-4][0-9]|)" + R"([01]?[0-9][0-9]?)\.){3}(?:25[0-5]|)" + R"(2[0-4][0-9]|)" + R"([01]?[0-9][0-9]?))|)" + R"((?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|)" + R"((?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)|)" + R"([Vv][0-9A-Fa-f]+\.[A-Za-z0-9\-._~!$&'()*+,;=:]+)\]|)" + R"((?:(?:25[0-5]|)" + R"(2[0-4][0-9]|)" + R"([01]?[0-9][0-9]?)\.){3}(?:25[0-5]|)" + R"(2[0-4][0-9]|)" + R"([01]?[0-9][0-9]?)|)" + R"((?:[A-Za-z0-9\-._~!$&'()*+,;=]|)" + R"(%[0-9A-Fa-f]{2})*))(?::([0-9]*))?((?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" + R"(%[0-9A-Fa-f]{2})*)*)|)" + R"(\/((?:(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" + R"(%[0-9A-Fa-f]{2})+(?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" + R"(%[0-9A-Fa-f]{2})*)*)?)|)" + R"(((?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" + R"(%[0-9A-Fa-f]{2})+(?:\/(?:[A-Za-z0-9\-._~!$&'()*+,;=:@]|)" + R"(%[0-9A-Fa-f]{2})*)*)|))"}; + + const static std::string query{R"((?:\?((?:[A-Za-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9A-Fa-f]{2})*))?)"}; + const static std::string fragment{ + R"((?:\#((?:[A-Za-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9A-Fa-f]{2})*))?)"}; + const static std::string uriFormat{scheme + hierPart + query + fragment}; + + const static REGEX_NAMESPACE::regex uriRegex{uriFormat}; + + if (!REGEX_NAMESPACE::regex_match(value, uriRegex)) { + throw std::invalid_argument(value + " is not a URI string according to RFC 3986."); + } +} + +} // namespace + +namespace nlohmann +{ +namespace json_schema +{ +/** + * Checks validity for built-ins by converting the definitions given as ABNF in the linked RFC from + * @see https://json-schema.org/understanding-json-schema/reference/string.html#built-in-formats + * into regular expressions using @see https://www.msweet.org/abnf/ and some manual editing. + * + * @see https://json-schema.org/latest/json-schema-validation.html + */ +void default_string_format_check(const std::string &format, const std::string &value) +{ + if (format == "date-time") { + rfc3339_date_time_check(value); + } else if (format == "date") { + rfc3339_date_check(value); + } else if (format == "time") { + rfc3339_time_check(value); + } else if (format == "uri") { + rfc3986_uri_check(value); + } else if (format == "email") { + if (!is_ascii(value)) { + throw std::invalid_argument(value + " contains non-ASCII values, not RFC 5321 compliant."); + } + if (!is_address(&*value.begin(), &*value.end())) { + throw std::invalid_argument(value + " is not a valid email according to RFC 5321."); + } + } else if (format == "idn-email") { + if (!is_address(&*value.begin(), &*value.end())) { + throw std::invalid_argument(value + " is not a valid idn-email according to RFC 6531."); + } + } else if (format == "hostname") { + static const REGEX_NAMESPACE::regex hostRegex{hostname}; + if (!REGEX_NAMESPACE::regex_match(value, hostRegex)) { + throw std::invalid_argument(value + " is not a valid hostname according to RFC 3986 Appendix A."); + } + } else if (format == "ipv4") { + const static REGEX_NAMESPACE::regex ipv4Regex{"^" + ipv4Address + "$"}; + if (!REGEX_NAMESPACE::regex_match(value, ipv4Regex)) { + throw std::invalid_argument(value + " is not an IPv4 string according to RFC 2673."); + } + } else if (format == "ipv6") { + static const REGEX_NAMESPACE::regex ipv6Regex{ipv6Address}; + if (!REGEX_NAMESPACE::regex_match(value, ipv6Regex)) { + throw std::invalid_argument(value + " is not an IPv6 string according to RFC 5954."); + } + } else if (format == "uuid") { + static const REGEX_NAMESPACE::regex uuidRegex{uuid}; + if (!REGEX_NAMESPACE::regex_match(value, uuidRegex)) { + throw std::invalid_argument(value + " is not an uuid string according to RFC 4122."); + } + } else if (format == "regex") { + try { + REGEX_NAMESPACE::regex re(value, std::regex::ECMAScript); + } catch (std::exception &exception) { + throw exception; + } + } else { + /* yet unsupported JSON schema draft 7 built-ins */ + static const std::vector jsonSchemaStringFormatBuiltIns{ + "date-time", "time", "date", "email", "idn-email", "hostname", "idn-hostname", "ipv4", "ipv6", "uri", + "uri-reference", "iri", "iri-reference", "uri-template", "json-pointer", "relative-json-pointer", "regex"}; + if (std::find(jsonSchemaStringFormatBuiltIns.begin(), jsonSchemaStringFormatBuiltIns.end(), format) != jsonSchemaStringFormatBuiltIns.end()) { + throw std::logic_error("JSON schema string format built-in " + format + " not yet supported. " + + "Please open an issue or use a custom format checker."); + } + + throw std::logic_error("Don't know how to validate " + format); + } +} +} // namespace json_schema +} // namespace nlohmann diff --git a/externals/nlohmann/LICENSE.MIT b/externals/json/nlohmann/LICENSE.MIT similarity index 100% rename from externals/nlohmann/LICENSE.MIT rename to externals/json/nlohmann/LICENSE.MIT diff --git a/externals/nlohmann/json.hpp b/externals/json/nlohmann/json.hpp similarity index 100% rename from externals/nlohmann/json.hpp rename to externals/json/nlohmann/json.hpp diff --git a/python/cbxp/cbxp.py b/python/cbxp/cbxp.py index d01e768..c566e51 100644 --- a/python/cbxp/cbxp.py +++ b/python/cbxp/cbxp.py @@ -42,6 +42,12 @@ class CBXPErrorCode(Enum): BAD_INCLUDE = 2 BAD_FILTER = 3 DATA_TOO_SMALL = 4 + NULL_DATA_POINTER = 5 + BAD_CBXP_PATH = 6 + CANT_REACH_BLOCK = 7 + JSON_FAIL_PARSE = 8 + JSON_FAIL_SCHEMA = 9 + JSON_BAD_VALUE = 10 class CBXPError(Exception): @@ -65,6 +71,18 @@ def __init__(self, return_code: int, control_block_name: str): "Data provided is not large enough for specified " f"control block: {control_block_name}" ) + case CBXPErrorCode.NULL_DATA_POINTER.value: + message = "A null data pointer was provided" + case CBXPErrorCode.BAD_CBXP_PATH.value: + message = "Error with your CBXPPATH environment variable" + case CBXPErrorCode.CANT_REACH_BLOCK.value: + message = "Cannot reach control block" + case CBXPErrorCode.JSON_FAIL_PARSE.value: + message = "Could not parse a JSON file" + case CBXPErrorCode.JSON_FAIL_SCHEMA.value: + message = "Could not validate a JSON file" + case CBXPErrorCode.JSON_BAD_VALUE.value: + message = "Could not load a JSON file" case _: message = "An unknown error occurred" super().__init__(message) diff --git a/setup.py b/setup.py index a342796..38e72ee 100644 --- a/setup.py +++ b/setup.py @@ -2,13 +2,56 @@ import os from glob import glob +from pathlib import Path from setuptools import Extension, setup from setuptools.command.build_ext import build_ext +def _escape_for_macro(text: str) -> str: + """Collapse whitespace and escape characters unsafe in a C string literal.""" + return ( + text.replace("\\", "\\\\") + .replace('"', '\\"') + .replace("\n", " ") + .replace("\r", "") + ) + + +def generate_headers(): + """Generate .hpp headers from .json files, mirroring the CMake process.""" + # Schema header + schema_json = _escape_for_macro( + Path("cbxp/schemas/control_block.json").read_text(), + ) + Path("cbxp/schemas/control_block.hpp").write_text( + "#ifndef CBXP_SCHEMA_CONTROL_BLOCK_V1_JSON_HPP\n" + "#define CBXP_SCHEMA_CONTROL_BLOCK_V1_JSON_HPP\n" + "\n" + f'#define CBXP_SCHEMA_JSON "{schema_json}"\n' + "\n" + "#endif // CBXP_SCHEMA_CONTROL_BLOCK_V1_JSON_HPP\n", + ) + + # Mapping headers + for json_path in Path("cbxp/mappings").glob("*.json"): + name = json_path.stem.upper() + guard = f"{name}_JSON_HPP" + macro = f"{name}_JSON" + mapping_json = _escape_for_macro(json_path.read_text()) + json_path.with_suffix(".hpp").write_text( + f"#ifndef {guard}\n" + f"#define {guard}\n" + "\n" + f'#define {macro} "{mapping_json}"\n' + "\n" + f"#endif // {guard}\n", + ) + + def main(): """Python extension build entrypoint.""" + generate_headers() os.environ["CC"] = "ibm-clang64" os.environ["CFLAGS"] = "-std=c11" os.environ["CXX"] = "ibm-clang++64" @@ -24,26 +67,28 @@ def main(): if file not in glob("cbxp/cli/*.cpp") ] + glob("cbxp/*.cpp") + + glob("externals/json-schema-validator/*.cpp") + ["cbxp/python/_cbxp.c"] ), include_dirs=( glob("cbxp/**/") - + [ - "cbxp", - "externals", - "/usr/include/zos", - ] + + glob("externals/*/") + + ["cbxp", "/usr/include/zos"] ), extra_link_args=[ "-m64", "-Wl,-b,edit=no", ], - extra_compile_args=[ - "-O2", - "-fzos-le-char-mode=ascii", - "-fstack-protector-strong", - "-Wno-trigraphs", - ], + extra_compile_args=( + [ + "-O2", + "-fzos-le-char-mode=ascii", + "-fstack-protector-strong", + "-Wno-trigraphs", + ] + + [f"-include{h}" for h in glob("cbxp/schemas/*.hpp")] + + [f"-include{h}" for h in glob("cbxp/mappings/*.hpp")] + ), ), ], "cmdclass": {"build_ext": build_ext}, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0f2c299..e723fc1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -165,7 +165,7 @@ cbxp_test_fail(ExtractErrorIncludeAsvtAscbPsa ${EXE} extract -i asvt.asc cbxp_test_fail(ExtractErrorIncludeAscbPsa ${EXE} extract -i ascb psa) cbxp_test_fail(ExtractErrorIncludeEcvtAscb ${EXE} extract -i ecvt ascb) cbxp_test_fail(ExtractErrorIncludeCvtEcvtCvtAscbPsa ${EXE} extract -i cvt.ecvt -i cvt.ascb psa) -cbxp_test_fail(ExtractErrorIncludeCvtAsvtAscbEcvtPsa ${EXE} extract -i cvt.asvt.ascb -i ecvt psa) +cbxp_test_fail(ExtractErrorIncludeCvtAsvtAscbLdaxPsa ${EXE} extract -i cvt.asvt.ascb -i ldax psa) cbxp_test_fail(ExtractErrorIncludeCvtCvt ${EXE} extract -i cvt cvt) cbxp_test_fail(ExtractErrorIncludeLdaxPsa ${EXE} extract -i ldax psa) cbxp_test_fail(ExtractErrorIncludeLdaxCvt ${EXE} extract -i ldax cvt) @@ -257,3 +257,22 @@ cbxp_test_fail(FormatErrorFileAndPipe # Format - Errors: Data Too Small # ============================================================================= cbxp_test_fail(FormatErrorDataTooSmall ${EXE} format -F ${SAMPLES}/ascb.bin psa) + +# ============================================================================= +# CBXPPATH Fixtures +# ============================================================================= +file(GLOB FIXTURE_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/fixtures/cbxppath ${CMAKE_CURRENT_SOURCE_DIR}/fixtures/cbxppath/*) + +foreach(fixture_name IN LISTS FIXTURE_DIRS) + set(fixture_dir "${CMAKE_CURRENT_SOURCE_DIR}/fixtures/cbxppath/${fixture_name}") + if(IS_DIRECTORY "${fixture_dir}") + add_test(NAME cbxp.fixture.${fixture_name} + COMMAND ${CMAKE_COMMAND} + -DEXE=${EXE} + -DFIXTURE_DIR=${fixture_dir} + -DSAMPLES_DIR=${SAMPLES} + -P ${CMAKE_CURRENT_SOURCE_DIR}/run_fixture.cmake + ) + set_property(TEST cbxp.fixture.${fixture_name} PROPERTY FIXTURES_REQUIRED cbxp.built) + endif() +endforeach() diff --git a/tests/fixtures/cbxppath/err_bad_json/case.conf b/tests/fixtures/cbxppath/err_bad_json/case.conf new file mode 100644 index 0000000..503338b --- /dev/null +++ b/tests/fixtures/cbxppath/err_bad_json/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=8 +MESSAGE='Could not parse a JSON file' +COMMAND=format +CBXPPATH='@CASE@/mappings' +BLOCK=mycb +SAMPLE=mycb.bin diff --git a/tests/fixtures/cbxppath/err_bad_json/mappings/broken.json b/tests/fixtures/cbxppath/err_bad_json/mappings/broken.json new file mode 100644 index 0000000..31ef5a9 --- /dev/null +++ b/tests/fixtures/cbxppath/err_bad_json/mappings/broken.json @@ -0,0 +1,6 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fi diff --git a/tests/fixtures/cbxppath/err_dangling_pointed_to_by/case.conf b/tests/fixtures/cbxppath/err_dangling_pointed_to_by/case.conf new file mode 100644 index 0000000..9495a07 --- /dev/null +++ b/tests/fixtures/cbxppath/err_dangling_pointed_to_by/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=10 +MESSAGE='Could not load a JSON file' +COMMAND=format +CBXPPATH='@CASE@/mappings' +BLOCK=mycb +SAMPLE=mycb.bin diff --git a/tests/fixtures/cbxppath/err_dangling_pointed_to_by/mappings/mycb.json b/tests/fixtures/cbxppath/err_dangling_pointed_to_by/mappings/mycb.json new file mode 100644 index 0000000..cd89a04 --- /dev/null +++ b/tests/fixtures/cbxppath/err_dangling_pointed_to_by/mappings/mycb.json @@ -0,0 +1,43 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "nothere" + ], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/err_dir_named_json/case.conf b/tests/fixtures/cbxppath/err_dir_named_json/case.conf new file mode 100644 index 0000000..c483106 --- /dev/null +++ b/tests/fixtures/cbxppath/err_dir_named_json/case.conf @@ -0,0 +1,10 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +# mappings/looks_like_a_file.json is a directory, not a file. It is not skipped by +# the loader, but reading it yields no data, so it must be reported as bad JSON. +EXPECT=err +CODE=8 +MESSAGE='Could not parse a JSON file' +COMMAND=format +CBXPPATH='@CASE@/mappings' +BLOCK=cvt +SAMPLE=cvt.bin diff --git a/tests/fixtures/cbxppath/err_dir_named_json/mappings/looks_like_a_file.json/.gitkeep b/tests/fixtures/cbxppath/err_dir_named_json/mappings/looks_like_a_file.json/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/cbxppath/err_nonexistent_dir/case.conf b/tests/fixtures/cbxppath/err_nonexistent_dir/case.conf new file mode 100644 index 0000000..91abf2f --- /dev/null +++ b/tests/fixtures/cbxppath/err_nonexistent_dir/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=6 +MESSAGE='Error with your CBXPPATH environment variable' +COMMAND=format +CBXPPATH='@CASE@/missing' +BLOCK=ascb +SAMPLE=ascb.bin diff --git a/tests/fixtures/cbxppath/err_not_common_storage_no_filter/case.conf b/tests/fixtures/cbxppath/err_not_common_storage_no_filter/case.conf new file mode 100644 index 0000000..77c31dd --- /dev/null +++ b/tests/fixtures/cbxppath/err_not_common_storage_no_filter/case.conf @@ -0,0 +1,7 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=7 +MESSAGE='Cannot reach control block' +COMMAND=extract +CBXPPATH='@CASE@/mappings' +BLOCK=mycb diff --git a/tests/fixtures/cbxppath/err_not_common_storage_no_filter/mappings/mycb.json b/tests/fixtures/cbxppath/err_not_common_storage_no_filter/mappings/mycb.json new file mode 100644 index 0000000..4bc77b6 --- /dev/null +++ b/tests/fixtures/cbxppath/err_not_common_storage_no_filter/mappings/mycb.json @@ -0,0 +1,43 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [ + 230 + ], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/err_path_is_file/case.conf b/tests/fixtures/cbxppath/err_path_is_file/case.conf new file mode 100644 index 0000000..9404330 --- /dev/null +++ b/tests/fixtures/cbxppath/err_path_is_file/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=6 +MESSAGE='Error with your CBXPPATH environment variable' +COMMAND=format +CBXPPATH='@CASE@/not_a_dir.txt' +BLOCK=ascb +SAMPLE=ascb.bin diff --git a/tests/fixtures/cbxppath/err_path_is_file/not_a_dir.txt b/tests/fixtures/cbxppath/err_path_is_file/not_a_dir.txt new file mode 100644 index 0000000..5976806 --- /dev/null +++ b/tests/fixtures/cbxppath/err_path_is_file/not_a_dir.txt @@ -0,0 +1 @@ +not a directory diff --git a/tests/fixtures/cbxppath/err_protected_storage/case.conf b/tests/fixtures/cbxppath/err_protected_storage/case.conf new file mode 100644 index 0000000..77c31dd --- /dev/null +++ b/tests/fixtures/cbxppath/err_protected_storage/case.conf @@ -0,0 +1,7 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=7 +MESSAGE='Cannot reach control block' +COMMAND=extract +CBXPPATH='@CASE@/mappings' +BLOCK=mycb diff --git a/tests/fixtures/cbxppath/err_protected_storage/mappings/mycb.json b/tests/fixtures/cbxppath/err_protected_storage/mappings/mycb.json new file mode 100644 index 0000000..d04617c --- /dev/null +++ b/tests/fixtures/cbxppath/err_protected_storage/mappings/mycb.json @@ -0,0 +1,43 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [ + 239 + ], + "key": 1, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/err_repeated_bad_count/case.conf b/tests/fixtures/cbxppath/err_repeated_bad_count/case.conf new file mode 100644 index 0000000..9495a07 --- /dev/null +++ b/tests/fixtures/cbxppath/err_repeated_bad_count/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=10 +MESSAGE='Could not load a JSON file' +COMMAND=format +CBXPPATH='@CASE@/mappings' +BLOCK=mycb +SAMPLE=mycb.bin diff --git a/tests/fixtures/cbxppath/err_repeated_bad_count/mappings/mycb.json b/tests/fixtures/cbxppath/err_repeated_bad_count/mappings/mycb.json new file mode 100644 index 0000000..d632ea2 --- /dev/null +++ b/tests/fixtures/cbxppath/err_repeated_bad_count/mappings/mycb.json @@ -0,0 +1,49 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + }, + { + "name": "MYCBREP", + "offset": 8, + "length": 4, + "type": "unsigned-integer", + "repeated": true, + "count": "MYCBMISSING" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/err_schema_invalid/case.conf b/tests/fixtures/cbxppath/err_schema_invalid/case.conf new file mode 100644 index 0000000..d83cede --- /dev/null +++ b/tests/fixtures/cbxppath/err_schema_invalid/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=9 +MESSAGE='Could not validate a JSON file' +COMMAND=format +CBXPPATH='@CASE@/mappings' +BLOCK=mycb +SAMPLE=mycb.bin diff --git a/tests/fixtures/cbxppath/err_schema_invalid/mappings/invalid.json b/tests/fixtures/cbxppath/err_schema_invalid/mappings/invalid.json new file mode 100644 index 0000000..423ab7d --- /dev/null +++ b/tests/fixtures/cbxppath/err_schema_invalid/mappings/invalid.json @@ -0,0 +1 @@ +{"version": 1, "name": "mycb"} diff --git a/tests/fixtures/cbxppath/err_unknown_file_stem/case.conf b/tests/fixtures/cbxppath/err_unknown_file_stem/case.conf new file mode 100644 index 0000000..985aa83 --- /dev/null +++ b/tests/fixtures/cbxppath/err_unknown_file_stem/case.conf @@ -0,0 +1,8 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=err +CODE=1 +MESSAGE='Unknown control block: foo' +COMMAND=format +CBXPPATH='@CASE@/mappings' +BLOCK=foo +SAMPLE=mycb.bin diff --git a/tests/fixtures/cbxppath/err_unknown_file_stem/mappings/foo.json b/tests/fixtures/cbxppath/err_unknown_file_stem/mappings/foo.json new file mode 100644 index 0000000..0599c88 --- /dev/null +++ b/tests/fixtures/cbxppath/err_unknown_file_stem/mappings/foo.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/err_unreadable_parent_pointer/case.conf b/tests/fixtures/cbxppath/err_unreadable_parent_pointer/case.conf new file mode 100644 index 0000000..361b588 --- /dev/null +++ b/tests/fixtures/cbxppath/err_unreadable_parent_pointer/case.conf @@ -0,0 +1,11 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +# mycb has no parent, so its root is address 0 (the PSA) and its pointer to +# mychild sits at offset 2048, in the fetch-protected half of the PSA. +# Finding the root of mychild reads that pointer. The fault must be trapped +# and reported as unreachable instead of abending. +EXPECT=err +CODE=7 +MESSAGE='Cannot reach control block' +COMMAND=extract +CBXPPATH='@CASE@/mappings' +BLOCK=mychild diff --git a/tests/fixtures/cbxppath/err_unreadable_parent_pointer/mappings/mycb.json b/tests/fixtures/cbxppath/err_unreadable_parent_pointer/mappings/mycb.json new file mode 100644 index 0000000..0380db1 --- /dev/null +++ b/tests/fixtures/cbxppath/err_unreadable_parent_pointer/mappings/mycb.json @@ -0,0 +1,29 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBPTR", + "offset": 2048, + "length": 4, + "type": "address", + "pointsTo": "mychild" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/err_unreadable_parent_pointer/mappings/mychild.json b/tests/fixtures/cbxppath/err_unreadable_parent_pointer/mappings/mychild.json new file mode 100644 index 0000000..c7f887b --- /dev/null +++ b/tests/fixtures/cbxppath/err_unreadable_parent_pointer/mappings/mychild.json @@ -0,0 +1,30 @@ +{ + "version": 1, + "name": "mychild", + "commonName": "Test mychild", + "macroId": "mychild", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [ + "mycb" + ], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mychild", + "fields": [ + { + "name": "MYCHNUM", + "offset": 0, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_debug_unreadable_storage/case.conf b/tests/fixtures/cbxppath/ok_debug_unreadable_storage/case.conf new file mode 100644 index 0000000..15b83f1 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_debug_unreadable_storage/case.conf @@ -0,0 +1,13 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +# This psa mapping overrides the built-in one and is large enough that the +# debug hex dump (2060 bytes) reaches the fetch-protected half of the PSA at +# offset 2048. The dump must report unreadable storage instead of abending. +# The extract still succeeds because fields past the readable length are +# never read. +EXPECT=ok +COMMAND=extract +DEBUG=1 +CBXPPATH='@CASE@/mappings' +BLOCK=psa +CONTAINS='"psafld":' +LOG_CONTAINS='' diff --git a/tests/fixtures/cbxppath/ok_debug_unreadable_storage/mappings/psa.json b/tests/fixtures/cbxppath/ok_debug_unreadable_storage/mappings/psa.json new file mode 100644 index 0000000..baf9527 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_debug_unreadable_storage/mappings/psa.json @@ -0,0 +1,34 @@ +{ + "version": 1, + "name": "psa", + "commonName": "Test psa", + "macroId": "psa", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "psa", + "fields": [ + { + "name": "PSAFLD", + "offset": 0, + "length": 4, + "type": "unsigned-integer" + }, + { + "name": "PSAEND", + "offset": 4124, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_empty/case.conf b/tests/fixtures/cbxppath/ok_empty/case.conf new file mode 100644 index 0000000..0aeaf34 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_empty/case.conf @@ -0,0 +1,6 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='' +BLOCK=ascb +SAMPLE=ascb.bin +CONTAINS='"ascbasid"' diff --git a/tests/fixtures/cbxppath/ok_field_types/case.conf b/tests/fixtures/cbxppath/ok_field_types/case.conf new file mode 100644 index 0000000..a07c1e8 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_field_types/case.conf @@ -0,0 +1,6 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='@CASE@/mappings' +BLOCK=ftypes +SAMPLE=ftypes.bin +EXPECT_OUTPUT_FILE=expected.json diff --git a/tests/fixtures/cbxppath/ok_field_types/expected.json b/tests/fixtures/cbxppath/ok_field_types/expected.json new file mode 100644 index 0000000..7d7032c --- /dev/null +++ b/tests/fixtures/cbxppath/ok_field_types/expected.json @@ -0,0 +1 @@ +{"ftadr4":"0x00fe1000","ftbit4":"10000000000000000000000000000001","fthex4":"0xdeadbeef","fthex8":"0x0123456789abcdef","ftid":"FTYP","ftsi2":-2,"ftsi4":-3,"ftsi8":-4,"ftstr":"ABCD","ftui4":7,"ftui8":8} diff --git a/tests/fixtures/cbxppath/ok_field_types/mappings/ftypes.json b/tests/fixtures/cbxppath/ok_field_types/mappings/ftypes.json new file mode 100644 index 0000000..a5613f4 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_field_types/mappings/ftypes.json @@ -0,0 +1,95 @@ +{ + "version": 1, + "name": "ftypes", + "commonName": "Test ftypes", + "macroId": "ftypes", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "ftypes", + "fields": [ + { + "name": "FTID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "FTYP" + } + ], + "eyecatcher": true + }, + { + "name": "FTSTR", + "offset": 4, + "length": 4, + "type": "string" + }, + { + "name": "FTSI2", + "offset": 8, + "length": 2, + "type": "signed-integer" + }, + { + "name": "FTSI4", + "offset": 12, + "length": 4, + "type": "signed-integer" + }, + { + "name": "FTSI8", + "offset": 16, + "length": 8, + "type": "signed-integer" + }, + { + "name": "FTUI4", + "offset": 24, + "length": 4, + "type": "unsigned-integer" + }, + { + "name": "FTUI8", + "offset": 32, + "length": 8, + "type": "unsigned-integer" + }, + { + "name": "FTHEX4", + "offset": 40, + "length": 4, + "type": "hex" + }, + { + "name": "FTHEX8", + "offset": 48, + "length": 8, + "type": "hex" + }, + { + "name": "FTBIT4", + "offset": 56, + "length": 4, + "type": "bitstring" + }, + { + "name": "FTADR4", + "offset": 60, + "length": 4, + "type": "address" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_name_vs_stem/case.conf b/tests/fixtures/cbxppath/ok_name_vs_stem/case.conf new file mode 100644 index 0000000..3fff6c5 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_name_vs_stem/case.conf @@ -0,0 +1,6 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='@CASE@/mappings' +BLOCK=mycb +SAMPLE=mycb.bin +CONTAINS='"mycbnum":42' diff --git a/tests/fixtures/cbxppath/ok_name_vs_stem/mappings/foo.json b/tests/fixtures/cbxppath/ok_name_vs_stem/mappings/foo.json new file mode 100644 index 0000000..0599c88 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_name_vs_stem/mappings/foo.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_nested_path/a/b/mappings/mycb.json b/tests/fixtures/cbxppath/ok_nested_path/a/b/mappings/mycb.json new file mode 100644 index 0000000..0599c88 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_nested_path/a/b/mappings/mycb.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_nested_path/case.conf b/tests/fixtures/cbxppath/ok_nested_path/case.conf new file mode 100644 index 0000000..1c310e6 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_nested_path/case.conf @@ -0,0 +1,6 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='@CASE@/a/b/mappings' +BLOCK=mycb +SAMPLE=mycb.bin +CONTAINS='"mycbnum":42' diff --git a/tests/fixtures/cbxppath/ok_new_block/case.conf b/tests/fixtures/cbxppath/ok_new_block/case.conf new file mode 100644 index 0000000..3fff6c5 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_new_block/case.conf @@ -0,0 +1,6 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='@CASE@/mappings' +BLOCK=mycb +SAMPLE=mycb.bin +CONTAINS='"mycbnum":42' diff --git a/tests/fixtures/cbxppath/ok_new_block/mappings/mycb.json b/tests/fixtures/cbxppath/ok_new_block/mappings/mycb.json new file mode 100644 index 0000000..0599c88 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_new_block/mappings/mycb.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_override_cvt/case.conf b/tests/fixtures/cbxppath/ok_override_cvt/case.conf new file mode 100644 index 0000000..ecb9bd4 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_override_cvt/case.conf @@ -0,0 +1,7 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='@CASE@/mappings' +BLOCK=cvt +SAMPLE=cvt.bin +CONTAINS='"cvtonly":' +NOT_CONTAINS='"cvtasmvt"' diff --git a/tests/fixtures/cbxppath/ok_override_cvt/mappings/cvt.json b/tests/fixtures/cbxppath/ok_override_cvt/mappings/cvt.json new file mode 100644 index 0000000..eb320a5 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_override_cvt/mappings/cvt.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "cvt", + "commonName": "Test cvt", + "macroId": "cvt", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "cvt", + "fields": [ + { + "name": "CVTONLY", + "offset": 0, + "length": 4, + "type": "unsigned-integer" + }, + { + "name": "CVTCVT", + "offset": 96, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": " CVT" + } + ], + "eyecatcher": true + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_two_dirs/case.conf b/tests/fixtures/cbxppath/ok_two_dirs/case.conf new file mode 100644 index 0000000..710eedd --- /dev/null +++ b/tests/fixtures/cbxppath/ok_two_dirs/case.conf @@ -0,0 +1,6 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +CBXPPATH='@CASE@/one:@CASE@/two' +BLOCK=mycb2 +SAMPLE=mycb.bin +CONTAINS='"mycbnum":42' diff --git a/tests/fixtures/cbxppath/ok_two_dirs/one/mycb.json b/tests/fixtures/cbxppath/ok_two_dirs/one/mycb.json new file mode 100644 index 0000000..0599c88 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_two_dirs/one/mycb.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "mycb", + "commonName": "Test mycb", + "macroId": "mycb", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_two_dirs/two/mycb2.json b/tests/fixtures/cbxppath/ok_two_dirs/two/mycb2.json new file mode 100644 index 0000000..ad2bf04 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_two_dirs/two/mycb2.json @@ -0,0 +1,41 @@ +{ + "version": 1, + "name": "mycb2", + "commonName": "Test mycb2", + "macroId": "mycb2", + "description": "CBXPPATH test fixture", + "type": "control-block", + "aliases": [], + "pointedToBy": [], + "storageAttributes": { + "subpools": [], + "key": 0, + "residency": 31 + }, + "sections": [ + { + "name": "mycb2", + "fields": [ + { + "name": "MYCBID", + "offset": 0, + "length": 4, + "type": "string", + "init": [ + { + "type": "string", + "value": "MYCB" + } + ], + "eyecatcher": true + }, + { + "name": "MYCBNUM", + "offset": 4, + "length": 4, + "type": "unsigned-integer" + } + ] + } + ] +} diff --git a/tests/fixtures/cbxppath/ok_unset/case.conf b/tests/fixtures/cbxppath/ok_unset/case.conf new file mode 100644 index 0000000..935c676 --- /dev/null +++ b/tests/fixtures/cbxppath/ok_unset/case.conf @@ -0,0 +1,5 @@ +# CBXPPATH fixture. Values are shell-quoted; @CASE@ is the absolute fixture directory. +EXPECT=ok +BLOCK=ascb +SAMPLE=ascb.bin +CONTAINS='"ascbasid"' diff --git a/tests/run_fixture.cmake b/tests/run_fixture.cmake new file mode 100644 index 0000000..4aabdd5 --- /dev/null +++ b/tests/run_fixture.cmake @@ -0,0 +1,146 @@ +# ============================================================================= +# run_fixture.cmake +# Helper script to run a single CBXPPATH fixture and validate its behavior. +# Passed variables: +# EXE - Path to the cbxp executable +# FIXTURE_DIR - Absolute path to the fixture directory +# SAMPLES_DIR - Absolute path to the samples directory +# case.conf keys: EXPECT, COMMAND, BLOCK, SAMPLE, CBXPPATH, CONTAINS, +# NOT_CONTAINS, EXPECT_OUTPUT_FILE, CODE, MESSAGE, plus +# DEBUG (any value: run with debug logging on) and +# LOG_CONTAINS (string the debug log must contain; needs DEBUG). +# ============================================================================= + +if(NOT EXE OR NOT FIXTURE_DIR OR NOT SAMPLES_DIR) + message(FATAL_ERROR "Missing required variables: EXE, FIXTURE_DIR, or SAMPLES_DIR") +endif() + +# 1. Parse case.conf +if(NOT EXISTS "${FIXTURE_DIR}/case.conf") + message(FATAL_ERROR "case.conf does not exist in ${FIXTURE_DIR}") +endif() + +file(STRINGS "${FIXTURE_DIR}/case.conf" CONF_LINES) + +set(EXPECT "ok") +set(CBXPPATH "") +set(BLOCK "") +set(SAMPLE "") +set(COMMAND "format") +set(DEBUG "") +set(CONTAINS "") +set(NOT_CONTAINS "") +set(LOG_CONTAINS "") +set(EXPECT_OUTPUT_FILE "") +set(MESSAGE "") +set(CODE "") + +foreach(line IN LISTS CONF_LINES) + # Remove comments and strip leading/trailing whitespace + string(REGEX REPLACE "^[ \t]*#[^\n]*" "" line "${line}") + string(STRIP "${line}" line) + if(line STREQUAL "") + continue() + endif() + + # Match key=value + string(REGEX MATCH "^([^=]+)=(.*)$" MATCHED "${line}") + if(CMAKE_MATCH_1) + set(key "${CMAKE_MATCH_1}") + set(val "${CMAKE_MATCH_2}") + string(STRIP "${key}" key) + string(STRIP "${val}" val) + + # Strip single or double quotes + if((val MATCHES "^'.*'$") OR (val MATCHES "^\".*\"$")) + string(LENGTH "${val}" val_len) + math(EXPR val_len "${val_len} - 2") + if(val_len GREATER_EQUAL 0) + string(SUBSTRING "${val}" 1 ${val_len} val) + else() + set(val "") + endif() + endif() + + set(${key} "${val}") + endif() +endforeach() + +# 2. Prepare environment and command +if(NOT "${CBXPPATH}" STREQUAL "") + string(REPLACE "@CASE@" "${FIXTURE_DIR}" CBXPPATH "${CBXPPATH}") + set(ENV{CBXPPATH} "${CBXPPATH}") +else() + unset(ENV{CBXPPATH}) +endif() + +set(DEBUG_FLAG "") +if(NOT "${DEBUG}" STREQUAL "") + set(DEBUG_FLAG "-d") +endif() + +if("${COMMAND}" STREQUAL "extract") + set(CMD "${EXE}" extract ${DEBUG_FLAG} "${BLOCK}") +else() + set(CMD "${EXE}" format -F "${SAMPLES_DIR}/${SAMPLE}" ${DEBUG_FLAG} "${BLOCK}") +endif() + +# 3. Execute process +execute_process( + COMMAND ${CMD} + OUTPUT_VARIABLE STDOUT_VAR + ERROR_VARIABLE STDERR_VAR + RESULT_VARIABLE RESULT_VAR +) + +# 4. Perform validation +if("${EXPECT}" STREQUAL "ok") + if(NOT RESULT_VAR EQUAL 0) + message(FATAL_ERROR "Unexpected exit code: got ${RESULT_VAR}, expected 0\nStderr: ${STDERR_VAR}") + endif() + + if(NOT "${CONTAINS}" STREQUAL "") + string(FIND "${STDOUT_VAR}" "${CONTAINS}" FIND_POS) + if(FIND_POS EQUAL -1) + message(FATAL_ERROR "Output does not contain expected string: ${CONTAINS}\nStdout: ${STDOUT_VAR}") + endif() + endif() + + if(NOT "${NOT_CONTAINS}" STREQUAL "") + string(FIND "${STDOUT_VAR}" "${NOT_CONTAINS}" FIND_POS) + if(NOT FIND_POS EQUAL -1) + message(FATAL_ERROR "Output unexpectedly contains string: ${NOT_CONTAINS}\nStdout: ${STDOUT_VAR}") + endif() + endif() + + if(NOT "${LOG_CONTAINS}" STREQUAL "") + string(FIND "${STDOUT_VAR}" "${LOG_CONTAINS}" FIND_POS) + if(FIND_POS EQUAL -1) + message(FATAL_ERROR "Debug log does not contain expected string: ${LOG_CONTAINS}\nStdout: ${STDOUT_VAR}") + endif() + endif() + + if(NOT "${EXPECT_OUTPUT_FILE}" STREQUAL "") + file(READ "${FIXTURE_DIR}/${EXPECT_OUTPUT_FILE}" EXPECTED_CONTENT) + string(STRIP "${EXPECTED_CONTENT}" EXPECTED_CONTENT) + string(STRIP "${STDOUT_VAR}" ACTUAL_CONTENT) + + if(NOT ACTUAL_CONTENT STREQUAL EXPECTED_CONTENT) + message(FATAL_ERROR "Output does not match expected output file ${EXPECT_OUTPUT_FILE}\nExpected:\n${EXPECTED_CONTENT}\nGot:\n${ACTUAL_CONTENT}") + endif() + endif() +else() + # Expecting failure / error (exit code 255) + if(NOT RESULT_VAR EQUAL 255) + message(FATAL_ERROR "Unexpected exit code: got ${RESULT_VAR}, expected 255\nStdout: ${STDOUT_VAR}\nStderr: ${STDERR_VAR}") + endif() + + if(NOT "${MESSAGE}" STREQUAL "") + string(FIND "${STDERR_VAR}" "${MESSAGE}" FIND_POS) + if(FIND_POS EQUAL -1) + message(FATAL_ERROR "Error output does not contain expected message: ${MESSAGE}\nStderr: ${STDERR_VAR}") + endif() + endif() +endif() + +message(STATUS "Fixture behaved as expected.") diff --git a/tests/samples/ftypes.bin b/tests/samples/ftypes.bin new file mode 100644 index 0000000..b2a5abb Binary files /dev/null and b/tests/samples/ftypes.bin differ diff --git a/tests/samples/mycb.bin b/tests/samples/mycb.bin new file mode 100644 index 0000000..86a9263 Binary files /dev/null and b/tests/samples/mycb.bin differ diff --git a/tests/samples/oucb.bin b/tests/samples/oucb.bin index dfaefd7..15a969a 100644 Binary files a/tests/samples/oucb.bin and b/tests/samples/oucb.bin differ diff --git a/tests/samples/oucb_offset_0x03a8.bin b/tests/samples/oucb_offset_0x03a8.bin index fd9670c..73c46e5 100644 Binary files a/tests/samples/oucb_offset_0x03a8.bin and b/tests/samples/oucb_offset_0x03a8.bin differ diff --git a/tests/test.py b/tests/test.py index 08a776c..33a7d78 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1,11 +1,44 @@ +import json +import multiprocessing +import os +import shlex +import tempfile import unittest from pathlib import Path from cbxp import CBXPError, CBXPFilter, CBXPFilterOperation, cbxp +def _cbxppath_worker(queue, cbxppath, command, block, sample, debug, log_path): + # Runs in a spawned process because the control block mappings (including + # any found through CBXPPATH) are loaded once per process. Nothing has + # called cbxp yet in a spawned interpreter, so CBXPPATH is read fresh. + if cbxppath is None: + os.environ.pop("CBXPPATH", None) + else: + os.environ["CBXPPATH"] = cbxppath + + # The library logs through C++ std::cout, so redirect file descriptor 1 + # (sys.stdout redirection would not capture it). + log_fd = os.open(log_path, os.O_WRONLY | os.O_TRUNC) + os.dup2(log_fd, 1) + os.close(log_fd) + + try: + if command == "extract": + data = cbxp.extract(block, debug=debug) + else: + with open(sample, "rb") as sample_file: + data = cbxp.format(block, data=sample_file.read(), debug=debug) + queue.put({"ok": True, "data": data}) + except CBXPError as e: + queue.put({"ok": False, "rc": e.rc, "message": str(e)}) + + class TestCBXP(unittest.TestCase): - SAMPLE_DIR = Path(__file__).resolve().parent / "samples" + TEST_DIR = Path(__file__).resolve().parent + SAMPLE_DIR = TEST_DIR / "samples" + FIXTURE_DIR = TEST_DIR / "fixtures" / "cbxppath" # ============================================================================ # Utility Functions @@ -14,6 +47,13 @@ class TestCBXP(unittest.TestCase): def read_sample(filename: str) -> bytes: return (TestCBXP.SAMPLE_DIR / filename).read_bytes() + @staticmethod + def psa_data(length: int) -> bytes: + # Zeroed PSA buffer with the "PSA " eyecatcher (in EBCDIC) at offset 512 + data = bytearray(length) + data[512:516] = "PSA ".encode("cp037") + return bytes(data) + @staticmethod def get_cvtasmvt_values() -> tuple[int, str]: cbdata = cbxp.extract("cvt") @@ -87,15 +127,15 @@ def test_cbxp_extract_cvt_and_include_asvt(self): cbdata = cbxp.extract("cvt", includes=["asvt"]) self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["cvtasvt"]), dict) - self.assertIs(type(cbdata["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), str) def test_cbxp_extract_asvt_and_include_ascb(self): cbdata = cbxp.extract("asvt", includes=["ascb"]) self.assertIs(type(cbdata), dict) - self.assertIs(type(cbdata["asvtenty"]), list) - for entry in cbdata["asvtenty"]: + self.assertIs(type(cbdata["asvtentys"]), list) + for entry in cbdata["asvtentys"]: self.assertIs(type(entry), dict) def test_cbxp_extract_ascb_and_include_assb(self): @@ -115,8 +155,8 @@ def test_cbxp_extract_ascb_and_include_oucb(self): def test_cbxp_extract_asvt_and_include_ascb_assb_ldax(self): cbdata = cbxp.extract("asvt", includes=["ascb.assb.ldax"]) self.assertIs(type(cbdata), dict) - self.assertIs(type(cbdata["asvtenty"]), list) - for entry in cbdata["asvtenty"]: + self.assertIs(type(cbdata["asvtentys"]), list) + for entry in cbdata["asvtentys"]: self.assertIs(type(entry), dict) self.assertIs(type(entry["ascbassb"]), dict) self.assertIs(type(entry["ascbassb"]["assbldax"]), dict) @@ -126,8 +166,8 @@ def test_cbxp_extract_psa_and_include_cvt_asvt_ascb_assb_ldax(self): self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) self.assertIs(type(entry["ascbassb"]), dict) self.assertIs(type(entry["ascbassb"]["assbldax"]), dict) @@ -158,16 +198,16 @@ def test_cbxp_extract_psa_and_include_cvt_ecvt_ascb(self): self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) def test_cbxp_extract_cvt_and_include_asvt_ascb(self): cbdata = cbxp.extract("cvt", includes=["asvt.ascb"]) self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["cvtasvt"]), dict) - self.assertIs(type(cbdata["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) def test_cbxp_extract_cvt_and_include_ecvt_and_asvt(self): @@ -175,8 +215,8 @@ def test_cbxp_extract_cvt_and_include_ecvt_and_asvt(self): self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["cvtecvt"]), dict) self.assertIs(type(cbdata["cvtasvt"]), dict) - self.assertIs(type(cbdata["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), str) def test_cbxp_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb( @@ -187,8 +227,8 @@ def test_cbxp_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb( self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtecvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) def test_cbxp_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb_assb( @@ -199,8 +239,8 @@ def test_cbxp_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb_assb( self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtecvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) self.assertIs(type(entry["ascbassb"]), dict) @@ -212,8 +252,8 @@ def test_cbxp_extract_psa_and_include_ecvt_asvt_and_cvt_asvt_ascb_oucb( self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtecvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) self.assertIs(type(entry["ascboucb"]), dict) @@ -223,12 +263,14 @@ def test_cbxp_extract_psa_and_include_cvt_recursive_wildcard(self): self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtecvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) self.assertIs(type(entry["ascbassb"]), dict) self.assertIs(type(entry["ascbassb"]["assbldax"]), dict) - self.assertIs(type(entry["ascboucb"]), dict) + # Under ** traversal, ascboucb may be a raw pointer hex string if its + # target oucb was mid-visit when this ascb's ascboucb field was reached. + self.assertIn(type(entry["ascboucb"]), (dict, str)) def test_cbxp_extract_psa_and_include_cvt_wildcard(self): cbdata = cbxp.extract("psa", includes=["cvt.*"]) @@ -236,8 +278,8 @@ def test_cbxp_extract_psa_and_include_cvt_wildcard(self): self.assertIs(type(cbdata["flccvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtecvt"]), dict) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), str) def test_cbxp_extract_cvt_and_include_wildcard_and_asvt_wildcard(self): @@ -245,8 +287,8 @@ def test_cbxp_extract_cvt_and_include_wildcard_and_asvt_wildcard(self): self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["cvtecvt"]), dict) self.assertIs(type(cbdata["cvtasvt"]), dict) - self.assertIs(type(cbdata["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) def test_cbxp_extract_cvt_and_include_wildcard_and_asvt_recursive_wildcard( @@ -256,11 +298,13 @@ def test_cbxp_extract_cvt_and_include_wildcard_and_asvt_recursive_wildcard( self.assertIs(type(cbdata), dict) self.assertIs(type(cbdata["cvtecvt"]), dict) self.assertIs(type(cbdata["cvtasvt"]), dict) - self.assertIs(type(cbdata["cvtasvt"]["asvtenty"]), list) - for entry in cbdata["cvtasvt"]["asvtenty"]: + self.assertIs(type(cbdata["cvtasvt"]["asvtentys"]), list) + for entry in cbdata["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) self.assertIs(type(entry["ascbassb"]), dict) - self.assertIs(type(entry["ascboucb"]), dict) + # Under ** traversal, ascboucb may be a raw pointer hex string if its + # target oucb was mid-visit when this ascb's ascboucb field was reached. + self.assertIn(type(entry["ascboucb"]), (dict, str)) def test_cbxp_extract_ascb_and_include_assb_recursive_wildcard(self): cbdata = cbxp.extract("ascb", includes=["assb.**"]) @@ -583,18 +627,19 @@ def test_cbxp_extract_filter_on_psa_cvt_asvt_ascb_assb_ldax_tcthwm_with_include( self.assertIs(type(cbdata["flccvt"]), dict) self.assertIn("cvtasvt", cbdata["flccvt"]) self.assertIs(type(cbdata["flccvt"]["cvtasvt"]), dict) - self.assertIn("asvtenty", cbdata["flccvt"]["cvtasvt"]) - self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), list) + self.assertIn("asvtentys", cbdata["flccvt"]["cvtasvt"]) + self.assertIs(type(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), list) # Verify at least one entry matches the filter - self.assertGreater(len(cbdata["flccvt"]["cvtasvt"]["asvtenty"]), 0) - for entry in cbdata["flccvt"]["cvtasvt"]["asvtenty"]: + self.assertGreater(len(cbdata["flccvt"]["cvtasvt"]["asvtentys"]), 0) + for entry in cbdata["flccvt"]["cvtasvt"]["asvtentys"]: self.assertIs(type(entry), dict) self.assertIn("ascbassb", entry) self.assertIs(type(entry["ascbassb"]), dict) self.assertIn("assbldax", entry["ascbassb"]) self.assertIs(type(entry["ascbassb"]["assbldax"]), dict) self.assertEqual( - entry["ascbassb"]["assbldax"]["ldax_tcthwm"], 0, + entry["ascbassb"]["assbldax"]["ldax_tcthwm"], + 0, ) def test_cbxp_extract_null_filter_string( @@ -656,12 +701,12 @@ def test_cbxp_extract_raises_cbxp_error_if_cvt_ascb_is_included_with_the_psa( cbxp.extract("psa", includes=["cvt.ecvt", "cvt.ascb"]) self.assertEqual("A bad include pattern was provided", str(e.exception)) - def test_cbxp_extract_raises_cbxp_error_if_ecvt_is_included_with_the_psa( + def test_cbxp_extract_raises_cbxp_error_if_oucb_is_included_with_the_psa( self, ): # cvt.asvt.ascb is also included but is not error source with self.assertRaises(CBXPError) as e: - cbxp.extract("psa", includes=["ecvt", "cvt.asvt.ascb"]) + cbxp.extract("psa", includes=["oucb", "cvt.asvt.ascb"]) self.assertEqual("A bad include pattern was provided", str(e.exception)) def test_cbxp_extract_raises_cbxp_error_if_cvt_is_included_with_the_cvt(self): @@ -779,6 +824,7 @@ def test_cbxp_extract_raises_cbxp_error_if_ldax_included_with_ascb(self): with self.assertRaises(CBXPError) as e: cbxp.extract("ascb", includes=["ldax"]) self.assertEqual("A bad include pattern was provided", str(e.exception)) + # ============================================================================ # Format -- Basic Usage # ============================================================================ @@ -835,6 +881,228 @@ def test_cbxp_format_raises_cbxp_error_if_data_is_too_small(self): str(e.exception), ) + # ============================================================================ + # Extract -- Output Shape + # ============================================================================ + def test_cbxp_extract_repeated_field_is_a_list_named_with_a_trailing_s(self): + cbdata = cbxp.extract("asvt") + self.assertIs(type(cbdata["asvtentys"]), list) + self.assertNotIn("asvtenty", cbdata) + for entry in cbdata["asvtentys"]: + self.assertIs(type(entry), str) + + def test_cbxp_extract_pointer_field_that_is_not_included_is_a_hex_string(self): + cbdata = cbxp.extract("cvt") + self.assertIs(type(cbdata["cvtasvt"]), str) + self.assertTrue(cbdata["cvtasvt"].startswith("0x")) + self.assertNotIn("cvtasvt_ptr", cbdata) + + def test_cbxp_extract_included_pointer_field_keeps_the_raw_pointer_as_ptr_key( + self, + ): + raw_pointer = cbxp.extract("cvt")["cvtasvt"] + cbdata = cbxp.extract("cvt", includes=["asvt"]) + self.assertIs(type(cbdata["cvtasvt"]), dict) + self.assertEqual(raw_pointer, cbdata["cvtasvt_ptr"]) + + # ============================================================================ + # Extract -- Traversal + # ============================================================================ + def test_cbxp_extract_oucb_and_include_recursive_wildcard_terminates(self): + cbdata = cbxp.extract("oucb", includes=["**"]) + self.assertIs(type(cbdata), list) + for entry in cbdata: + self.assertIs(type(entry), dict) + + def test_cbxp_extract_psa_and_include_recursive_wildcard_terminates(self): + cbdata = cbxp.extract("psa", includes=["**"]) + self.assertIs(type(cbdata), dict) + self.assertIs(type(cbdata["flccvt"]), dict) + + # ============================================================================ + # Extract -- Filters on Included Control Blocks + # ============================================================================ + def test_cbxp_extract_filter_on_included_pointer_field_matches_raw_pointer( + self, + ): + raw_pointer = cbxp.extract("cvt")["cvtasvt"] + cbdata = cbxp.extract( + "cvt", + includes=["asvt"], + filters=[CBXPFilter("cvtasvt", CBXPFilterOperation.EQUAL, raw_pointer)], + ) + self.assertIs(type(cbdata), dict) + self.assertIs(type(cbdata["cvtasvt"]), dict) + + def test_cbxp_extract_filter_on_included_pointer_field_without_match_is_none( + self, + ): + cbdata = cbxp.extract( + "cvt", + includes=["asvt"], + filters=[CBXPFilter("cvtasvt", CBXPFilterOperation.EQUAL, "0x00000001")], + ) + self.assertIsNone(cbdata) + + def test_cbxp_extract_child_filter_only_drops_the_non_matching_entries(self): + cbdata = cbxp.extract( + "asvt", + includes=["ascb"], + filters=[CBXPFilter("ascb.ascbasid", CBXPFilterOperation.EQUAL, 1)], + ) + self.assertIs(type(cbdata["asvtentys"]), list) + self.assertGreater(len(cbdata["asvtentys"]), 0) + for entry in cbdata["asvtentys"]: + self.assertEqual(entry["ascbasid"], 1) + + def test_cbxp_extract_child_filter_matching_no_entries_rejects_the_parent(self): + cbdata = cbxp.extract( + "asvt", + includes=["ascb"], + filters=[CBXPFilter("ascb.ascbasid", CBXPFilterOperation.EQUAL, 65000)], + ) + self.assertIsNone(cbdata) + + # ============================================================================ + # Format -- Eyecatcher + # ============================================================================ + def test_cbxp_format_returns_none_if_the_eyecatcher_does_not_match(self): + data = self.read_sample("ascb.bin") + cbdata = cbxp.format("ascb", data=b"\x00" * 4 + data[4:]) + self.assertIsNone(cbdata) + + def test_cbxp_format_ignores_trailing_spaces_in_the_expected_eyecatcher(self): + # The PSA eyecatcher is "PSA " and the formatted value has the trailing + # space trimmed. + cbdata = cbxp.format("psa", data=self.psa_data(self.PSA_READABLE_LENGTH)) + self.assertEqual("PSA", cbdata["psapsa"]) + + # ============================================================================ + # Format -- Buffer Length + # ============================================================================ + # The back half of the PSA is fetch protected, so only (4096 - 8) / 2 bytes + # of it are required. + PSA_READABLE_LENGTH = 2044 + + def test_cbxp_format_psa_succeeds_with_exactly_the_readable_length(self): + cbdata = cbxp.format("psa", data=self.psa_data(self.PSA_READABLE_LENGTH)) + self.assertIs(type(cbdata), dict) + + def test_cbxp_format_psa_raises_cbxp_error_one_byte_below_the_readable_length( + self, + ): + with self.assertRaises(CBXPError) as e: + cbxp.format("psa", data=bytes(self.PSA_READABLE_LENGTH - 1)) + self.assertEqual( + "Data provided is not large enough for specified control block: psa", + str(e.exception), + ) + + # ============================================================================ + # Error Codes + # ============================================================================ + def test_cbxp_error_messages_for_codes_5_through_9(self): + expected_messages = { + 5: "A null data pointer was provided", + 6: "Error with your CBXPPATH environment variable", + 7: "Cannot reach control block", + 8: "Could not parse a JSON file", + 9: "Could not validate a JSON file", + 10: "Could not load a JSON file", + } + for return_code, message in expected_messages.items(): + with self.subTest(return_code=return_code): + error = CBXPError(return_code, "psa") + self.assertEqual(return_code, error.rc) + self.assertEqual(message, str(error)) + + def test_cbxp_error_message_for_an_undefined_code_is_generic(self): + self.assertEqual( + "An unknown error occurred", + str(CBXPError(99, "psa")), + ) + + # ============================================================================ + # CBXPPATH Fixtures (shared with CMakeLists.txt) + # ============================================================================ + @staticmethod + def load_fixture_conf(fixture_dir: Path) -> dict[str, str]: + conf = {} + for line in (fixture_dir / "case.conf").read_text().splitlines(): + if not line.strip() or line.startswith("#"): + continue + key, _, value = shlex.split(line)[0].partition("=") + conf[key] = value + return conf + + def run_cbxppath_fixture(self, fixture_dir: Path): + conf = self.load_fixture_conf(fixture_dir) + cbxppath = conf.get("CBXPPATH") + if cbxppath is not None: + cbxppath = cbxppath.replace("@CASE@", str(fixture_dir)) + + ctx = multiprocessing.get_context("spawn") + queue = ctx.Queue() + with tempfile.NamedTemporaryFile(suffix=".log") as log_file: + process = ctx.Process( + target=_cbxppath_worker, + args=( + queue, + cbxppath, + conf.get("COMMAND", "format"), + conf["BLOCK"], + str(self.SAMPLE_DIR / conf.get("SAMPLE", "")), + "DEBUG" in conf, + log_file.name, + ), + ) + process.start() + try: + # Read the result before join() so a full pipe cannot deadlock. + response = queue.get(timeout=60) + except Exception: + process.kill() + self.fail("Worker produced no result (crash or timeout)") + finally: + process.join() + self.assertEqual(0, process.exitcode) + log_output = Path(log_file.name).read_text() + + if conf["EXPECT"] == "ok": + self.assertTrue(response["ok"], response) + if "LOG_CONTAINS" in conf: + self.assertIn(conf["LOG_CONTAINS"], log_output) + output = json.dumps(response["data"], sort_keys=True, separators=(",", ":")) + if "CONTAINS" in conf: + self.assertIn(conf["CONTAINS"], output) + if "NOT_CONTAINS" in conf: + self.assertNotIn(conf["NOT_CONTAINS"], output) + if "EXPECT_OUTPUT_FILE" in conf: + expected = json.loads( + (fixture_dir / conf["EXPECT_OUTPUT_FILE"]).read_text(), + ) + self.assertEqual(expected, response["data"]) + else: + self.assertFalse(response["ok"], response) + self.assertEqual(int(conf["CODE"]), response["rc"]) + self.assertEqual(conf["MESSAGE"], response["message"]) + + +def _make_cbxppath_fixture_test(fixture_dir: Path): + def test(self): + self.run_cbxppath_fixture(fixture_dir) + + return test + + +for _fixture_dir in sorted(TestCBXP.FIXTURE_DIR.iterdir()): + if _fixture_dir.is_dir(): + setattr( + TestCBXP, + f"test_cbxppath_fixture_{_fixture_dir.name}", + _make_cbxppath_fixture_test(_fixture_dir), + ) + if __name__ == "__main__": unittest.main(verbosity=2, failfast=True, buffer=True)