C未使用的指针参数
C unused pointer parameter
我在 Linux 来源中找到了以下函数定义:
static int __ref kernel_init(void *unused)
{
int ret;
kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
ftrace_free_init_mem();
free_initmem();
mark_readonly();
/*
* Kernel mappings are now finalized - update the userspace page-table
* to finalize PTI.
*/
pti_finalize();
system_state = SYSTEM_RUNNING;
numa_default_policy();
rcu_end_inkernel_boot();
if (ramdisk_execute_command) {
ret = run_init_process(ramdisk_execute_command);
if (!ret)
return 0;
pr_err("Failed to execute %s (error %d)\n",
ramdisk_execute_command, ret);
}
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
我的问题涉及函数的 unused 参数。我已经看到其他一些问题,其中可以使用 GCC 属性说明符将参数声明为未使用和其他一些技术,但是这个问题看起来会生成一些奇怪的编译器警告,因为我在这里没有看到任何抑制技术的使用。有谁知道这个参数在这里有什么用?
未使用的参数在那里,因为 kernel_init
是 运行 作为 kernel_thread
,它期望指向 int(void*)
函数的指针作为第一个参数。
来自here:
pid = kernel_thread(kernel_init, NULL, CLONE_FS);
我在 Linux 来源中找到了以下函数定义:
static int __ref kernel_init(void *unused)
{
int ret;
kernel_init_freeable();
/* need to finish all async __init code before freeing the memory */
async_synchronize_full();
ftrace_free_init_mem();
free_initmem();
mark_readonly();
/*
* Kernel mappings are now finalized - update the userspace page-table
* to finalize PTI.
*/
pti_finalize();
system_state = SYSTEM_RUNNING;
numa_default_policy();
rcu_end_inkernel_boot();
if (ramdisk_execute_command) {
ret = run_init_process(ramdisk_execute_command);
if (!ret)
return 0;
pr_err("Failed to execute %s (error %d)\n",
ramdisk_execute_command, ret);
}
/*
* We try each of these until one succeeds.
*
* The Bourne shell can be used instead of init if we are
* trying to recover a really broken machine.
*/
if (execute_command) {
ret = run_init_process(execute_command);
if (!ret)
return 0;
panic("Requested init %s failed (error %d).",
execute_command, ret);
}
if (!try_to_run_init_process("/sbin/init") ||
!try_to_run_init_process("/etc/init") ||
!try_to_run_init_process("/bin/init") ||
!try_to_run_init_process("/bin/sh"))
return 0;
panic("No working init found. Try passing init= option to kernel. "
"See Linux Documentation/admin-guide/init.rst for guidance.");
}
我的问题涉及函数的 unused 参数。我已经看到其他一些问题,其中可以使用 GCC 属性说明符将参数声明为未使用和其他一些技术,但是这个问题看起来会生成一些奇怪的编译器警告,因为我在这里没有看到任何抑制技术的使用。有谁知道这个参数在这里有什么用?
未使用的参数在那里,因为 kernel_init
是 运行 作为 kernel_thread
,它期望指向 int(void*)
函数的指针作为第一个参数。
来自here:
pid = kernel_thread(kernel_init, NULL, CLONE_FS);