I want to pass some params to rust linux kernel module. In C language, I can use module_param(). But I can't find a functional equivalent method in rust kernel.
I found similar method called kernel::miscdev::Registration::register_with_options(). But it needs a Options struct and that can only be created in kernel codes.
So, is there any way to pass parameters from cmd line to rust kernel module?
Related
Rust code can be debugged using LLDB. The representation of variables used by tools like CodeLLDB, though, is simply a breakdown of the in-memory contents of the variable and does not show any information from the standard Debug trait.
Is there any way using LLDB I can invoke the actual Debug representation of a variable at runtime? This often has a significant amount of useful information which is not clear from a simple memory snapshot.
The "Debug" trait in Rust looks like a pretty close equivalent to the ObjC and Swift object description methods: it provides a to-string method that prints a developer-friendly view of the object. From what I can tell this trait cooperates with the standard formatted printing machinery in Rust.
If that's right, the natural way to give access to the Rust Debug Trait in lldb would be to implement the "Object Description" part of lldb's "Rust LanguageRuntime" and call the print function under the covers. This would be accessed by the po or print-object command in lldb.
Unfortunately, Rust doesn't have a "Rust LanguageRuntime" in lldb or really much of any support currently. The only mentions of Rust in the lldb sources are a recognizer for the Rust mangling scheme and a define that says "other than mangling, pretend Rust is C++". So that isn't a viable option at present.
You could also try calling Rust's print directly in the expression evaluator, but YMMV as calling Rust code in lldb doesn't always work: as it turns out, Rust is not C++...
From what I see here:
I can call "roundss" (SSE 4.2) by using the Rust intrinsic: core::arch::x86_64::_mm_round_ss.
but I'm unable to find an equivalent for "vroundss" (AVX?). Is there a way to call this instruction in Rust?
I found no match in Rust documentation for this specific instruction.
I'm currently in the progress of learning Rust. I'm mainly using The Rust Programming Language book and this nice reference which relates Rust features/syntax to C++ equivalents.
I'm having a hard time understanding where the core language stops and the standard library starts. I've encountered a lot of operators and/or traits which seems to have a special relationship with the compiler. For example, Rust has a trait (which from what I understand is like an interface) called Deref which let's a type implementing it be de-referenced using the * operator:
fn main() {
let x = 5;
let y = Box::new(x);
assert_eq!(5, x);
assert_eq!(5, *y);
}
Another example is the ? operator, which seems to depend on the Result and Option types.
Can code that uses those operators can be compiled without the standard library? And if not, what parts of the Rust language are depending on the standard library? Is it even possible to compile any Rust code without it?
The Rust standard library is in fact separated into three distinct crates:
core, which is the glue between the language and the standard library. All types, traits and functions required by the language are found in this crate. This includes operator traits (found in core::ops), the Future trait (used by async fn), and compiler intrinsics. The core crate does not have any dependencies, so you can always use it.
alloc, which contains types and traits related to or requiring dynamic memory allocation. This includes dynamically allocated types such as Box<T>, Vec<T> and String.
std, which contains the whole standard library, including things from core and alloc but also things with further requirements, such as file system access, networking, etc.
If your environment does not provide the functionality required by the std crate, you can choose to compile without it. If your environment also does not provide dynamic memory allocation, you can choose to compile without the alloc crate as well. This option is useful for targets such as embedded systems or writing operating systems, where you usually won't have all of the things that the standard library usually requires.
You can use the #![no_std] attribute in the root of your crate to tell the compiler to compile without the standard library (only core). Many libraries also usually support "no-std" compilation (e.g. base64 and futures), where functionality may be restricted but it will work when compiling without the std crate.
DISCLAIMER: This is likely not the answer you're looking for. Consider reading the other answers about no_std, if you're trying to solve a problem. I suggest you only read on, if you're interested in trivia about the inner workings of Rust.
If you really want full control over the environment you use, it is possible to use Rust without the core library using the no_core attribute.
If you decide to do so, you will run into some problems, because the compiler is integrated with some items defined in core.
This integration works by applying the #[lang = "..."] attribute to those items, making them so called "lang items".
If you use no_core, you'll have to define your own lang items for the parts of the language you'll actually use.
For more information I suggest the following blog posts, which go into more detail on the topic of lang items and no_core:
Rust Tidbits: What Is a Lang Item?
Oxidizing the technical interview
So yes, in theory it is possible to run Rust code without any sort of standard library and supplied types, but only if you then supply the required types yourself.
Also this is not stable and will likely never be stabilized and it is generally not a recommended way of using Rust.
When you're not using std, you rely on core, which is a subset of the std library which is always (?) available. This is what's called a no_std environment, which is commonly used for some types of "embedded" programming. You can find more about no_std in the Rust Embedded book, including some guidance on how to get started with no_std programming.
Does anyone know the general rule for exactly which LLVM IR code will be executed before main?
When using Clang++ 3.6, it seems that global class variables have their constructors called via a function in the ".text.startup" section of the object file. For example:
define internal void #__cxx_global_var_init() section ".text.startup" {
call void #_ZN7MyClassC2Ev(%class.MyClass* #M)
ret void
}
From this example, I'd guess that I should be looking for exactly those IR function definitions that specify section ".text.startup".
I have two reasons to suspect my theory is correct:
I don't see anything else in my LLVM IR file (.ll) suggesting that the global object constructors should be run first, if we assume that LLVM isn't sniffing for C++ -specific function names like "__cxx_global_var_init". So section ".text.startup" is the only obvious means of saying that code should run before main(). But even if that's correct, we've identified a sufficient condition for causing a function to run before main(), but haven't shown that it's the only way in LLVM IR to cause a function to run before main().
The Gnu linker, in some cases, will use the first instruction in the .text section to be the program entry point. This article on Raspberry Pi programming describes causing the .text.startup content to be the first body of code appearing in the program's .text section, as a means of causing the .text.startup code to run first.
Unfortunately I'm not finding much else to support my theory:
When I grep the LLVM 3.6 source code for the string ".startup", I only find it in the CLang-specific parts of the LLVM code. For my theory to be correct, I would expect to have found that string in other parts of the LLVM code as well; in particular, parts outside of the C++ front-end.
This article on data initialization in C++ seems to hint at ".text.startup" having a special role, but it doesn't come right out and say that the Linux program loader actually looks for a section of that name. Even if it did, I'd be surprised to find a potentially Linux-specific section name carrying special meaning in platform-neutral LLVM IR.
The Linux 3.13.0 source code doesn't seem to contain the string ".startup", suggesting to me that the program loader isn't sniffing for a section with the name ".text.startup".
The answer is pretty easy - LLVM is not executing anything behind the scenes. It's a job of the C runtime (CRT) to perform all necessary preparations before running main(). This includes (but not limited to) to static ctors and similar things. The runtime is usually informed about these objects via addresses of constructores being emitted in the special sections (e.g. .init_array or .ctors). See e.g. http://wiki.osdev.org/Calling_Global_Constructors for more information.
Google translate :
The interpreter is created, an array of bytes into the array in a machine language to cast the enum type and function, I have made an approach to dynamically execute a function, reference Please tell me if the machine-language site.
Babelfish translate:
It is to make the interpreter, but inserting machine language in arrangement at the byte unit, but if it is it makes function dynamically with the approach that it arranges the very the cast, it executes that in functional type through enum, there is a sight of the machine language which becomes reference, please teach.
Original question:
インタプリタを作っているのですが、機械語をバイト単位で配列に入れて
その配列をenumを通して関数型にキャストし、それを実行するというアプローチで関数を動的に作っているのですが、
参考になる機械語のサイトがあれば教えてください。
I'm going to make a guess - a pure guess:
You have an array of bytes containing the machine code for a function. How can you write a cast such that the function can be executed?
In which case, the answer is likely to be:
In most modern operating systems, the system protects you from converting data into executable code. The best way to deal with it would be to package the code as a function in a dynamically-loaded (shared) library, and then use the standard calls for the operating system to load that library and execute the function.