Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zlm 第一阶段任务二(王之栋) #17

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added apps/c/arch_prctl/arch_prctl
Binary file not shown.
31 changes: 31 additions & 0 deletions apps/c/arch_prctl/arch_prctl_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdint.h>
#include <sys/prctl.h>
#include <asm/prctl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main() {
//获取当前 FS 寄存器的值
unsigned long* current_fs_value = 0;
if (arch_prctl(ARCH_GET_FS, &current_fs_value) != 0) {
perror("arch_prctl(ARCH_GET_FS)");
return 1;
}
printf("Current FS value set: 0x%lx\n", current_fs_value);

// 设置新的 FS 寄存器的值
unsigned long new_fs_value = current_fs_value;
if (arch_prctl(ARCH_SET_FS, new_fs_value) != 0) {
perror("arch_prctl(ARCH_SET_FS)");
return 1;
}

printf("New FS value set: 0x%lx\n", new_fs_value);

return 0;
}
15 changes: 15 additions & 0 deletions apps/c/futex/futex.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/futex.h>

int main() {
int futex_var = 0;

// 创建一个 futex,初始值为 0
int *futex_ptr = &futex_var;

// 唤醒等待在 futex 上的线程(私有唤醒)
syscall(SYS_futex, futex_ptr, FUTEX_WAKE_PRIVATE, 1, NULL, NULL, 0);

return 0;
}
Binary file added testcases/testsuits-x86_64-linux-musl/arch_prctl
Binary file not shown.
Binary file added testcases/testsuits-x86_64-linux-musl/futex
Binary file not shown.
1 change: 1 addition & 0 deletions ulib/axstarry/syscall_entry/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ pub const OSTRAIN_TESTCASES: &[&str] = &[
pub const SDCARD_TESTCASES: &[&str] = &[
// "busybox sh",
"./MediaServer -h",
// "./arch_prctl",
// "busybox sh ./test_all.sh",
// "./riscv64-linux-musl-native/bin/riscv64-linux-musl-gcc ./hello.c -static",
// "./a.out",
Expand Down
15 changes: 11 additions & 4 deletions ulib/axstarry/syscall_task/src/imp/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ pub fn syscall_setsid() -> SyscallResult {

/// arch_prc
#[cfg(target_arch = "x86_64")]
pub fn syscall_arch_prctl(code: usize, addr: usize) -> SyscallResult {
pub fn syscall_arch_prctl(code: usize, addr: *mut usize) -> SyscallResult {
/*
#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
Expand All @@ -428,15 +428,22 @@ pub fn syscall_arch_prctl(code: usize, addr: usize) -> SyscallResult {
0x1002 => {
#[cfg(target_arch = "x86_64")]
unsafe {
axhal::arch::write_thread_pointer(addr);
axhal::arch::write_thread_pointer(*addr as usize);
// *(read_thread_pointer() as *mut usize) = addr;
}
Ok(0)
}
0x1001 | 0x1003 | 0x1004 => todo!(),
0x1003 => {
#[cfg(target_arch = "x86_64")]
unsafe {
*addr = *(axhal::arch::read_thread_pointer() as *mut usize);
}
Ok(0)
}
0x1001 | 0x1004 => todo!(),
_ => Err(SyscallError::EINVAL)
}
// Ok(0)
//Ok(0)
}

pub fn syscall_fork() -> SyscallResult {
Expand Down
2 changes: 1 addition & 1 deletion ulib/axstarry/syscall_task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn task_syscall(syscall_id: task_syscall_id::TaskSyscallId, args: [usize; 6]
SOCKETPAIR => Err(SyscallError::EAFNOSUPPORT),
// syscall below just for x86_64
#[cfg(target_arch = "x86_64")]
ARCH_PRCTL => syscall_arch_prctl(args[0], args[1]),
ARCH_PRCTL => syscall_arch_prctl(args[0], args[1] as *mut usize),
#[cfg(target_arch = "x86_64")]
FORK => syscall_fork(),
#[cfg(target_arch = "x86_64")]
Expand Down
Loading