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

add environ functions #3

Merged
merged 1 commit into from
Sep 15, 2023
Merged

add environ functions #3

merged 1 commit into from
Sep 15, 2023

Conversation

KouweiLee
Copy link
Contributor

@KouweiLee KouweiLee commented Sep 10, 2023

  1. add environ functions for x86, aarch64, riscv64 qemu.
  2. add dtb crate
  3. add argv for C main function

To use environment variables and command-line parameters, use ARGS="xxx" and ENVS="xxx=xxx" when make run, e.g.,
make ARCH=aarch64 A=apps/c/env_test ARGS="arg1 arg2" ENVS="HOSTNAME=QEMU LOGNAME=arceos_user" run.

strnlen(s, usize::MAX)
}

unsafe fn strnlen(s: *const c_char, size: usize) -> usize {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this two functions into another file string.rs, and remove strlen and strnlen in axlibc/c/string.c.

@@ -53,6 +53,10 @@ NET_DEV ?= user
IP ?= 10.0.2.15
GW ?= 10.0.2.2

#args and env
ARGS ?=
ENVS ?=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add this two parameter to the doc in the head of this file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this env test can be put into another file. Also test using ARGS=xxx ENVS=xxx in test_cmd

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this crate into the root Cargo.toml

///
/// The Multiboot information structure may be placed anywhere in memory by the boot loader,
/// so we should save cmdline in a buf before this memory is set free
pub static mut COMLINE_BUF: [u8; 256] = [0; 256];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable ONLY used in x86? If so, try to add #[cfg(...)]

@coolyjg
Copy link
Contributor

coolyjg commented Sep 13, 2023

Try to run Redis with ARGS=xxx ENVS=xxx, remove related changes in redis.patch (in the start of redis/src/server.c/main)

Copy link
Contributor

@coolyjg coolyjg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix warnings generated by cargo clippy, and rebase these commits into one.
I think it's ok to merge. @MrRobertYuan

Some((a, e)) => (a, e),
None => ("", ""),
};
let envs: Vec<&str> = envs.split(",").collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix warning in cargo clippy

OUR_ENVIRON.push(core::ptr::null_mut());
environ = OUR_ENVIRON.as_mut_ptr();
// set up argvs
let args: Vec<&str> = args.split(",").filter(|i| i.len() != 0).collect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix warning in cargo clippy

let mbi = mbi as *const u32;
let flag = mbi.read();
if (flag & (1 << 2)) > 0 {
let cmdline = *mbi.add(4) as *const u8; // cmdline的物理地址
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this Chinese word

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to narrow down unsafe block size. That is to say:
When use unsafe fn xxxx, please point out which expression line is unsafe, and wrap corresponding expression with unsafe {} .
Line 76: unsafe { core::ptr::xxx}

pub static mut environ: *mut *mut c_char = ptr::null_mut();

/// Save environment variables
pub static mut OUR_ENVIRON: Vec<*mut c_char> = Vec::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to RX_ENVIRON

@coolyjg coolyjg merged commit a6f622a into syswonder:dev Sep 15, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants