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;
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.c
or Makefile
to make this work?
c linux linux-kernel kernel-module
add a comment |
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.c
or Makefile
to make this work?
c linux linux-kernel kernel-module
3
I think you have to export the symbol first. You can do that by addingEXPORT_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 usingEXPORT_SYMBOL
, but note howdo_mmap
has not been exported.
– Hadi Brais
Mar 23 at 21:02
add a comment |
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.c
or Makefile
to make this work?
c linux linux-kernel kernel-module
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.c
or Makefile
to make this work?
c linux linux-kernel kernel-module
c linux linux-kernel kernel-module
asked Mar 23 at 19:51
andreasandreas
433
433
3
I think you have to export the symbol first. You can do that by addingEXPORT_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 usingEXPORT_SYMBOL
, but note howdo_mmap
has not been exported.
– Hadi Brais
Mar 23 at 21:02
add a comment |
3
I think you have to export the symbol first. You can do that by addingEXPORT_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 usingEXPORT_SYMBOL
, but note howdo_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
add a comment |
1 Answer
1
active
oldest
votes
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);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
add a comment |
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);
add a comment |
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);
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);
answered Mar 24 at 7:46
ccxxshowccxxshow
68425
68425
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 usingEXPORT_SYMBOL
, but note howdo_mmap
has not been exported.– Hadi Brais
Mar 23 at 21:02