Skip to content

Commit

Permalink
Supplement and modify syscalls
Browse files Browse the repository at this point in the history
  • Loading branch information
Miochyann committed Dec 20, 2023
1 parent f86128e commit 064bba3
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
15 changes: 15 additions & 0 deletions api/arceos_posix_api/src/imp/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ pub unsafe fn sys_fstat(fd: c_int, kst: *mut core::ffi::c_void) -> c_int {
}
})
}
/// Obtain a valid user ID for the process
///
/// return 1000 if success.
pub unsafe fn sys_geteuid() -> c_int {
debug!("sys_geteuid ");
syscall_body!(sys_geteuid, Ok(1000))
}

/// Obtain a valid group ID for the process
///
/// return 1000 if success.
pub unsafe fn sys_getegid() -> c_int {
debug!("sys_getegid ");
syscall_body!(sys_getegid, Ok(1000))
}

/// Get the metadata of the symbolic link and write into `buf`.
///
Expand Down
33 changes: 20 additions & 13 deletions api/arceos_posix_api/src/imp/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,33 @@ impl FileLike for Pipe {
}
let mut read_size = 0usize;
let max_len = buf.len();
loop {
let mut ring_buffer = self.buffer.lock();
let mut ring_buffer = self.buffer.lock();
loop{
let loop_read = ring_buffer.available_read();
if loop_read == 0 {
// write end is closed
if self.write_end_close() {
return Ok(read_size);
return Ok(0);
}else{// write end is open
drop(ring_buffer);
// Data not ready, wait for write end
crate::sys_sched_yield(); // TODO: use synconize primitive
ring_buffer = self.buffer.lock();
}
drop(ring_buffer);
// Data not ready, wait for write end
crate::sys_sched_yield(); // TODO: use synconize primitive
continue;
}else {
break;
}
for _ in 0..loop_read {
if read_size == max_len {
return Ok(read_size);
}
buf[read_size] = ring_buffer.read_byte();
read_size += 1;
}
let loop_read = ring_buffer.available_read();
for _ in 0..loop_read {
info!("this\n");
if read_size == max_len {
return Ok(read_size);
}
buf[read_size] = ring_buffer.read_byte();
read_size += 1;
}
Ok(read_size)
}

fn write(&self, buf: &[u8]) -> LinuxResult<usize> {
Expand Down
2 changes: 1 addition & 1 deletion api/arceos_posix_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub use imp::fd_ops::{sys_close, sys_dup, sys_dup2, sys_fcntl};
#[cfg(feature = "fs")]
pub use imp::fs::{
sys_fstat, sys_fsync, sys_getcwd, sys_lseek, sys_lstat, sys_mkdir, sys_mkdirat, sys_newfstatat,
sys_open, sys_openat, sys_rename, sys_rmdir, sys_stat, sys_unlink, sys_unlinkat,
sys_open, sys_openat, sys_rename, sys_rmdir, sys_stat, sys_unlink, sys_unlinkat,sys_getegid,sys_geteuid
};
#[cfg(feature = "epoll")]
pub use imp::io_mpx::{sys_epoll_create, sys_epoll_ctl, sys_epoll_pwait, sys_epoll_wait};
Expand Down
50 changes: 50 additions & 0 deletions doc/apps_udpserver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# INTRODUCTION
| App | Extra modules | Enabled features | Description |
|-|-|-|-|
| [udpserver](../apps/c/udpserver) | axalloc, axnet, axdriver, axtask | alloc, paging, net, multitask | UDP server test|

# RUN
``` bash
make A=apps/c/udpserver MUSL=y NET=y ARCH=aarch64 run
```
# RESULT
```
d8888 .d88888b. .d8888b.
d88888 d88P" "Y88b d88P Y88b
d88P888 888 888 Y88b.
d88P 888 888d888 .d8888b .d88b. 888 888 "Y888b.
d88P 888 888P" d88P" d8P Y8b 888 888 "Y88b.
d88P 888 888 888 88888888 888 888 "888
d8888888888 888 Y88b. Y8b. Y88b. .d88P Y88b d88P
d88P 888 888 "Y8888P "Y8888 "Y88888P" "Y8888P"
arch = aarch64
platform = aarch64-qemu-virt
target = aarch64-unknown-none-softfloat
smp = 1
build_mode = release
log_level = warn
Hello, ArceOS C UDP server!
listen on: 0.0.0.0:5555
recv: 19 Bytes from 10.0.2.2:34354
Hello, UDP Server!
```
Then create a new terminal and run:
``` bash
chmod +x apps/c/udpserver/udpserver_test.sh
apps/c/udpserver/udpserver_test.sh
```
This will send a message to port 5555 of localhost , If the UDP service is running correctly the result will be:

```
Hello, ArceOS C UDP server!
listen on: 0.0.0.0:5555
recv: 19 Bytes from 10.0.2.2:40463
Hello, UDP Server!
recv: 1024 Bytes from 10.0.2.2:48431
Big message, it should fail#####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
received message too long
```

0 comments on commit 064bba3

Please sign in to comment.