aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2022-01-13 08:02:41 +0000
committerRon Yorston <rmy@pobox.com>2022-01-13 08:02:41 +0000
commit4734416a21312488a5099a297907783bee4ccc22 (patch)
treee42b034f9685a0a07ad080076b757bfba654cf7d
parentb8751bbc9ac24e71fbe1e79c69074b4c87a134d8 (diff)
parentb3eec1651fb02d70716caa355f49320719f74c75 (diff)
downloadbusybox-w32-4734416a21312488a5099a297907783bee4ccc22.tar.gz
busybox-w32-4734416a21312488a5099a297907783bee4ccc22.tar.bz2
busybox-w32-4734416a21312488a5099a297907783bee4ccc22.zip
Merge busybox into merge
Fix merge conflicts in coreutils/ls.c and shell/ash.c. Update config files to turn off SHA1_HWACCEL. It uses non-portable assembler.
-rw-r--r--configs/mingw32_defconfig2
-rw-r--r--configs/mingw64_defconfig2
-rw-r--r--console-tools/reset.c2
-rw-r--r--coreutils/ls.c13
-rw-r--r--coreutils/md5_sha1_sum.c10
-rw-r--r--editors/awk.c29
-rw-r--r--include/libbb.h18
-rw-r--r--libbb/Config.src7
-rw-r--r--libbb/Kbuild.src2
-rw-r--r--libbb/hash_md5_sha.c35
-rw-r--r--libbb/hash_md5_sha_x86-32_shaNI.S231
-rw-r--r--libbb/hash_md5_sha_x86-64.S14
-rwxr-xr-xlibbb/hash_md5_sha_x86-64.S.sh36
-rw-r--r--libbb/hash_md5_sha_x86-64_shaNI.S225
-rw-r--r--libbb/setup_environment.c8
-rw-r--r--loginutils/login.c4
-rw-r--r--loginutils/sulogin.c48
-rw-r--r--procps/nmeter.c46
-rw-r--r--procps/powertop.c5
-rw-r--r--shell/ash.c17
-rwxr-xr-xtestsuite/awk.tests12
-rw-r--r--util-linux/fdisk.c1
22 files changed, 694 insertions, 73 deletions
diff --git a/configs/mingw32_defconfig b/configs/mingw32_defconfig
index d41899fdc..408b13eb8 100644
--- a/configs/mingw32_defconfig
+++ b/configs/mingw32_defconfig
@@ -112,6 +112,8 @@ CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
112# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set 112# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
113CONFIG_PASSWORD_MINLEN=6 113CONFIG_PASSWORD_MINLEN=6
114CONFIG_MD5_SMALL=1 114CONFIG_MD5_SMALL=1
115CONFIG_SHA1_SMALL=3
116# CONFIG_SHA1_HWACCEL is not set
115CONFIG_SHA3_SMALL=1 117CONFIG_SHA3_SMALL=1
116# CONFIG_FEATURE_FAST_TOP is not set 118# CONFIG_FEATURE_FAST_TOP is not set
117# CONFIG_FEATURE_ETC_NETWORKS is not set 119# CONFIG_FEATURE_ETC_NETWORKS is not set
diff --git a/configs/mingw64_defconfig b/configs/mingw64_defconfig
index 449f16ae6..05596ab8e 100644
--- a/configs/mingw64_defconfig
+++ b/configs/mingw64_defconfig
@@ -112,6 +112,8 @@ CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
112# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set 112# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
113CONFIG_PASSWORD_MINLEN=6 113CONFIG_PASSWORD_MINLEN=6
114CONFIG_MD5_SMALL=1 114CONFIG_MD5_SMALL=1
115CONFIG_SHA1_SMALL=3
116# CONFIG_SHA1_HWACCEL is not set
115CONFIG_SHA3_SMALL=1 117CONFIG_SHA3_SMALL=1
116# CONFIG_FEATURE_FAST_TOP is not set 118# CONFIG_FEATURE_FAST_TOP is not set
117# CONFIG_FEATURE_ETC_NETWORKS is not set 119# CONFIG_FEATURE_ETC_NETWORKS is not set
diff --git a/console-tools/reset.c b/console-tools/reset.c
index 2f65aad15..e0d228d50 100644
--- a/console-tools/reset.c
+++ b/console-tools/reset.c
@@ -24,7 +24,7 @@
24//usage:#define reset_trivial_usage 24//usage:#define reset_trivial_usage
25//usage: "" 25//usage: ""
26//usage:#define reset_full_usage "\n\n" 26//usage:#define reset_full_usage "\n\n"
27//usage: "Reset the screen" 27//usage: "Reset terminal (ESC codes) and termios (signals, buffering, echo)"
28 28
29/* "Standard" version of this tool is in ncurses package */ 29/* "Standard" version of this tool is in ncurses package */
30 30
diff --git a/coreutils/ls.c b/coreutils/ls.c
index 58b8fde75..d8cfe27d3 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -505,9 +505,16 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
505#else 505#else
506 column += printf("%19"LL_FMT"u ", (long long) dn->dn_ino); 506 column += printf("%19"LL_FMT"u ", (long long) dn->dn_ino);
507#endif 507#endif
508//TODO: -h should affect -s too: 508 if (opt & OPT_s) { /* show allocated blocks */
509 if (opt & OPT_s) /* show allocated blocks */ 509 if (opt & OPT_h) {
510 column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1)); 510 column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
511 /* print size, show one fractional, use suffixes */
512 make_human_readable_str((off_t)dn->dn_blocks << 9, 1, 0)
513 );
514 } else {
515 column += printf("%6"OFF_FMT"u ", (off_t)(dn->dn_blocks >> 1));
516 }
517 }
511 if (opt & OPT_l) { 518 if (opt & OPT_l) {
512 /* long listing: show mode */ 519 /* long listing: show mode */
513 char modestr[12]; 520 char modestr[12];
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 3b389cb6b..0e57673f1 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -300,12 +300,10 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
300 char *filename_ptr; 300 char *filename_ptr;
301 301
302 count_total++; 302 count_total++;
303 filename_ptr = strstr(line, " "); 303 filename_ptr = strchr(line, ' ');
304 /* handle format for binary checksums */ 304 if (filename_ptr == NULL
305 if (filename_ptr == NULL) { 305 || (filename_ptr[1] != ' ' && filename_ptr[1] != '*')
306 filename_ptr = strstr(line, " *"); 306 ) {
307 }
308 if (filename_ptr == NULL) {
309 if (flags & FLAG_WARN) { 307 if (flags & FLAG_WARN) {
310 bb_simple_error_msg("invalid format"); 308 bb_simple_error_msg("invalid format");
311 } 309 }
diff --git a/editors/awk.c b/editors/awk.c
index 17710e57e..9b4d4dc3d 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -852,7 +852,7 @@ static char *nextword(char **s)
852static char nextchar(char **s) 852static char nextchar(char **s)
853{ 853{
854 char c, *pps; 854 char c, *pps;
855 855 again:
856 c = *(*s)++; 856 c = *(*s)++;
857 pps = *s; 857 pps = *s;
858 if (c == '\\') 858 if (c == '\\')
@@ -863,8 +863,11 @@ static char nextchar(char **s)
863 */ 863 */
864 if (c == '\\' && *s == pps) { /* unrecognized \z? */ 864 if (c == '\\' && *s == pps) { /* unrecognized \z? */
865 c = *(*s); /* yes, fetch z */ 865 c = *(*s); /* yes, fetch z */
866 if (c) 866 if (c) { /* advance unless z = NUL */
867 (*s)++; /* advance unless z = NUL */ 867 (*s)++;
868 if (c == '\n') /* \<newline>? eat it */
869 goto again;
870 }
868 } 871 }
869 return c; 872 return c;
870} 873}
@@ -886,7 +889,13 @@ static ALWAYS_INLINE int isalnum_(int c)
886static double my_strtod(char **pp) 889static double my_strtod(char **pp)
887{ 890{
888 char *cp = *pp; 891 char *cp = *pp;
889 if (ENABLE_DESKTOP && cp[0] == '0') { 892 return strtod(cp, pp);
893}
894#if ENABLE_DESKTOP
895static double my_strtod_or_hexoct(char **pp)
896{
897 char *cp = *pp;
898 if (cp[0] == '0') {
890 /* Might be hex or octal integer: 0x123abc or 07777 */ 899 /* Might be hex or octal integer: 0x123abc or 07777 */
891 char c = (cp[1] | 0x20); 900 char c = (cp[1] | 0x20);
892 if (c == 'x' || isdigit(cp[1])) { 901 if (c == 'x' || isdigit(cp[1])) {
@@ -905,6 +914,9 @@ static double my_strtod(char **pp)
905 } 914 }
906 return strtod(cp, pp); 915 return strtod(cp, pp);
907} 916}
917#else
918# define my_strtod_or_hexoct(p) my_strtod(p)
919#endif
908 920
909/* -------- working with variables (set/get/copy/etc) -------- */ 921/* -------- working with variables (set/get/copy/etc) -------- */
910 922
@@ -1018,6 +1030,7 @@ static double getvar_i(var *v)
1018 if (s && *s) { 1030 if (s && *s) {
1019 debug_printf_eval("getvar_i: '%s'->", s); 1031 debug_printf_eval("getvar_i: '%s'->", s);
1020 v->number = my_strtod(&s); 1032 v->number = my_strtod(&s);
1033 /* ^^^ hex/oct NOT allowed here! */
1021 debug_printf_eval("%f (s:'%s')\n", v->number, s); 1034 debug_printf_eval("%f (s:'%s')\n", v->number, s);
1022 if (v->type & VF_USER) { 1035 if (v->type & VF_USER) {
1023//TODO: skip_spaces() also skips backslash+newline, is it intended here? 1036//TODO: skip_spaces() also skips backslash+newline, is it intended here?
@@ -1129,10 +1142,10 @@ static uint32_t next_token(uint32_t expected)
1129 if (*p == '\0') { 1142 if (*p == '\0') {
1130 tc = TC_EOF; 1143 tc = TC_EOF;
1131 debug_printf_parse("%s: token found: TC_EOF\n", __func__); 1144 debug_printf_parse("%s: token found: TC_EOF\n", __func__);
1132 } else if (*p == '\"') { 1145 } else if (*p == '"') {
1133 /* it's a string */ 1146 /* it's a string */
1134 char *s = t_string = ++p; 1147 char *s = t_string = ++p;
1135 while (*p != '\"') { 1148 while (*p != '"') {
1136 char *pp; 1149 char *pp;
1137 if (*p == '\0' || *p == '\n') 1150 if (*p == '\0' || *p == '\n')
1138 syntax_error(EMSG_UNEXP_EOS); 1151 syntax_error(EMSG_UNEXP_EOS);
@@ -1170,7 +1183,8 @@ static uint32_t next_token(uint32_t expected)
1170 } else if (*p == '.' || isdigit(*p)) { 1183 } else if (*p == '.' || isdigit(*p)) {
1171 /* it's a number */ 1184 /* it's a number */
1172 char *pp = p; 1185 char *pp = p;
1173 t_double = my_strtod(&pp); 1186 t_double = my_strtod_or_hexoct(&pp);
1187 /* ^^^ awk only allows hex/oct consts in _program_, not in _input_ */
1174 p = pp; 1188 p = pp;
1175 if (*p == '.') 1189 if (*p == '.')
1176 syntax_error(EMSG_UNEXP_TOKEN); 1190 syntax_error(EMSG_UNEXP_TOKEN);
@@ -3528,6 +3542,7 @@ static var *evaluate(node *op, var *res)
3528 i = (Ld == 0); 3542 i = (Ld == 0);
3529 break; 3543 break;
3530 } 3544 }
3545 debug_printf_eval("COMPARE result: %d\n", (i == 0) ^ (opn & 1));
3531 setvar_i(res, (i == 0) ^ (opn & 1)); 3546 setvar_i(res, (i == 0) ^ (opn & 1));
3532 break; 3547 break;
3533 } 3548 }
diff --git a/include/libbb.h b/include/libbb.h
index e332f165a..e540f2a90 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1776,15 +1776,16 @@ extern void selinux_or_die(void) FAST_FUNC;
1776 1776
1777 1777
1778/* setup_environment: 1778/* setup_environment:
1779 * if chdir pw->pw_dir: ok: else if to_tmp == 1: goto /tmp else: goto / or die 1779 * if !SETUP_ENV_NO_CHDIR:
1780 * if clear_env = 1: cd(pw->pw_dir), clear environment, then set 1780 * if cd(pw->pw_dir): ok: else if SETUP_ENV_TO_TMP: cd(/tmp) else: cd(/) or die
1781 * if SETUP_ENV_CLEARENV: cd(pw->pw_dir), clear environment, then set
1781 * TERM=(old value) 1782 * TERM=(old value)
1782 * USER=pw->pw_name, LOGNAME=pw->pw_name 1783 * USER=pw->pw_name, LOGNAME=pw->pw_name
1783 * PATH=bb_default_[root_]path 1784 * PATH=bb_default_[root_]path
1784 * HOME=pw->pw_dir 1785 * HOME=pw->pw_dir
1785 * SHELL=shell 1786 * SHELL=shell
1786 * else if change_env = 1: 1787 * else if SETUP_ENV_CHANGEENV:
1787 * if not root (if pw->pw_uid != 0): 1788 * if not root (if pw->pw_uid != 0) or if SETUP_ENV_CHANGEENV_LOGNAME:
1788 * USER=pw->pw_name, LOGNAME=pw->pw_name 1789 * USER=pw->pw_name, LOGNAME=pw->pw_name
1789 * HOME=pw->pw_dir 1790 * HOME=pw->pw_dir
1790 * SHELL=shell 1791 * SHELL=shell
@@ -1793,10 +1794,11 @@ extern void selinux_or_die(void) FAST_FUNC;
1793 * NB: CHANGEENV and CLEARENV use setenv() - this leaks memory! 1794 * NB: CHANGEENV and CLEARENV use setenv() - this leaks memory!
1794 * If setup_environment() is used is vforked child, this leaks memory _in parent too_! 1795 * If setup_environment() is used is vforked child, this leaks memory _in parent too_!
1795 */ 1796 */
1796#define SETUP_ENV_CHANGEENV (1 << 0) 1797#define SETUP_ENV_CHANGEENV (1 << 0)
1797#define SETUP_ENV_CLEARENV (1 << 1) 1798#define SETUP_ENV_CHANGEENV_LOGNAME (1 << 1)
1798#define SETUP_ENV_TO_TMP (1 << 2) 1799#define SETUP_ENV_CLEARENV (1 << 2)
1799#define SETUP_ENV_NO_CHDIR (1 << 4) 1800#define SETUP_ENV_TO_TMP (1 << 3)
1801#define SETUP_ENV_NO_CHDIR (1 << 4)
1800void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC; 1802void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
1801void nuke_str(char *str) FAST_FUNC; 1803void nuke_str(char *str) FAST_FUNC;
1802#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM 1804#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
diff --git a/libbb/Config.src b/libbb/Config.src
index c80bee286..708d3b0c8 100644
--- a/libbb/Config.src
+++ b/libbb/Config.src
@@ -63,6 +63,13 @@ config SHA1_SMALL
63 1 224 229 654 732 63 1 224 229 654 732
64 2,3 200 195 358 380 64 2,3 200 195 358 380
65 65
66config SHA1_HWACCEL
67 bool "SHA1: Use hardware accelerated instructions if possible"
68 default y
69 help
70 On x86, this adds ~590 bytes of code. Throughput
71 is about twice as fast as fully-unrolled generic code.
72
66config SHA3_SMALL 73config SHA3_SMALL
67 int "SHA3: Trade bytes for speed (0:fast, 1:slow)" 74 int "SHA3: Trade bytes for speed (0:fast, 1:slow)"
68 default 1 # all "fast or small" options default to small 75 default 1 # all "fast or small" options default to small
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 41bf54e75..67d3c7cf7 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -46,6 +46,8 @@ lib-y += llist.o
46lib-y += make_directory.o 46lib-y += make_directory.o
47lib-y += hash_md5_sha.o 47lib-y += hash_md5_sha.o
48lib-y += hash_md5_sha_x86-64.o 48lib-y += hash_md5_sha_x86-64.o
49lib-y += hash_md5_sha_x86-64_shaNI.o
50lib-y += hash_md5_sha_x86-32_shaNI.o
49# Alternative (disabled) MD5 implementation 51# Alternative (disabled) MD5 implementation
50#lib-y += hash_md5prime.o 52#lib-y += hash_md5prime.o
51lib-y += messages.o 53lib-y += messages.o
diff --git a/libbb/hash_md5_sha.c b/libbb/hash_md5_sha.c
index ee19c1cb7..a23db5152 100644
--- a/libbb/hash_md5_sha.c
+++ b/libbb/hash_md5_sha.c
@@ -699,7 +699,7 @@ static void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx UNUSED_PARAM)
699 699
700/* in hash_md5_sha_x86-64.S */ 700/* in hash_md5_sha_x86-64.S */
701struct ASM_expects_80 { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; }; 701struct ASM_expects_80 { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; };
702void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx UNUSED_PARAM); 702void FAST_FUNC sha1_process_block64(sha1_ctx_t *ctx);
703 703
704# else 704# else
705/* Fast, fully-unrolled SHA1. +3800 bytes of code on x86. 705/* Fast, fully-unrolled SHA1. +3800 bytes of code on x86.
@@ -1142,6 +1142,25 @@ static void FAST_FUNC sha512_process_block128(sha512_ctx_t *ctx)
1142} 1142}
1143#endif /* NEED_SHA512 */ 1143#endif /* NEED_SHA512 */
1144 1144
1145#if ENABLE_SHA1_HWACCEL
1146# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1147static void cpuid(unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
1148{
1149 asm ("cpuid"
1150 : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx)
1151 : "0"(*eax), "1"(*ebx), "2"(*ecx), "3"(*edx)
1152 );
1153}
1154void FAST_FUNC sha1_process_block64_shaNI(sha1_ctx_t *ctx);
1155# if defined(__i386__)
1156struct ASM_expects_76_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 76)]; };
1157# endif
1158# if defined(__x86_64__)
1159struct ASM_expects_80_shaNI { char t[1 - 2*(offsetof(sha1_ctx_t, hash) != 80)]; };
1160# endif
1161# endif
1162#endif
1163
1145void FAST_FUNC sha1_begin(sha1_ctx_t *ctx) 1164void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
1146{ 1165{
1147 ctx->hash[0] = 0x67452301; 1166 ctx->hash[0] = 0x67452301;
@@ -1151,6 +1170,20 @@ void FAST_FUNC sha1_begin(sha1_ctx_t *ctx)
1151 ctx->hash[4] = 0xc3d2e1f0; 1170 ctx->hash[4] = 0xc3d2e1f0;
1152 ctx->total64 = 0; 1171 ctx->total64 = 0;
1153 ctx->process_block = sha1_process_block64; 1172 ctx->process_block = sha1_process_block64;
1173#if ENABLE_SHA1_HWACCEL
1174# if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
1175 {
1176 static smallint shaNI;
1177 if (!shaNI) {
1178 unsigned eax = 7, ebx = ebx, ecx = 0, edx = edx;
1179 cpuid(&eax, &ebx, &ecx, &edx);
1180 shaNI = ((ebx >> 29) << 1) - 1;
1181 }
1182 if (shaNI > 0)
1183 ctx->process_block = sha1_process_block64_shaNI;
1184 }
1185# endif
1186#endif
1154} 1187}
1155 1188
1156static const uint32_t init256[] ALIGN4 = { 1189static const uint32_t init256[] ALIGN4 = {
diff --git a/libbb/hash_md5_sha_x86-32_shaNI.S b/libbb/hash_md5_sha_x86-32_shaNI.S
new file mode 100644
index 000000000..166cfd38a
--- /dev/null
+++ b/libbb/hash_md5_sha_x86-32_shaNI.S
@@ -0,0 +1,231 @@
1#if ENABLE_SHA1_HWACCEL && defined(__GNUC__) && defined(__i386__)
2/* The code is adapted from Linux kernel's source */
3
4// We use shorter insns, even though they are for "wrong"
5// data type (fp, not int).
6// For Intel, there is no penalty for doing it at all
7// (CPUs which do have such penalty do not support SHA1 insns).
8// For AMD, the penalty is one extra cycle
9// (allegedly: I failed to find measurable difference).
10
11//#define mova128 movdqa
12#define mova128 movaps
13//#define movu128 movdqu
14#define movu128 movups
15//#define xor128 pxor
16#define xor128 xorps
17//#define shuf128_32 pshufd
18#define shuf128_32 shufps
19
20#define extr128_32 pextrd
21//#define extr128_32 extractps # not shorter
22
23 .section .text.sha1_process_block64_shaNI,"ax",@progbits
24 .globl sha1_process_block64_shaNI
25 .hidden sha1_process_block64_shaNI
26 .type sha1_process_block64_shaNI, @function
27
28#define ABCD %xmm0
29#define E0 %xmm1 /* Need two E's b/c they ping pong */
30#define E1 %xmm2
31#define MSG0 %xmm3
32#define MSG1 %xmm4
33#define MSG2 %xmm5
34#define MSG3 %xmm6
35#define SHUF_MASK %xmm7
36
37 .balign 8 # allow decoders to fetch at least 3 first insns
38sha1_process_block64_shaNI:
39 pushl %ebp
40 movl %esp, %ebp
41 subl $32, %esp
42 andl $~0xF, %esp # paddd needs aligned memory operand
43
44 /* load initial hash values */
45 xor128 E0, E0
46 movu128 76(%eax), ABCD
47 pinsrd $3, 76+4*4(%eax), E0 # load to uppermost 32-bit word
48 shuf128_32 $0x1B, ABCD, ABCD # DCBA -> ABCD
49
50 mova128 PSHUFFLE_BYTE_FLIP_MASK, SHUF_MASK
51
52 /* Save hash values for addition after rounds */
53 movu128 E0, 16(%esp)
54 movu128 ABCD, (%esp)
55
56 /* Rounds 0-3 */
57 movu128 0*16(%eax), MSG0
58 pshufb SHUF_MASK, MSG0
59 paddd MSG0, E0
60 mova128 ABCD, E1
61 sha1rnds4 $0, E0, ABCD
62
63 /* Rounds 4-7 */
64 movu128 1*16(%eax), MSG1
65 pshufb SHUF_MASK, MSG1
66 sha1nexte MSG1, E1
67 mova128 ABCD, E0
68 sha1rnds4 $0, E1, ABCD
69 sha1msg1 MSG1, MSG0
70
71 /* Rounds 8-11 */
72 movu128 2*16(%eax), MSG2
73 pshufb SHUF_MASK, MSG2
74 sha1nexte MSG2, E0
75 mova128 ABCD, E1
76 sha1rnds4 $0, E0, ABCD
77 sha1msg1 MSG2, MSG1
78 xor128 MSG2, MSG0
79
80 /* Rounds 12-15 */
81 movu128 3*16(%eax), MSG3
82 pshufb SHUF_MASK, MSG3
83 sha1nexte MSG3, E1
84 mova128 ABCD, E0
85 sha1msg2 MSG3, MSG0
86 sha1rnds4 $0, E1, ABCD
87 sha1msg1 MSG3, MSG2
88 xor128 MSG3, MSG1
89
90 /* Rounds 16-19 */
91 sha1nexte MSG0, E0
92 mova128 ABCD, E1
93 sha1msg2 MSG0, MSG1
94 sha1rnds4 $0, E0, ABCD
95 sha1msg1 MSG0, MSG3
96 xor128 MSG0, MSG2
97
98 /* Rounds 20-23 */
99 sha1nexte MSG1, E1
100 mova128 ABCD, E0
101 sha1msg2 MSG1, MSG2
102 sha1rnds4 $1, E1, ABCD
103 sha1msg1 MSG1, MSG0
104 xor128 MSG1, MSG3
105
106 /* Rounds 24-27 */
107 sha1nexte MSG2, E0
108 mova128 ABCD, E1
109 sha1msg2 MSG2, MSG3
110 sha1rnds4 $1, E0, ABCD
111 sha1msg1 MSG2, MSG1
112 xor128 MSG2, MSG0
113
114 /* Rounds 28-31 */
115 sha1nexte MSG3, E1
116 mova128 ABCD, E0
117 sha1msg2 MSG3, MSG0
118 sha1rnds4 $1, E1, ABCD
119 sha1msg1 MSG3, MSG2
120 xor128 MSG3, MSG1
121
122 /* Rounds 32-35 */
123 sha1nexte MSG0, E0
124 mova128 ABCD, E1
125 sha1msg2 MSG0, MSG1
126 sha1rnds4 $1, E0, ABCD
127 sha1msg1 MSG0, MSG3
128 xor128 MSG0, MSG2
129
130 /* Rounds 36-39 */
131 sha1nexte MSG1, E1
132 mova128 ABCD, E0
133 sha1msg2 MSG1, MSG2
134 sha1rnds4 $1, E1, ABCD
135 sha1msg1 MSG1, MSG0
136 xor128 MSG1, MSG3
137
138 /* Rounds 40-43 */
139 sha1nexte MSG2, E0
140 mova128 ABCD, E1
141 sha1msg2 MSG2, MSG3
142 sha1rnds4 $2, E0, ABCD
143 sha1msg1 MSG2, MSG1
144 xor128 MSG2, MSG0
145
146 /* Rounds 44-47 */
147 sha1nexte MSG3, E1
148 mova128 ABCD, E0
149 sha1msg2 MSG3, MSG0
150 sha1rnds4 $2, E1, ABCD
151 sha1msg1 MSG3, MSG2
152 xor128 MSG3, MSG1
153
154 /* Rounds 48-51 */
155 sha1nexte MSG0, E0
156 mova128 ABCD, E1
157 sha1msg2 MSG0, MSG1
158 sha1rnds4 $2, E0, ABCD
159 sha1msg1 MSG0, MSG3
160 xor128 MSG0, MSG2
161
162 /* Rounds 52-55 */
163 sha1nexte MSG1, E1
164 mova128 ABCD, E0
165 sha1msg2 MSG1, MSG2
166 sha1rnds4 $2, E1, ABCD
167 sha1msg1 MSG1, MSG0
168 xor128 MSG1, MSG3
169
170 /* Rounds 56-59 */
171 sha1nexte MSG2, E0
172 mova128 ABCD, E1
173 sha1msg2 MSG2, MSG3
174 sha1rnds4 $2, E0, ABCD
175 sha1msg1 MSG2, MSG1
176 xor128 MSG2, MSG0
177
178 /* Rounds 60-63 */
179 sha1nexte MSG3, E1
180 mova128 ABCD, E0
181 sha1msg2 MSG3, MSG0
182 sha1rnds4 $3, E1, ABCD
183 sha1msg1 MSG3, MSG2
184 xor128 MSG3, MSG1
185
186 /* Rounds 64-67 */
187 sha1nexte MSG0, E0
188 mova128 ABCD, E1
189 sha1msg2 MSG0, MSG1
190 sha1rnds4 $3, E0, ABCD
191 sha1msg1 MSG0, MSG3
192 xor128 MSG0, MSG2
193
194 /* Rounds 68-71 */
195 sha1nexte MSG1, E1
196 mova128 ABCD, E0
197 sha1msg2 MSG1, MSG2
198 sha1rnds4 $3, E1, ABCD
199 xor128 MSG1, MSG3
200
201 /* Rounds 72-75 */
202 sha1nexte MSG2, E0
203 mova128 ABCD, E1
204 sha1msg2 MSG2, MSG3
205 sha1rnds4 $3, E0, ABCD
206
207 /* Rounds 76-79 */
208 sha1nexte MSG3, E1
209 mova128 ABCD, E0
210 sha1rnds4 $3, E1, ABCD
211
212 /* Add current hash values with previously saved */
213 sha1nexte 16(%esp), E0
214 paddd (%esp), ABCD
215
216 /* Write hash values back in the correct order */
217 shuf128_32 $0x1B, ABCD, ABCD
218 movu128 ABCD, 76(%eax)
219 extr128_32 $3, E0, 76+4*4(%eax)
220
221 movl %ebp, %esp
222 popl %ebp
223 ret
224 .size sha1_process_block64_shaNI, .-sha1_process_block64_shaNI
225
226.section .rodata.cst16.PSHUFFLE_BYTE_FLIP_MASK, "aM", @progbits, 16
227.align 16
228PSHUFFLE_BYTE_FLIP_MASK:
229 .octa 0x000102030405060708090a0b0c0d0e0f
230
231#endif
diff --git a/libbb/hash_md5_sha_x86-64.S b/libbb/hash_md5_sha_x86-64.S
index ff78fc049..87fb616a1 100644
--- a/libbb/hash_md5_sha_x86-64.S
+++ b/libbb/hash_md5_sha_x86-64.S
@@ -2,8 +2,8 @@
2 2
3#if CONFIG_SHA1_SMALL == 0 && defined(__GNUC__) && defined(__x86_64__) 3#if CONFIG_SHA1_SMALL == 0 && defined(__GNUC__) && defined(__x86_64__)
4 .section .text.sha1_process_block64,"ax",@progbits 4 .section .text.sha1_process_block64,"ax",@progbits
5 .globl sha1_process_block64 5 .globl sha1_process_block64
6 .hidden sha1_process_block64 6 .hidden sha1_process_block64
7 .type sha1_process_block64, @function 7 .type sha1_process_block64, @function
8 8
9 .balign 8 # allow decoders to fetch at least 5 first insns 9 .balign 8 # allow decoders to fetch at least 5 first insns
@@ -1273,15 +1273,15 @@ sha1_process_block64:
1273 1273
1274 popq %rdi # 1274 popq %rdi #
1275 popq %r12 # 1275 popq %r12 #
1276 addl %eax, 80(%rdi) # ctx->hash[0] += a 1276 addl %eax, 80(%rdi) # ctx->hash[0] += a
1277 popq %r13 # 1277 popq %r13 #
1278 addl %ebx, 84(%rdi) # ctx->hash[1] += b 1278 addl %ebx, 84(%rdi) # ctx->hash[1] += b
1279 popq %r14 # 1279 popq %r14 #
1280 addl %ecx, 88(%rdi) # ctx->hash[2] += c 1280 addl %ecx, 88(%rdi) # ctx->hash[2] += c
1281 popq %r15 # 1281 popq %r15 #
1282 addl %edx, 92(%rdi) # ctx->hash[3] += d 1282 addl %edx, 92(%rdi) # ctx->hash[3] += d
1283 popq %rbx # 1283 popq %rbx #
1284 addl %ebp, 96(%rdi) # ctx->hash[4] += e 1284 addl %ebp, 96(%rdi) # ctx->hash[4] += e
1285 popq %rbp # 1285 popq %rbp #
1286 1286
1287 ret 1287 ret
diff --git a/libbb/hash_md5_sha_x86-64.S.sh b/libbb/hash_md5_sha_x86-64.S.sh
index 7e50b64fb..901896e6e 100755
--- a/libbb/hash_md5_sha_x86-64.S.sh
+++ b/libbb/hash_md5_sha_x86-64.S.sh
@@ -6,13 +6,35 @@
6# also contains the diff of the generated file. 6# also contains the diff of the generated file.
7exec >hash_md5_sha_x86-64.S 7exec >hash_md5_sha_x86-64.S
8 8
9# There is a way to use XMM registers (which always exist for x86-64!) for W[]
10# For example, if we load W as follows:
11# %xmm0: w[0x0] w[0x1] w[0x2] w[0x3]
12# %xmm4: w[0x4] w[0x5] w[0x6] w[0x7]
13# %xmm8: w[0x8] w[0x9] w[0xa] w[0xb]
14# %xmm12: w[0xc] w[0xd] w[0xe] w[0xf]
15# then the xor'ing operation to generate next W[0..3] is:
16# movaps %xmm0, %xmmT2
17# palignr $0x8, %xmm4, %xmmT2 # form (w[0x2],w[0x3],w[0x4],w[0x5])
18# # Right-shifts xmm4:xmmT2 by 8 bytes. Writes shifted result to xmmT2. SSSE3 insn.
19# movaps %xmm0, %xmmT13
20# palignr $0x4,%xmm0,%xmmT13 # form (w[0xd],w[0xe],w[0xf],w[0x0])
21# xmm0 = xmm0 ^ t2 ^ xmm8 ^ t13
22# xmm0 = rol32(xmm0,1) # no such insn, have to use pslld+psrld+or
23# and then results can be extracted for use:
24# movd %xmm0, %esi # new W[0]
25# pextrd $1, %xmm0, %esi # new W[1]
26# # SSE4.1 insn. Can use EXTRACTPS (also SSE4.1)
27# pextrd $2, %xmm0, %esi # new W[2]
28# pextrd $3, %xmm0, %esi # new W[3]
29# ... but this requires SSE4.1 and SSSE3, which are not universally available on x86-64.
30
9echo \ 31echo \
10'### Generated by hash_md5_sha_x86-64.S.sh ### 32'### Generated by hash_md5_sha_x86-64.S.sh ###
11 33
12#if CONFIG_SHA1_SMALL == 0 && defined(__GNUC__) && defined(__x86_64__) 34#if CONFIG_SHA1_SMALL == 0 && defined(__GNUC__) && defined(__x86_64__)
13 .section .text.sha1_process_block64,"ax",@progbits 35 .section .text.sha1_process_block64,"ax",@progbits
14 .globl sha1_process_block64 36 .globl sha1_process_block64
15 .hidden sha1_process_block64 37 .hidden sha1_process_block64
16 .type sha1_process_block64, @function 38 .type sha1_process_block64, @function
17 39
18 .balign 8 # allow decoders to fetch at least 5 first insns 40 .balign 8 # allow decoders to fetch at least 5 first insns
@@ -265,15 +287,15 @@ RD2 ax bx cx dx bp 75; RD2 bp ax bx cx dx 76; RD2 dx bp ax bx cx 77; RD2 cx dx b
265echo " 287echo "
266 popq %rdi # 288 popq %rdi #
267 popq %r12 # 289 popq %r12 #
268 addl %eax, 80(%rdi) # ctx->hash[0] += a 290 addl %eax, 80(%rdi) # ctx->hash[0] += a
269 popq %r13 # 291 popq %r13 #
270 addl %ebx, 84(%rdi) # ctx->hash[1] += b 292 addl %ebx, 84(%rdi) # ctx->hash[1] += b
271 popq %r14 # 293 popq %r14 #
272 addl %ecx, 88(%rdi) # ctx->hash[2] += c 294 addl %ecx, 88(%rdi) # ctx->hash[2] += c
273 popq %r15 # 295 popq %r15 #
274 addl %edx, 92(%rdi) # ctx->hash[3] += d 296 addl %edx, 92(%rdi) # ctx->hash[3] += d
275 popq %rbx # 297 popq %rbx #
276 addl %ebp, 96(%rdi) # ctx->hash[4] += e 298 addl %ebp, 96(%rdi) # ctx->hash[4] += e
277 popq %rbp # 299 popq %rbp #
278 300
279 ret 301 ret
diff --git a/libbb/hash_md5_sha_x86-64_shaNI.S b/libbb/hash_md5_sha_x86-64_shaNI.S
new file mode 100644
index 000000000..33cc3bf7f
--- /dev/null
+++ b/libbb/hash_md5_sha_x86-64_shaNI.S
@@ -0,0 +1,225 @@
1#if ENABLE_SHA1_HWACCEL && defined(__GNUC__) && defined(__x86_64__)
2/* The code is adapted from Linux kernel's source */
3
4// We use shorter insns, even though they are for "wrong"
5// data type (fp, not int).
6// For Intel, there is no penalty for doing it at all
7// (CPUs which do have such penalty do not support SHA1 insns).
8// For AMD, the penalty is one extra cycle
9// (allegedly: I failed to find measurable difference).
10
11//#define mova128 movdqa
12#define mova128 movaps
13//#define movu128 movdqu
14#define movu128 movups
15//#define xor128 pxor
16#define xor128 xorps
17//#define shuf128_32 pshufd
18#define shuf128_32 shufps
19
20#define extr128_32 pextrd
21//#define extr128_32 extractps # not shorter
22
23 .section .text.sha1_process_block64_shaNI,"ax",@progbits
24 .globl sha1_process_block64_shaNI
25 .hidden sha1_process_block64_shaNI
26 .type sha1_process_block64_shaNI, @function
27
28#define ABCD %xmm0
29#define E0 %xmm1 /* Need two E's b/c they ping pong */
30#define E1 %xmm2
31#define MSG0 %xmm3
32#define MSG1 %xmm4
33#define MSG2 %xmm5
34#define MSG3 %xmm6
35#define SHUF_MASK %xmm7
36
37 .balign 8 # allow decoders to fetch at least 2 first insns
38sha1_process_block64_shaNI:
39 /* load initial hash values */
40
41 xor128 E0, E0
42 movu128 80(%rdi), ABCD
43 pinsrd $3, 80+4*4(%rdi), E0 # load to uppermost 32-bit word
44 shuf128_32 $0x1B, ABCD, ABCD # DCBA -> ABCD
45
46 mova128 PSHUFFLE_BYTE_FLIP_MASK(%rip), SHUF_MASK
47
48 /* Save hash values for addition after rounds */
49 mova128 E0, %xmm9
50 mova128 ABCD, %xmm8
51
52 /* Rounds 0-3 */
53 movu128 0*16(%rdi), MSG0
54 pshufb SHUF_MASK, MSG0
55 paddd MSG0, E0
56 mova128 ABCD, E1
57 sha1rnds4 $0, E0, ABCD
58
59 /* Rounds 4-7 */
60 movu128 1*16(%rdi), MSG1
61 pshufb SHUF_MASK, MSG1
62 sha1nexte MSG1, E1
63 mova128 ABCD, E0
64 sha1rnds4 $0, E1, ABCD
65 sha1msg1 MSG1, MSG0
66
67 /* Rounds 8-11 */
68 movu128 2*16(%rdi), MSG2
69 pshufb SHUF_MASK, MSG2
70 sha1nexte MSG2, E0
71 mova128 ABCD, E1
72 sha1rnds4 $0, E0, ABCD
73 sha1msg1 MSG2, MSG1
74 xor128 MSG2, MSG0
75
76 /* Rounds 12-15 */
77 movu128 3*16(%rdi), MSG3
78 pshufb SHUF_MASK, MSG3
79 sha1nexte MSG3, E1
80 mova128 ABCD, E0
81 sha1msg2 MSG3, MSG0
82 sha1rnds4 $0, E1, ABCD
83 sha1msg1 MSG3, MSG2
84 xor128 MSG3, MSG1
85
86 /* Rounds 16-19 */
87 sha1nexte MSG0, E0
88 mova128 ABCD, E1
89 sha1msg2 MSG0, MSG1
90 sha1rnds4 $0, E0, ABCD
91 sha1msg1 MSG0, MSG3
92 xor128 MSG0, MSG2
93
94 /* Rounds 20-23 */
95 sha1nexte MSG1, E1
96 mova128 ABCD, E0
97 sha1msg2 MSG1, MSG2
98 sha1rnds4 $1, E1, ABCD
99 sha1msg1 MSG1, MSG0
100 xor128 MSG1, MSG3
101
102 /* Rounds 24-27 */
103 sha1nexte MSG2, E0
104 mova128 ABCD, E1
105 sha1msg2 MSG2, MSG3
106 sha1rnds4 $1, E0, ABCD
107 sha1msg1 MSG2, MSG1
108 xor128 MSG2, MSG0
109
110 /* Rounds 28-31 */
111 sha1nexte MSG3, E1
112 mova128 ABCD, E0
113 sha1msg2 MSG3, MSG0
114 sha1rnds4 $1, E1, ABCD
115 sha1msg1 MSG3, MSG2
116 xor128 MSG3, MSG1
117
118 /* Rounds 32-35 */
119 sha1nexte MSG0, E0
120 mova128 ABCD, E1
121 sha1msg2 MSG0, MSG1
122 sha1rnds4 $1, E0, ABCD
123 sha1msg1 MSG0, MSG3
124 xor128 MSG0, MSG2
125
126 /* Rounds 36-39 */
127 sha1nexte MSG1, E1
128 mova128 ABCD, E0
129 sha1msg2 MSG1, MSG2
130 sha1rnds4 $1, E1, ABCD
131 sha1msg1 MSG1, MSG0
132 xor128 MSG1, MSG3
133
134 /* Rounds 40-43 */
135 sha1nexte MSG2, E0
136 mova128 ABCD, E1
137 sha1msg2 MSG2, MSG3
138 sha1rnds4 $2, E0, ABCD
139 sha1msg1 MSG2, MSG1
140 xor128 MSG2, MSG0
141
142 /* Rounds 44-47 */
143 sha1nexte MSG3, E1
144 mova128 ABCD, E0
145 sha1msg2 MSG3, MSG0
146 sha1rnds4 $2, E1, ABCD
147 sha1msg1 MSG3, MSG2
148 xor128 MSG3, MSG1
149
150 /* Rounds 48-51 */
151 sha1nexte MSG0, E0
152 mova128 ABCD, E1
153 sha1msg2 MSG0, MSG1
154 sha1rnds4 $2, E0, ABCD
155 sha1msg1 MSG0, MSG3
156 xor128 MSG0, MSG2
157
158 /* Rounds 52-55 */
159 sha1nexte MSG1, E1
160 mova128 ABCD, E0
161 sha1msg2 MSG1, MSG2
162 sha1rnds4 $2, E1, ABCD
163 sha1msg1 MSG1, MSG0
164 xor128 MSG1, MSG3
165
166 /* Rounds 56-59 */
167 sha1nexte MSG2, E0
168 mova128 ABCD, E1
169 sha1msg2 MSG2, MSG3
170 sha1rnds4 $2, E0, ABCD
171 sha1msg1 MSG2, MSG1
172 xor128 MSG2, MSG0
173
174 /* Rounds 60-63 */
175 sha1nexte MSG3, E1
176 mova128 ABCD, E0
177 sha1msg2 MSG3, MSG0
178 sha1rnds4 $3, E1, ABCD
179 sha1msg1 MSG3, MSG2
180 xor128 MSG3, MSG1
181
182 /* Rounds 64-67 */
183 sha1nexte MSG0, E0
184 mova128 ABCD, E1
185 sha1msg2 MSG0, MSG1
186 sha1rnds4 $3, E0, ABCD
187 sha1msg1 MSG0, MSG3
188 xor128 MSG0, MSG2
189
190 /* Rounds 68-71 */
191 sha1nexte MSG1, E1
192 mova128 ABCD, E0
193 sha1msg2 MSG1, MSG2
194 sha1rnds4 $3, E1, ABCD
195 xor128 MSG1, MSG3
196
197 /* Rounds 72-75 */
198 sha1nexte MSG2, E0
199 mova128 ABCD, E1
200 sha1msg2 MSG2, MSG3
201 sha1rnds4 $3, E0, ABCD
202
203 /* Rounds 76-79 */
204 sha1nexte MSG3, E1
205 mova128 ABCD, E0
206 sha1rnds4 $3, E1, ABCD
207
208 /* Add current hash values with previously saved */
209 sha1nexte %xmm9, E0
210 paddd %xmm8, ABCD
211
212 /* Write hash values back in the correct order */
213 shuf128_32 $0x1B, ABCD, ABCD
214 movu128 ABCD, 80(%rdi)
215 extr128_32 $3, E0, 80+4*4(%rdi)
216
217 ret
218 .size sha1_process_block64_shaNI, .-sha1_process_block64_shaNI
219
220.section .rodata.cst16.PSHUFFLE_BYTE_FLIP_MASK, "aM", @progbits, 16
221.align 16
222PSHUFFLE_BYTE_FLIP_MASK:
223 .octa 0x000102030405060708090a0b0c0d0e0f
224
225#endif
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index f8de44967..df2983958 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -54,15 +54,15 @@ void FAST_FUNC setup_environment(const char *shell, int flags, const struct pass
54 xsetenv("TERM", term); 54 xsetenv("TERM", term);
55 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); 55 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path));
56 goto shortcut; 56 goto shortcut;
57 // No, gcc (4.2.1) is not clever enougn to do it itself. 57 // No, gcc (4.2.1) is not clever enough to do it itself.
58 //xsetenv("USER", pw->pw_name); 58 //xsetenv("USER", pw->pw_name);
59 //xsetenv("LOGNAME", pw->pw_name); 59 //xsetenv("LOGNAME", pw->pw_name);
60 //xsetenv("HOME", pw->pw_dir); 60 //xsetenv("HOME", pw->pw_dir);
61 //xsetenv("SHELL", shell); 61 //xsetenv("SHELL", shell);
62 } else if (flags & SETUP_ENV_CHANGEENV) { 62 } else if (flags & SETUP_ENV_CHANGEENV) {
63 /* Set HOME, SHELL, and if not becoming a super-user, 63 /* Set HOME, SHELL, and if not becoming a super-user
64 * USER and LOGNAME. */ 64 * or if SETUP_ENV_CHANGEENV_LOGNAME, USER and LOGNAME. */
65 if (pw->pw_uid) { 65 if ((flags & SETUP_ENV_CHANGEENV_LOGNAME) || pw->pw_uid != 0) {
66 shortcut: 66 shortcut:
67 xsetenv("USER", pw->pw_name); 67 xsetenv("USER", pw->pw_name);
68 xsetenv("LOGNAME", pw->pw_name); 68 xsetenv("LOGNAME", pw->pw_name);
diff --git a/loginutils/login.c b/loginutils/login.c
index 569053c12..cac4349b2 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -608,7 +608,9 @@ int login_main(int argc UNUSED_PARAM, char **argv)
608 * But without this, bash 3.0 will not enable ctrl-c either. 608 * But without this, bash 3.0 will not enable ctrl-c either.
609 * Maybe bash is buggy? 609 * Maybe bash is buggy?
610 * Need to find out what standards say about /bin/login - 610 * Need to find out what standards say about /bin/login -
611 * should we leave SIGINT etc enabled or disabled? */ 611 * should we leave SIGINT etc enabled or disabled?
612 * Also note: sulogin does not do it! Why?
613 */
612 signal(SIGINT, SIG_DFL); 614 signal(SIGINT, SIG_DFL);
613 615
614 /* Exec login shell with no additional parameters */ 616 /* Exec login shell with no additional parameters */
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 69d8b5ec7..c9817960c 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -20,7 +20,8 @@
20//usage: "[-t N] [TTY]" 20//usage: "[-t N] [TTY]"
21//usage:#define sulogin_full_usage "\n\n" 21//usage:#define sulogin_full_usage "\n\n"
22//usage: "Single user login\n" 22//usage: "Single user login\n"
23//usage: "\n -t N Timeout" 23//usage: "\n -p Start a login shell"
24//usage: "\n -t SEC Timeout"
24 25
25#include "libbb.h" 26#include "libbb.h"
26#include <syslog.h> 27#include <syslog.h>
@@ -28,7 +29,9 @@
28int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 29int sulogin_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29int sulogin_main(int argc UNUSED_PARAM, char **argv) 30int sulogin_main(int argc UNUSED_PARAM, char **argv)
30{ 31{
32 int tsid;
31 int timeout = 0; 33 int timeout = 0;
34 unsigned opts;
32 struct passwd *pwd; 35 struct passwd *pwd;
33 const char *shell; 36 const char *shell;
34 37
@@ -43,7 +46,7 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
43 logmode = LOGMODE_BOTH; 46 logmode = LOGMODE_BOTH;
44 openlog(applet_name, 0, LOG_AUTH); 47 openlog(applet_name, 0, LOG_AUTH);
45 48
46 getopt32(argv, "t:+", &timeout); 49 opts = getopt32(argv, "pt:+", &timeout);
47 argv += optind; 50 argv += optind;
48 51
49 if (argv[0]) { 52 if (argv[0]) {
@@ -63,12 +66,13 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
63 int r; 66 int r;
64 67
65 r = ask_and_check_password_extended(pwd, timeout, 68 r = ask_and_check_password_extended(pwd, timeout,
66 "Give root password for system maintenance\n" 69 "Give root password for maintenance\n"
67 "(or type Control-D for normal startup):" 70 "(or type Ctrl-D to continue): "
68 ); 71 );
69 if (r < 0) { 72 if (r < 0) {
70 /* ^D, ^C, timeout, or read error */ 73 /* ^D, ^C, timeout, or read error */
71 bb_simple_info_msg("normal startup"); 74 /* util-linux 2.36.1 compat: no message */
75 /*bb_simple_info_msg("normal startup");*/
72 return 0; 76 return 0;
73 } 77 }
74 if (r > 0) { 78 if (r > 0) {
@@ -78,7 +82,8 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
78 bb_simple_info_msg("Login incorrect"); 82 bb_simple_info_msg("Login incorrect");
79 } 83 }
80 84
81 bb_simple_info_msg("starting shell for system maintenance"); 85 /* util-linux 2.36.1 compat: no message */
86 /*bb_simple_info_msg("starting shell for system maintenance");*/
82 87
83 IF_SELINUX(renew_current_security_context()); 88 IF_SELINUX(renew_current_security_context());
84 89
@@ -88,6 +93,33 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
88 if (!shell) 93 if (!shell)
89 shell = pwd->pw_shell; 94 shell = pwd->pw_shell;
90 95
91 /* Exec login shell with no additional parameters. Never returns. */ 96 /* util-linux 2.36.1 compat: cd to root's HOME, set a few envvars */
92 exec_login_shell(shell); 97 setup_environment(shell, SETUP_ENV_CHANGEENV | SETUP_ENV_CHANGEENV_LOGNAME, pwd);
98 // no SETUP_ENV_CLEARENV
99 // SETUP_ENV_CHANGEENV[+LOGNAME] - set HOME, SHELL, USER,and LOGNAME
100 // no SETUP_ENV_NO_CHDIR - IOW: cd to $HOME
101
102 /* util-linux 2.36.1 compat: steal ctty if we don't have it yet
103 * (yes, util-linux uses force=1) */
104 tsid = tcgetsid(STDIN_FILENO);
105 if (tsid < 0 || getpid() != tsid) {
106 if (ioctl(STDIN_FILENO, TIOCSCTTY, /*force:*/ (long)1) != 0) {
107// bb_perror_msg("TIOCSCTTY1 tsid:%d", tsid);
108 if (setsid() > 0) {
109// bb_error_msg("done setsid()");
110 /* If it still does not work, ignore */
111 if (ioctl(STDIN_FILENO, TIOCSCTTY, /*force:*/ (long)1) != 0) {
112// bb_perror_msg("TIOCSCTTY2 tsid:%d", tsid);
113 }
114 }
115 }
116 }
117
118 /*
119 * Note: login does this (should we do it too?):
120 */
121 /*signal(SIGINT, SIG_DFL);*/
122
123 /* Exec shell with no additional parameters. Never returns. */
124 exec_shell(shell, /* -p? then shell is login:*/(opts & 1), NULL);
93} 125}
diff --git a/procps/nmeter.c b/procps/nmeter.c
index f08938654..2310e9844 100644
--- a/procps/nmeter.c
+++ b/procps/nmeter.c
@@ -27,6 +27,8 @@
27//usage: "\n (displays: S:system U:user N:niced D:iowait I:irq i:softirq)" 27//usage: "\n (displays: S:system U:user N:niced D:iowait I:irq i:softirq)"
28//usage: "\n %[nINTERFACE] Network INTERFACE" 28//usage: "\n %[nINTERFACE] Network INTERFACE"
29//usage: "\n %m Allocated memory" 29//usage: "\n %m Allocated memory"
30//usage: "\n %[md] Dirty file-backed memory"
31//usage: "\n %[mw] Memory being written to storage"
30//usage: "\n %[mf] Free memory" 32//usage: "\n %[mf] Free memory"
31//usage: "\n %[mt] Total memory" 33//usage: "\n %[mt] Total memory"
32//usage: "\n %s Allocated swap" 34//usage: "\n %s Allocated swap"
@@ -208,7 +210,7 @@ enum conv_type {
208// Reads decimal values from line. Values start after key, for example: 210// Reads decimal values from line. Values start after key, for example:
209// "cpu 649369 0 341297 4336769..." - key is "cpu" here. 211// "cpu 649369 0 341297 4336769..." - key is "cpu" here.
210// Values are stored in vec[]. 212// Values are stored in vec[].
211// posbits is a bit lit of positions we are interested in. 213// posbits is a bit list of positions we are interested in.
212// for example: 00100110 - we want 1st, 2nd and 5th value. 214// for example: 00100110 - we want 1st, 2nd and 5th value.
213// posbits.bit0 encodes conversion type. 215// posbits.bit0 encodes conversion type.
214static int rdval(const char* p, const char* key, ullong *vec, long posbits) 216static int rdval(const char* p, const char* key, ullong *vec, long posbits)
@@ -661,13 +663,31 @@ S_STAT_END(mem_stat)
661//Hugepagesize: 4096 kB 663//Hugepagesize: 4096 kB
662static void FAST_FUNC collect_mem(mem_stat *s) 664static void FAST_FUNC collect_mem(mem_stat *s)
663{ 665{
664 ullong m_total = 0; 666 ullong m_total;
665 ullong m_free = 0; 667 ullong m_free;
666 ullong m_bufs = 0; 668 ullong m_bufs;
667 ullong m_cached = 0; 669 ullong m_cached;
668 ullong m_slab = 0; 670 ullong m_slab;
669 671
670 if (rdval(get_file(&proc_meminfo), "MemTotal:", &m_total, 1 << 1)) { 672 const char *meminfo = get_file(&proc_meminfo);
673
674 if (s->opt == 'd' /* dirty page cache */
675 || s->opt == 'w' /* under writeback */
676 ) {
677 m_total = 0; /* temporary reuse m_total */
678 if (rdval(meminfo,
679 (s->opt == 'd' ? "Dirty:" : "Writeback:"),
680 &m_total, 1 << 1)
681 ) {
682 put_question_marks(4);
683 return;
684 }
685 scale(m_total << 10);
686 return;
687 }
688
689 m_total = 0;
690 if (rdval(meminfo, "MemTotal:", &m_total, 1 << 1)) {
671 put_question_marks(4); 691 put_question_marks(4);
672 return; 692 return;
673 } 693 }
@@ -676,10 +696,14 @@ static void FAST_FUNC collect_mem(mem_stat *s)
676 return; 696 return;
677 } 697 }
678 698
679 if (rdval(proc_meminfo.file, "MemFree:", &m_free , 1 << 1) 699 m_free = 0;
680 || rdval(proc_meminfo.file, "Buffers:", &m_bufs , 1 << 1) 700 m_bufs = 0;
681 || rdval(proc_meminfo.file, "Cached:", &m_cached, 1 << 1) 701 m_cached = 0;
682 || rdval(proc_meminfo.file, "Slab:", &m_slab , 1 << 1) 702 m_slab = 0;
703 if (rdval(meminfo, "MemFree:", &m_free , 1 << 1)
704 || rdval(meminfo, "Buffers:", &m_bufs , 1 << 1)
705 || rdval(meminfo, "Cached:", &m_cached, 1 << 1)
706 || rdval(meminfo, "Slab:", &m_slab , 1 << 1)
683 ) { 707 ) {
684 put_question_marks(4); 708 put_question_marks(4);
685 return; 709 return;
diff --git a/procps/powertop.c b/procps/powertop.c
index 24c2b320f..18ddaa3ec 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -506,12 +506,9 @@ static void cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
506{ 506{
507 /* EAX value specifies what information to return */ 507 /* EAX value specifies what information to return */
508 asm ( 508 asm (
509 " pushl %%ebx\n" /* Save EBX */
510 " cpuid\n" 509 " cpuid\n"
511 " movl %%ebx, %1\n" /* Save content of EBX */
512 " popl %%ebx\n" /* Restore EBX */
513 : "=a"(*eax), /* Output */ 510 : "=a"(*eax), /* Output */
514 "=r"(*ebx), 511 "=b"(*ebx),
515 "=c"(*ecx), 512 "=c"(*ecx),
516 "=d"(*edx) 513 "=d"(*edx)
517 : "0"(*eax), /* Input */ 514 : "0"(*eax), /* Input */
diff --git a/shell/ash.c b/shell/ash.c
index 09659c1da..a1d01447a 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -11655,12 +11655,16 @@ preadfd(void)
11655 line_input_state->path_lookup = pathval(); 11655 line_input_state->path_lookup = pathval();
11656# endif 11656# endif
11657 reinit_unicode_for_ash(); 11657 reinit_unicode_for_ash();
11658 again:
11658 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ); 11659 nr = read_line_input(line_input_state, cmdedit_prompt, buf, IBUFSIZ);
11659 if (nr == 0) { 11660 if (nr == 0) {
11660 /* ^C pressed, "convert" to SIGINT */ 11661 /* ^C pressed, "convert" to SIGINT */
11661# if !ENABLE_PLATFORM_MINGW32 11662# if !ENABLE_PLATFORM_MINGW32
11662 write(STDOUT_FILENO, "^C", 2); 11663 write(STDOUT_FILENO, "^C", 2);
11663 raise(SIGINT); 11664 raise(SIGINT);
11665 /* raise(SIGINT) did not work! (e.g. if SIGINT
11666 * is SIG_INGed on startup, it stays SIG_IGNed)
11667 */
11664# else 11668# else
11665 raise_interrupt(); 11669 raise_interrupt();
11666# endif 11670# endif
@@ -11670,7 +11674,9 @@ preadfd(void)
11670 return 1; 11674 return 1;
11671 } 11675 }
11672 exitstatus = 128 + SIGINT; 11676 exitstatus = 128 + SIGINT;
11673 return -1; 11677 /* bash behavior on ^C + ignored SIGINT: */
11678 write(STDOUT_FILENO, "\n", 1);
11679 goto again;
11674 } 11680 }
11675 if (nr < 0) { 11681 if (nr < 0) {
11676 if (errno == 0) { 11682 if (errno == 0) {
@@ -12235,7 +12241,7 @@ options(int *login_sh)
12235 int val; 12241 int val;
12236 int c; 12242 int c;
12237 12243
12238 if (login_sh) { 12244 if (login_sh != NULL) { /* if we came from startup code */
12239 minusc = NULL; 12245 minusc = NULL;
12240#if ENABLE_PLATFORM_MINGW32 12246#if ENABLE_PLATFORM_MINGW32
12241 dirarg = NULL; 12247 dirarg = NULL;
@@ -12251,7 +12257,7 @@ options(int *login_sh)
12251 if (c == '-') { 12257 if (c == '-') {
12252 val = 1; 12258 val = 1;
12253 if (p[0] == '\0' || LONE_DASH(p)) { 12259 if (p[0] == '\0' || LONE_DASH(p)) {
12254 if (!login_sh) { 12260 if (login_sh == NULL) { /* we came from setcmd() */
12255 /* "-" means turn off -x and -v */ 12261 /* "-" means turn off -x and -v */
12256 if (p[0] == '\0') 12262 if (p[0] == '\0')
12257 xflag = vflag = 0; 12263 xflag = vflag = 0;
@@ -12264,7 +12270,7 @@ options(int *login_sh)
12264 } 12270 }
12265 /* first char was + or - */ 12271 /* first char was + or - */
12266 while ((c = *p++) != '\0') { 12272 while ((c = *p++) != '\0') {
12267 if (login_sh) { 12273 if (login_sh != NULL) { /* if we came from startup code */
12268 /* bash 3.2 indeed handles -c CMD and +c CMD the same */ 12274 /* bash 3.2 indeed handles -c CMD and +c CMD the same */
12269 if (c == 'c') { 12275 if (c == 'c') {
12270 minusc = p; /* command is after shell args */ 12276 minusc = p; /* command is after shell args */
@@ -12306,6 +12312,9 @@ options(int *login_sh)
12306 if (strcmp(p, "login") == 0) { 12312 if (strcmp(p, "login") == 0) {
12307 *login_sh = 1; 12313 *login_sh = 1;
12308 } 12314 }
12315/* TODO: --noprofile: e.g. if I want to run emergency shell from sulogin,
12316 * I want minimal/no shell init scripts - but it insists on running it as "-ash"...
12317 */
12309 break; 12318 break;
12310 } 12319 }
12311 } 12320 }
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index bcaafe8fd..93e25d8c1 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -102,9 +102,13 @@ testing "awk unused function args are evaluated" \
102optional DESKTOP 102optional DESKTOP
103testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n" 103testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n"
104testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n" 104testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n"
105testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n" 105testing "awk oct const" "awk '{ print or(01234,1) }'" "669\n" "" "\n"
106SKIP= 106SKIP=
107 107
108# check that "hex/oct integer" heuristic doesn't kick in on input
109# (must be done only when parsing program text)
110testing "awk input is never oct" "awk '{ print \$1, \$1+1 }'" "011 12\n" "" "011\n"
111
108# check that "hex/oct integer" heuristic doesn't kick in on 00NN.NNN 112# check that "hex/oct integer" heuristic doesn't kick in on 00NN.NNN
109testing "awk floating const with leading zeroes" \ 113testing "awk floating const with leading zeroes" \
110 "awk '{ printf \"%f %f\n\", \"000.123\", \"009.123\" }'" \ 114 "awk '{ printf \"%f %f\n\", \"000.123\", \"009.123\" }'" \
@@ -469,4 +473,10 @@ testing 'awk printf %% prints one %' \
469 "%\n" \ 473 "%\n" \
470 '' '' 474 '' ''
471 475
476testing 'awk backslash+newline eaten with no trace' \
477 "awk 'BEGIN { printf \"Hello\\
478 world\n\" }'" \
479 "Hello world\n" \
480 '' ''
481
472exit $FAILCOUNT 482exit $FAILCOUNT
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 9c393b8fc..20e7d56fa 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -355,6 +355,7 @@ static const char *const i386_sys_types[] ALIGN_PTR = {
355 "\xef" "EFI (FAT-12/16/32)", /* Intel EFI System Partition */ 355 "\xef" "EFI (FAT-12/16/32)", /* Intel EFI System Partition */
356 "\xf0" "Linux/PA-RISC boot", /* Linux/PA-RISC boot loader */ 356 "\xf0" "Linux/PA-RISC boot", /* Linux/PA-RISC boot loader */
357 "\xf2" "DOS secondary", /* DOS 3.3+ secondary */ 357 "\xf2" "DOS secondary", /* DOS 3.3+ secondary */
358 "\xf8" "EBBR protective", /* Arm EBBR firmware protective partition */
358 "\xfd" "Linux raid autodetect", /* New (2.2.x) raid partition with 359 "\xfd" "Linux raid autodetect", /* New (2.2.x) raid partition with
359 autodetect using persistent 360 autodetect using persistent
360 superblock */ 361 superblock */