Enable libc's printf

This commit is contained in:
Tate, Hongliang Tian 2018-11-30 16:25:42 +08:00
parent 10e3da87cc
commit 4107a65248
5 changed files with 11 additions and 9 deletions

@ -185,8 +185,6 @@ impl SgxFileInner {
for buf in bufs { for buf in bufs {
match file.write(buf) { match file.write(buf) {
Ok(this_bytes) => { Ok(this_bytes) => {
if this_bytes == 0 { break; }
total_bytes += this_bytes; total_bytes += this_bytes;
if this_bytes < buf.len() { break; } if this_bytes < buf.len() { break; }
} }
@ -221,8 +219,6 @@ impl SgxFileInner {
for buf in bufs { for buf in bufs {
match file.read(buf) { match file.read(buf) {
Ok(this_bytes) => { Ok(this_bytes) => {
if this_bytes == 0 { break; }
total_bytes += this_bytes; total_bytes += this_bytes;
if this_bytes < buf.len() { break; } if this_bytes < buf.len() { break; }
} }
@ -282,7 +278,6 @@ impl File for StdoutFile {
for buf in bufs { for buf in bufs {
match guard.write(buf) { match guard.write(buf) {
Ok(this_len) => { Ok(this_len) => {
if this_len == 0 { break; }
total_bytes += this_len; total_bytes += this_len;
if this_len < buf.len() { break; } if this_len < buf.len() { break; }
} }
@ -352,7 +347,6 @@ impl File for StdinFile {
for buf in bufs { for buf in bufs {
match guard.read(buf) { match guard.read(buf) {
Ok(this_len) => { Ok(this_len) => {
if this_len == 0 { break; }
total_bytes += this_len; total_bytes += this_len;
if this_len < buf.len() { break; } if this_len < buf.len() { break; }
} }

@ -24,6 +24,7 @@ use std::panic;
use sgx_types::*; use sgx_types::*;
use sgx_trts::libc; use sgx_trts::libc;
#[macro_use]
mod prelude; mod prelude;
mod elf_helper; mod elf_helper;
mod errno; mod errno;

@ -21,3 +21,9 @@ pub use errno::Error as Error;
pub use errno::Errno; pub use errno::Errno;
pub use fs::off_t; pub use fs::off_t;
macro_rules! debug_trace {
() => {
println!("> Line = {}, File = {}", line!(), file!())
};
}

@ -92,7 +92,7 @@ fn do_writev(fd: c_int, iov: *const iovec_t, count: c_int)
let buf = unsafe { let buf = unsafe {
std::slice::from_raw_parts(iov.base as * const u8, iov.len) std::slice::from_raw_parts(iov.base as * const u8, iov.len)
}; };
bufs_vec[iov_i] = buf; bufs_vec.push(buf);
} }
bufs_vec bufs_vec
}; };
@ -122,7 +122,7 @@ fn do_readv(fd: c_int, iov: *mut iovec_t, count: c_int)
let buf = unsafe { let buf = unsafe {
std::slice::from_raw_parts_mut(iov.base as * mut u8, iov.len) std::slice::from_raw_parts_mut(iov.base as * mut u8, iov.len)
}; };
bufs_vec[iov_i] = buf; bufs_vec.push(buf);
} }
bufs_vec bufs_vec
}; };

@ -1,9 +1,10 @@
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <stdio.h>
static const char* msg = "Hello World\n"; static const char* msg = "Hello World\n";
int main(void) { int main(void) {
write(1, msg, strlen(msg) + 1); printf("%s", msg);
return 0; return 0;
} }