I have a kernel module which was probably written for the 2.6xx kernel version. Now I currently want to plug that module onto kernel version 3.1x and above. I have tweaked and changed the code and apparently now there is compilation error except the below mentioned warnings.
WARNING: "do_mmap_pgoff" [/home/abdullah/Downloads/my_mod.ko] undefined!
WARNING: "putname" [/home/abdullah/Downloads/my_mod.ko] undefined!
WARNING: "get_task_cred" [/home/abdullah/Downloads/my_mod.ko] undefined!
Now when I checked my kernel Module.symvers I did not find all three of the functions in it for exports. Which results in a fatal error when inserting the module. Now my question: Does anybody know the alternative to these functions? Any help will be really appreciated. Below is a sample function which illustrates the scenario as the complete function is to long.
int function_1(const char *fname)
{
struct cred *task_cred;
struct filename *filename = NULL;
filename = getname(__user(fname));
task_cred = (struct cred *)get_task_cred(current);
putname(filename);
filename = NULL;
return 1;
}
Well, there is another way also which is bit unsafe, any body who is not on a production system he can export these function in the kernel source file as I did
Related
I just compiled my own version of gcc/9.2.0 using gcc/4.8.2. After successful compilation and installation of gcc/9.2.0 I try compiling ucx-1.5.1. When I try to run the ucx configure script I get the following message "checking attribute((constructor))... configure: error: Cannot continue. Please use compiler that supports attribute((constructor))".
When I run the script using the old gcc/4.8.2 I get no error at all.
Any idea what went wrong?
Any idea what went wrong?
No.
You can have a look at the respective config.log file, it usually contains additional information. In general, not every compilation error during configue indicates a problem, it's usually just feature test that just revealed a specific feature is not available.
Ucx uses next code to determine support of attribute __attribute__((constructor)). You can test it by yourself:
gcc -x c - <<EOF
static int rc = 1;
static void constructor_test() __attribute__((constructor));
static void constructor_test() { rc = 0; }
int main() { return rc; }
EOF
And post here if you have some errors.
I had the same problem, because I installed a software named "binutils-devel" on CentOS 8.4.
When "binutils-devel" was removed, the compile of ucx was successful.
I'm trying to write some JNA code that accesses glibc, specifically functions defined in mmap.h.
I have tried to define it exactly as shown in man shm_open. The getuid() function call just before it works, but shm_open doesn't return.
I'm constrained to using JNA 4.4.0 and JNA Platform 3.4.0.
interface LibC extends Library {
LibC INSTANCE = Native.loadLibrary("c", LibC.class);
int shm_open(String name, int oFlag, int mode);
}
// ...
int fileDescriptor = LibC.INSTANCE.shm_open("/some_memory.123", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
// ...
I expect a file descriptor to be returned, but I get these exceptions:
When I load "libc.so.6": java.lang.UnsatisfiedLinkError: Error looking up function 'shm_open': /lib/x86_64-linux-gnu/libc.so.6: undefined symbol: shm_open
When I load "c": java.lang.UnsatisfiedLinkError: Error looking up function 'shm_open': /usr/lib/jvm/java-8-openjdk-amd64/bin/java: undefined symbol: shm_open
Well, I figured out the issue while writing the question.
While getuid() and friends are defined in libc, shm_open and friends are defined in librt. I really should have realized that because the manpage for shm_open explicitly states "Link with -lrt", indicating it residing in the "rt" lib.
In short: I need a new interface for LibRT alongside LibC, loaded with name rt.
I am using an extensive piece of code which compiles in Windows and Linux with gcc>=4.7. It is a utility to seamlessly generate mex functions in Matlab from m-scripts written by someone. I am having trouble compiling a short c script (not provided here) in Mac os x. I am using gcc-4.8 with C++11. It uses Boost library only for headers. The piece of utility code where it gets stuck is:
/* gets mxClassID, given C type>
eg. mx_class_id<float>()*/
template<typename T>
struct mx_class_id
{
operator mxClassID()
{
return static_cast<mxClassID>(boost::mpl::at<mxInverseTypeMap,T>::type::value);
}
};
required by
template<typename T>
mxArray* mxCreateScalar(const T & val)
{
//mxClassID cid=static_cast<mxClassID>(boost::mpl::at<mxInverseTypeMap,T>::type::value);
mxArray * arr=mxCreateNumericMatrix(1,1,mx_class_id<T>(),mxREAL);
mxSetValue(arr,val);
return arr;
}
What am I missing? Is it conflicting with built-in clang libraries? Or is it a header not specified (boost/mpl/at.hpp is included)? As I mention it does compile in Matlab for Windows and Linux.I have tried boost 1.51.0 (this is what we use) and also 1.56.0 (this is what Matlab uses) but I get the same error message.
The code I use to compile is
mex -v /usr/local/bin/gcc-4.8 -I path-to-boost-library -I path-to-private-library -I /usr/local/lib -std=C++11 script.cc
Here is the error message I am getting:
error: 'value' is not a member of 'boost::mpl::aux::wrapped_type <
boost::mpl::aux::type_wrapper < mpl_::void_> > ::type {aka
mpl_::void_}'
Any pointers or help appreciated. Thanks
This was resolved by the conflicting use of 'size_t' and 'unsigned long int'.
I think in Linux, Windows, size_t was employed in the code with the assumption it to be uint64_t. And it compiled in both.
However, for mac os x, it is either size_type or unsigned long int. This especially created problem because the code was matching c type to Matlab mex type with one-to-one mapping. In inverse mapping, with the use of size_t this one-to-one mapping was getting lost and instead became many-to-one. Once that was addressed it was easy to fix the rest.
I created simple application, which uses sqlite3 as it's datastore back-end. I faced no problems when building and running it on Linux, but after I tried to build it on Windows, I see weird linking error:
Linking dist\build\hnotes\hnotes.exe ...
C:\Documents and Settings\Admin\Application Data\cabal\sqlite-0.5.2.2\ghc-7.0.4/libHSsqlite-0.5.2.2.
a(sqlite3-local.o):sqlite3-local.c:(.text+0x21): undefined reference to `sqlite3_temp_directory'
C:\Documents and Settings\Admin\Application Data\cabal\sqlite-0.5.2.2\ghc-7.0.4/libHSsqlite-0.5.2.2.
a(sqlite3-local.o):sqlite3-local.c:(.text+0x40): undefined reference to `sqlite3_temp_directory'
collect2: v ld 1
cabal.EXE: Error: some packages failed to install:
hnotes-0.1 failed during the building phase. The exception was:
ExitFailure 1
What may be wrong there? I suspect that qalite3.dll has to be added to linking stage, but have no idea how to do that. Adding --extra-lib-dirs=path-to-sqlite-dll doesn't help either (perhaps because I need to update my cabal file somehow, to support this?).
Not sure if It's a bug or not, but the error comes from the sqlite3.h include of the sqlite package.
A look in the file shows this
/*
** CAPI3REF: Name Of The Folder Holding Temporary Files {H10310} <S20000>
**
** If this global variable is made to point to a string which is
** the name of a folder (a.k.a. directory), then all temporary files
** created by SQLite will be placed in that directory. If this variable
** is a NULL pointer, then SQLite performs a search for an appropriate
** temporary file directory.
**
** It is not safe to modify this variable once a [database connection]
** has been opened. It is intended that this variable be set once
** as part of process initialization and before any SQLite interface
** routines have been call and remain unchanged thereafter.
*/
SQLITE_EXTERN char *sqlite3_temp_directory;
so it's declared as an extern. So simple test:
module Main where
import Database.SQLite
main
= do hwd <- openConnection "test"
closeConnection hwd
putStrLn "done"
This crashes during linking as expected with the error you have above.
So I created a small C test file foo.c
#include "sqlite-0.5.2.2\\include\\sqlite3-local.h"
char* sqlite3_temp_directory = "C:\\test2";
So I'm defining a temp_directory and then I pass the c file along during compilation of the haskell source
$ ghc test.hs foo.c
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test.exe ...
and then running it also returns the expected result
$ ./test
done
So it seems that you just need to give a value for the sqlite3_temp_directory, which if you set it to a NULL pointer will use the TMP/TEMP etc variables as defined in the SQLLITE manual.
edit, follow up on why it worked on Linux but not on windows
In the sqlite package, there's a file sqlite3.c under the folder sqlite3.6. This provides a bunch of defaults for the sqlite package.
when on linux OS_UNIX is defined and when on linux it uses the defines under OS_WIN.
The function we're interested in is the function which sets the temporary directory. for unix this'll be unixGetTempname and for windows winGetTempname.
If you look at the implementation of both these functions, for the unix one it has list of directories that it'll try
static const char *azDirs[] = {
0,
"/var/tmp",
"/usr/tmp",
"/tmp",
".",
};
it tries to access them in order and the one it can write to it uses to generate a temporary folder in.
For windows however one of the first lines are:
if( sqlite3_temp_directory ){
sqlite3_snprintf(MAX_PATH-30, zTempPath, "%s", sqlite3_temp_directory);
}else if( isNT() ){
so for windows sqlite3_temp_directory is actually used. This is why it doesn't compile if It can't find it.
I want to use the LSM framework with kernel ubuntu 2.6.36.
When I compiled the kernel module, it wrote:
WARNING: "register_security " undefined!
After a lot of googlings, I found the reason is that the register_security() symbol is no longer exported in the 2.6 kernel.
So I added EXPORT_SYMBOL(register_security) in the ../security/security.c file, and recompiled the kernel.
After booting with the new kernel, I added extern int register_security(struct security_operations *ops) in my kernel module file, and compiled the module again.
However, the WARNING information still existed. If I continued to insmode the module, the dmesg told me that
Unknown symbol register_security
What should I do? How can I register a Linux Security Module?
Make sure newly loaded kernel is the one, which is compiled by you.
Check the Licence of your module (Ref: http://lists.jammed.com/linux-security-module/2004/08/0053.html)
In modern kernels register_security symbol does not exported. It means that you can't register LSM module as a module. But if you really wish to do that you can do that :) Look at the exported LSM-symbols like security_sb_copy_data. They are simple wrappers over the security_ops->some_lsm_method. So, you can use their code to determine security_ops pointer value. It needs disassembler though.
Unknown symbol register_security
Happened at the line that you unregister your LSM.
So add unregister_security() in security.c and export it:
/**
* unregister_security - allows security modules to be moved
* #ops : a pointer to the struct security_options that had been registered before.
*/
int unregister_security(struct security_operations *ops)
{
if (ops != security_ops)
{
printk (KERN_INFO "%s: trying to unregister "
"a security_opts structure that is not "
"registered, failing.\n", __FUNCTION__);
return -EINVAL;
}
security_ops = &dummy_security_ops;
return 0;
}
EXPORT_SYMBOL(unregister_security);
And recompiled the kernel.