mirror of
https://github.com/zeek/zeek.git
synced 2025-10-06 16:48:19 +00:00
Improve how primary/top-level BIFs get initialized
This commit is contained in:
parent
1bbae2368d
commit
4a8640d702
6 changed files with 67 additions and 52 deletions
59
src/Func.cc
59
src/Func.cc
|
@ -902,6 +902,37 @@ void emit_builtin_exception(const char* msg, Obj* arg)
|
|||
emit_builtin_error_common(msg, arg, true);
|
||||
}
|
||||
|
||||
void init_primary_bifs()
|
||||
{
|
||||
if ( did_builtin_init )
|
||||
return;
|
||||
|
||||
ProcStats = id::find_type<RecordType>("ProcStats");
|
||||
NetStats = id::find_type<RecordType>("NetStats");
|
||||
MatcherStats = id::find_type<RecordType>("MatcherStats");
|
||||
ConnStats = id::find_type<RecordType>("ConnStats");
|
||||
ReassemblerStats = id::find_type<RecordType>("ReassemblerStats");
|
||||
DNSStats = id::find_type<RecordType>("DNSStats");
|
||||
GapStats = id::find_type<RecordType>("GapStats");
|
||||
EventStats = id::find_type<RecordType>("EventStats");
|
||||
TimerStats = id::find_type<RecordType>("TimerStats");
|
||||
FileAnalysisStats = id::find_type<RecordType>("FileAnalysisStats");
|
||||
ThreadStats = id::find_type<RecordType>("ThreadStats");
|
||||
BrokerStats = id::find_type<RecordType>("BrokerStats");
|
||||
ReporterStats = id::find_type<RecordType>("ReporterStats");
|
||||
|
||||
var_sizes = id::find_type("var_sizes")->AsTableType();
|
||||
|
||||
#include "zeek.bif.func_init"
|
||||
#include "stats.bif.func_init"
|
||||
#include "reporter.bif.func_init"
|
||||
#include "strings.bif.func_init"
|
||||
#include "option.bif.func_init"
|
||||
#include "supervisor.bif.func_init"
|
||||
|
||||
did_builtin_init = true;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
|
@ -936,31 +967,3 @@ void builtin_error(const char* msg, zeek::Obj* arg)
|
|||
{
|
||||
zeek::emit_builtin_error(msg, arg);
|
||||
}
|
||||
|
||||
void init_builtin_funcs()
|
||||
{
|
||||
ProcStats = zeek::id::find_type<zeek::RecordType>("ProcStats");
|
||||
NetStats = zeek::id::find_type<zeek::RecordType>("NetStats");
|
||||
MatcherStats = zeek::id::find_type<zeek::RecordType>("MatcherStats");
|
||||
ConnStats = zeek::id::find_type<zeek::RecordType>("ConnStats");
|
||||
ReassemblerStats = zeek::id::find_type<zeek::RecordType>("ReassemblerStats");
|
||||
DNSStats = zeek::id::find_type<zeek::RecordType>("DNSStats");
|
||||
GapStats = zeek::id::find_type<zeek::RecordType>("GapStats");
|
||||
EventStats = zeek::id::find_type<zeek::RecordType>("EventStats");
|
||||
TimerStats = zeek::id::find_type<zeek::RecordType>("TimerStats");
|
||||
FileAnalysisStats = zeek::id::find_type<zeek::RecordType>("FileAnalysisStats");
|
||||
ThreadStats = zeek::id::find_type<zeek::RecordType>("ThreadStats");
|
||||
BrokerStats = zeek::id::find_type<zeek::RecordType>("BrokerStats");
|
||||
ReporterStats = zeek::id::find_type<zeek::RecordType>("ReporterStats");
|
||||
|
||||
var_sizes = zeek::id::find_type("var_sizes")->AsTableType();
|
||||
|
||||
#include "zeek.bif.func_init"
|
||||
#include "stats.bif.func_init"
|
||||
#include "reporter.bif.func_init"
|
||||
#include "strings.bif.func_init"
|
||||
#include "option.bif.func_init"
|
||||
#include "supervisor.bif.func_init"
|
||||
|
||||
zeek::detail::did_builtin_init = true;
|
||||
}
|
||||
|
|
|
@ -277,6 +277,7 @@ extern std::vector<CallInfo> call_stack;
|
|||
// This is set to true after the built-in functions have been initialized.
|
||||
extern bool did_builtin_init;
|
||||
extern std::vector<void (*)()> bif_initializers;
|
||||
extern void init_primary_bifs();
|
||||
|
||||
inline void run_bif_initializers()
|
||||
{
|
||||
|
@ -310,11 +311,6 @@ using function_ingredients [[deprecated("Remove in v4.1. Use zeek::detail::funct
|
|||
constexpr auto check_built_in_call [[deprecated("Remove in v4.1. Use zeek::detail::check_built_in_call.")]] = zeek::detail::check_built_in_call;
|
||||
constexpr auto render_call_stack [[deprecated("Remove in v4.1. Use zeek::render_call_stack.")]] = zeek::render_call_stack;
|
||||
|
||||
// TODO: these are still here because of how all of the bif code gets included in Func.c. There could be a
|
||||
// renamed version inside the namespace, but the way that the code gets included complicates the matter. It
|
||||
// might need to be revisited after everything is namespaced everywhere else.
|
||||
void init_builtin_funcs();
|
||||
|
||||
// TODO: do call_stack and did_builtin_init need to be aliased?
|
||||
|
||||
// These have to be implemented as actual methods due to function overloading breaking the use of aliases.
|
||||
|
|
10
src/scan.l
10
src/scan.l
|
@ -842,16 +842,6 @@ int yywrap()
|
|||
if ( zeek::reporter->Errors() > 0 )
|
||||
return 1;
|
||||
|
||||
if ( ! did_builtin_init && file_stack.length() == 1 )
|
||||
{
|
||||
// ### This is a gross hack - we know that the first file
|
||||
// we parse is init-bare.zeek, and after it it's safe to initialize
|
||||
// the built-ins. Furthermore, we want to initialize the
|
||||
// built-in's *right* after parsing bro.init, so that other
|
||||
// source files can use built-in's when initializing globals.
|
||||
init_builtin_funcs();
|
||||
}
|
||||
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
|
||||
if ( file_stack.length() > 0 )
|
||||
|
|
|
@ -62,6 +62,7 @@ extern "C" {
|
|||
#include "broker/Manager.h"
|
||||
|
||||
#include "binpac_zeek.h"
|
||||
#include "module_util.h"
|
||||
|
||||
#include "3rdparty/sqlite3.h"
|
||||
|
||||
|
@ -388,8 +389,7 @@ static std::vector<std::string> get_script_signature_files()
|
|||
return rval;
|
||||
}
|
||||
|
||||
SetupResult setup(int argc, char** argv,
|
||||
Options* zopts)
|
||||
SetupResult setup(int argc, char** argv, Options* zopts)
|
||||
{
|
||||
ZEEK_LSAN_DISABLE();
|
||||
std::set_new_handler(bro_new_handler);
|
||||
|
@ -628,6 +628,19 @@ SetupResult setup(int argc, char** argv,
|
|||
HeapLeakChecker::Disabler disabler;
|
||||
#endif
|
||||
|
||||
auto ipbid = install_ID("__init_primary_bifs", GLOBAL_MODULE_NAME,
|
||||
true, true);
|
||||
auto ipbft = make_intrusive<FuncType>(make_intrusive<RecordType>(nullptr),
|
||||
base_type(TYPE_BOOL),
|
||||
FUNC_FLAVOR_FUNCTION);
|
||||
ipbid->SetType(std::move(ipbft));
|
||||
auto init_bifs = [](Frame* frame, const Args* args) -> BifReturnVal
|
||||
{
|
||||
init_primary_bifs();
|
||||
return val_mgr->True();
|
||||
};
|
||||
auto ipbb = make_intrusive<BuiltinFunc>(init_bifs, ipbid->Name(), false);
|
||||
|
||||
run_state::is_parsing = true;
|
||||
yyparse();
|
||||
run_state::is_parsing = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue