当前位置: 首页>>代码示例>>C++>>正文


C++ Tracer::fork方法代码示例

本文整理汇总了C++中Tracer::fork方法的典型用法代码示例。如果您正苦于以下问题:C++ Tracer::fork方法的具体用法?C++ Tracer::fork怎么用?C++ Tracer::fork使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tracer的用法示例。


在下文中一共展示了Tracer::fork方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sc

TEST(HooksTest, UnknownChildHook)
{
    pid_t child_pid = fork();
    if (child_pid == 0) {
        _exit(0);
    }

    ASSERT_GE(child_pid, 0);

    std::optional<pid_t> exited_pid;
    std::optional<pid_t> unknown_pid;

    Tracer tracer;

    // Tracee must remain alive long enough for child_pid to exit
    auto tracee = tracer.fork([] { while (true) pause(); });
    ASSERT_TRUE(tracee);

    auto tracee_tid = tracee.value()->tid;

    Hooks hooks;

    hooks.syscall_entry = [&](auto t, auto &info) {
        if (unknown_pid) {
            SysCall sc("exit_group", info.syscall.abi());
            assert(sc);
            (void) t->modify_syscall_args(sc.num(), {});
        }
        return action::Default{};
    };

    hooks.tracee_exit = [&](auto pid, auto) {
        exited_pid = pid;
        return action::Default{};
    };

    hooks.unknown_child = [&](auto pid, auto) {
        unknown_pid = pid;

        // tracee must be a valid pointer because this hook would not have been
        // called if the only tracee exited or died
        (void) tracee.value()->interrupt();
    };

    ASSERT_TRUE(tracer.execute(hooks));

    ASSERT_EQ(exited_pid, tracee_tid);
    ASSERT_EQ(unknown_pid, child_pid);
}
开发者ID:chenxiaolong,项目名称:DualBootPatcher,代码行数:49,代码来源:test_hooks.cpp

示例2: raise

TEST(HooksTest, TraceeDeathHook)
{
    std::optional<int> death_signal;

    Hooks hooks;

    hooks.tracee_death = [&](auto, auto signal) {
        death_signal = signal;
        return action::Default{};
    };

    Tracer tracer;

    ASSERT_TRUE(tracer.fork([&] {
        raise(SIGTERM);
    }));

    ASSERT_TRUE(tracer.execute(hooks));

    ASSERT_EQ(death_signal, SIGTERM);
}
开发者ID:chenxiaolong,项目名称:DualBootPatcher,代码行数:21,代码来源:test_hooks.cpp

示例3:

TEST(HooksTest, TraceeExitHook)
{
    std::optional<int> exit_code;

    Hooks hooks;

    hooks.tracee_exit = [&](auto, auto ec) {
        exit_code = ec;
        return action::Default{};
    };

    Tracer tracer;

    ASSERT_TRUE(tracer.fork([&] {
        _exit(10);
    }));

    ASSERT_TRUE(tracer.execute(hooks));

    ASSERT_EQ(exit_code, 10);
}
开发者ID:chenxiaolong,项目名称:DualBootPatcher,代码行数:21,代码来源:test_hooks.cpp


注:本文中的Tracer::fork方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。