remove unnecessary "extern "C"" annotations

This commit is contained in:
Garen Tyler 2023-10-31 15:28:28 -06:00
parent ac33c19b5f
commit fa9daf279b
Signed by: garentyler
GPG Key ID: D7A048C454CB7054
15 changed files with 229 additions and 219 deletions

89
externs.txt Normal file
View File

@ -0,0 +1,89 @@
kernel/rustkernel/src/console/printf.rs:32:pub extern "C" fn printint(n: i32) {
kernel/rustkernel/src/console/printf.rs:37:pub extern "C" fn printhex(n: i32) {
kernel/rustkernel/src/console/printf.rs:42:pub extern "C" fn printptr(p: u64) {
kernel/rustkernel/src/console/printf.rs:47:pub unsafe extern "C" fn printstr(s: *const c_char) {
kernel/rustkernel/src/lib.rs:60:pub unsafe extern "C" fn main() -> ! {
kernel/rustkernel/src/lib.rs:126:pub unsafe extern "C" fn panic(_: *const c_char) -> ! {
kernel/rustkernel/src/string.rs:13:pub unsafe extern "C" fn strlen(s: *const c_char) -> i32 {
kernel/rustkernel/src/string.rs:18:pub unsafe extern "C" fn strncmp(mut a: *const u8, mut b: *const u8, mut max_chars: u32) -> i32 {
kernel/rustkernel/src/string.rs:32:pub unsafe extern "C" fn strncpy(
kernel/rustkernel/src/string.rs:56:pub unsafe extern "C" fn safestrcpy(
kernel/rustkernel/src/start.rs:17:pub unsafe extern "C" fn start() {
kernel/rustkernel/src/start.rs:57:pub unsafe extern "C" fn timerinit() {
kernel/rustkernel/src/fs/file.rs:142:pub unsafe extern "C" fn filealloc() -> *mut File {
kernel/rustkernel/src/fs/file.rs:157:pub unsafe extern "C" fn filedup(file: *mut File) -> *mut File {
kernel/rustkernel/src/fs/file.rs:173:pub unsafe extern "C" fn fileclose(file: *mut File) {
kernel/rustkernel/src/fs/file.rs:203:pub unsafe extern "C" fn filestat(file: *mut File, addr: u64) -> i32 {
kernel/rustkernel/src/fs/file.rs:233:pub unsafe extern "C" fn fileread(file: *mut File, addr: u64, n: i32) -> i32 {
kernel/rustkernel/src/fs/file.rs:266:pub unsafe extern "C" fn filewrite(file: *mut File, addr: u64, n: i32) -> i32 {
kernel/rustkernel/src/trap.rs:26:pub unsafe extern "C" fn trapinithart() {
kernel/rustkernel/src/trap.rs:31:pub unsafe extern "C" fn clockintr() {
kernel/rustkernel/src/trap.rs:44:pub unsafe extern "C" fn devintr() -> i32 {
kernel/rustkernel/src/trap.rs:129:pub unsafe extern "C" fn usertrapret() {
kernel/rustkernel/src/trap.rs:183:pub unsafe extern "C" fn kerneltrap() {
kernel/rustkernel/src/trap.rs:213:pub unsafe extern "C" fn usertrap() {
kernel/rustkernel/src/trap.rs:274:pub unsafe extern "C" fn push_intr_off() {
kernel/rustkernel/src/trap.rs:285:pub unsafe extern "C" fn pop_intr_off() {
kernel/rustkernel/src/io/pipe.rs:46:pub unsafe extern "C" fn pipealloc(a: *mut *mut File, b: *mut *mut File) -> i32 {
kernel/rustkernel/src/io/pipe.rs:78:pub unsafe extern "C" fn pipeclose(pipe: *mut Pipe, writable: i32) {
kernel/rustkernel/src/io/pipe.rs:95:pub unsafe extern "C" fn pipewrite(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
kernel/rustkernel/src/io/pipe.rs:124:pub unsafe extern "C" fn piperead(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
kernel/rustkernel/src/io/bio.rs:56:// pub unsafe extern "C" fn bget(dev: u32, blockno: u32) -> *mut Buffer {
kernel/rustkernel/src/io/bio.rs:93:// pub unsafe extern "C" fn bread(dev: u32, blockno: u32) -> *mut Buffer {
kernel/rustkernel/src/io/bio.rs:105:// pub unsafe extern "C" fn bwrite(b: *mut Buffer) {
kernel/rustkernel/src/io/bio.rs:115:// pub unsafe extern "C" fn bpin(b: *mut Buffer) {
kernel/rustkernel/src/io/bio.rs:122:// pub unsafe extern "C" fn bunpin(b: *mut Buffer) {
kernel/rustkernel/src/proc.rs:228:pub unsafe extern "C" fn cpuid() -> i32 {
kernel/rustkernel/src/proc.rs:235:pub unsafe extern "C" fn mycpu() -> *mut Cpu {
kernel/rustkernel/src/proc.rs:242:pub unsafe extern "C" fn myproc() -> *mut Proc {
kernel/rustkernel/src/proc.rs:249:pub unsafe extern "C" fn allocpid() -> i32 {
kernel/rustkernel/src/proc.rs:259:pub unsafe extern "C" fn freeproc(p: *mut Proc) {
kernel/rustkernel/src/proc.rs:281:pub unsafe extern "C" fn reparent(p: *mut Proc) {
kernel/rustkernel/src/proc.rs:293:pub unsafe extern "C" fn growproc(n: i32) -> i32 {
kernel/rustkernel/src/proc.rs:311:pub unsafe extern "C" fn r#yield() {
kernel/rustkernel/src/proc.rs:326:pub unsafe extern "C" fn sched() {
kernel/rustkernel/src/proc.rs:346:pub unsafe extern "C" fn sleep_lock(chan: *mut c_void, lock: *mut Spinlock) {
kernel/rustkernel/src/proc.rs:372:pub unsafe extern "C" fn kill(pid: i32) -> i32 {
kernel/rustkernel/src/proc.rs:391:pub unsafe extern "C" fn setkilled(p: *mut Proc) {
kernel/rustkernel/src/proc.rs:397:pub unsafe extern "C" fn killed(p: *mut Proc) -> i32 {
kernel/rustkernel/src/syscall.rs:185:pub unsafe extern "C" fn fetchaddr(addr: u64, ip: *mut u64) -> i32 {
kernel/rustkernel/src/syscall.rs:208:pub unsafe extern "C" fn fetchstr(addr: u64, buf: *mut u8, max: i32) -> i32 {
kernel/rustkernel/src/syscall.rs:218:pub unsafe extern "C" fn argraw(n: i32) -> u64 {
kernel/rustkernel/src/syscall.rs:233:pub unsafe extern "C" fn argint(n: i32, ip: *mut i32) {
kernel/rustkernel/src/syscall.rs:242:pub unsafe extern "C" fn argaddr(n: i32, ip: *mut u64) {
kernel/rustkernel/src/syscall.rs:251:pub unsafe extern "C" fn argstr(n: i32, buf: *mut u8, max: i32) -> i32 {
kernel/rustkernel/src/syscall.rs:258:pub unsafe extern "C" fn syscall() {
kernel/rustkernel/src/mem/kalloc.rs:36:pub unsafe extern "C" fn kinit() {
kernel/rustkernel/src/mem/kalloc.rs:42:pub unsafe extern "C" fn freerange(pa_start: *mut u8, pa_end: *mut u8) {
kernel/rustkernel/src/mem/kalloc.rs:56:pub unsafe extern "C" fn kfree(pa: *mut u8) {
kernel/rustkernel/src/mem/kalloc.rs:78:pub unsafe extern "C" fn kalloc() -> *mut u8 {
kernel/rustkernel/src/mem/virtual_memory.rs:108:pub unsafe extern "C" fn walk(
kernel/rustkernel/src/mem/virtual_memory.rs:150:pub unsafe extern "C" fn walkaddr(pagetable: Pagetable, virtual_addr: u64) -> u64 {
kernel/rustkernel/src/mem/virtual_memory.rs:168:pub unsafe extern "C" fn kvmmap(
kernel/rustkernel/src/mem/virtual_memory.rs:186:pub unsafe extern "C" fn mappages(
kernel/rustkernel/src/mem/virtual_memory.rs:228:pub unsafe extern "C" fn uvmunmap(
kernel/rustkernel/src/mem/virtual_memory.rs:260:pub unsafe extern "C" fn uvmcreate() -> Pagetable {
kernel/rustkernel/src/mem/virtual_memory.rs:273:pub unsafe extern "C" fn uvmfirst(pagetable: Pagetable, src: *mut u8, size: u32) {
kernel/rustkernel/src/mem/virtual_memory.rs:295:pub unsafe extern "C" fn uvmalloc(
kernel/rustkernel/src/mem/virtual_memory.rs:342:pub unsafe extern "C" fn uvmdealloc(pagetable: Pagetable, old_size: u64, new_size: u64) -> u64 {
kernel/rustkernel/src/mem/virtual_memory.rs:359:pub unsafe extern "C" fn freewalk(pagetable: Pagetable) {
kernel/rustkernel/src/mem/virtual_memory.rs:377:pub unsafe extern "C" fn uvmfree(pagetable: Pagetable, size: u64) {
kernel/rustkernel/src/mem/virtual_memory.rs:391:pub unsafe extern "C" fn uvmcopy(old: Pagetable, new: Pagetable, size: u64) -> i32 {
kernel/rustkernel/src/mem/virtual_memory.rs:429:pub unsafe extern "C" fn uvmclear(pagetable: Pagetable, virtual_addr: u64) {
kernel/rustkernel/src/mem/virtual_memory.rs:442:pub unsafe extern "C" fn copyout(
kernel/rustkernel/src/mem/virtual_memory.rs:477:pub unsafe extern "C" fn copyin(
kernel/rustkernel/src/mem/virtual_memory.rs:513:pub unsafe extern "C" fn copyinstr(
kernel/rustkernel/src/mem/mod.rs:5:pub unsafe extern "C" fn memset(dst: *mut u8, data: i32, max_bytes: u32) -> *mut u8 {
kernel/rustkernel/src/mem/mod.rs:13:pub unsafe extern "C" fn memcmp(mut a: *const u8, mut b: *const u8, max_bytes: u32) -> i32 {
kernel/rustkernel/src/mem/mod.rs:26:pub unsafe extern "C" fn memmove(mut dst: *mut u8, mut src: *const u8, max_bytes: u32) -> *mut u8 {
kernel/rustkernel/src/mem/mod.rs:54:pub unsafe extern "C" fn memcpy(dst: *mut u8, src: *const u8, max_bytes: u32) -> *mut u8 {
kernel/rustkernel/src/arch/riscv/plic.rs:9:pub unsafe extern "C" fn plicinit() {
kernel/rustkernel/src/arch/riscv/plic.rs:16:pub unsafe extern "C" fn plicinithart() {
kernel/rustkernel/src/arch/riscv/plic.rs:29:pub unsafe extern "C" fn plic_claim() -> i32 {
kernel/rustkernel/src/arch/riscv/plic.rs:36:pub unsafe extern "C" fn plic_complete(irq: i32) {
kernel/rustkernel/src/sync/sleeplock.rs:48:pub unsafe extern "C" fn initsleeplock(lock: *mut Sleeplock, _name: *mut c_char) {
kernel/rustkernel/src/sync/sleeplock.rs:53:pub unsafe extern "C" fn acquiresleep(lock: *mut Sleeplock) {
kernel/rustkernel/src/sync/sleeplock.rs:58:pub unsafe extern "C" fn releasesleep(lock: *mut Sleeplock) {
kernel/rustkernel/src/sync/spinlock.rs:70:pub unsafe extern "C" fn initlock(lock: *mut Spinlock, _name: *mut c_char) {
kernel/rustkernel/src/sync/spinlock.rs:75:pub unsafe extern "C" fn acquire(lock: *mut Spinlock) {
kernel/rustkernel/src/sync/spinlock.rs:80:pub unsafe extern "C" fn release(lock: *mut Spinlock) {

View File

@ -16,168 +16,140 @@ struct stat;
struct superblock;
// bio.c
void binit(void);
struct buf* bread(uint, uint);
void brelse(struct buf*);
void bwrite(struct buf*);
void bpin(struct buf*);
void bunpin(struct buf*);
// console.c
void consoleintr(int);
void consputc(int);
void binit(void);
struct buf *bread(uint, uint);
void brelse(struct buf *);
void bwrite(struct buf *);
void bpin(struct buf *);
void bunpin(struct buf *);
// exec.c
int exec(char*, char**);
int exec(char *, char **);
// file.c
struct file* filealloc(void);
void fileclose(struct file*);
struct file* filedup(struct file*);
void fileinit(void);
int fileread(struct file*, uint64, int n);
int filestat(struct file*, uint64 addr);
int filewrite(struct file*, uint64, int n);
struct file *filealloc(void);
void fileclose(struct file *);
struct file *filedup(struct file *);
void fileinit(void);
int fileread(struct file *, uint64, int n);
int filestat(struct file *, uint64 addr);
int filewrite(struct file *, uint64, int n);
// fs.c
void fsinit(int);
int dirlink(struct inode*, char*, uint);
struct inode* dirlookup(struct inode*, char*, uint*);
struct inode* ialloc(uint, short);
struct inode* idup(struct inode*);
void iinit();
void ilock(struct inode*);
void iput(struct inode*);
void iunlock(struct inode*);
void iunlockput(struct inode*);
void iupdate(struct inode*);
int namecmp(const char*, const char*);
struct inode* namei(char*);
struct inode* nameiparent(char*, char*);
int readi(struct inode*, int, uint64, uint, uint);
void stati(struct inode*, struct stat*);
int writei(struct inode*, int, uint64, uint, uint);
void itrunc(struct inode*);
void fsinit(int);
int dirlink(struct inode *, char *, uint);
struct inode *dirlookup(struct inode *, char *, uint *);
struct inode *ialloc(uint, short);
struct inode *idup(struct inode *);
void iinit();
void ilock(struct inode *);
void iput(struct inode *);
void iunlock(struct inode *);
void iunlockput(struct inode *);
void iupdate(struct inode *);
int namecmp(const char *, const char *);
struct inode *namei(char *);
struct inode *nameiparent(char *, char *);
int readi(struct inode *, int, uint64, uint, uint);
void stati(struct inode *, struct stat *);
int writei(struct inode *, int, uint64, uint, uint);
void itrunc(struct inode *);
// ramdisk.c
void ramdiskinit(void);
void ramdiskintr(void);
void ramdiskrw(struct buf*);
void ramdiskinit(void);
void ramdiskintr(void);
void ramdiskrw(struct buf *);
// kalloc.c
void* kalloc(void);
void kfree(void *);
void kinit(void);
void *kalloc(void);
void kfree(void *);
// log.c
void initlog(int, struct superblock*);
void log_write(struct buf*);
void begin_op(void);
void end_op(void);
void initlog(int, struct superblock *);
void log_write(struct buf *);
void begin_op(void);
void end_op(void);
// pipe.c
int pipealloc(struct file**, struct file**);
void pipeclose(struct pipe*, int);
int piperead(struct pipe*, uint64, int);
int pipewrite(struct pipe*, uint64, int);
int pipealloc(struct file **, struct file **);
// printf.c
__attribute__((noreturn)) void panic(char *s);
void printstr(char *s);
void printint(int n);
void printhex(int n);
void printptr(uint64 p);
// proc.c
int cpuid(void);
void exit(int);
int fork(void);
int growproc(int);
void proc_mapstacks(pagetable_t);
pagetable_t proc_pagetable(struct proc *);
void proc_freepagetable(pagetable_t, uint64);
int kill(int);
int killed(struct proc*);
void setkilled(struct proc*);
struct cpu* mycpu(void);
struct cpu* getmycpu(void);
struct proc* myproc();
void procinit(void);
void scheduler(void) __attribute__((noreturn));
void sched(void);
void exit(int);
int fork(void);
void proc_mapstacks(pagetable_t);
pagetable_t proc_pagetable(struct proc *);
void proc_freepagetable(pagetable_t, uint64);
int kill(int);
int killed(struct proc *);
void setkilled(struct proc *);
struct cpu *mycpu(void);
struct proc *myproc();
void procinit(void);
void scheduler(void) __attribute__((noreturn));
void sched(void);
void sleep_lock(void *, struct spinlock *);
void userinit(void);
int wait(uint64);
void wakeup(void*);
void yield(void);
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
void procdump(void);
void userinit(void);
int wait(uint64);
void wakeup(void *);
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
void procdump(void);
// swtch.S
void swtch(struct context*, struct context*);
void swtch(struct context *, struct context *);
// spinlock.rs
void acquire(struct spinlock *);
void initlock(struct spinlock*, char*);
void release(struct spinlock*);
void push_off(void);
void pop_off(void);
void initlock(struct spinlock *, char *);
void release(struct spinlock *);
// sleeplock.c
void acquiresleep(struct sleeplock*);
void acquiresleep(struct sleeplock *);
void releasesleep(struct sleeplock *);
void initsleeplock(struct sleeplock*, char*);
void initsleeplock(struct sleeplock *, char *);
// string.c
int memcmp(const void*, const void*, uint);
void* memmove(void*, const void*, uint);
void* memset(void*, int, uint);
char* safestrcpy(char*, const char*, int);
int strlen(const char*);
int strncmp(const char*, const char*, uint);
char* strncpy(char*, const char*, int);
void *memmove(void *, const void *, uint);
void *memset(void *, int, uint);
char *safestrcpy(char *, const char *, int);
int strlen(const char *);
int strncmp(const char *, const char *, uint);
char *strncpy(char *, const char *, int);
// syscall.c
void argint(int, int*);
int argstr(int, char*, int);
void argaddr(int, uint64 *);
int fetchstr(uint64, char*, int);
int fetchaddr(uint64, uint64*);
void syscall();
void argint(int, int *);
int argstr(int, char *, int);
void argaddr(int, uint64 *);
int fetchstr(uint64, char *, int);
int fetchaddr(uint64, uint64 *);
// trap.c
void trapinithart(void);
void usertrapret(void);
void uartintr(void);
void usertrapret(void);
// vm.c
void kvmmap(pagetable_t, uint64, uint64, uint64, int);
int mappages(pagetable_t, uint64, uint64, uint64, int);
pagetable_t uvmcreate(void);
void uvmfirst(pagetable_t, uchar *, uint);
uint64 uvmalloc(pagetable_t, uint64, uint64, int);
uint64 uvmdealloc(pagetable_t, uint64, uint64);
int uvmcopy(pagetable_t, pagetable_t, uint64);
void uvmfree(pagetable_t, uint64);
void uvmunmap(pagetable_t, uint64, uint64, int);
void uvmclear(pagetable_t, uint64);
pte_t * walk(pagetable_t, uint64, int);
uint64 walkaddr(pagetable_t, uint64);
int copyout(pagetable_t, uint64, char *, uint64);
int copyin(pagetable_t, char *, uint64, uint64);
int copyinstr(pagetable_t, char *, uint64, uint64);
// plic.c
void plicinit(void);
void plicinithart(void);
int plic_claim(void);
void plic_complete(int);
void kvmmap(pagetable_t, uint64, uint64, uint64, int);
int mappages(pagetable_t, uint64, uint64, uint64, int);
pagetable_t uvmcreate(void);
void uvmfirst(pagetable_t, uchar *, uint);
uint64 uvmalloc(pagetable_t, uint64, uint64, int);
uint64 uvmdealloc(pagetable_t, uint64, uint64);
int uvmcopy(pagetable_t, pagetable_t, uint64);
void uvmfree(pagetable_t, uint64);
void uvmunmap(pagetable_t, uint64, uint64, int);
void uvmclear(pagetable_t, uint64);
uint64 walkaddr(pagetable_t, uint64);
int copyout(pagetable_t, uint64, char *, uint64);
int copyin(pagetable_t, char *, uint64, uint64);
// virtio_disk.c
void virtio_disk_init(void);
void virtio_disk_rw(struct buf *, int);
void virtio_disk_intr(void);
void virtio_disk_init(void);
void virtio_disk_rw(struct buf *, int);
void virtio_disk_intr(void);
// number of elements in fixed-size array
#define NELEM(x) (sizeof(x)/sizeof((x)[0]))
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))

View File

@ -187,10 +187,6 @@ userinit(void)
release(&p->lock);
}
// Grow or shrink user memory by n bytes.
// Return 0 on success, -1 on failure.
int growproc(int n);
// Create a new process, copying the parent.
// Sets up child kernel stack to return as if from fork() system call.
int
@ -386,9 +382,6 @@ scheduler(void)
// there's no process.
void sched(void);
// Give up the CPU for one scheduling round.
void yield(void);
// A fork child's very first scheduling by scheduler()
// will swtch to forkret.
void

View File

@ -111,5 +111,4 @@ struct proc {
char name[16]; // Process name (debugging)
};
int cpuid();
int allocpid();

View File

@ -1 +1 @@
pub mod riscv;
pub mod riscv;

View File

@ -1,19 +1,17 @@
//! The RISC-V Platform Level Interrupt Controller (PLIC)
use crate::{
proc::cpuid,
arch::riscv::{plic_sclaim, plic_senable, plic_spriority, PLIC, UART0_IRQ, VIRTIO0_IRQ},
proc::cpuid,
};
#[no_mangle]
pub unsafe extern "C" fn plicinit() {
pub unsafe fn plicinit() {
// Set desired IRQ priorities non-zero (otherwise disabled).
*((PLIC + UART0_IRQ as u64 * 4) as *mut u32) = 1;
*((PLIC + VIRTIO0_IRQ as u64 * 4) as *mut u32) = 1;
}
#[no_mangle]
pub unsafe extern "C" fn plicinithart() {
pub unsafe fn plicinithart() {
let hart = cpuid() as u64;
// Set enable bits for this hart's S-mode
@ -25,15 +23,13 @@ pub unsafe extern "C" fn plicinithart() {
}
/// Ask the PLIC what interrupt we should serve.
#[no_mangle]
pub unsafe extern "C" fn plic_claim() -> i32 {
pub unsafe fn plic_claim() -> i32 {
let hart = cpuid() as u64;
*(plic_sclaim(hart) as *const i32)
}
/// Tell the PLIC we've served this IRQ.
#[no_mangle]
pub unsafe extern "C" fn plic_complete(irq: i32) {
pub unsafe fn plic_complete(irq: i32) {
let hart = cpuid() as u64;
*(plic_sclaim(hart) as *mut i32) = irq;
}

View File

@ -33,16 +33,6 @@ pub extern "C" fn printint(n: i32) {
print!("{}", n);
}
#[no_mangle]
pub extern "C" fn printhex(n: i32) {
print!("{:0x}", n);
}
#[no_mangle]
pub extern "C" fn printptr(p: u64) {
print!("{:#018x}", p);
}
#[no_mangle]
pub unsafe extern "C" fn printstr(s: *const c_char) {
let s = CStr::from_ptr(s).to_str().unwrap_or_default();

View File

@ -42,13 +42,6 @@ impl Default for Pipe {
}
}
extern "C" {
// pub fn pipealloc(a: *mut *mut File, b: *mut *mut File) -> i32;
// pub fn pipeclose(pipe: *mut Pipe, writable: i32);
// pub fn pipewrite(pipe: *mut Pipe, addr: u64, n: i32) -> i32;
// pub fn piperead(pipe: *mut Pipe, addr: u64, n: i32) -> i32;
}
#[no_mangle]
pub unsafe extern "C" fn pipealloc(a: *mut *mut File, b: *mut *mut File) -> i32 {
*a = filealloc();
@ -81,8 +74,7 @@ pub unsafe extern "C" fn pipealloc(a: *mut *mut File, b: *mut *mut File) -> i32
}
}
#[no_mangle]
pub unsafe extern "C" fn pipeclose(pipe: *mut Pipe, writable: i32) {
pub unsafe fn pipeclose(pipe: *mut Pipe, writable: i32) {
let _guard = (*pipe).lock.lock();
if writable > 0 {
@ -98,8 +90,7 @@ pub unsafe extern "C" fn pipeclose(pipe: *mut Pipe, writable: i32) {
}
}
#[no_mangle]
pub unsafe extern "C" fn pipewrite(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
pub unsafe fn pipewrite(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
let mut i = 0;
let p = myproc();
let lock = (*pipe).lock.lock();
@ -126,9 +117,8 @@ pub unsafe extern "C" fn pipewrite(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
i
}
#[no_mangle]
#[allow(clippy::while_immutable_condition)]
pub unsafe extern "C" fn piperead(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
pub unsafe fn piperead(pipe: *mut Pipe, addr: u64, n: i32) -> i32 {
let mut i = 0;
let p = myproc();
let lock = (*pipe).lock.lock();

View File

@ -8,18 +8,18 @@
extern crate alloc;
extern crate core;
pub mod console;
pub mod fs;
pub mod io;
pub mod mem;
pub mod proc;
pub mod queue;
pub(crate) mod arch;
pub mod start;
pub mod string;
pub mod sync;
pub mod syscall;
pub mod trap;
mod arch;
mod console;
mod fs;
mod io;
mod mem;
mod proc;
mod queue;
mod start;
mod string;
mod sync;
mod syscall;
mod trap;
use crate::{proc::cpuid, sync::mutex::Mutex};
use core::ffi::{c_char, CStr};
@ -56,8 +56,7 @@ pub const FSSIZE: usize = 2000;
/// Maximum file path size
pub const MAXPATH: usize = 128;
#[no_mangle]
pub unsafe extern "C" fn main() -> ! {
pub unsafe fn main() -> ! {
if cpuid() == 0 {
console::consoleinit();
mem::kalloc::kinit();

View File

@ -3,8 +3,8 @@
//! and pipe buffers. Allocates whole 4096-byte pages.
use crate::{
mem::memset,
arch::riscv::{memlayout::PHYSTOP, pg_round_up, PGSIZE},
mem::memset,
sync::spinlock::Spinlock,
};
use core::ptr::{addr_of_mut, null_mut};
@ -32,14 +32,12 @@ pub struct KernelMemory {
pub freelist: *mut Run,
}
#[no_mangle]
pub unsafe extern "C" fn kinit() {
pub unsafe fn kinit() {
kmem.lock = Spinlock::new();
freerange(addr_of_mut!(end).cast(), PHYSTOP as *mut u8)
}
#[no_mangle]
pub unsafe extern "C" fn freerange(pa_start: *mut u8, pa_end: *mut u8) {
unsafe fn freerange(pa_start: *mut u8, pa_end: *mut u8) {
let mut p = pg_round_up(pa_start as usize as u64) as *mut u8;
while p.add(PGSIZE as usize) <= pa_end {

View File

@ -1,13 +1,13 @@
use crate::{
arch::riscv::{
memlayout::{KERNBASE, PHYSTOP, TRAMPOLINE},
*,
},
mem::{
kalloc::{kalloc, kfree},
memmove, memset,
},
proc::proc_mapstacks,
arch::riscv::{
memlayout::{KERNBASE, PHYSTOP, TRAMPOLINE},
*,
},
};
use core::ptr::{addr_of, addr_of_mut, null_mut};
@ -104,12 +104,7 @@ pub unsafe fn kvminithart() {
/// - 21..30: 9 bits of level 0 index.
/// - 30..39: 9 bits of level 0 index.
/// - 39..64: Must be zero.
#[no_mangle]
pub unsafe extern "C" fn walk(
mut pagetable: Pagetable,
virtual_addr: u64,
alloc: i32,
) -> *mut PagetableEntry {
pub unsafe fn walk(mut pagetable: Pagetable, virtual_addr: u64, alloc: i32) -> *mut PagetableEntry {
if virtual_addr > MAXVA {
panic!("walk");
}
@ -509,8 +504,7 @@ pub unsafe extern "C" fn copyin(
/// Copy bytes to `dst` from virtual address `src_virtual_addr`
/// in a given pagetable, until b'\0' or `max` is reached.
/// Returns 0 on success, -1 on error.
#[no_mangle]
pub unsafe extern "C" fn copyinstr(
pub unsafe fn copyinstr(
pagetable: Pagetable,
mut dst: *mut u8,
mut src_virtual_addr: u64,

View File

@ -1,8 +1,8 @@
#![allow(clippy::comparison_chain)]
use crate::{
arch::riscv::{intr_get, r_tp, Pagetable, PTE_W},
mem::kalloc::kfree,
arch::riscv::{Pagetable, PTE_W, intr_get, r_tp},
sync::spinlock::{Spinlock, SpinlockGuard},
};
use core::{
@ -224,8 +224,7 @@ pub struct Proc {
/// Must be called with interrupts disabled
/// to prevent race with process being moved
/// to a different CPU.
#[no_mangle]
pub unsafe extern "C" fn cpuid() -> i32 {
pub unsafe fn cpuid() -> i32 {
r_tp() as i32
}
@ -289,8 +288,7 @@ pub unsafe extern "C" fn reparent(p: *mut Proc) {
/// Grow or shrink user memory by n bytes.
/// Return 0 on success, -1 on failure.
#[no_mangle]
pub unsafe extern "C" fn growproc(n: i32) -> i32 {
pub unsafe fn growproc(n: i32) -> i32 {
let p = myproc();
let mut sz = (*p).sz;
@ -307,8 +305,7 @@ pub unsafe extern "C" fn growproc(n: i32) -> i32 {
}
/// Give up the CPU for one scheduling round.
#[no_mangle]
pub unsafe extern "C" fn r#yield() {
pub unsafe fn r#yield() {
let p = myproc();
let _guard = (*p).lock.lock();
(*p).state = ProcState::Runnable;

View File

@ -1,4 +1,4 @@
use crate::{main, arch::riscv::*, NCPU};
use crate::{arch::riscv::*, main, NCPU};
use core::{arch::asm, ptr::addr_of};
extern "C" {
@ -53,8 +53,7 @@ pub unsafe extern "C" fn start() {
/// at timervec in kernelvec.S,
/// which turns them into software interrupts for
/// devintr() in trap.c.
#[no_mangle]
pub unsafe extern "C" fn timerinit() {
pub unsafe fn timerinit() {
// Each CPU has a separate source of timer interrupts.
let id = r_mhartid();

View File

@ -1,8 +1,8 @@
use crate::{
arch::riscv::memlayout::QEMU_POWER,
mem::virtual_memory::{copyin, copyinstr},
println,
proc::{self, myproc},
arch::riscv::memlayout::QEMU_POWER,
string::strlen,
trap::CLOCK_TICKS,
};
@ -254,8 +254,7 @@ pub unsafe extern "C" fn argstr(n: i32, buf: *mut u8, max: i32) -> i32 {
fetchstr(addr, buf, max)
}
#[no_mangle]
pub unsafe extern "C" fn syscall() {
pub unsafe fn syscall() {
let p = myproc();
let num = (*(*p).trapframe).a7;

View File

@ -1,7 +1,7 @@
use crate::{
arch::riscv::*,
println,
proc::{cpuid, exit, killed, mycpu, myproc, r#yield, setkilled, wakeup, ProcState},
arch::riscv::*,
sync::mutex::Mutex,
syscall::syscall,
};
@ -22,13 +22,11 @@ extern "C" {
pub static CLOCK_TICKS: Mutex<usize> = Mutex::new(0);
/// Set up to take exceptions and traps while in the kernel.
#[no_mangle]
pub unsafe extern "C" fn trapinithart() {
pub unsafe fn trapinithart() {
w_stvec(kernelvec as usize as u64);
}
#[no_mangle]
pub unsafe extern "C" fn clockintr() {
pub fn clockintr() {
let mut ticks = CLOCK_TICKS.lock_spinning();
*ticks += 1;
@ -40,8 +38,7 @@ pub unsafe extern "C" fn clockintr() {
/// Check if it's an external interrupt or software interrupt and handle it.
///
/// Returns 2 if timer interrupt, 1 if other device, 0 if not recognized.
#[no_mangle]
pub unsafe extern "C" fn devintr() -> i32 {
pub unsafe fn devintr() -> i32 {
let scause = r_scause();
if (scause & 0x8000000000000000 > 0) && (scause & 0xff) == 9 {
@ -270,8 +267,7 @@ pub unsafe extern "C" fn usertrap() {
// it takes two pop_intr_off()s to undo two push_intr_off()s. Also, if interrupts
// are initially off, then push_intr_off, pop_intr_off leaves them off.
#[no_mangle]
pub unsafe extern "C" fn push_intr_off() {
pub unsafe fn push_intr_off() {
let old = intr_get();
let cpu = mycpu();
@ -281,8 +277,7 @@ pub unsafe extern "C" fn push_intr_off() {
}
(*cpu).interrupt_disable_layers += 1;
}
#[no_mangle]
pub unsafe extern "C" fn pop_intr_off() {
pub unsafe fn pop_intr_off() {
let cpu = mycpu();
if intr_get() == 1 {