Skip to content

Commit 17495b1

Browse files
committed
LATX, fix: Convert SigPnd, ShdPnd, SigBlk, SigIgn and SigCgt values when reading /proc/<pid>/status.
This fixes an issue where the Java attach listener could not start properly. Signed-off-by: liuchaoyi <liuchaoyi@loongson.cn>
1 parent f1986d0 commit 17495b1

1 file changed

Lines changed: 70 additions & 0 deletions

File tree

linux-user/syscall.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10482,6 +10482,75 @@ static int open_other_cmdline(void *cpu_env, int fd, const char *oldpath)
1048210482
return ret;
1048310483
}
1048410484

10485+
static uint64_t convert_sigcgt_host_to_x86(const char *hex128)
10486+
{
10487+
uint64_t words[2] = {0, 0};
10488+
10489+
sscanf(hex128, "%16lx%16lx", &words[1], &words[0]);
10490+
10491+
uint64_t result = 0;
10492+
10493+
for (int sig = 1; sig < 128; sig++) {
10494+
int idx = (sig - 1) / 64;
10495+
int bit = (sig - 1) % 64;
10496+
10497+
if (words[idx] & (1ULL << bit)) {
10498+
10499+
int tsig = host_to_target_signal(sig);
10500+
10501+
if (tsig >= 1 && tsig <= 64) {
10502+
result |= (1ULL << (tsig - 1));
10503+
}
10504+
}
10505+
}
10506+
10507+
return result;
10508+
}
10509+
10510+
static void convert_sigcgt_line(const char *src, char *dst, size_t dstsz)
10511+
{
10512+
const char *hex = src + 7;
10513+
10514+
while (*hex == ' ' || *hex == '\t') hex++;
10515+
10516+
char buf[128];
10517+
snprintf(buf, sizeof(buf), "%s", hex);
10518+
10519+
char *nl = strchr(buf, '\n');
10520+
if (nl) *nl = '\0';
10521+
10522+
uint64_t result= convert_sigcgt_host_to_x86(buf);
10523+
10524+
snprintf(dst, dstsz, "SigCgt:\t%016lx\n", result);
10525+
}
10526+
10527+
static int open_proc_status_other(void *cpu_env, int fd, const char *path)
10528+
{
10529+
char line[512];
10530+
10531+
FILE *fp = fopen(path, "r");
10532+
if (!fp) {
10533+
return -1;
10534+
}
10535+
10536+
while (fgets(line, sizeof(line), fp)) {
10537+
if (strncmp(line, "SigPnd:", 7) == 0 ||
10538+
strncmp(line, "ShdPnd:", 7) == 0 ||
10539+
strncmp(line, "SigBlk:", 7) == 0 ||
10540+
strncmp(line, "SigIgn:", 7) == 0 ||
10541+
strncmp(line, "SigCgt:", 7) == 0) {
10542+
char new_line[512];
10543+
convert_sigcgt_line(line, new_line, sizeof(new_line));
10544+
dprintf(fd, "%s", new_line);
10545+
} else {
10546+
dprintf(fd, "%s", line);
10547+
}
10548+
}
10549+
10550+
fclose(fp);
10551+
return 0;
10552+
}
10553+
1048510554
struct open_self_maps_data {
1048610555
TaskState *ts;
1048710556
IntervalTreeRoot *host_maps;
@@ -11139,6 +11208,7 @@ static int do_openat(void *cpu_env, int dirfd, const char *pathname, int flags,
1113911208
{ "auxv", open_self_auxv, is_proc_myself },
1114011209
{ "cmdline", open_self_cmdline, is_proc_myself },
1114111210
{ "cmdline", open_other_cmdline, is_proc_other},
11211+
{ "status", open_proc_status_other, is_proc_other },
1114211212
#if defined(HOST_WORDS_BIGENDIAN) != defined(TARGET_WORDS_BIGENDIAN)
1114311213
{ "/proc/net/route", open_net_route, is_proc },
1114411214
#endif

0 commit comments

Comments
 (0)