-
Notifications
You must be signed in to change notification settings - Fork 646
Reduce nsh stack consumption #2954
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
Conversation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
|
[Experimental Bot, please feedback here] No, this PR summary does not fully meet the NuttX requirements. While it addresses what is changed, it lacks crucial details about why and how. Here's a breakdown: Missing from Summary:
Missing from Impact:
Missing from Testing:
Example of an improved summary: nsh> pwd // Demonstrating some path-related command and its output before the change nsh> pwd // The same command after the change |
to save the stack consumption Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
cederom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @xiaoxiang781216 :-)
|
|
||
| for (i = 0; i < count; i++) | ||
| { | ||
| FAR char *buffer = lib_get_tempbuffer(LINE_MAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not get at line 595 & put at line 615 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because line 613 call sleep, which may sleep for a long time.
GUIDINGLI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| { | ||
| if (recursive) | ||
| { | ||
| strlcpy(buf, fullpath, PATH_MAX); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @xiaoxiang781216, I believe this change was wrong;
In the fullpath is commonly allocated with strdup, e.g. in here:
nuttx-apps/nshlib/nsh_envcmds.c
Line 206 in 6028b42
| return strdup(relpath); |
And in unlink_recursive the file name is added to the fullpath in here:
nuttx-apps/nshlib/nsh_fscmds.c
Line 2170 in 6028b42
| snprintf(&path[len], PATH_MAX - len, "/%s", d->d_name); |
But, the size of the allocated buffer is actually just "len + 1" on the above line, since the buffer originates from strdup.
So the temporary buffer in here is not useless, it is absolutely needed.
I just found this out when I tried "rm -rf /fs/sdcard/folder", with file in in "folder". This corrupts heap and results in full system crash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, you are right, we need call lib_get_pathbuffer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I noticed that recently with simpler rm -rf / :-P Should we revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps do what @xiaoxiang781216 proposed, instead of allocating the buffer from the stack, we could use lib_get_pathbuffer to keep stack usage smaller. I can make a patch for this if so wanted...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #3222 for the issue. @xiaoxiang781216 , @cederom please have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlaitine thanks to fix my fault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @jlaitine !! No worries @xiaoxiang781216 !! :-) <3
Summary
Impact
Testing
sim:nsh