驅動程式 - VxWorks - 23.09 - C/C++ - Task Hook



參考資訊:
https://zhuanlan.zhihu.com/p/597577575
https://cloud.tencent.com/developer/article/1460923
https://studies.ac.upc.edu/doctorat/ENGRAP/VxWorks-device-drivers.htm
https://forums.windriver.com/t/vxworks-software-development-kit-sdk/43
https://mail.prz-rzeszow.pl/~ssamolej/vxworks/vxworks_kernel_programmers_guide_6.6.pdf
https://d13321s3lxgewa.cloudfront.net/downloads/wrsdk-vxworks7-docs/2309/README_qemu.html
https://learning.windriver.com/path/vxworks7-essentials-workbench-and-tools/vxworks-kernel-shell

main.c

#include <stdio.h>
#include <taskLib.h>
#include <taskHookLib.h>
#include <private/taskLibP.h>

int create_hook(WIND_TCB *pNewTcb)
{
    return OK;
}

void cont_hook(WIND_TCB *pNewTcb)
{
}

void stop_hook(WIND_TCB *pNewTcb)
{
}

int switch_hook(WIND_TCB *pOldTcb, WIND_TCB *pNewTcb)
{
    return OK;
}

void swap_hook(WIND_TCB *pOldTcb, WIND_TCB *pNewTcb)
{
}

int delete_hook(WIND_TCB *pTcb)
{
    WIND_TCB *self = (WIND_TCB*)taskIdSelf();

    printf("%s: %s\n", __func__, self->objCore.name);
    return OK;
}

int add_hook(void)
{
    taskCreateHookAdd(create_hook);
    taskContHookAdd(cont_hook);
    taskStopHookAdd(stop_hook);
    taskSwapHookAdd(switch_hook);
    taskSwitchHookAdd(switch_hook);
    taskDeleteHookAdd(delete_hook);
    return OK;
}

app.c

#include <stdio.h>

int main(int argc, char **argv)
{
    return 0;
}

編譯

$ wr-cc app.c -o app
$ wr-cc main.c -o main -dkm

執行

-> ld < main

-> add_hook

-> cmd

[vxWorks *]# app
    delete_hook: tJobTask

[vxWorks *]# C

-> unld "main"