1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 //! Printing facilities. 3 //! Printing facilities. 4 //! 4 //! 5 //! C header: [`include/linux/printk.h`](srctr !! 5 //! C header: [`include/linux/printk.h`](../../../../include/linux/printk.h) 6 //! 6 //! 7 //! Reference: <https://docs.kernel.org/core-a !! 7 //! Reference: <https://www.kernel.org/doc/html/latest/core-api/printk-basics.html> 8 8 9 use core::{ 9 use core::{ 10 ffi::{c_char, c_void}, 10 ffi::{c_char, c_void}, 11 fmt, 11 fmt, 12 }; 12 }; 13 13 14 use crate::str::RawFormatter; 14 use crate::str::RawFormatter; 15 15 >> 16 #[cfg(CONFIG_PRINTK)] >> 17 use crate::bindings; >> 18 16 // Called from `vsprintf` with format specifie 19 // Called from `vsprintf` with format specifier `%pA`. 17 #[no_mangle] 20 #[no_mangle] 18 unsafe extern "C" fn rust_fmt_argument( 21 unsafe extern "C" fn rust_fmt_argument( 19 buf: *mut c_char, 22 buf: *mut c_char, 20 end: *mut c_char, 23 end: *mut c_char, 21 ptr: *const c_void, 24 ptr: *const c_void, 22 ) -> *mut c_char { 25 ) -> *mut c_char { 23 use fmt::Write; 26 use fmt::Write; 24 // SAFETY: The C contract guarantees that 27 // SAFETY: The C contract guarantees that `buf` is valid if it's less than `end`. 25 let mut w = unsafe { RawFormatter::from_pt 28 let mut w = unsafe { RawFormatter::from_ptrs(buf.cast(), end.cast()) }; 26 let _ = w.write_fmt(unsafe { *(ptr as *con 29 let _ = w.write_fmt(unsafe { *(ptr as *const fmt::Arguments<'_>) }); 27 w.pos().cast() 30 w.pos().cast() 28 } 31 } 29 32 30 /// Format strings. 33 /// Format strings. 31 /// 34 /// 32 /// Public but hidden since it should only be 35 /// Public but hidden since it should only be used from public macros. 33 #[doc(hidden)] 36 #[doc(hidden)] 34 pub mod format_strings { 37 pub mod format_strings { >> 38 use crate::bindings; >> 39 35 /// The length we copy from the `KERN_*` k 40 /// The length we copy from the `KERN_*` kernel prefixes. 36 const LENGTH_PREFIX: usize = 2; 41 const LENGTH_PREFIX: usize = 2; 37 42 38 /// The length of the fixed format strings 43 /// The length of the fixed format strings. 39 pub const LENGTH: usize = 10; 44 pub const LENGTH: usize = 10; 40 45 41 /// Generates a fixed format string for th 46 /// Generates a fixed format string for the kernel's [`_printk`]. 42 /// 47 /// 43 /// The format string is always the same f 48 /// The format string is always the same for a given level, i.e. for a 44 /// given `prefix`, which are the kernel's 49 /// given `prefix`, which are the kernel's `KERN_*` constants. 45 /// 50 /// 46 /// [`_printk`]: srctree/include/linux/pri !! 51 /// [`_printk`]: ../../../../include/linux/printk.h 47 const fn generate(is_cont: bool, prefix: & 52 const fn generate(is_cont: bool, prefix: &[u8; 3]) -> [u8; LENGTH] { 48 // Ensure the `KERN_*` macros are what 53 // Ensure the `KERN_*` macros are what we expect. 49 assert!(prefix[0] == b'\x01'); 54 assert!(prefix[0] == b'\x01'); 50 if is_cont { 55 if is_cont { 51 assert!(prefix[1] == b'c'); 56 assert!(prefix[1] == b'c'); 52 } else { 57 } else { 53 assert!(prefix[1] >= b'0' && prefi 58 assert!(prefix[1] >= b'0' && prefix[1] <= b'7'); 54 } 59 } 55 assert!(prefix[2] == b'\x00'); 60 assert!(prefix[2] == b'\x00'); 56 61 57 let suffix: &[u8; LENGTH - LENGTH_PREF 62 let suffix: &[u8; LENGTH - LENGTH_PREFIX] = if is_cont { 58 b"%pA\0\0\0\0\0" 63 b"%pA\0\0\0\0\0" 59 } else { 64 } else { 60 b"%s: %pA\0" 65 b"%s: %pA\0" 61 }; 66 }; 62 67 63 [ 68 [ 64 prefix[0], prefix[1], suffix[0], s 69 prefix[0], prefix[1], suffix[0], suffix[1], suffix[2], suffix[3], suffix[4], suffix[5], 65 suffix[6], suffix[7], 70 suffix[6], suffix[7], 66 ] 71 ] 67 } 72 } 68 73 69 // Generate the format strings at compile- 74 // Generate the format strings at compile-time. 70 // 75 // 71 // This avoids the compiler generating the 76 // This avoids the compiler generating the contents on the fly in the stack. 72 // 77 // 73 // Furthermore, `static` instead of `const 78 // Furthermore, `static` instead of `const` is used to share the strings 74 // for all the kernel. 79 // for all the kernel. 75 pub static EMERG: [u8; LENGTH] = generate( 80 pub static EMERG: [u8; LENGTH] = generate(false, bindings::KERN_EMERG); 76 pub static ALERT: [u8; LENGTH] = generate( 81 pub static ALERT: [u8; LENGTH] = generate(false, bindings::KERN_ALERT); 77 pub static CRIT: [u8; LENGTH] = generate(f 82 pub static CRIT: [u8; LENGTH] = generate(false, bindings::KERN_CRIT); 78 pub static ERR: [u8; LENGTH] = generate(fa 83 pub static ERR: [u8; LENGTH] = generate(false, bindings::KERN_ERR); 79 pub static WARNING: [u8; LENGTH] = generat 84 pub static WARNING: [u8; LENGTH] = generate(false, bindings::KERN_WARNING); 80 pub static NOTICE: [u8; LENGTH] = generate 85 pub static NOTICE: [u8; LENGTH] = generate(false, bindings::KERN_NOTICE); 81 pub static INFO: [u8; LENGTH] = generate(f 86 pub static INFO: [u8; LENGTH] = generate(false, bindings::KERN_INFO); 82 pub static DEBUG: [u8; LENGTH] = generate( 87 pub static DEBUG: [u8; LENGTH] = generate(false, bindings::KERN_DEBUG); 83 pub static CONT: [u8; LENGTH] = generate(t 88 pub static CONT: [u8; LENGTH] = generate(true, bindings::KERN_CONT); 84 } 89 } 85 90 86 /// Prints a message via the kernel's [`_print 91 /// Prints a message via the kernel's [`_printk`]. 87 /// 92 /// 88 /// Public but hidden since it should only be 93 /// Public but hidden since it should only be used from public macros. 89 /// 94 /// 90 /// # Safety 95 /// # Safety 91 /// 96 /// 92 /// The format string must be one of the ones 97 /// The format string must be one of the ones in [`format_strings`], and 93 /// the module name must be null-terminated. 98 /// the module name must be null-terminated. 94 /// 99 /// 95 /// [`_printk`]: srctree/include/linux/_printk !! 100 /// [`_printk`]: ../../../../include/linux/_printk.h 96 #[doc(hidden)] 101 #[doc(hidden)] 97 #[cfg_attr(not(CONFIG_PRINTK), allow(unused_va 102 #[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))] 98 pub unsafe fn call_printk( 103 pub unsafe fn call_printk( 99 format_string: &[u8; format_strings::LENGT 104 format_string: &[u8; format_strings::LENGTH], 100 module_name: &[u8], 105 module_name: &[u8], 101 args: fmt::Arguments<'_>, 106 args: fmt::Arguments<'_>, 102 ) { 107 ) { 103 // `_printk` does not seem to fail in any 108 // `_printk` does not seem to fail in any path. 104 #[cfg(CONFIG_PRINTK)] 109 #[cfg(CONFIG_PRINTK)] 105 unsafe { 110 unsafe { 106 bindings::_printk( 111 bindings::_printk( 107 format_string.as_ptr() as _, 112 format_string.as_ptr() as _, 108 module_name.as_ptr(), 113 module_name.as_ptr(), 109 &args as *const _ as *const c_void 114 &args as *const _ as *const c_void, 110 ); 115 ); 111 } 116 } 112 } 117 } 113 118 114 /// Prints a message via the kernel's [`_print 119 /// Prints a message via the kernel's [`_printk`] for the `CONT` level. 115 /// 120 /// 116 /// Public but hidden since it should only be 121 /// Public but hidden since it should only be used from public macros. 117 /// 122 /// 118 /// [`_printk`]: srctree/include/linux/printk. !! 123 /// [`_printk`]: ../../../../include/linux/printk.h 119 #[doc(hidden)] 124 #[doc(hidden)] 120 #[cfg_attr(not(CONFIG_PRINTK), allow(unused_va 125 #[cfg_attr(not(CONFIG_PRINTK), allow(unused_variables))] 121 pub fn call_printk_cont(args: fmt::Arguments<' 126 pub fn call_printk_cont(args: fmt::Arguments<'_>) { 122 // `_printk` does not seem to fail in any 127 // `_printk` does not seem to fail in any path. 123 // 128 // 124 // SAFETY: The format string is fixed. 129 // SAFETY: The format string is fixed. 125 #[cfg(CONFIG_PRINTK)] 130 #[cfg(CONFIG_PRINTK)] 126 unsafe { 131 unsafe { 127 bindings::_printk( 132 bindings::_printk( 128 format_strings::CONT.as_ptr() as _ 133 format_strings::CONT.as_ptr() as _, 129 &args as *const _ as *const c_void 134 &args as *const _ as *const c_void, 130 ); 135 ); 131 } 136 } 132 } 137 } 133 138 134 /// Performs formatting and forwards the strin 139 /// Performs formatting and forwards the string to [`call_printk`]. 135 /// 140 /// 136 /// Public but hidden since it should only be 141 /// Public but hidden since it should only be used from public macros. 137 #[doc(hidden)] 142 #[doc(hidden)] 138 #[cfg(not(testlib))] 143 #[cfg(not(testlib))] 139 #[macro_export] 144 #[macro_export] 140 #[allow(clippy::crate_in_macro_def)] 145 #[allow(clippy::crate_in_macro_def)] 141 macro_rules! print_macro ( 146 macro_rules! print_macro ( 142 // The non-continuation cases (most of the 147 // The non-continuation cases (most of them, e.g. `INFO`). 143 ($format_string:path, false, $($arg:tt)+) 148 ($format_string:path, false, $($arg:tt)+) => ( 144 // To remain sound, `arg`s must be exp 149 // To remain sound, `arg`s must be expanded outside the `unsafe` block. 145 // Typically one would use a `let` bin 150 // Typically one would use a `let` binding for that; however, `format_args!` 146 // takes borrows on the arguments, but 151 // takes borrows on the arguments, but does not extend the scope of temporaries. 147 // Therefore, a `match` expression is 152 // Therefore, a `match` expression is used to keep them around, since 148 // the scrutinee is kept until the end 153 // the scrutinee is kept until the end of the `match`. 149 match format_args!($($arg)+) { 154 match format_args!($($arg)+) { 150 // SAFETY: This hidden macro shoul 155 // SAFETY: This hidden macro should only be called by the documented 151 // printing macros which ensure th 156 // printing macros which ensure the format string is one of the fixed 152 // ones. All `__LOG_PREFIX`s are n 157 // ones. All `__LOG_PREFIX`s are null-terminated as they are generated 153 // by the `module!` proc macro or 158 // by the `module!` proc macro or fixed values defined in a kernel 154 // crate. 159 // crate. 155 args => unsafe { 160 args => unsafe { 156 $crate::print::call_printk( 161 $crate::print::call_printk( 157 &$format_string, 162 &$format_string, 158 crate::__LOG_PREFIX, 163 crate::__LOG_PREFIX, 159 args, 164 args, 160 ); 165 ); 161 } 166 } 162 } 167 } 163 ); 168 ); 164 169 165 // The `CONT` case. 170 // The `CONT` case. 166 ($format_string:path, true, $($arg:tt)+) = 171 ($format_string:path, true, $($arg:tt)+) => ( 167 $crate::print::call_printk_cont( 172 $crate::print::call_printk_cont( 168 format_args!($($arg)+), 173 format_args!($($arg)+), 169 ); 174 ); 170 ); 175 ); 171 ); 176 ); 172 177 173 /// Stub for doctests 178 /// Stub for doctests 174 #[cfg(testlib)] 179 #[cfg(testlib)] 175 #[macro_export] 180 #[macro_export] 176 macro_rules! print_macro ( 181 macro_rules! print_macro ( 177 ($format_string:path, $e:expr, $($arg:tt)+ 182 ($format_string:path, $e:expr, $($arg:tt)+) => ( 178 () 183 () 179 ); 184 ); 180 ); 185 ); 181 186 182 // We could use a macro to generate these macr 187 // We could use a macro to generate these macros. However, doing so ends 183 // up being a bit ugly: it requires the dollar 188 // up being a bit ugly: it requires the dollar token trick to escape `$` as 184 // well as playing with the `doc` attribute. F 189 // well as playing with the `doc` attribute. Furthermore, they cannot be easily 185 // imported in the prelude due to [1]. So, for 190 // imported in the prelude due to [1]. So, for the moment, we just write them 186 // manually, like in the C side; while keeping 191 // manually, like in the C side; while keeping most of the logic in another 187 // macro, i.e. [`print_macro`]. 192 // macro, i.e. [`print_macro`]. 188 // 193 // 189 // [1]: https://github.com/rust-lang/rust/issu 194 // [1]: https://github.com/rust-lang/rust/issues/52234 190 195 191 /// Prints an emergency-level message (level 0 196 /// Prints an emergency-level message (level 0). 192 /// 197 /// 193 /// Use this level if the system is unusable. 198 /// Use this level if the system is unusable. 194 /// 199 /// 195 /// Equivalent to the kernel's [`pr_emerg`] ma 200 /// Equivalent to the kernel's [`pr_emerg`] macro. 196 /// 201 /// 197 /// Mimics the interface of [`std::print!`]. S 202 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 198 /// `alloc::format!` for information about the 203 /// `alloc::format!` for information about the formatting syntax. 199 /// 204 /// 200 /// [`pr_emerg`]: https://docs.kernel.org/core !! 205 /// [`pr_emerg`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_emerg 201 /// [`std::print!`]: https://doc.rust-lang.org 206 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 202 /// 207 /// 203 /// # Examples 208 /// # Examples 204 /// 209 /// 205 /// ``` 210 /// ``` 206 /// pr_emerg!("hello {}\n", "there"); 211 /// pr_emerg!("hello {}\n", "there"); 207 /// ``` 212 /// ``` 208 #[macro_export] 213 #[macro_export] 209 macro_rules! pr_emerg ( 214 macro_rules! pr_emerg ( 210 ($($arg:tt)*) => ( 215 ($($arg:tt)*) => ( 211 $crate::print_macro!($crate::print::fo 216 $crate::print_macro!($crate::print::format_strings::EMERG, false, $($arg)*) 212 ) 217 ) 213 ); 218 ); 214 219 215 /// Prints an alert-level message (level 1). 220 /// Prints an alert-level message (level 1). 216 /// 221 /// 217 /// Use this level if action must be taken imm 222 /// Use this level if action must be taken immediately. 218 /// 223 /// 219 /// Equivalent to the kernel's [`pr_alert`] ma 224 /// Equivalent to the kernel's [`pr_alert`] macro. 220 /// 225 /// 221 /// Mimics the interface of [`std::print!`]. S 226 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 222 /// `alloc::format!` for information about the 227 /// `alloc::format!` for information about the formatting syntax. 223 /// 228 /// 224 /// [`pr_alert`]: https://docs.kernel.org/core !! 229 /// [`pr_alert`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_alert 225 /// [`std::print!`]: https://doc.rust-lang.org 230 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 226 /// 231 /// 227 /// # Examples 232 /// # Examples 228 /// 233 /// 229 /// ``` 234 /// ``` 230 /// pr_alert!("hello {}\n", "there"); 235 /// pr_alert!("hello {}\n", "there"); 231 /// ``` 236 /// ``` 232 #[macro_export] 237 #[macro_export] 233 macro_rules! pr_alert ( 238 macro_rules! pr_alert ( 234 ($($arg:tt)*) => ( 239 ($($arg:tt)*) => ( 235 $crate::print_macro!($crate::print::fo 240 $crate::print_macro!($crate::print::format_strings::ALERT, false, $($arg)*) 236 ) 241 ) 237 ); 242 ); 238 243 239 /// Prints a critical-level message (level 2). 244 /// Prints a critical-level message (level 2). 240 /// 245 /// 241 /// Use this level for critical conditions. 246 /// Use this level for critical conditions. 242 /// 247 /// 243 /// Equivalent to the kernel's [`pr_crit`] mac 248 /// Equivalent to the kernel's [`pr_crit`] macro. 244 /// 249 /// 245 /// Mimics the interface of [`std::print!`]. S 250 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 246 /// `alloc::format!` for information about the 251 /// `alloc::format!` for information about the formatting syntax. 247 /// 252 /// 248 /// [`pr_crit`]: https://docs.kernel.org/core- !! 253 /// [`pr_crit`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_crit 249 /// [`std::print!`]: https://doc.rust-lang.org 254 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 250 /// 255 /// 251 /// # Examples 256 /// # Examples 252 /// 257 /// 253 /// ``` 258 /// ``` 254 /// pr_crit!("hello {}\n", "there"); 259 /// pr_crit!("hello {}\n", "there"); 255 /// ``` 260 /// ``` 256 #[macro_export] 261 #[macro_export] 257 macro_rules! pr_crit ( 262 macro_rules! pr_crit ( 258 ($($arg:tt)*) => ( 263 ($($arg:tt)*) => ( 259 $crate::print_macro!($crate::print::fo 264 $crate::print_macro!($crate::print::format_strings::CRIT, false, $($arg)*) 260 ) 265 ) 261 ); 266 ); 262 267 263 /// Prints an error-level message (level 3). 268 /// Prints an error-level message (level 3). 264 /// 269 /// 265 /// Use this level for error conditions. 270 /// Use this level for error conditions. 266 /// 271 /// 267 /// Equivalent to the kernel's [`pr_err`] macr 272 /// Equivalent to the kernel's [`pr_err`] macro. 268 /// 273 /// 269 /// Mimics the interface of [`std::print!`]. S 274 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 270 /// `alloc::format!` for information about the 275 /// `alloc::format!` for information about the formatting syntax. 271 /// 276 /// 272 /// [`pr_err`]: https://docs.kernel.org/core-a !! 277 /// [`pr_err`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_err 273 /// [`std::print!`]: https://doc.rust-lang.org 278 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 274 /// 279 /// 275 /// # Examples 280 /// # Examples 276 /// 281 /// 277 /// ``` 282 /// ``` 278 /// pr_err!("hello {}\n", "there"); 283 /// pr_err!("hello {}\n", "there"); 279 /// ``` 284 /// ``` 280 #[macro_export] 285 #[macro_export] 281 macro_rules! pr_err ( 286 macro_rules! pr_err ( 282 ($($arg:tt)*) => ( 287 ($($arg:tt)*) => ( 283 $crate::print_macro!($crate::print::fo 288 $crate::print_macro!($crate::print::format_strings::ERR, false, $($arg)*) 284 ) 289 ) 285 ); 290 ); 286 291 287 /// Prints a warning-level message (level 4). 292 /// Prints a warning-level message (level 4). 288 /// 293 /// 289 /// Use this level for warning conditions. 294 /// Use this level for warning conditions. 290 /// 295 /// 291 /// Equivalent to the kernel's [`pr_warn`] mac 296 /// Equivalent to the kernel's [`pr_warn`] macro. 292 /// 297 /// 293 /// Mimics the interface of [`std::print!`]. S 298 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 294 /// `alloc::format!` for information about the 299 /// `alloc::format!` for information about the formatting syntax. 295 /// 300 /// 296 /// [`pr_warn`]: https://docs.kernel.org/core- !! 301 /// [`pr_warn`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_warn 297 /// [`std::print!`]: https://doc.rust-lang.org 302 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 298 /// 303 /// 299 /// # Examples 304 /// # Examples 300 /// 305 /// 301 /// ``` 306 /// ``` 302 /// pr_warn!("hello {}\n", "there"); 307 /// pr_warn!("hello {}\n", "there"); 303 /// ``` 308 /// ``` 304 #[macro_export] 309 #[macro_export] 305 macro_rules! pr_warn ( 310 macro_rules! pr_warn ( 306 ($($arg:tt)*) => ( 311 ($($arg:tt)*) => ( 307 $crate::print_macro!($crate::print::fo 312 $crate::print_macro!($crate::print::format_strings::WARNING, false, $($arg)*) 308 ) 313 ) 309 ); 314 ); 310 315 311 /// Prints a notice-level message (level 5). 316 /// Prints a notice-level message (level 5). 312 /// 317 /// 313 /// Use this level for normal but significant 318 /// Use this level for normal but significant conditions. 314 /// 319 /// 315 /// Equivalent to the kernel's [`pr_notice`] m 320 /// Equivalent to the kernel's [`pr_notice`] macro. 316 /// 321 /// 317 /// Mimics the interface of [`std::print!`]. S 322 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 318 /// `alloc::format!` for information about the 323 /// `alloc::format!` for information about the formatting syntax. 319 /// 324 /// 320 /// [`pr_notice`]: https://docs.kernel.org/cor !! 325 /// [`pr_notice`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_notice 321 /// [`std::print!`]: https://doc.rust-lang.org 326 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 322 /// 327 /// 323 /// # Examples 328 /// # Examples 324 /// 329 /// 325 /// ``` 330 /// ``` 326 /// pr_notice!("hello {}\n", "there"); 331 /// pr_notice!("hello {}\n", "there"); 327 /// ``` 332 /// ``` 328 #[macro_export] 333 #[macro_export] 329 macro_rules! pr_notice ( 334 macro_rules! pr_notice ( 330 ($($arg:tt)*) => ( 335 ($($arg:tt)*) => ( 331 $crate::print_macro!($crate::print::fo 336 $crate::print_macro!($crate::print::format_strings::NOTICE, false, $($arg)*) 332 ) 337 ) 333 ); 338 ); 334 339 335 /// Prints an info-level message (level 6). 340 /// Prints an info-level message (level 6). 336 /// 341 /// 337 /// Use this level for informational messages. 342 /// Use this level for informational messages. 338 /// 343 /// 339 /// Equivalent to the kernel's [`pr_info`] mac 344 /// Equivalent to the kernel's [`pr_info`] macro. 340 /// 345 /// 341 /// Mimics the interface of [`std::print!`]. S 346 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 342 /// `alloc::format!` for information about the 347 /// `alloc::format!` for information about the formatting syntax. 343 /// 348 /// 344 /// [`pr_info`]: https://docs.kernel.org/core- !! 349 /// [`pr_info`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_info 345 /// [`std::print!`]: https://doc.rust-lang.org 350 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 346 /// 351 /// 347 /// # Examples 352 /// # Examples 348 /// 353 /// 349 /// ``` 354 /// ``` 350 /// pr_info!("hello {}\n", "there"); 355 /// pr_info!("hello {}\n", "there"); 351 /// ``` 356 /// ``` 352 #[macro_export] 357 #[macro_export] 353 #[doc(alias = "print")] 358 #[doc(alias = "print")] 354 macro_rules! pr_info ( 359 macro_rules! pr_info ( 355 ($($arg:tt)*) => ( 360 ($($arg:tt)*) => ( 356 $crate::print_macro!($crate::print::fo 361 $crate::print_macro!($crate::print::format_strings::INFO, false, $($arg)*) 357 ) 362 ) 358 ); 363 ); 359 364 360 /// Prints a debug-level message (level 7). 365 /// Prints a debug-level message (level 7). 361 /// 366 /// 362 /// Use this level for debug messages. 367 /// Use this level for debug messages. 363 /// 368 /// 364 /// Equivalent to the kernel's [`pr_debug`] ma 369 /// Equivalent to the kernel's [`pr_debug`] macro, except that it doesn't support dynamic debug 365 /// yet. 370 /// yet. 366 /// 371 /// 367 /// Mimics the interface of [`std::print!`]. S 372 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 368 /// `alloc::format!` for information about the 373 /// `alloc::format!` for information about the formatting syntax. 369 /// 374 /// 370 /// [`pr_debug`]: https://docs.kernel.org/core !! 375 /// [`pr_debug`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_debug 371 /// [`std::print!`]: https://doc.rust-lang.org 376 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 372 /// 377 /// 373 /// # Examples 378 /// # Examples 374 /// 379 /// 375 /// ``` 380 /// ``` 376 /// pr_debug!("hello {}\n", "there"); 381 /// pr_debug!("hello {}\n", "there"); 377 /// ``` 382 /// ``` 378 #[macro_export] 383 #[macro_export] 379 #[doc(alias = "print")] 384 #[doc(alias = "print")] 380 macro_rules! pr_debug ( 385 macro_rules! pr_debug ( 381 ($($arg:tt)*) => ( 386 ($($arg:tt)*) => ( 382 if cfg!(debug_assertions) { 387 if cfg!(debug_assertions) { 383 $crate::print_macro!($crate::print 388 $crate::print_macro!($crate::print::format_strings::DEBUG, false, $($arg)*) 384 } 389 } 385 ) 390 ) 386 ); 391 ); 387 392 388 /// Continues a previous log message in the sa 393 /// Continues a previous log message in the same line. 389 /// 394 /// 390 /// Use only when continuing a previous `pr_*! 395 /// Use only when continuing a previous `pr_*!` macro (e.g. [`pr_info!`]). 391 /// 396 /// 392 /// Equivalent to the kernel's [`pr_cont`] mac 397 /// Equivalent to the kernel's [`pr_cont`] macro. 393 /// 398 /// 394 /// Mimics the interface of [`std::print!`]. S 399 /// Mimics the interface of [`std::print!`]. See [`core::fmt`] and 395 /// `alloc::format!` for information about the 400 /// `alloc::format!` for information about the formatting syntax. 396 /// 401 /// 397 /// [`pr_info!`]: crate::pr_info! !! 402 /// [`pr_cont`]: https://www.kernel.org/doc/html/latest/core-api/printk-basics.html#c.pr_cont 398 /// [`pr_cont`]: https://docs.kernel.org/core- << 399 /// [`std::print!`]: https://doc.rust-lang.org 403 /// [`std::print!`]: https://doc.rust-lang.org/std/macro.print.html 400 /// 404 /// 401 /// # Examples 405 /// # Examples 402 /// 406 /// 403 /// ``` 407 /// ``` 404 /// # use kernel::pr_cont; 408 /// # use kernel::pr_cont; 405 /// pr_info!("hello"); 409 /// pr_info!("hello"); 406 /// pr_cont!(" {}\n", "there"); 410 /// pr_cont!(" {}\n", "there"); 407 /// ``` 411 /// ``` 408 #[macro_export] 412 #[macro_export] 409 macro_rules! pr_cont ( 413 macro_rules! pr_cont ( 410 ($($arg:tt)*) => ( 414 ($($arg:tt)*) => ( 411 $crate::print_macro!($crate::print::fo 415 $crate::print_macro!($crate::print::format_strings::CONT, true, $($arg)*) 412 ) 416 ) 413 ); 417 );
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.