mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-20 05:56:32 +00:00
fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)
* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。
This commit is contained in:
@ -1150,7 +1150,9 @@ impl Syscall {
|
||||
back_color: u32,
|
||||
) -> Result<usize, SystemError> {
|
||||
// todo: 删除这个系统调用
|
||||
let s = check_and_clone_cstr(s, Some(4096))?;
|
||||
let s = check_and_clone_cstr(s, Some(4096))?
|
||||
.into_string()
|
||||
.map_err(|_| SystemError::EINVAL)?;
|
||||
let fr = (front_color & 0x00ff0000) >> 16;
|
||||
let fg = (front_color & 0x0000ff00) >> 8;
|
||||
let fb = front_color & 0x000000ff;
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
use core::{
|
||||
mem::size_of,
|
||||
num::NonZero,
|
||||
slice::{from_raw_parts, from_raw_parts_mut},
|
||||
};
|
||||
|
||||
use alloc::{string::String, vec::Vec};
|
||||
use alloc::{ffi::CString, vec::Vec};
|
||||
|
||||
use crate::mm::{verify_area, VirtAddr};
|
||||
|
||||
@ -70,10 +71,11 @@ pub unsafe fn copy_from_user(dst: &mut [u8], src: VirtAddr) -> Result<usize, Sys
|
||||
/// ## 错误
|
||||
///
|
||||
/// - `EFAULT`:用户态地址不合法
|
||||
/// - `EINVAL`:字符串不是合法的 C 字符串
|
||||
pub fn check_and_clone_cstr(
|
||||
user: *const u8,
|
||||
max_length: Option<usize>,
|
||||
) -> Result<String, SystemError> {
|
||||
) -> Result<CString, SystemError> {
|
||||
if user.is_null() {
|
||||
return Err(SystemError::EFAULT);
|
||||
}
|
||||
@ -93,9 +95,12 @@ pub fn check_and_clone_cstr(
|
||||
if c[0] == 0 {
|
||||
break;
|
||||
}
|
||||
buffer.push(c[0]);
|
||||
buffer.push(NonZero::new(c[0]).ok_or(SystemError::EINVAL)?);
|
||||
}
|
||||
String::from_utf8(buffer).map_err(|_| SystemError::EFAULT)
|
||||
|
||||
let cstr = CString::from(buffer);
|
||||
|
||||
return Ok(cstr);
|
||||
}
|
||||
|
||||
/// 检查并从用户态拷贝一个 C 字符串数组
|
||||
@ -112,7 +117,7 @@ pub fn check_and_clone_cstr(
|
||||
/// ## 错误
|
||||
///
|
||||
/// - `EFAULT`:用户态地址不合法
|
||||
pub fn check_and_clone_cstr_array(user: *const *const u8) -> Result<Vec<String>, SystemError> {
|
||||
pub fn check_and_clone_cstr_array(user: *const *const u8) -> Result<Vec<CString>, SystemError> {
|
||||
if user.is_null() {
|
||||
Ok(Vec::new())
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user