Skip to content

Commit

Permalink
linux-user: Use getcwd syscall directly
Browse files Browse the repository at this point in the history
The glibc getcwd function returns different errors than the getcwd
syscall, which triggers an assertion failure in the glibc getcwd function
when running under the emulation.

When the syscall returns ENAMETOOLONG, the glibc wrapper uses a fallback
implementation that potentially handles an unlimited path length, and
returns with ERANGE if the provided buffer is too small.  The qemu
emulation cannot distinguish the two cases, and thus always returns ERANGE.
This is unexpected by the glibc wrapper.

Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <mvmmu3qplvi.fsf@suse.de>
[lv: updated description]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
  • Loading branch information
andreas-schwab authored and vivier committed Jul 27, 2020
1 parent 4d21300 commit 0f6bb19
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,7 @@ static bitmask_transtbl fcntl_flags_tbl[] = {
{ 0, 0, 0, 0 }
};

static int sys_getcwd1(char *buf, size_t size)
{
if (getcwd(buf, size) == NULL) {
/* getcwd() sets errno */
return (-1);
}
return strlen(buf)+1;
}
_syscall2(int, sys_getcwd1, char *, buf, size_t, size)

#ifdef TARGET_NR_utimensat
#if defined(__NR_utimensat)
Expand Down

0 comments on commit 0f6bb19

Please sign in to comment.