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

Remove CChar #126

Merged
merged 2 commits into from
Aug 12, 2020
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
14 changes: 5 additions & 9 deletions kernel-rs/src/bio.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::libc;
use crate::{
buf::Buf, param::NBUF, printf::panic, spinlock::Spinlock, virtio_disk::virtio_disk_rw,
};
Expand Down Expand Up @@ -30,7 +29,7 @@ impl Buf {
/// Write self's contents to disk. Must be locked.
pub unsafe fn write(&mut self) {
if (*self).lock.holding() == 0 {
panic(b"bwrite\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"bwrite\x00" as *const u8 as *mut u8);
}
virtio_disk_rw(self, 1);
}
Expand All @@ -41,7 +40,7 @@ impl Buf {
let bcache = BCACHE.get_mut();

if (*self).lock.holding() == 0 {
panic(b"release\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"release\x00" as *const u8 as *mut u8);
}
(*self).lock.release();
bcache.lock.acquire();
Expand Down Expand Up @@ -76,9 +75,7 @@ impl Buf {
pub unsafe fn binit() {
let bcache = BCACHE.get_mut();

bcache
.lock
.initlock(b"bcache\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
bcache.lock.initlock(b"bcache\x00" as *const u8 as *mut u8);

// Create linked list of buffers
bcache.head.prev = &mut bcache.head;
Expand All @@ -87,8 +84,7 @@ pub unsafe fn binit() {
while b < bcache.buf.as_mut_ptr().offset(NBUF as isize) {
(*b).next = bcache.head.next;
(*b).prev = &mut bcache.head;
(*b).lock
.initlock(b"buffer\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
(*b).lock.initlock(b"buffer\x00" as *const u8 as *mut u8);
(*bcache.head.next).prev = b;
bcache.head.next = b;
b = b.offset(1)
Expand Down Expand Up @@ -129,7 +125,7 @@ unsafe fn bget(dev: u32, blockno: u32) -> *mut Buf {
}
b = (*b).prev
}
panic(b"bget: no buffers\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"bget: no buffers\x00" as *const u8 as *mut u8);
}

/// Return a locked buf with the contents of the indicated block.
Expand Down
15 changes: 7 additions & 8 deletions kernel-rs/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const INPUT_BUF: usize = 128;

struct Console {
lock: Spinlock,
buf: [libc::CChar; 128],
buf: [u8; 128],

/// Read index
r: u32,
Expand Down Expand Up @@ -74,9 +74,9 @@ static mut CONS: Console = Console::zeroed();
unsafe fn consolewrite(user_src: i32, src: usize, n: i32) -> i32 {
CONS.lock.acquire();
for i in 0..n {
let mut c: libc::CChar = 0;
let mut c: u8 = 0;
if either_copyin(
&mut c as *mut libc::CChar as *mut libc::CVoid,
&mut c as *mut u8 as *mut libc::CVoid,
user_src,
src.wrapping_add(i as usize),
1usize,
Expand Down Expand Up @@ -121,11 +121,11 @@ unsafe fn consoleread(user_dst: i32, mut dst: usize, mut n: i32) -> i32 {
break;
} else {
// copy the input byte to the user-space buffer.
let mut cbuf = cin as libc::CChar;
let mut cbuf = cin as u8;
if either_copyout(
user_dst,
dst,
&mut cbuf as *mut libc::CChar as *mut libc::CVoid,
&mut cbuf as *mut u8 as *mut libc::CVoid,
1usize,
) == -1
{
Expand Down Expand Up @@ -184,7 +184,7 @@ pub unsafe fn consoleintr(mut cin: i32) {
// store for consumption by consoleread().
let fresh1 = CONS.e;
CONS.e = CONS.e.wrapping_add(1);
CONS.buf[fresh1.wrapping_rem(INPUT_BUF as u32) as usize] = cin as libc::CChar;
CONS.buf[fresh1.wrapping_rem(INPUT_BUF as u32) as usize] = cin as u8;
if cin == '\n' as i32
|| cin == ctrl('D')
|| CONS.e == CONS.r.wrapping_add(INPUT_BUF as u32)
Expand All @@ -201,8 +201,7 @@ pub unsafe fn consoleintr(mut cin: i32) {
}

pub unsafe fn consoleinit() {
CONS.lock
.initlock(b"CONS\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
CONS.lock.initlock(b"CONS\x00" as *const u8 as *mut u8);
uartinit();

// connect read and write system calls
Expand Down
21 changes: 7 additions & 14 deletions kernel-rs/src/exec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::libc;
use crate::{
elf::{ElfHdr, ProgHdr, ELF_MAGIC, ELF_PROG_LOAD},
file::Inode,
Expand All @@ -13,7 +12,7 @@ use crate::{
};
use core::ptr;

pub unsafe fn exec(path: *mut libc::CChar, argv: *mut *mut libc::CChar) -> i32 {
pub unsafe fn exec(path: *mut u8, argv: *mut *mut u8) -> i32 {
let mut sz: usize = 0;
let mut ustack: [usize; MAXARG + 1] = [0; MAXARG + 1];
let mut elf: ElfHdr = Default::default();
Expand Down Expand Up @@ -154,7 +153,7 @@ pub unsafe fn exec(path: *mut libc::CChar, argv: *mut *mut libc::CChar) -> i32 {
&& copyout(
pagetable,
sp,
ustack.as_mut_ptr() as *mut libc::CChar,
ustack.as_mut_ptr() as *mut u8,
argc.wrapping_add(1)
.wrapping_mul(::core::mem::size_of::<usize>()),
) >= 0
Expand All @@ -166,8 +165,8 @@ pub unsafe fn exec(path: *mut libc::CChar, argv: *mut *mut libc::CChar) -> i32 {
(*(*p).tf).a1 = sp;

// Save program name for debugging.
let mut s: *mut libc::CChar = path;
let mut last: *mut libc::CChar = s;
let mut s: *mut u8 = path;
let mut last: *mut u8 = s;
while *s != 0 {
if *s as i32 == '/' as i32 {
last = s.offset(1isize)
Expand All @@ -177,7 +176,7 @@ pub unsafe fn exec(path: *mut libc::CChar, argv: *mut *mut libc::CChar) -> i32 {
safestrcpy(
(*p).name.as_mut_ptr(),
last,
::core::mem::size_of::<[libc::CChar; 16]>() as i32,
::core::mem::size_of::<[u8; 16]>() as i32,
);

// Commit to the user image.
Expand Down Expand Up @@ -214,19 +213,13 @@ unsafe fn loadseg(
sz: u32,
) -> Result<(), ()> {
if va.wrapping_rem(PGSIZE as usize) != 0 {
panic(
b"loadseg: va must be page aligned\x00" as *const u8 as *const libc::CChar
as *mut libc::CChar,
);
panic(b"loadseg: va must be page aligned\x00" as *const u8 as *mut u8);
}

for i in num_iter::range_step(0, sz, PGSIZE as _) {
let pa = walkaddr(pagetable, va.wrapping_add(i as usize));
if pa == 0 {
panic(
b"loadseg: address should exist\x00" as *const u8 as *const libc::CChar
as *mut libc::CChar,
);
panic(b"loadseg: address should exist\x00" as *const u8 as *mut u8);
}

let n = if sz.wrapping_sub(i) < PGSIZE as u32 {
Expand Down
24 changes: 9 additions & 15 deletions kernel-rs/src/file.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! Support functions for system calls that involve file descriptors.
use crate::libc;
use crate::{
fs::{stati, BSIZE},
log::{begin_op, end_op},
Expand All @@ -23,8 +22,8 @@ pub struct File {
/// reference count
ref_0: i32,

pub readable: libc::CChar,
pub writable: libc::CChar,
pub readable: u8,
pub writable: u8,

/// FD_PIPE
pub pipe: *mut Pipe,
Expand Down Expand Up @@ -103,7 +102,7 @@ impl File {
pub unsafe fn dup(&mut self) -> *mut File {
FTABLE.lock.acquire();
if (*self).ref_0 < 1 {
panic(b"File::dup\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"File::dup\x00" as *const u8 as *mut u8);
}
(*self).ref_0 += 1;
FTABLE.lock.release();
Expand All @@ -114,7 +113,7 @@ impl File {
pub unsafe fn close(&mut self) {
FTABLE.lock.acquire();
if (*self).ref_0 < 1 {
panic(b"File::close\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"File::close\x00" as *const u8 as *mut u8);
}
(*self).ref_0 -= 1;
if (*self).ref_0 > 0 {
Expand Down Expand Up @@ -150,7 +149,7 @@ impl File {
if copyout(
(*p).pagetable,
addr,
&mut st as *mut Stat as *mut libc::CChar,
&mut st as *mut Stat as *mut u8,
::core::mem::size_of::<Stat>() as usize,
) < 0
{
Expand Down Expand Up @@ -189,7 +188,7 @@ impl File {
(*(*self).ip).unlock();
r
} else {
panic(b"File::read\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"File::read\x00" as *const u8 as *mut u8);
}
}

Expand Down Expand Up @@ -238,10 +237,7 @@ impl File {
break;
}
if r != n1 {
panic(
b"short File::write\x00" as *const u8 as *const libc::CChar
as *mut libc::CChar,
);
panic(b"short File::write\x00" as *const u8 as *mut u8);
}
i += r
}
Expand All @@ -251,7 +247,7 @@ impl File {
-1
}
} else {
panic(b"File::write\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
panic(b"File::write\x00" as *const u8 as *mut u8);
}
}

Expand Down Expand Up @@ -289,7 +285,5 @@ pub static mut DEVSW: [Devsw; NDEV as usize] = [Devsw {
static mut FTABLE: Ftable = Ftable::zeroed();

pub unsafe fn fileinit() {
FTABLE
.lock
.initlock(b"FTABLE\x00" as *const u8 as *const libc::CChar as *mut libc::CChar);
FTABLE.lock.initlock(b"FTABLE\x00" as *const u8 as *mut u8);
}
Loading