mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-20 18:26:32 +00:00
完善libc,构建了OS-specific工具链,编译了基于gcc-11.3.0的DragonOS userland compiler,移植了mpfr,gmp,mpc库 (#134)
* 修改include路径 * 添加了创建libsysapi.a和/bin/sysroot/usr/include/+lib/的代码 * 修补.gitignore * 删除多余项 * 优化脚本可读性 * 新增crt0 crti crtn * 编译binutils所需的东西 * fflush()和fprintf()的简单实现 * 应用程序启动前,调用初始化libc的函数 * 自动创建sysroot * 添加了stderr的初始化 * 修改了stderr的初始化 * 内核添加对stdio的简略处理 * 格式化代码 * 修正打开stdio文件描述符的问题 * bugfix: 修复fprintf忘记释放buf的问题 * 修复shell错误地把入口设置为main而不是_start的问题 * 新增__cxa_atexit (gcc要求libc提供这个) * 增加putchar puts * 更新写入磁盘镜像的脚本,默认无参数时,使用legacy方式安装 * 更新编译脚本 * stdio增加eof的定义 * 新增extern cplusplus * mpfr gmp mpc 构建脚本 * 更新libsysapi.a为libc.a * 加上ferror fopen fclose * 更新移植的软件的构建脚本 * 更改build_gcc_toolchain.sh中的-save参数名为-save-cache Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -136,7 +136,7 @@ unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned
|
||||
// 唤醒进程
|
||||
process_wakeup(tsk);
|
||||
|
||||
//创建对应procfs文件
|
||||
// 创建对应procfs文件
|
||||
procfs_register_pid(tsk->pid);
|
||||
|
||||
return retval;
|
||||
@ -188,8 +188,10 @@ int process_copy_files(uint64_t clone_flags, struct process_control_block *pcb)
|
||||
if (clone_flags & CLONE_FS)
|
||||
return retval;
|
||||
|
||||
// TODO: 这里是临时性的特殊处理stdio,待文件系统重构及tty设备实现后,需要改写这里
|
||||
process_open_stdio(current_pcb);
|
||||
// 为新进程拷贝新的文件描述符
|
||||
for (int i = 0; i < PROC_MAX_FD_NUM; ++i)
|
||||
for (int i = 3; i < PROC_MAX_FD_NUM; ++i)
|
||||
{
|
||||
if (current_pcb->fds[i] == NULL)
|
||||
continue;
|
||||
|
@ -409,6 +409,8 @@ ul do_execve(struct pt_regs *regs, char *path, char *argv[], char *envp[])
|
||||
|
||||
// 关闭之前的文件描述符
|
||||
process_exit_files(current_pcb);
|
||||
|
||||
process_open_stdio(current_pcb);
|
||||
|
||||
// 清除进程的vfork标志位
|
||||
current_pcb->flags &= ~PF_VFORK;
|
||||
@ -640,6 +642,10 @@ void process_init()
|
||||
|
||||
// 初始化init进程的signal相关的信息
|
||||
initial_proc_init_signal(current_pcb);
|
||||
|
||||
// TODO: 这里是临时性的特殊处理stdio,待文件系统重构及tty设备实现后,需要改写这里
|
||||
process_open_stdio(current_pcb);
|
||||
|
||||
// 临时设置IDLE进程的的虚拟运行时间为0,防止下面的这些内核线程的虚拟运行时间出错
|
||||
current_pcb->virtual_runtime = 0;
|
||||
barrier();
|
||||
@ -724,11 +730,13 @@ int process_wakeup_immediately(struct process_control_block *pcb)
|
||||
*/
|
||||
uint64_t process_exit_files(struct process_control_block *pcb)
|
||||
{
|
||||
// TODO: 当stdio不再被以-1来特殊处理时,在这里要释放stdio文件的内存
|
||||
|
||||
// 不与父进程共享文件描述符
|
||||
if (!(pcb->flags & PF_VFORK))
|
||||
{
|
||||
|
||||
for (int i = 0; i < PROC_MAX_FD_NUM; ++i)
|
||||
for (int i = 3; i < PROC_MAX_FD_NUM; ++i)
|
||||
{
|
||||
if (pcb->fds[i] == NULL)
|
||||
continue;
|
||||
@ -843,15 +851,15 @@ int process_release_pcb(struct process_control_block *pcb)
|
||||
int process_fd_alloc(struct vfs_file_t *file)
|
||||
{
|
||||
int fd_num = -1;
|
||||
struct vfs_file_t **f = current_pcb->fds;
|
||||
|
||||
for (int i = 0; i < PROC_MAX_FD_NUM; ++i)
|
||||
{
|
||||
// kdebug("currentpcb->fds[%d]=%#018lx", i, current_pcb->fds[i]);
|
||||
/* 找到指针数组中的空位 */
|
||||
if (f[i] == NULL)
|
||||
if (current_pcb->fds[i] == NULL)
|
||||
{
|
||||
fd_num = i;
|
||||
f[i] = file;
|
||||
current_pcb->fds[i] = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -882,3 +890,14 @@ void process_set_pcb_name(struct process_control_block *pcb, const char *pcb_nam
|
||||
{
|
||||
__set_pcb_name(pcb, pcb_name);
|
||||
}
|
||||
|
||||
void process_open_stdio(struct process_control_block *pcb)
|
||||
{
|
||||
// TODO: 这里是临时性的特殊处理stdio,待文件系统重构及tty设备实现后,需要改写这里
|
||||
// stdin
|
||||
pcb->fds[0] = -1UL;
|
||||
// stdout
|
||||
pcb->fds[1] = -1UL;
|
||||
// stderr
|
||||
pcb->fds[2] = -1UL;
|
||||
}
|
@ -220,4 +220,6 @@ extern int process_try_to_wake_up(struct process_control_block *_pcb, uint64_t _
|
||||
* @return false 唤醒失败
|
||||
*/
|
||||
extern int process_wake_up_state(struct process_control_block *pcb, uint64_t state);
|
||||
void __switch_to(struct process_control_block *prev, struct process_control_block *next);
|
||||
void __switch_to(struct process_control_block *prev, struct process_control_block *next);
|
||||
|
||||
void process_open_stdio(struct process_control_block * pcb);
|
@ -6,8 +6,8 @@
|
||||
#include <driver/disk/ahci/ahci.h>
|
||||
#include <exception/gate.h>
|
||||
#include <exception/irq.h>
|
||||
#include <filesystem/vfs/VFS.h>
|
||||
#include <filesystem/fat32/fat32.h>
|
||||
#include <filesystem/vfs/VFS.h>
|
||||
#include <mm/slab.h>
|
||||
#include <process/process.h>
|
||||
#include <time/sleep.h>
|
||||
@ -19,10 +19,10 @@ extern uint64_t sys_mstat(struct pt_regs *regs);
|
||||
extern uint64_t sys_open(struct pt_regs *regs);
|
||||
extern uint64_t sys_unlink_at(struct pt_regs *regs);
|
||||
extern uint64_t sys_kill(struct pt_regs *regs);
|
||||
extern uint64_t sys_sigaction(struct pt_regs * regs);
|
||||
extern uint64_t sys_rt_sigreturn(struct pt_regs * regs);
|
||||
extern uint64_t sys_getpid(struct pt_regs * regs);
|
||||
extern uint64_t sys_sched(struct pt_regs * regs);
|
||||
extern uint64_t sys_sigaction(struct pt_regs *regs);
|
||||
extern uint64_t sys_rt_sigreturn(struct pt_regs *regs);
|
||||
extern uint64_t sys_getpid(struct pt_regs *regs);
|
||||
extern uint64_t sys_sched(struct pt_regs *regs);
|
||||
|
||||
/**
|
||||
* @brief 导出系统调用处理函数的符号
|
||||
@ -173,6 +173,18 @@ uint64_t sys_read(struct pt_regs *regs)
|
||||
if (count < 0)
|
||||
return -EINVAL;
|
||||
|
||||
switch (fd_num)
|
||||
{
|
||||
case 0: // stdin
|
||||
return 0;
|
||||
break;
|
||||
case 1: // stdout
|
||||
return 0;
|
||||
break;
|
||||
case 2: // stderr
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
struct vfs_file_t *file_ptr = current_pcb->fds[fd_num];
|
||||
uint64_t ret = 0;
|
||||
if (file_ptr->file_ops && file_ptr->file_ops->read)
|
||||
@ -212,6 +224,20 @@ uint64_t sys_write(struct pt_regs *regs)
|
||||
if (count < 0)
|
||||
return -EINVAL;
|
||||
|
||||
switch (fd_num)
|
||||
{
|
||||
case 0: // stdin
|
||||
return 0;
|
||||
break;
|
||||
case 1: // stdout
|
||||
printk("%s", buf);
|
||||
return count;
|
||||
break;
|
||||
case 2: // stderr
|
||||
printk("%s", buf);
|
||||
return count;
|
||||
break;
|
||||
}
|
||||
struct vfs_file_t *file_ptr = current_pcb->fds[fd_num];
|
||||
uint64_t ret = 0;
|
||||
if (file_ptr->file_ops && file_ptr->file_ops->write)
|
||||
|
Reference in New Issue
Block a user