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



參考資訊:
https://zhuanlan.zhihu.com/p/597577575
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 <private/rtpLibP.h>

STATUS create_hook(const char *rtpFileName, const char *argv[], const char *envp[], 
    int priority, size_t uStackSize, int options, int taskOptions)
{
    printf("%s, %s\n", __func__, rtpFileName);
    return OK;
}

void delete_hook(const RTP_ID rtpId, const int exitCode)
{
    printf("%s\n", __func__);
}

void init_hook(const RTP_ID rtpId)
{
    printf("%s\n", __func__);
}

STATUS post_hook(const RTP_ID rtpId)
{
    printf("%s\n", __func__);
    return OK;
}

int add_hook(void)
{
    rtpPreCreateHookAdd(create_hook, FALSE);
    rtpInitCompleteHookAdd(init_hook, FALSE);
    rtpPostCreateHookAdd(post_hook, FALSE);
    rtpDeleteHookAdd(delete_hook, FALSE);
    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
    create_hook, ./app
    post_hook
    init_hook

[vxWorks *]# C

-> unld "main"