I am using Ubuntu-11.04 OS. i wrote a basic interactive kernel module mid.c
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/init.h>
static int __init insert(void)
{
pr_info(" The module is inserted into the kernel \n");
return 0;
}
static void __exit remove(void)
{
pr_info("the module is removed from kernel \n");
}
module_init(insert);
module_exit(remove);
i can compile the module by using the command
make -C /lib/modules/2.6.38-8-generic/build M=$(PWD) modules
but when i try to insert the module using the command
insmod mod.ko
an error occurs saying :
cannot insert mod.ko permission denied
you need to add a sudo before insmod
Related
I tried to build simple kernel module (using source downloaded from developer.sonymobile.com) but after compiling i can't insmod it: Unknown symbol __gnu_mcount_nc so i founded a solution and I wrote another module using assembler and I exported this function. After this module insmoded correctly but I see in lsmod that all modules are permament. I have a problem with simple filesystem (Permission denied - default action when pointer is null), on PC this code works without any errors.
I guess the config is wrong in source code, (probably offset of some fields in structure is another than in device).
Version of built is: 24.0.A.5.14 (downloaded from developer.sonymobile.com site).
Can I do anything to get this same configuration as in device?
I had not /proc/config.gz so I can't get it easily.
Module source:
#include <linux/module.h>
#include <linux/kernel.h>
int __init example_init(void)
{
printk("Hello world!\n");
return 0;
}
void __exit example_exit(void)
{
printk("example module exit\n");
}
module_init(example_init);
module_exit(example_exit);
And I see Hello World! in dmesg but module is still permament.
Source of __gnu_mcount_nc i found here: http://doc.ironwoodlabs.com/arm-arm-none-eabi/html/getting-started/arm-mcount.html
Do you compile with with profile enable -pg flag when you build the kernel module? It looks that way.
The kernel module Makefile for CFLAGS.
i'm trying run a simple malloc program to see whether my hugepage environment has been properly setup. the libhugetlbfs is installed in the default system directory only /usr/local. OS is RHEL 6.7. I checked that the libhugetlbfs.so is ther in /usr/lib64 folder. When i run i code with
HUGETLB_MORECORE=yes LD_PRELOAD=libhugetlbfs.so
the code
#include<stdio.h>
#include<stdlib.h>
int main()
{
double *x;
int y,i;
y = 15000000;
x = (double *)malloc(y*sizeof(double));
if (x != NULL)
{
printf("\nmalloc successful\n");
}
else
{
printf("malloc unsuccesfull");
}
}
output gives
**ERROR: ld.so: object 'libhugetlbfs.so' from LD_PRELOAD cannot be preloaded: ignored.**
malloc successful
its clear that the malloc dint happen using hugepage. I checked all environment variables.. not able to find problem.. any sugestion???
It means that libhugetlbfs.so is not found.
You have to specify in LD_PRELOAD the full path:
LD_PRELOAD=/your/path/libhugetlbfs.so
Therefore, open a console and type
export LD_PRELOAD=/your/path/libhugetlbfs.so
export HUGETLB_MORECORE=yes
./your_binary
I was also facing error as below
ERROR: ld.so: object '/usr/lib64/libjemalloc.so.1' from LD_PRELOAD cannot be preloaded
Below were my steps resolved the error for me.
Go to the path /usr/lib64 and lok for the libjemalloc using below commands*
#cd /usr/lib64
#ls | grep libjemalloc
if you dont find you dont have that package installed in your system
$sudo yum whatprovides libjemalloc*
$sudo yum install jemalloc-3.6.0-1.amzn2.x86_64
I am pretty new to linux and i wanted to try to make a small opengl
program just as a test. I'm using glfw and i made a very easy test:
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace std;
int main()
{
if (!glfwInit())
{
return -1;
}
GLFWwindow *window = glfwCreateWindow(800, 600, "Het werkt", NULL, NULL);
if (!window)
{
glfwTerminate();
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
glfwSwapBuffers(window);
}
}
Now if i try to run this in Code::Blocks itself, it runs fine, debug, release, it doesn't matter, it works. But when i try to execute it outside Code::Blocks, it goes wrong. If i double click the executable nothing happens, and if i ./ExecutableName in the terminal it gives me this error:
error while loading shared libraries: libglfw.so.3: cannot open shared object file: No such file or directory
All of the libs are in the same directory as the executable, so i don't get why it gives this error.
By the way i'm working on Linux Mint.
Thanks in advance for your help!
You should place those libraries in your $PATH. Issue a echo $PATH command and see if you can find the libraries in there (within those paths) - if not, you will have to put them in there someway. I'm not sure if you can just copy-paste the libraries in there, so probably you may want to search for them using your linux distribution's package management system. As you are using Linux Mint, maybe you could try searching with sudo aptitude search glfw and then try installing the corresponding packages.
I use GCC and GNU Binutils on Linux, to compile and link code for i386 Linux. I'd like to disallow the section named .custom, so I'd like the following to fail with a compile error or a link error:
__attribute__((section(".custom"))) int foo() { return 42; }
int main(void) { return 0; }
, but this one should succeed as usual:
__attribute__((section(".other" ))) int foo() { return 42; }
int main(void) { return 0; }
The code doing __attribute__((section(".custom"))) is not under my control (so I can't simply replace it with an #error in the .c file), but the gcc and ld command-line flags (and the build process) are under my control.
Is there a command-line flag for gcc or ld or some other trick which can force the error? I couldn't find anything relevant in the man pages.
My fallback solution is to parse the generated executable (e.g. using objdump -x), and fail with an error message if the .custom section has made it to the final executable.
You can use a linker script to discard all symbols in the .custom section:
SECTIONS
{
/DISCARD/ : { *(.custom) }
}
If you really wanted to punish your users with an error, rather than simply discarding the symbols, I suppose you could instead have the linker script ASSERT that the size of the .custom section was 0. I think you'd have to force the section to be generated for that to work, though.. otherwise it'd give you an error that the section didn't exist.
/*
* hello-1.c - The simplest kernel module.
*/
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
int init_module(void)
{
printk(KERN_INFO "Hello world 1.\n");
/*
* A non 0 return means init_module failed; module can't be loaded.
*/
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye world 1.\n");
}
MAKEFILE
obj-m += hello.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
After the make command I am getting the following error. What is the reason for this error and how can i resolve this?
make -C /lib/modules/2.6.32-358.el6.x86_64/build M=/home/hello modules
make: *** /lib/modules/2.6.32-358.el6.x86_64/build: No such file or directory. Stop.
make: *** [all] Error 2
-C option in make command instruct to change directory to one provided with -C. In your case, it is /lib/modules/2.6.32-358.el6.x86_64/build. But when it tries to change to that directory, compilation gives error with "No such file or directory", which means that you don't have build directory at /lib/modules/2.6.32-358.el6.x86_64/.
A lot of time it happens that build in the given path may not be a directory, but it may be a soft link pointing to a kernel source code directory.
So you need to check either there should be build directory at the required path which contains kernel source or it should be a soft link to kernel source.
Apart from all those build related comments, there are few things you have to follow while writing a kernel module. Your code will not work as you expect even after you fix those build issues. Why? you have the init and cleanup routines built, but you haven't specified/directed which one is your init routine and which is cleanup.
You have to do that this way,
at the end of the file add these two line.
module_init ( foo_init_fn);
module_exit ( bar_exit_fn);
Also, you have to specify the module license details etc. like below
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Copyright (c) 2006 by xxxx xxxxx, Inc.");
MODULE_DESCRIPTION("klm_vdc");