Skip to content

Commit 13dfb24

Browse files
Andrew HsiehGerrit Code Review
authored andcommitted
Merge "[MIPS] Cleaned up sig_0 error messages and added a few more checks."
2 parents 703b256 + b294db4 commit 13dfb24

File tree

1 file changed

+55
-7
lines changed
  • ndk/sources/android/libportable/arch-mips

1 file changed

+55
-7
lines changed

ndk/sources/android/libportable/arch-mips/signal.c

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ __hidden char *map_portable_signum_to_name(int portable_signum)
6363
char *name;
6464

6565
switch(portable_signum) {
66+
case 0: name = "SIG_0_PORTABLE:0"; break;
6667
case SIGHUP_PORTABLE: name = "SIGHUP_PORTABLE:1"; break;
6768
case SIGINT_PORTABLE: name = "SIGINT_PORTABLE:2"; break;
6869
case SIGQUIT_PORTABLE: name = "SIGQUIT_PORTABLE:3"; break;
@@ -140,6 +141,7 @@ __hidden char *map_mips_signum_to_name(int mips_signum)
140141
char *name;
141142

142143
switch(mips_signum) {
144+
case 0: name = "SIG_0:0"; break;
143145
case SIGHUP: name = "SIGHUP:1"; break;
144146
case SIGINT: name = "SIGINT:2"; break;
145147
case SIGQUIT: name = "SIGQUIT:3"; break;
@@ -223,6 +225,10 @@ __hidden int signum_pton(int portable_signum)
223225
int mips_signum = -1;
224226

225227
switch(portable_signum) {
228+
229+
case 0: /* 0 */
230+
return 0;
231+
226232
case SIGHUP_PORTABLE: /* 1 */
227233
return SIGHUP;
228234

@@ -340,8 +346,8 @@ __hidden int signum_pton(int portable_signum)
340346
} else if (portable_signum > NSIG_PORTABLE) {
341347
mips_signum = (portable_signum - NSIG_PORTABLE) + NSIG;
342348
} else {
343-
ALOGE("%s: 0 <= portable_signum:%d <= NSIG_PORTABLE:%d; Not supported, return(0);",
344-
__func__, portable_signum, NSIG_PORTABLE);
349+
ALOGE("%s: 0 < portable_signum:%d <= NSIG_PORTABLE:%d; Not supported, return(0);",
350+
__func__, portable_signum, NSIG_PORTABLE);
345351

346352
mips_signum = 0;
347353
}
@@ -362,6 +368,9 @@ __hidden int signum_ntop(int mips_signum)
362368
int portable_ssignum = -1;
363369

364370
switch(mips_signum) {
371+
case 0: /* 0 */
372+
return 0;
373+
365374
case SIGHUP: /* 1 */
366375
return SIGHUP_PORTABLE;
367376

@@ -696,9 +705,10 @@ do_signal_portable(int portable_signum, sighandler_portable_t portable_handler,
696705

697706
mips_signum = signum_pton(portable_signum);
698707

699-
if ((portable_signum != 0) && ((mips_signum <= 0) || (mips_signum > NSIG))) {
708+
if ((mips_signum <= 0) || (mips_signum > NSIG)) {
700709
/*
701-
* Invalid request; Let the kernel generate the proper return value and set errno.
710+
* Invalid signal number, perhaps zero. Let the kernel generate the
711+
* proper return value and set errno.
702712
*/
703713
mips_handler = sighandler_pton(portable_handler, 0);
704714
rv = mips_signal_fn(mips_signum, mips_handler);
@@ -801,6 +811,11 @@ static int do_kill(int id, int portable_signum, int (*fn)(int, int))
801811

802812
mips_signum = signum_pton(portable_signum);
803813

814+
/*
815+
* SIG_0 gets passed down to the kernel to test for the existence of a process.
816+
* If a non-zero portable_signum has been mapped to 0,
817+
* it's unsupported and will be ignored.
818+
*/
804819
if ((portable_signum != 0) && (mips_signum == 0)) {
805820
rv = 0;
806821
} else {
@@ -876,6 +891,10 @@ int WRAP(tgkill)(int tgid, int tid, int portable_signum)
876891

877892
mips_signum = signum_pton(portable_signum);
878893

894+
/*
895+
* If a non-zero portable_signum has been mapped to 0,
896+
* it is unsupported and will be ignored.
897+
*/
879898
if ((portable_signum != 0) && (mips_signum == 0))
880899
rv = 0;
881900
else
@@ -895,6 +914,11 @@ int WRAP(raise)(int portable_signum)
895914

896915
ALOGV("%s(portable_signum:%d:'%s') {", __func__, portable_signum, portable_signame);
897916

917+
/*
918+
* SIG_0 gets passed down to the kernel to test for the existence of a process.
919+
* If a non-zero portable_signum has been mapped to 0,
920+
* it's unsupported and will be ignored.
921+
*/
898922
if ((portable_signum != 0) && (mips_signum == 0))
899923
rv = 0;
900924
else
@@ -1098,8 +1122,11 @@ static int do_sigaction_portable(int portable_signum, const struct sigaction_por
10981122
mips_signum = signum_pton(portable_signum);
10991123
mips_signame = map_mips_signum_to_name(mips_signum);
11001124

1125+
/*
1126+
* If a non-zero portable_signum has been mapped to 0,
1127+
* it's unsupported and will be ignored.
1128+
*/
11011129
if ((portable_signum != 0) && (mips_signum == 0)) {
1102-
/* We got a portable signum that we can't map; Ignore the request */
11031130
rv = 0;
11041131
goto done;
11051132
}
@@ -1407,9 +1434,11 @@ int WRAP(siginterrupt)(int portable_signum, int flag)
14071434

14081435
mips_signum = signum_pton(portable_signum);
14091436

1437+
/*
1438+
* If a non-zero portable_signum has been mapped to 0,
1439+
* it's unsupported and will be ignored.
1440+
*/
14101441
if ((portable_signum != 0) && (mips_signum == 0)) {
1411-
ALOGE("%s: Unsupported portable_signum:%d; Ignoring.", __func__,
1412-
portable_signum);
14131442
rv = 0;
14141443
} else {
14151444
rv = REAL(siginterrupt)(mips_signum, flag);
@@ -1663,6 +1692,15 @@ int WRAP(rt_sigqueueinfo)(pid_t pid, int portable_sig, siginfo_portable_t *porta
16631692

16641693
native_sig = signum_pton(portable_sig);
16651694

1695+
/*
1696+
* If a non-zero portable_signum has been mapped to 0,
1697+
* it's unsupported and will be ignored.
1698+
*/
1699+
if ((portable_sig != 0) && (native_sig == 0)) {
1700+
rv = 0;
1701+
goto done;
1702+
}
1703+
16661704
if (portable_sip != NULL) {
16671705
native_sip = &native_siginfo;
16681706
siginfo_pton(portable_sip, native_sip);
@@ -1671,6 +1709,7 @@ int WRAP(rt_sigqueueinfo)(pid_t pid, int portable_sig, siginfo_portable_t *porta
16711709
}
16721710
rv = syscall(__NR_rt_sigqueueinfo, pid, native_sig, native_sip);
16731711

1712+
done:
16741713
ALOGV("%s: return(rv:%d); }", __func__, rv);
16751714
return rv;
16761715
}
@@ -1694,6 +1733,14 @@ int WRAP(rt_tgsigqueueinfo)(pid_t tgid, pid_t pid, int portable_sig,
16941733

16951734
native_sig = signum_pton(portable_sig);
16961735

1736+
/*
1737+
* If a non-zero portable_signum has been mapped to 0,
1738+
* it's unsupported and will be ignored.
1739+
*/
1740+
if ((portable_sig != 0) && (native_sig == 0)) {
1741+
rv = 0;
1742+
goto done;
1743+
}
16971744
if (portable_sip != NULL) {
16981745
native_sip = &native_siginfo;
16991746
siginfo_pton(portable_sip, native_sip);
@@ -1702,6 +1749,7 @@ int WRAP(rt_tgsigqueueinfo)(pid_t tgid, pid_t pid, int portable_sig,
17021749
}
17031750
rv = syscall(__NR_rt_tgsigqueueinfo, pid, native_sig, native_sip);
17041751

1752+
done:
17051753
ALOGV("%s: return(rv:%d); }", __func__, rv);
17061754
return rv;
17071755
}

0 commit comments

Comments
 (0)