call _strlen后,结果存放在哪里
时间: 2024-04-01 09:31:22 浏览: 8
在这段代码中,`_strlen` 函数返回的字符串长度被存储在栈中,具体的存储位置为 `[esp+7Ch]`。其中 `esp` 是当前栈指针的值,`7Ch` 是一个偏移量,表示从栈顶向下偏移了 `7Ch` 个字节的位置。因此,通过将返回值存储在 `[esp+7Ch]` 的位置,可以将字符串长度传递给调用者。
相关问题
call _strlen后结果会不会存放到eax中
在这段代码中,`_strlen` 函数的返回值(即字符串长度)确实存储在了 `eax` 寄存器中,但是在该段代码中并没有将 `eax` 中的值直接使用,而是将其存储到了 `[esp+7Ch]` 的内存位置。这是因为在函数调用过程中,函数的返回值通常是存储在寄存器中的,但是为了在调用函数后能够使用这个返回值,必须将其存储到内存中。因此,虽然 `eax` 中存储了 `_strlen` 函数的返回值,但是它并不是这段代码的最终结果。
安卓内核内如何在关机的时候保存一个变量,开机时再获取
在安卓内核中,在关机时保存一个变量,开机时再获取,可以通过以下步骤实现:
1. 定义一个需要保存的变量,可以通过定义全局变量或者定义一个驱动的属性来实现。
2. 在系统关机时,将变量的值保存到一个持久化存储介质中,比如说硬盘、eMMC、NAND Flash等。
3. 在系统开机时,从持久化存储介质中读取变量的值,并将其设置到内核中。
具体实现可以参考以下步骤:
1. 定义需要保存的变量
可以在内核中定义一个全局变量,比如说:
```
static int shutdown_var;
```
或者定义一个驱动属性:
```
static DEVICE_ATTR(shutdown_var, 0644, my_show, my_store);
```
2. 在系统关机时保存变量的值
可以使用系统关机时的钩子函数来保存变量的值,比如说:
```
static int my_shutdown(struct notifier_block *nb, unsigned long action, void *data)
{
struct file *fp;
int ret;
char buf[20];
fp = filp_open("/data/shutdown_var", O_WRONLY | O_CREAT, 0644);
if (IS_ERR(fp)) {
return PTR_ERR(fp);
}
snprintf(buf, sizeof(buf), "%d\n", shutdown_var);
ret = kernel_write(fp, buf, strlen(buf), 0);
filp_close(fp, NULL);
return ret;
}
static struct notifier_block my_notifier_block = {
.notifier_call = my_shutdown,
};
```
在上面的例子中,我们将变量的值写入到了`/data/shutdown_var`文件中。
3. 在系统开机时获取变量的值
可以在驱动的初始化函数中从持久化存储介质中读取变量的值,比如说:
```
static int my_driver_probe(struct platform_device *pdev)
{
struct file *fp;
char buf[20];
int ret;
fp = filp_open("/data/shutdown_var", O_RDONLY, 0);
if (IS_ERR(fp)) {
return PTR_ERR(fp);
}
ret = kernel_read(fp, buf, sizeof(buf), 0);
filp_close(fp, NULL);
if (ret > 0) {
shutdown_var = simple_strtol(buf, NULL, 10);
}
return 0;
}
```
在上面的例子中,我们从`/data/shutdown_var`文件中读取变量的值,并将其设置到全局变量`shutdown_var`中。
需要注意的是,在执行读写文件的操作时,需要确保持久化存储介质已经被挂载并且可用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)