How to use do_mmap() in kernel moduleUse do_mmap() in Linux device driverHow do you set, clear, and toggle a single bit?How to symlink a file in Linux?How do I find all files containing specific text on Linux?“scripts recordmcount: Syntax error” when I try to build a linux kernel module on a 64-bit 3.9 kernelLinux Kernel Module (*.ko) compatibility between kernelsCompiling linux kernel with nvccHow to print linux kernel version number in kernel modulecompile a static kernel driver to modulecompile linux kernel module with mkfileFailied to building Linux kernel module for specific kernel version

Hotel booking: Why is Agoda much cheaper than booking.com?

What does it mean for a program to be 32 or 64 bit?

How would a physicist explain this starship engine?

How to prove the emptiness of intersection of two context free languages is undecidable?

Statue Park: Five

How could Dwarves prevent sand from filling up their settlements

What to call a small, open stone or cement reservoir that supplies fresh water from a spring or other natural source?

Why was Harry at the Weasleys' at the beginning of Goblet of Fire but at the Dursleys' after?

Do seaplanes need to get clearance for takeoff?

Salesforce bug enabled "Modify All"

Was murdering a slave illegal in American slavery, and if so, what punishments were given for it?

Separate the element after every 2nd ',' and push into next row in bash

If you attack a Tarrasque while swallowed, what AC do you need to beat to hit it?

Existence of a model of ZFC in which the natural numbers are really the natural numbers

What Species of Trees are These?

Requirement for splicing neutrals in a switch

Ribbon Cable Cross Talk - Is there a fix after the fact?

Story about encounter with hostile aliens

What should I wear to go and sign an employment contract?

why "American-born", not "America-born"?

Are there historical examples of audiences drawn to a work that was "so bad it's good"?

Removing Doubles Destroy Topology

Warped chessboard

How do we explain the use of a software on a math paper?



How to use do_mmap() in kernel module


Use do_mmap() in Linux device driverHow do you set, clear, and toggle a single bit?How to symlink a file in Linux?How do I find all files containing specific text on Linux?“scripts recordmcount: Syntax error” when I try to build a linux kernel module on a 64-bit 3.9 kernelLinux Kernel Module (*.ko) compatibility between kernelsCompiling linux kernel with nvccHow to print linux kernel version number in kernel modulecompile a static kernel driver to modulecompile linux kernel module with mkfileFailied to building Linux kernel module for specific kernel version






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








4















I would like to use do_mmap() in a kernel module. According to this question this should be possible.



Here is a minimal non-working example:



hp_km.c:

#include <linux/module.h>
#include <linux/mm.h>

MODULE_LICENSE("GPL");

static int __init hp_km_init(void)
do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;


static void __exit hp_km_exit(void)


module_init(hp_km_init);
module_exit(hp_km_exit);


Makefile:

obj-m += hp_km.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


Running make results in WARNING: "do_mmap" [...] undefined!



What do I need to change in hp_km.cor Makefile to make this work?










share|improve this question

















  • 3





    I think you have to export the symbol first. You can do that by adding EXPORT_SYMBOL(do_mmap); in the mmap.c file below the definition of the function and then recompile the kernel. You can use any of the functions that have been exported using EXPORT_SYMBOL, but note how do_mmap has not been exported.

    – Hadi Brais
    Mar 23 at 21:02

















4















I would like to use do_mmap() in a kernel module. According to this question this should be possible.



Here is a minimal non-working example:



hp_km.c:

#include <linux/module.h>
#include <linux/mm.h>

MODULE_LICENSE("GPL");

static int __init hp_km_init(void)
do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;


static void __exit hp_km_exit(void)


module_init(hp_km_init);
module_exit(hp_km_exit);


Makefile:

obj-m += hp_km.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


Running make results in WARNING: "do_mmap" [...] undefined!



What do I need to change in hp_km.cor Makefile to make this work?










share|improve this question

















  • 3





    I think you have to export the symbol first. You can do that by adding EXPORT_SYMBOL(do_mmap); in the mmap.c file below the definition of the function and then recompile the kernel. You can use any of the functions that have been exported using EXPORT_SYMBOL, but note how do_mmap has not been exported.

    – Hadi Brais
    Mar 23 at 21:02













4












4








4


1






I would like to use do_mmap() in a kernel module. According to this question this should be possible.



Here is a minimal non-working example:



hp_km.c:

#include <linux/module.h>
#include <linux/mm.h>

MODULE_LICENSE("GPL");

static int __init hp_km_init(void)
do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;


static void __exit hp_km_exit(void)


module_init(hp_km_init);
module_exit(hp_km_exit);


Makefile:

obj-m += hp_km.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


Running make results in WARNING: "do_mmap" [...] undefined!



What do I need to change in hp_km.cor Makefile to make this work?










share|improve this question














I would like to use do_mmap() in a kernel module. According to this question this should be possible.



Here is a minimal non-working example:



hp_km.c:

#include <linux/module.h>
#include <linux/mm.h>

MODULE_LICENSE("GPL");

static int __init hp_km_init(void)
do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;


static void __exit hp_km_exit(void)


module_init(hp_km_init);
module_exit(hp_km_exit);


Makefile:

obj-m += hp_km.o

all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean


Running make results in WARNING: "do_mmap" [...] undefined!



What do I need to change in hp_km.cor Makefile to make this work?







c linux linux-kernel kernel-module






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 19:51









andreasandreas

433




433







  • 3





    I think you have to export the symbol first. You can do that by adding EXPORT_SYMBOL(do_mmap); in the mmap.c file below the definition of the function and then recompile the kernel. You can use any of the functions that have been exported using EXPORT_SYMBOL, but note how do_mmap has not been exported.

    – Hadi Brais
    Mar 23 at 21:02












  • 3





    I think you have to export the symbol first. You can do that by adding EXPORT_SYMBOL(do_mmap); in the mmap.c file below the definition of the function and then recompile the kernel. You can use any of the functions that have been exported using EXPORT_SYMBOL, but note how do_mmap has not been exported.

    – Hadi Brais
    Mar 23 at 21:02







3




3





I think you have to export the symbol first. You can do that by adding EXPORT_SYMBOL(do_mmap); in the mmap.c file below the definition of the function and then recompile the kernel. You can use any of the functions that have been exported using EXPORT_SYMBOL, but note how do_mmap has not been exported.

– Hadi Brais
Mar 23 at 21:02





I think you have to export the symbol first. You can do that by adding EXPORT_SYMBOL(do_mmap); in the mmap.c file below the definition of the function and then recompile the kernel. You can use any of the functions that have been exported using EXPORT_SYMBOL, but note how do_mmap has not been exported.

– Hadi Brais
Mar 23 at 21:02












1 Answer
1






active

oldest

votes


















4














In addition to rebuild the kernel, you can also use kallsyms_lookup_name to find the address corresponding to the symbol



such as below:



#include <linux/module.h>
#include <linux/mm.h>
#include <linux/kallsyms.h>

MODULE_LICENSE("GPL");

unsigned long (*orig_do_mmap)(struct file *file, unsigned long addr,
unsigned long len, unsigned long prot,
unsigned long flags, vm_flags_t vm_flags,
unsigned long pgoff, unsigned long *populate,
struct list_head *uf);

static int __init hp_km_init(void)

orig_do_mmap = (void*)kallsyms_lookup_name("do_mmap");
if (orig_do_mmap == NULL)
return -EINVAL;

orig_do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
return 0;


static void __exit hp_km_exit(void)



module_init(hp_km_init);
module_exit(hp_km_exit);





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317743%2fhow-to-use-do-mmap-in-kernel-module%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4














    In addition to rebuild the kernel, you can also use kallsyms_lookup_name to find the address corresponding to the symbol



    such as below:



    #include <linux/module.h>
    #include <linux/mm.h>
    #include <linux/kallsyms.h>

    MODULE_LICENSE("GPL");

    unsigned long (*orig_do_mmap)(struct file *file, unsigned long addr,
    unsigned long len, unsigned long prot,
    unsigned long flags, vm_flags_t vm_flags,
    unsigned long pgoff, unsigned long *populate,
    struct list_head *uf);

    static int __init hp_km_init(void)

    orig_do_mmap = (void*)kallsyms_lookup_name("do_mmap");
    if (orig_do_mmap == NULL)
    return -EINVAL;

    orig_do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
    return 0;


    static void __exit hp_km_exit(void)



    module_init(hp_km_init);
    module_exit(hp_km_exit);





    share|improve this answer



























      4














      In addition to rebuild the kernel, you can also use kallsyms_lookup_name to find the address corresponding to the symbol



      such as below:



      #include <linux/module.h>
      #include <linux/mm.h>
      #include <linux/kallsyms.h>

      MODULE_LICENSE("GPL");

      unsigned long (*orig_do_mmap)(struct file *file, unsigned long addr,
      unsigned long len, unsigned long prot,
      unsigned long flags, vm_flags_t vm_flags,
      unsigned long pgoff, unsigned long *populate,
      struct list_head *uf);

      static int __init hp_km_init(void)

      orig_do_mmap = (void*)kallsyms_lookup_name("do_mmap");
      if (orig_do_mmap == NULL)
      return -EINVAL;

      orig_do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
      return 0;


      static void __exit hp_km_exit(void)



      module_init(hp_km_init);
      module_exit(hp_km_exit);





      share|improve this answer

























        4












        4








        4







        In addition to rebuild the kernel, you can also use kallsyms_lookup_name to find the address corresponding to the symbol



        such as below:



        #include <linux/module.h>
        #include <linux/mm.h>
        #include <linux/kallsyms.h>

        MODULE_LICENSE("GPL");

        unsigned long (*orig_do_mmap)(struct file *file, unsigned long addr,
        unsigned long len, unsigned long prot,
        unsigned long flags, vm_flags_t vm_flags,
        unsigned long pgoff, unsigned long *populate,
        struct list_head *uf);

        static int __init hp_km_init(void)

        orig_do_mmap = (void*)kallsyms_lookup_name("do_mmap");
        if (orig_do_mmap == NULL)
        return -EINVAL;

        orig_do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
        return 0;


        static void __exit hp_km_exit(void)



        module_init(hp_km_init);
        module_exit(hp_km_exit);





        share|improve this answer













        In addition to rebuild the kernel, you can also use kallsyms_lookup_name to find the address corresponding to the symbol



        such as below:



        #include <linux/module.h>
        #include <linux/mm.h>
        #include <linux/kallsyms.h>

        MODULE_LICENSE("GPL");

        unsigned long (*orig_do_mmap)(struct file *file, unsigned long addr,
        unsigned long len, unsigned long prot,
        unsigned long flags, vm_flags_t vm_flags,
        unsigned long pgoff, unsigned long *populate,
        struct list_head *uf);

        static int __init hp_km_init(void)

        orig_do_mmap = (void*)kallsyms_lookup_name("do_mmap");
        if (orig_do_mmap == NULL)
        return -EINVAL;

        orig_do_mmap(0, 0, 0, 0, 0, 0, 0, 0, 0);
        return 0;


        static void __exit hp_km_exit(void)



        module_init(hp_km_init);
        module_exit(hp_km_exit);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 7:46









        ccxxshowccxxshow

        68425




        68425





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317743%2fhow-to-use-do-mmap-in-kernel-module%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현