Finding linux version inside a device driver - driver

I am new to linux device driver development. I am trying to write a simple hello world module that would display the version of kernel running on the system where I try to insert hello_world module into kernel.
I used LINUX_VERSION_CODE in version.h to get linux version and built the module.
When I try to insert the ko file on a different system other than where it was built, it still shows the version of kernel where it was built
I believe issue lies with using C macro.
Can someone help me how to find linux version of local machine where the ko is to be inserted instead of finding version of kernel where my module gets built

You're right - LINUX_VERSION_CODE is a macro that provides compile-time info about the version of the Linux headers that you're using to compile the module. The macro cannot have any knowledge about the version of the kernel that the module will actually be loaded into.
The utsname() function in <linux/utsname.h> provides a pointer to a new_utsname struct, which has sysname, release and version members that contain what you're looking for.
The information from these members is used in /proc/version, as shown in fs/proc/version.c :
static int version_proc_show(struct seq_file *m, void *v)
{
seq_printf(m, linux_proc_banner,
utsname()->sysname,
utsname()->release,
utsname()->version);
return 0;
}
linux_proc_banner is a string that is currently defined as follows :
const char linux_proc_banner[] =
"%s version %s"
" (" LINUX_COMPILE_BY "#" LINUX_COMPILE_HOST ")"
" (" LINUX_COMPILER ") %s\n";
On my system, reading /proc/version - and thus reading these members - results in obtaining the following string :
Linux version 4.1.6-1-ARCH (builduser#tobias) (gcc version 5.2.0 (GCC) ) #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015
Thus, sysname is Linux, release is 4.1.6-1-ARCH, and version is #1 SMP PREEMPT Mon Aug 17 08:52:28 CEST 2015.

Related

Probable bug in java compiler for openjdk8, how to report and get it fixed?

I've prepared docker image that demonstrate the problem:
https://drive.google.com/uc?id=1i04_dVL0Rp5rxXCMuHaS4LYREkZjAAW1&export=download
This image is basically alpine:3.11 + apk add openjdk8 maven + my maven project containing sample minimal java class that shows problem
Which you can try with following commands:
# docker load -i bugexample.img
# docker run -w /root/bug-example --name bugtest bugexample /bin/ash build-until-sha-different.sh
If you are lucky enough (sometimes require several attempts) you will get following output:
Found! Sha1 of two subsequent otherwise identical builds are different!
--- 1.sha1
+++ 2.sha1
## -1,3 +1,3 ##
d8d46555c93da579adefc629f1764965a5493edb com/SimpleBug$1.class
75007242aab1e1877d24124d432cb246a79476a8 com/SimpleBug$SimpleBugBuilder.class
-23e8d0ea909b95a7955e0ec0adb4d12ae2193dd1 com/SimpleBug.class
+6a303d69d3f382b23ca04caee4102ee1cd7151e3 com/SimpleBug.class
The core issue with this build is that it produce different bytecode almost each time it get build even though nothing else (neither environment, nor code itself) had changed.
When I do compare these different class files I see that they differ in one single byte:
# cmp -lb 1_SimpleBug.class 2_SimpleBug.class
4053 66 6 65 5
Digging deeper into class file structure I've found that this difference come from stackmapframe constant pool pointers (StackMapTable attribute -> stack_map_frame entry with tag Object_variable_info -> cpool_index)
1_SimpleBug.class
#35 = Utf8 supSetStringParameter10
#36 = Utf8 Lcom/google/common/base/Supplier;
2_SimpleBug.class
#35 = Utf8 supSetStringParameter10
#36 = Utf8 Lcom/google/common/base/Supplier;
So one file points to #35 and another to #36. I don't think this is correct behavior.
I would like to sumbit this to a proper issue tracker but I don't know how to do that since all related JDK trackers are for devs only.
# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (IcedTea 3.15.0) (Alpine 8.242.08-r0)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/share/java/maven-3
Java version: 1.8.0_242, vendor: IcedTea, runtime: /usr/lib/jvm/java-1.8-openjdk/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-1050-kvm", arch: "amd64", family: "unix"
And here is archive with java project:
https://drive.google.com/uc?id=1ZBdRzUk00QtpkGGnKAzipMjMtcnkKGN4&export=download
Well... The Mountain in Labour...
All of this was for nothing. Maven was main culprit. First time I ran my build it downloads lots of stuff that maven require (apart from my project dependencies) and then start compilation in same jvm. Second time build runs there is no need to download so compilation starts immediately. I don't know exactly why but first invocation of compiler is somehow affected by state of the jvm and this cause it to produce slightly different bytecode.
Solution was to add <fork>true<fork> to my pom.xml file and build now is totally reproducible... though takes ~2x more time :)
I still believe that this should not happen even if initial compilation happened inside maven jvm, and it may still be topic for improvement in javac but this "workaround" is acceptable.

Dart: Float32Array not loaded

While trying to run some three.dart example codes, I get the following exception:
Exception: 'package:three/src/core/Matrix4.dart': Error: line 25 pos 24: type 'Float32Array' >is not loaded
: elements = new Float32Array(16) {
^
malformed type used.
Breaking on exception: 'package:three/src/core/Matrix4.dart': Error: line 25 pos 24: type 'Float32Array' is not loaded
I'm Running the code from Fedora 18 64.
Btw, I have Dart M4.
Did I miss the installation of some Dart package?
Did I miss the installation of some Fedora 32 package?
It seems to be a problem with three.dart, it's not ready to support Dart M4. Am I right?
You are probably running an outdated version of the three.dart benchmark. Float32Array has been renamed to Float32List and now lives in dart:typed_data.

Trivial snippet of F# code does not work under MONO

Here is a bit of code that won't win awards for complexity:
[<EntryPoint>]
let main argv =
let i = 1I
printfn "One is %A\n" i
0 // return an integer exit code
It's compiled as follows: "c:/Program Files (x86)/Microsoft SDKs/F#/3.0/Framework/v4.0/Fsc.exe" --out:numericstest.exe --debug:full --target:exe --standalone Program.fs
Under Windows it produces the expected result. However under Mono 3.0.7 compiled under Ubuntu it instead says:
mono numericstest.exe
Unhandled Exception: System.InvalidProgramException: Invalid IL code in System.Numerics.BigInteger:get_One (): method body is empty.
at Program.main (System.String[] argv) [0x00000] in <filename unknown>:0[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in System.Numerics.BigInteger:get_One (): method body is empty.
at Program.main (System.String[] argv) [0x00000] in <filename unknown>:0
What am I doing wrong please? Many thanks.
There's nothing wrong with your code -- that exception is due to your code anyway. It looks like there's something wrong with the System.Numerics.dll assembly on your machine; either it's not installed correctly, it's getting compiled incorrectly (e.g., by the Mono C# compiler), or it's doing some kind of type forwarding which is not working like it should, etc.
What happens if you run the code without using BigInteger (via the I suffix)?
I tried your code in my Ubuntu (12.04, 32-bit) VM running under VirtualBox. The code compiled and ran as expected. Here's the output if you want:
Compile/Run
jack#jack-linux:~/Desktop$ fsharpc --out:JoeHuha.exe --debug:full --target:exe --standalone JoeHuha.fs
F# Compiler for F# 3.0 (Open Source Edition)
Freely distributed under the Apache 2.0 Open Source License
jack#jack-linux:~/Desktop$ mono JoeHuha.exe
One is 1
Mono version info
jack#jack-linux:~/Desktop$ mono -V
Mono JIT compiler version 3.0.5 (master/1643364 Fri Feb 22 19:31:07 EST 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: x86
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)

IBM vs Oracle/Sun JDK, java.util.Timzone getOffset () behaving differently

IBM vs Oracle/Sun JDK, java.util.Timzone behaving differently ,
IBM JDK 1.5 vs Sun/Oracle JDK 1.6
import java.util.*;
class TimeTest {
public static void main(String args[]){
long now = System.currentTimeMillis();
System.out.println("EST : " + TimeZone.getTimeZone("EST").getOffset(now));
System.out.println("US/Eastern : " + TimeZone.getTimeZone("US/Eastern").getOffset(now));
}
}
***IBM JVM ouput
EST : -14400000
US/Eastern : -14400000
Oracle JVM
EST : -18000000
US/Eastern : -14400000
IBM JDK
java -version
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pxi32devifx-20090811 (SR10 +IZ56666+IZ56751))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20090707 (JIT enabled)
J9VM - 20090706_38445_lHdSMr
JIT - 20090623_1334_r8
GC - 200906_09)
JCL - 20090811
Oracle JDK
java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
update , tested with IBM JDK 6 , it matches the ouput of oracle/sun
java -version
java version "1.6.0"
Java(TM) SE Runtime Environment (build pxi3260sr6ifix-20091015_01(SR6+152211+155930+156106))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux x86-32 jvmxi3260sr6-20091001_43491 (JIT enabled, AOT enabled)
J9VM - 20091001_043491
JIT - r9_20090902_1330ifx1
GC - 20090817_AA)
JCL - 20091006_01
java TimeTest
EST : -18000000
US/Eastern : -14400000***
IBM tells us the answer:
In 2006, the meaning of the EST time zone identifier changed in the Olson database. Historically, EST referred to the American Eastern Standard Time and made adjustments for daylight saving time. Following the change, EST refers to Eastern Standard Time with no adjustment for daylight saving time. A new identifier EST5EDT was also introduced that had the same meaning as the original EST identifier.
I think it's safe to say your IBM JDK install has a much older timezone database that the other JDK installs. JDK 1.5 was released in 2004.

Installing luasql 2.2 with luarocks onto lua for windows install

So it turns out lua for windows install has some earlier 2.1 version of luasql on it, and I need to be able to use luasql 2.2 (particularly mysql). I've spent all day trying to install this thing with luarocks but keep hitting a wall. This is the 3rd wall I've hit but the first one that I just have no clue where to even begin.
I run: luarocks install luasql-mysql MYSQL_DIR="E:/Programs/MySQL/MySQL Server 5.5"
It goes through and outputs (removing a lot of the output where it's just repeating the same thing but different file):
Extracting luasql-2.2.0\src\jdbc
Extracting luasql-2.2.0\src\jdbc\Makefile
... (lots of these here)
Extracting luasql-2.2.0\vc6\sqlite.def
Everything is Ok
Folders: 17
Files: 84
Size: 358091
Compressed: 440320
cl /MD /O2 -c -Fosrc/luasql.obj -IF:/Code/Lua/5.1/include src/luasql.c -IE:/Prog
rams/MySQL/MySQL Server 5.5/include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
luasql.c
cl /MD /O2 -c -Fosrc/ls_mysql.obj -IF:/Code/Lua/5.1/include src/ls_mysql.c -IE:/
Programs/MySQL/MySQL Server 5.5/include
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
ls_mysql.c
e:\programs\mysql\mysql server 5.5\include\mysql_com.h(291) : error C2061: synta
x error : identifier 'SOCKET'
e:\programs\mysql\mysql server 5.5\include\mysql_com.h(337) : error C2059: synta
x error : '}'
... (lots of these here, same errors just different lines)
E:/Programs/MySQL/MySQL Server 5.5/include\mysql.h(374) : error C2143: syntax er
ror : missing '{' before '*'
E:/Programs/MySQL/MySQL Server 5.5/include\mysql.h(374) : fatal error C1003: err
or count exceeds 100; stopping compilation
Error: Build error: Failed compiling object src/ls_mysql.obj
Any idea where to start? I've had to a) install standalone mysql (was previously using one that came with WAMP since I was already using that before), and b) install visual studio 2010 (c# and c++ versions so far), and c) use visual studio command prompt to run the luarocks stuff, if I use regular command problem it breaks way before this.
I'm hoping this is an easy issue to fix for someone familiar with compiling C which is what this seems to be doing.
Add the following to ls_mysql.c after line 17:
#include <windows.h>
So that windows.h is included after winsock.h and before mysql.h.
References:
http://forums.mysql.com/read.php?45,37472,37472
C++ Redefinition Header Files (winsock2.h)

Resources