Lines 7482-7519
static int open_self_auxv(void *cpu_env, int fd)
Link Here
|
7482 |
return 0; |
7482 |
return 0; |
7483 |
} |
7483 |
} |
7484 |
|
7484 |
|
7485 |
static int is_proc_myself(const char *filename, const char *entry) |
7485 |
#define PROC "/proc/" |
7486 |
{ |
7486 |
#define SELF "self/" |
7487 |
if (!strncmp(filename, "/proc/", strlen("/proc/"))) { |
7487 |
|
7488 |
filename += strlen("/proc/"); |
7488 |
#define STARTS_WITH(path, CONSTANT) ( \ |
7489 |
if (!strncmp(filename, "self/", strlen("self/"))) { |
7489 |
strlen(path) >= strlen(CONSTANT) && \ |
7490 |
filename += strlen("self/"); |
7490 |
strncmp(path, CONSTANT, strlen(CONSTANT)) == 0 \ |
7491 |
} else if (*filename >= '1' && *filename <= '9') { |
7491 |
) |
7492 |
char myself[80]; |
7492 |
|
7493 |
snprintf(myself, sizeof(myself), "%d/", getpid()); |
7493 |
static inline char *scope_to_proc(const char *path) |
7494 |
if (!strncmp(filename, myself, strlen(myself))) { |
7494 |
{ |
7495 |
filename += strlen(myself); |
7495 |
if (STARTS_WITH(path, PROC)) { |
7496 |
} else { |
7496 |
return (char *)path + strlen(PROC); |
7497 |
return 0; |
|
|
7498 |
} |
7499 |
} else { |
7500 |
return 0; |
7501 |
} |
7502 |
if (!strcmp(filename, entry)) { |
7503 |
return 1; |
7504 |
} |
7505 |
} |
7497 |
} |
7506 |
return 0; |
7498 |
|
|
|
7499 |
return NULL; |
7500 |
} |
7501 |
|
7502 |
static inline char *scope_to_proc_myself(const char *path) |
7503 |
{ |
7504 |
char *scope_path = scope_to_proc(path); |
7505 |
if (scope_path == NULL) { |
7506 |
return NULL; |
7507 |
} |
7508 |
|
7509 |
if (STARTS_WITH(scope_path, SELF)) { |
7510 |
return scope_path + strlen(SELF); |
7511 |
} |
7512 |
|
7513 |
if (strlen(scope_path) >= 1 && |
7514 |
*scope_path >= '1' && *scope_path <= '9') { |
7515 |
char pid_path[80]; |
7516 |
snprintf(pid_path, sizeof(pid_path), "%d/", getpid()); |
7517 |
if (STARTS_WITH(scope_path, pid_path)) { |
7518 |
return scope_path + strlen(pid_path); |
7519 |
} |
7520 |
} |
7521 |
|
7522 |
return NULL; |
7507 |
} |
7523 |
} |
7508 |
|
7524 |
|
7509 |
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) || \ |
7525 |
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) || \ |
7510 |
defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) |
7526 |
defined(TARGET_SPARC) || defined(TARGET_M68K) || defined(TARGET_HPPA) |
7511 |
static int is_proc(const char *filename, const char *entry) |
7527 |
static int is_proc(const char *path, const char *entry) |
7512 |
{ |
7528 |
{ |
7513 |
return strcmp(filename, entry) == 0; |
7529 |
char *scope_path = scope_to_proc(path); |
|
|
7530 |
if (scope_path == NULL) { |
7531 |
return 0; |
7532 |
} |
7533 |
|
7534 |
return strcmp(scope_path, entry) == 0; |
7514 |
} |
7535 |
} |
7515 |
#endif |
7536 |
#endif |
7516 |
|
7537 |
|
|
|
7538 |
static int is_proc_myself(const char *path, const char *entry) |
7539 |
{ |
7540 |
char *scope_path = scope_to_proc_myself(path); |
7541 |
if (scope_path == NULL) { |
7542 |
return 0; |
7543 |
} |
7544 |
|
7545 |
return strcmp(scope_path, entry) == 0; |
7546 |
} |
7547 |
|
7517 |
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
7548 |
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
7518 |
static int open_net_route(void *cpu_env, int fd) |
7549 |
static int open_net_route(void *cpu_env, int fd) |
7519 |
{ |
7550 |
{ |
Lines 7601-7620
static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
Link Here
|
7601 |
{ "auxv", open_self_auxv, is_proc_myself }, |
7632 |
{ "auxv", open_self_auxv, is_proc_myself }, |
7602 |
{ "cmdline", open_self_cmdline, is_proc_myself }, |
7633 |
{ "cmdline", open_self_cmdline, is_proc_myself }, |
7603 |
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
7634 |
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN) |
7604 |
{ "/proc/net/route", open_net_route, is_proc }, |
7635 |
{ "net/route", open_net_route, is_proc }, |
7605 |
#endif |
7636 |
#endif |
7606 |
#if defined(TARGET_SPARC) || defined(TARGET_HPPA) |
7637 |
#if defined(TARGET_SPARC) || defined(TARGET_HPPA) |
7607 |
{ "/proc/cpuinfo", open_cpuinfo, is_proc }, |
7638 |
{ "cpuinfo", open_cpuinfo, is_proc }, |
7608 |
#endif |
7639 |
#endif |
7609 |
#if defined(TARGET_M68K) |
7640 |
#if defined(TARGET_M68K) |
7610 |
{ "/proc/hardware", open_hardware, is_proc }, |
7641 |
{ "hardware", open_hardware, is_proc }, |
7611 |
#endif |
7642 |
#endif |
7612 |
{ NULL, NULL, NULL } |
7643 |
{ NULL, NULL, NULL } |
7613 |
}; |
7644 |
}; |
7614 |
|
7645 |
|
7615 |
if (is_proc_myself(pathname, "exe")) { |
7646 |
if (is_proc_myself(pathname, "exe")) { |
7616 |
int execfd = qemu_getauxval(AT_EXECFD); |
7647 |
/* |
7617 |
return execfd ? execfd : safe_openat(dirfd, exec_path, flags, mode); |
7648 |
* We can't use AT_EXECFD here. |
|
|
7649 |
* User can close provided fd and another user will receive closed fd. |
7650 |
*/ |
7651 |
return safe_openat(dirfd, exec_path, flags, mode); |
7618 |
} |
7652 |
} |
7619 |
|
7653 |
|
7620 |
for (fake_open = fakes; fake_open->filename; fake_open++) { |
7654 |
for (fake_open = fakes; fake_open->filename; fake_open++) { |