From 631482e4f556e51bcac2ea6b9bbc38bc9fdc43f2 Mon Sep 17 00:00:00 2001 From: Dr-Carlos Date: Sat, 16 Apr 2022 08:43:54 +0930 Subject: [PATCH 1/6] _isc: add vspace as an option and fix it --- shell/i.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/shell/i.cpp b/shell/i.cpp index aff5642..6c04ecc 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -140,16 +140,14 @@ struct _isc_args static struct _isc_args parse_isc(Session &, Parser &parser) { - struct _isc_args args - { - }; + _isc_args args; parser.option("sort", [&args](std::string const &value) { args.sort = (value == "true"); }); + parser.option("vspace", + [&args](std::string const &value) { args.vspace_name = value; }); parser.accept_options(); - args.vspace_name = parser.at_end() ? "" : parser.symbol("vspace_name"); - parser.accept_options(); parser.end(); return args; @@ -169,16 +167,18 @@ bool operator<(const SyscallInfo &left, const SyscallInfo &right) void _isc(Session &session, std::string vspace_name, bool sort) { VirtualSpace *space = session.current_space; - if(vspace_name != "") + if(!vspace_name.empty()) space = session.get_space(vspace_name); - if(!space) - return; - // TODO: is doesn't work + if(!space) + throw CommandError("virtual space '{}' does not exist", vspace_name); OS *os = space->os_analysis(); - if(!os) - throw CommandError("os analysis on '{}' failed", vspace_name); + if(!os) { + if (!vspace_name.empty()) + throw CommandError("OS analysis on '{}' failed", vspace_name); + throw CommandError("OS analysis failed"); + } int total = os->syscall_count(); auto info = std::make_unique(total); @@ -257,7 +257,7 @@ static ShellCommand _isc_cmd( _isc(s, args.vspace_name, args.sort); }, [](Session &s, Parser &p) { parse_isc(s, p); }, "Info Syscalls", R"( -isc [sort=true] [] +isc [sort=true] [vspace=] Prints the syscall table for the specified virtual space (defaults to the current one). By default, syscalls are enumerated by syscall number. If From 86300fc1c7313ceeca96bf2d6d6b94548bd07b5d Mon Sep 17 00:00:00 2001 From: Dr-Carlos Date: Sun, 17 Apr 2022 12:58:52 +0930 Subject: [PATCH 2/6] _isc: add positional arg to specify printed info --- shell/i.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/shell/i.cpp b/shell/i.cpp index 6c04ecc..f97af63 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -135,10 +135,11 @@ void _io(Session &session, std::string name) struct _isc_args { std::string vspace_name; - bool sort; + bool sort = false; + std::vector addresses; }; -static struct _isc_args parse_isc(Session &, Parser &parser) +static struct _isc_args parse_isc(Session &session, Parser &parser) { _isc_args args; @@ -149,6 +150,9 @@ static struct _isc_args parse_isc(Session &, Parser &parser) parser.accept_options(); + while(!parser.at_end()) + args.addresses.push_back(parser.expr(session.current_space)); + parser.end(); return args; } @@ -164,7 +168,8 @@ bool operator<(const SyscallInfo &left, const SyscallInfo &right) return (left.address < right.address) || (left.id < right.id); } -void _isc(Session &session, std::string vspace_name, bool sort) +void _isc(Session &session, std::string vspace_name, bool sort, + std::vector addresses) { VirtualSpace *space = session.current_space; if(!vspace_name.empty()) @@ -175,7 +180,7 @@ void _isc(Session &session, std::string vspace_name, bool sort) OS *os = space->os_analysis(); if(!os) { - if (!vspace_name.empty()) + if(!vspace_name.empty()) throw CommandError("OS analysis on '{}' failed", vspace_name); throw CommandError("OS analysis failed"); } @@ -183,9 +188,19 @@ void _isc(Session &session, std::string vspace_name, bool sort) int total = os->syscall_count(); auto info = std::make_unique(total); - for(int i = 0; i < total; i++) { + for(int i = 0; i < total; i++) info[i] = (SyscallInfo) {.address = os->syscall(i), .id = i}; - } + + if(!addresses.empty()) + std::remove_if(&info[0], &info[total], + [addresses, &total](const SyscallInfo &item) { + if(std::find(addresses.begin(), addresses.end(), item.address) + == addresses.end()) { + total--; + return true; + } + return false; + }); if(sort) std::sort(&info[0], &info[total]); @@ -254,10 +269,10 @@ static ShellCommand _isc_cmd( "isc", [](Session &s, Parser &p) { auto args = parse_isc(s, p); - _isc(s, args.vspace_name, args.sort); + _isc(s, args.vspace_name, args.sort, args.addresses); }, [](Session &s, Parser &p) { parse_isc(s, p); }, "Info Syscalls", R"( -isc [sort=true] [vspace=] +isc [sort=true] [vspace=] [
...] Prints the syscall table for the specified virtual space (defaults to the current one). By default, syscalls are enumerated by syscall number. If From e037d5889c6e0836d5bdc7d9c6f232a8a4eaf69a Mon Sep 17 00:00:00 2001 From: Dr-Carlos Date: Mon, 18 Apr 2022 07:32:50 +0930 Subject: [PATCH 3/6] _isc: print instead of throwing error --- shell/i.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shell/i.cpp b/shell/i.cpp index f97af63..4355157 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -6,6 +6,7 @@ #include #include +#include //--- // ic @@ -175,14 +176,17 @@ void _isc(Session &session, std::string vspace_name, bool sort, if(!vspace_name.empty()) space = session.get_space(vspace_name); - if(!space) - throw CommandError("virtual space '{}' does not exist", vspace_name); + if(!space) { + FxOS_log(ERR, "virtual space '%s' does not exist", vspace_name); + return; + } OS *os = space->os_analysis(); if(!os) { if(!vspace_name.empty()) - throw CommandError("OS analysis on '{}' failed", vspace_name); - throw CommandError("OS analysis failed"); + FxOS_log(ERR, "OS analysis on '%s' failed", vspace_name); + FxOS_log(ERR, "OS analysis failed"); + return; } int total = os->syscall_count(); From 08c000539c3062f194aeb7a3d1136b733e8f0194 Mon Sep 17 00:00:00 2001 From: Dr-Carlos Date: Tue, 19 Apr 2022 07:32:09 +0930 Subject: [PATCH 4/6] _isc: use os->syscall_at instead of remove_if --- shell/i.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/shell/i.cpp b/shell/i.cpp index 4355157..a17412d 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -189,23 +189,26 @@ void _isc(Session &session, std::string vspace_name, bool sort, return; } + if(!addresses.empty()) { + for(uint32_t address: addresses) { + int syscall = os->find_syscall(address); + if(syscall == -1) + continue; + + fmt::print(theme(3), " 0x{:08x}", address); + fmt::print(theme(10), " %{:01x}", syscall); + fmt::print("\n"); + } + + return; + } + int total = os->syscall_count(); auto info = std::make_unique(total); for(int i = 0; i < total; i++) info[i] = (SyscallInfo) {.address = os->syscall(i), .id = i}; - if(!addresses.empty()) - std::remove_if(&info[0], &info[total], - [addresses, &total](const SyscallInfo &item) { - if(std::find(addresses.begin(), addresses.end(), item.address) - == addresses.end()) { - total--; - return true; - } - return false; - }); - if(sort) std::sort(&info[0], &info[total]); From 771b12eab84dc1b43c67672c7b7e5bd3c88cc6ab Mon Sep 17 00:00:00 2001 From: Dr-Carlos Date: Tue, 19 Apr 2022 21:21:21 +0930 Subject: [PATCH 5/6] _isc: resolve vspace when parsing and misc fixes --- shell/i.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/shell/i.cpp b/shell/i.cpp index a17412d..0d53f73 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -151,8 +151,21 @@ static struct _isc_args parse_isc(Session &session, Parser &parser) parser.accept_options(); + VirtualSpace *space = session.current_space; + if(!args.vspace_name.empty()) { + space = session.get_space(args.vspace_name); + if(!space) { + std::string msg + = format("virtual space '%s' does not exist", args.vspace_name); + if(parser.completing()) + throw Parser::CompletionRequest("_error", msg); + else + FxOS_log(ERR, "%s", msg); + } + } + while(!parser.at_end()) - args.addresses.push_back(parser.expr(session.current_space)); + args.addresses.push_back(parser.expr(space)); parser.end(); return args; @@ -173,6 +186,11 @@ void _isc(Session &session, std::string vspace_name, bool sort, std::vector addresses) { VirtualSpace *space = session.current_space; + if(!space) { + FxOS_log(ERR, "no virtual space selected"); + return; + } + if(!vspace_name.empty()) space = session.get_space(vspace_name); @@ -185,7 +203,8 @@ void _isc(Session &session, std::string vspace_name, bool sort, if(!os) { if(!vspace_name.empty()) FxOS_log(ERR, "OS analysis on '%s' failed", vspace_name); - FxOS_log(ERR, "OS analysis failed"); + else + FxOS_log(ERR, "OS analysis failed"); return; } From 3308f72773f6358bf97024e79581eb06de0421a1 Mon Sep 17 00:00:00 2001 From: Dr-Carlos Date: Tue, 19 Apr 2022 21:51:27 +0930 Subject: [PATCH 6/6] _isc: sort specific addresses if required --- shell/i.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/i.cpp b/shell/i.cpp index 0d53f73..28954de 100644 --- a/shell/i.cpp +++ b/shell/i.cpp @@ -209,6 +209,9 @@ void _isc(Session &session, std::string vspace_name, bool sort, } if(!addresses.empty()) { + if(sort) + std::sort(&addresses[0], &addresses[addresses.size()]); + for(uint32_t address: addresses) { int syscall = os->find_syscall(address); if(syscall == -1)