Skip to content

Commit

Permalink
add nginx app
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw2002426 committed Dec 3, 2023
1 parent 1bae47c commit febcd86
Show file tree
Hide file tree
Showing 746 changed files with 4,303 additions and 37 deletions.
Empty file modified .clang-format
100644 → 100755
Empty file.
Empty file modified .github/workflows/actions/setup-musl/action.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/actions/setup-qemu/action.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/build.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/docs.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/test.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions Cargo.lock
100644 → 100755

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ members = [
"apps/display/draw_map",
"apps/exception",
"apps/helloworld",
"apps/systime",
"apps/memtest",
"apps/fs/shell",
"apps/net/echoserver",
Expand Down
Empty file modified LICENSE.MulanPSL2
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,4 @@ clean_musl:
rm -rf ulib/axmusl/build_*
rm -rf ulib/axmusl/install

.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c clean_musl doc disk_image
.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c clean_musl doc disk_image
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified api/arceos_api/Cargo.toml
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/imp/display.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/imp/fs.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/imp/mem.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/imp/mod.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/imp/net.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/imp/task.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/lib.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_api/src/macros.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/.gitignore
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/Cargo.toml
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions api/arceos_posix_api/build.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ typedef struct {{
"RLIMIT_.*",
"EAI_.*",
"MAXADDRS",
"FIO.*",
"ITIMER_.*",
"SIG.*",
"EINVAL",
Expand Down
1 change: 1 addition & 0 deletions api/arceos_posix_api/ctypes.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/ioctl.h>
7 changes: 7 additions & 0 deletions api/arceos_posix_api/src/imp/fd_ops.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub trait FileLike: Send + Sync {
fn into_any(self: Arc<Self>) -> Arc<dyn core::any::Any + Send + Sync>;
fn poll(&self) -> LinuxResult<PollState>;
fn set_nonblocking(&self, nonblocking: bool) -> LinuxResult;
fn set_closeonexec(&self, closeonexec: bool) -> LinuxResult;
}

lazy_static::lazy_static! {
Expand Down Expand Up @@ -100,6 +101,8 @@ pub fn sys_dup2(old_fd: c_int, new_fd: c_int) -> c_int {
return Err(LinuxError::EBADF);
}

close_file_like(new_fd).map(|_| 0);

let f = get_file_like(old_fd)?;
FD_TABLE
.write()
Expand Down Expand Up @@ -145,6 +148,10 @@ pub fn sys_fcntl(fd: c_int, cmd: c_int, arg: usize) -> c_int {
// TODO: Change fd flags
dup_fd(fd)
}
ctypes::F_SETFD => {
get_file_like(fd)?.set_closeonexec(arg & (ctypes::O_CLOEXEC as usize) > 0)?;
Ok(0)
}
ctypes::F_SETFL => {
if fd == 0 || fd == 1 || fd == 2 {
return Ok(0);
Expand Down
53 changes: 46 additions & 7 deletions api/arceos_posix_api/src/imp/fs.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/

use crate::ctypes::off_t;
use alloc::sync::Arc;
use core::ffi::{c_char, c_int};
use core::ffi::{c_char, c_int, c_size_t, c_ssize_t, c_void};

use axerrno::{LinuxError, LinuxResult};
use axfs::fops::OpenOptions;
Expand Down Expand Up @@ -43,7 +43,8 @@ impl File {

impl FileLike for File {
fn read(&self, buf: &mut [u8]) -> LinuxResult<usize> {
Ok(self.inner.lock().read(buf)?)
let read_len = self.inner.lock().read(buf)?;
Ok(read_len)
}

fn write(&self, buf: &[u8]) -> LinuxResult<usize> {
Expand Down Expand Up @@ -82,6 +83,10 @@ impl FileLike for File {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

/// Convert open flags to [`OpenOptions`].
Expand Down Expand Up @@ -120,8 +125,25 @@ pub fn sys_open(filename: *const c_char, flags: c_int, mode: ctypes::mode_t) ->
debug!("sys_open <= {:?} {:#o} {:#o}", filename, flags, mode);
syscall_body!(sys_open, {
let options = flags_to_options(flags, mode);
let file = axfs::fops::File::open(filename?, &options)?;
File::new(file).add_to_fd_table()
/*let file = axfs::fops::File::open(filename?, &options)?;
File::new(file).add_to_fd_table()*/
let res = axfs::fops::File::open(filename?, &options);
match res {
Ok(file) => {
let add_res = File::new(file).add_to_fd_table();
match add_res {
Ok(num) => Ok(num),
Err(e) => {
error!("sys_open failed in add {}", e);
Err(e.into())
}
}
}
Err(e) => {
error!("sys_open failed {}", e);
Err(e.into())
}
}
})
}

Expand All @@ -133,8 +155,25 @@ pub fn sys_openat(_fd: usize, path: *const c_char, flags: c_int, mode: ctypes::m
debug!("sys_openat <= {:?}, {:#o} {:#o}", path, flags, mode);
syscall_body!(sys_openat, {
let options = flags_to_options(flags, mode);
let file = axfs::fops::File::open(path?, &options)?;
File::new(file).add_to_fd_table()
//let file = axfs::fops::File::open(path?, &options)?;
let res = axfs::fops::File::open(path?, &options);
match res {
Ok(file) => {
let add_res = File::new(file).add_to_fd_table();
match add_res {
Ok(num) => Ok(num),
Err(e) => {
error!("sys_open failed in add {}", e);
Err(e.into())
}
}
}
Err(e) => {
error!("sys_open failed {}", e);
Err(e.into())
}
}
//File::new(file).add_to_fd_table()
})
}

Expand Down
Empty file modified api/arceos_posix_api/src/imp/io.rs
100644 → 100755
Empty file.
46 changes: 44 additions & 2 deletions api/arceos_posix_api/src/imp/io_mpx/epoll.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@ impl EpollInstance {
}

fn control(&self, op: usize, fd: usize, event: &ctypes::epoll_event) -> LinuxResult<usize> {
info!("lhw debug EpollInstance control");
match get_file_like(fd as c_int) {
Ok(_) => {}
Err(e) => return Err(e),
}

match op as u32 {
ctypes::EPOLL_CTL_ADD => {
info!("lhw debug EpollInstance control add");
if let Entry::Vacant(e) = self.events.lock().entry(fd) {
e.insert(*event);
} else {
return Err(LinuxError::EEXIST);
}
}
ctypes::EPOLL_CTL_MOD => {
info!("lhw debug EpollInstance control mod");
let mut events = self.events.lock();
if let Entry::Occupied(mut ocp) = events.entry(fd) {
ocp.insert(*event);
Expand All @@ -68,6 +71,7 @@ impl EpollInstance {
}
}
ctypes::EPOLL_CTL_DEL => {
info!("lhw debug EpollInstance control del");
let mut events = self.events.lock();
if let Entry::Occupied(ocp) = events.entry(fd) {
ocp.remove_entry();
Expand All @@ -85,17 +89,19 @@ impl EpollInstance {
fn poll_all(&self, events: &mut [ctypes::epoll_event]) -> LinuxResult<usize> {
let ready_list = self.events.lock();
let mut events_num = 0;

for (infd, ev) in ready_list.iter() {
//info!("lhw debug EpollInstance ready list loop {}",*infd);
match get_file_like(*infd as c_int)?.poll() {
Err(_) => {
info!("lhw debug err in poll all");
if (ev.events & ctypes::EPOLLERR) != 0 {
events[events_num].events = ctypes::EPOLLERR;
events[events_num].data = ev.data;
events_num += 1;
}
}
Ok(state) => {
//info!("lhw debug EpollInstance poll all ok {} {} {} {}",state.readable , (ev.events & ctypes::EPOLLIN), state.readable ,(ev.events & ctypes::EPOLLIN));
if state.readable && (ev.events & ctypes::EPOLLIN != 0) {
events[events_num].events = ctypes::EPOLLIN;
events[events_num].data = ev.data;
Expand All @@ -109,7 +115,9 @@ impl EpollInstance {
}
}
}
//info!("lhw debug EpollInstance ready list loop {} end",*infd);
}
//info!("lhw debug EpollInstance poll all normal return");
Ok(events_num)
}
}
Expand Down Expand Up @@ -144,6 +152,10 @@ impl FileLike for EpollInstance {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

/// Creates a new epoll instance.
Expand Down Expand Up @@ -215,7 +227,37 @@ pub unsafe fn sys_epoll_wait(
loop {
#[cfg(feature = "net")]
axnet::poll_interfaces();
let events_num = epoll_instance.poll_all(events)?;
let poll_all_res = epoll_instance.poll_all(events);
let mut events_num = 0;
match poll_all_res {
Ok(num) => events_num = num,
Err(e) => {
error!("sys epoll events err {:?}", e);
if e == LinuxError::EBADF {
let mut deleted_fd: usize = 0;
{
let mut ready_list = epoll_instance.events.lock();
for (infd, ev) in ready_list.iter() {
match get_file_like(*infd as c_int) {
Ok(_) => {}
Err(_) => {
error!("sys epoll deleted fd err {}", *infd);
deleted_fd = *infd;
break;
}
}
}
}
{
let mut events = epoll_instance.events.lock();
if let Entry::Occupied(ocp) = events.entry(deleted_fd) {
ocp.remove_entry();
}
}
return Ok(0);
}
}
}
if events_num > 0 {
return Ok(events_num as c_int);
}
Expand Down
Empty file modified api/arceos_posix_api/src/imp/io_mpx/mod.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/io_mpx/poll.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/io_mpx/select.rs
100644 → 100755
Empty file.
13 changes: 9 additions & 4 deletions api/arceos_posix_api/src/imp/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* See the Mulan PSL v2 for more details.
*/

#[cfg(feature = "fd")]
use crate::imp::fd_ops::get_file_like;
use axerrno::LinuxError;
use core::ffi::c_int;

Expand All @@ -15,6 +17,7 @@ pub const TCGETS: usize = 0x5401;
pub const TIOCGPGRP: usize = 0x540F;
pub const TIOCSPGRP: usize = 0x5410;
pub const TIOCGWINSZ: usize = 0x5413;
pub const FIONBIO: usize = 21537;

#[derive(Clone, Copy, Default)]
pub struct ConsoleWinSize {
Expand All @@ -28,12 +31,14 @@ pub struct ConsoleWinSize {
/// currently only support fd = 1
pub fn sys_ioctl(fd: c_int, request: usize, data: usize) -> c_int {
debug!("sys_ioctl <= fd: {}, request: {}", fd, request);
if fd != 1 {
debug!("Only support fd = 1");
return -1;
}
syscall_body!(sys_ioctl, {
match request {
FIONBIO => {
unsafe {
get_file_like(fd)?.set_nonblocking(*(data as *const i32) > 0)?;
}
Ok(0)
}
TIOCGWINSZ => {
let winsize = data as *mut ConsoleWinSize;
unsafe {
Expand Down
Empty file modified api/arceos_posix_api/src/imp/mod.rs
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions api/arceos_posix_api/src/imp/net.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ impl FileLike for Socket {
}
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

impl From<SocketAddrV4> for ctypes::sockaddr_in {
Expand Down Expand Up @@ -412,6 +416,7 @@ pub fn sys_recv(
socket_fd, buf_ptr as usize, len, flag
);
syscall_body!(sys_recv, {
info!("lhw debug in sys_recv");
if buf_ptr.is_null() {
return Err(LinuxError::EFAULT);
}
Expand Down
4 changes: 4 additions & 0 deletions api/arceos_posix_api/src/imp/pipe.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ impl FileLike for Pipe {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

/// Create a pipe
Expand Down
Empty file modified api/arceos_posix_api/src/imp/pthread/condvar.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/pthread/mod.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/pthread/mutex.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/pthread/tsd.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/resources.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/signal.rs
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions api/arceos_posix_api/src/imp/stdio.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl super::fd_ops::FileLike for Stdin {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}

#[cfg(feature = "fd")]
Expand Down Expand Up @@ -176,4 +180,8 @@ impl super::fd_ops::FileLike for Stdout {
fn set_nonblocking(&self, _nonblocking: bool) -> LinuxResult {
Ok(())
}

fn set_closeonexec(&self, _closeonexec: bool) -> LinuxResult {
Ok(())
}
}
Empty file modified api/arceos_posix_api/src/imp/sys.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/task.rs
100644 → 100755
Empty file.
Empty file modified api/arceos_posix_api/src/imp/time.rs
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions api/arceos_posix_api/src/lib.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![feature(doc_cfg)]
#![feature(doc_auto_cfg)]
#![allow(clippy::missing_safety_doc)]
#![feature(c_size_t)]

#[macro_use]
extern crate axlog;
Expand Down
Empty file modified api/arceos_posix_api/src/utils.rs
100644 → 100755
Empty file.
Empty file modified api/axfeat/Cargo.toml
100644 → 100755
Empty file.
Empty file modified api/axfeat/src/lib.rs
100644 → 100755
Empty file.
Empty file modified apps/.gitignore
100644 → 100755
Empty file.
Empty file modified apps/c/envtest/expect_info.out
100644 → 100755
Empty file.
Empty file modified apps/c/envtest/features.txt
100644 → 100755
Empty file.
Empty file modified apps/c/envtest/main.c
100644 → 100755
Empty file.
Empty file modified apps/c/envtest/test_cmd
100644 → 100755
Empty file.
Empty file modified apps/c/filetest/expect_info.out
100644 → 100755
Empty file.
Empty file modified apps/c/filetest/features.txt
100644 → 100755
Empty file.
Empty file modified apps/c/filetest/main.c
100644 → 100755
Empty file.
Empty file modified apps/c/filetest/test_cmd
100644 → 100755
Empty file.
Empty file modified apps/c/helloworld/expect_info.out
100644 → 100755
Empty file.
Empty file modified apps/c/helloworld/expect_info_smp4.out
100644 → 100755
Empty file.
Empty file modified apps/c/helloworld/main.c
100644 → 100755
Empty file.
Empty file modified apps/c/helloworld/test_cmd
100644 → 100755
Empty file.
Empty file modified apps/c/httpclient/axbuild.mk
100644 → 100755
Empty file.
Empty file modified apps/c/httpclient/expect_info.out
100644 → 100755
Empty file.
Empty file modified apps/c/httpclient/features.txt
100644 → 100755
Empty file.
Empty file modified apps/c/httpclient/httpclient.c
100644 → 100755
Empty file.
Empty file modified apps/c/httpclient/test_cmd
100644 → 100755
Empty file.
Empty file modified apps/c/httpserver/axbuild.mk
100644 → 100755
Empty file.
Empty file modified apps/c/httpserver/features.txt
100644 → 100755
Empty file.
Empty file modified apps/c/httpserver/httpserver.c
100644 → 100755
Empty file.
Empty file modified apps/c/iperf/.gitignore
100644 → 100755
Empty file.
Empty file modified apps/c/iperf/README.md
100644 → 100755
Empty file.
Empty file modified apps/c/iperf/axbuild.mk
100644 → 100755
Empty file.
Empty file modified apps/c/iperf/features.txt
100644 → 100755
Empty file.
Empty file modified apps/c/iperf/iperf.patch
100644 → 100755
Empty file.
Empty file modified apps/c/memtest/axbuild.mk
100644 → 100755
Empty file.
Empty file modified apps/c/memtest/expect_trace.out
100644 → 100755
Empty file.
Empty file modified apps/c/memtest/features.txt
100644 → 100755
Empty file.
Empty file modified apps/c/memtest/memtest.c
100644 → 100755
Empty file.
Empty file modified apps/c/memtest/test_cmd
100644 → 100755
Empty file.
2 changes: 2 additions & 0 deletions apps/c/nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nginx-app
*.img
Loading

0 comments on commit febcd86

Please sign in to comment.