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

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript