syscall: Add readlink to x86 with special case /proc/self/exe
This patch implements the correct behavior.
This commit is contained in:
parent
4710eba588
commit
d0f6aad3c6
|
@ -485,7 +485,7 @@ static SyscallDesc syscallDescs64[] = {
|
||||||
/* 264 */ SyscallDesc("renameat", unimplementedFunc),
|
/* 264 */ SyscallDesc("renameat", unimplementedFunc),
|
||||||
/* 265 */ SyscallDesc("linkat", unimplementedFunc),
|
/* 265 */ SyscallDesc("linkat", unimplementedFunc),
|
||||||
/* 266 */ SyscallDesc("symlinkat", unimplementedFunc),
|
/* 266 */ SyscallDesc("symlinkat", unimplementedFunc),
|
||||||
/* 267 */ SyscallDesc("readlinkat", unimplementedFunc),
|
/* 267 */ SyscallDesc("readlinkat", readlinkFunc),
|
||||||
/* 268 */ SyscallDesc("fchmodat", unimplementedFunc),
|
/* 268 */ SyscallDesc("fchmodat", unimplementedFunc),
|
||||||
/* 269 */ SyscallDesc("faccessat", unimplementedFunc),
|
/* 269 */ SyscallDesc("faccessat", unimplementedFunc),
|
||||||
/* 270 */ SyscallDesc("pselect6", unimplementedFunc),
|
/* 270 */ SyscallDesc("pselect6", unimplementedFunc),
|
||||||
|
@ -626,7 +626,7 @@ static SyscallDesc syscallDescs32[] = {
|
||||||
/* 82 */ SyscallDesc("select", unimplementedFunc),
|
/* 82 */ SyscallDesc("select", unimplementedFunc),
|
||||||
/* 83 */ SyscallDesc("symlink", unimplementedFunc),
|
/* 83 */ SyscallDesc("symlink", unimplementedFunc),
|
||||||
/* 84 */ SyscallDesc("oldlstat", unimplementedFunc),
|
/* 84 */ SyscallDesc("oldlstat", unimplementedFunc),
|
||||||
/* 85 */ SyscallDesc("readlink", unimplementedFunc),
|
/* 85 */ SyscallDesc("readlink", readlinkFunc),
|
||||||
/* 86 */ SyscallDesc("uselib", unimplementedFunc),
|
/* 86 */ SyscallDesc("uselib", unimplementedFunc),
|
||||||
/* 87 */ SyscallDesc("swapon", unimplementedFunc),
|
/* 87 */ SyscallDesc("swapon", unimplementedFunc),
|
||||||
/* 88 */ SyscallDesc("reboot", unimplementedFunc),
|
/* 88 */ SyscallDesc("reboot", unimplementedFunc),
|
||||||
|
@ -846,7 +846,7 @@ static SyscallDesc syscallDescs32[] = {
|
||||||
/* 302 */ SyscallDesc("renameat", unimplementedFunc),
|
/* 302 */ SyscallDesc("renameat", unimplementedFunc),
|
||||||
/* 303 */ SyscallDesc("linkat", unimplementedFunc),
|
/* 303 */ SyscallDesc("linkat", unimplementedFunc),
|
||||||
/* 304 */ SyscallDesc("symlinkat", unimplementedFunc),
|
/* 304 */ SyscallDesc("symlinkat", unimplementedFunc),
|
||||||
/* 305 */ SyscallDesc("readlinkat", unimplementedFunc),
|
/* 305 */ SyscallDesc("readlinkat", readlinkFunc),
|
||||||
/* 306 */ SyscallDesc("fchmodat", unimplementedFunc),
|
/* 306 */ SyscallDesc("fchmodat", unimplementedFunc),
|
||||||
/* 307 */ SyscallDesc("faccessat", unimplementedFunc),
|
/* 307 */ SyscallDesc("faccessat", unimplementedFunc),
|
||||||
/* 308 */ SyscallDesc("pselect6", unimplementedFunc),
|
/* 308 */ SyscallDesc("pselect6", unimplementedFunc),
|
||||||
|
|
|
@ -365,12 +365,10 @@ getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
||||||
}
|
}
|
||||||
strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
|
strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
|
||||||
result = cwd.length();
|
result = cwd.length();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
|
if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
|
||||||
result = strlen((char *)buf.bufferPtr());
|
result = strlen((char *)buf.bufferPtr());
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
result = -1;
|
result = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,7 +403,30 @@ readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc,
|
||||||
|
|
||||||
BufferArg buf(bufPtr, bufsiz);
|
BufferArg buf(bufPtr, bufsiz);
|
||||||
|
|
||||||
int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
|
int result = -1;
|
||||||
|
if (path != "/proc/self/exe") {
|
||||||
|
result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
|
||||||
|
} else {
|
||||||
|
// readlink() will return the path of the binary given
|
||||||
|
// with the -c option, however it is possible that this
|
||||||
|
// will still result in incorrect behavior if one binary
|
||||||
|
// runs another, e.g., -c time -o "my_binary" where
|
||||||
|
// my_binary calls readlink(). this is a very unlikely case,
|
||||||
|
// so we issue a warning.
|
||||||
|
warn_once("readlink may yield unexpected results if multiple "
|
||||||
|
"binaries are used\n");
|
||||||
|
if (strlen(p->progName()) > bufsiz) {
|
||||||
|
// readlink will truncate the contents of the
|
||||||
|
// path to ensure it is no more than bufsiz
|
||||||
|
strncpy((char*)buf.bufferPtr(), p->progName(), bufsiz);
|
||||||
|
result = bufsiz;
|
||||||
|
} else {
|
||||||
|
// return the program's working path rather
|
||||||
|
// than the one for the gem5 binary itself.
|
||||||
|
strcpy((char*)buf.bufferPtr(), p->progName());
|
||||||
|
result = strlen((char*)buf.bufferPtr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buf.copyOut(tc->getMemProxy());
|
buf.copyOut(tc->getMemProxy());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue