svn commit: r334553 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sun Jun  3 05:20:11 2018
New Revision: 334553
URL: https://svnweb.freebsd.org/changeset/base/334553

Log:
  top(1): partial revert of r334517
  
  In fixing issues with uid > INT_MAX, I broke the uid without username
  case. The latter is more important so return the old state.
  
  Discussed with:   allanjude

Modified:
  head/usr.bin/top/machine.c
  head/usr.bin/top/machine.h
  head/usr.bin/top/top.c
  head/usr.bin/top/username.c
  head/usr.bin/top/username.h
  head/usr.bin/top/utils.c
  head/usr.bin/top/utils.h

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sun Jun  3 05:07:46 2018(r334552)
+++ head/usr.bin/top/machine.c  Sun Jun  3 05:20:11 2018(r334553)
@@ -918,7 +918,7 @@ get_process_info(struct system_info *si, struct proces
 static char fmt[512];  /* static area where result is built */
 
 char *
-format_next_process(caddr_t xhandle, char *(*get_userid)(uid_t), int flags)
+format_next_process(caddr_t xhandle, char *(*get_userid)(int), int flags)
 {
struct kinfo_proc *pp;
const struct kinfo_proc *oldp;

Modified: head/usr.bin/top/machine.h
==
--- head/usr.bin/top/machine.h  Sun Jun  3 05:07:46 2018(r334552)
+++ head/usr.bin/top/machine.h  Sun Jun  3 05:20:11 2018(r334553)
@@ -76,7 +76,7 @@ struct process_select
 /* routines defined by the machine dependent module */
 
 char   *format_header(char *uname_field);
-char   *format_next_process(caddr_t handle, char *(*get_userid)(uid_t),
+char   *format_next_process(caddr_t handle, char *(*get_userid)(int),
int flags);
 voidtoggle_pcpustats(void);
 voidget_system_info(struct system_info *si);

Modified: head/usr.bin/top/top.c
==
--- head/usr.bin/top/top.c  Sun Jun  3 05:07:46 2018(r334552)
+++ head/usr.bin/top/top.c  Sun Jun  3 05:20:11 2018(r334553)
@@ -206,7 +206,7 @@ main(int argc, char *argv[])
 int displays = 0;  /* indicates unspecified */
 int sel_ret = 0;
 time_t curr_time;
-char *(*get_userid)(uid_t) = username;
+char *(*get_userid)(int) = username;
 char *uname_field = "USERNAME";
 char *header_text;
 char *env_top;

Modified: head/usr.bin/top/username.c
==
--- head/usr.bin/top/username.c Sun Jun  3 05:07:46 2018(r334552)
+++ head/usr.bin/top/username.c Sun Jun  3 05:20:11 2018(r334553)
@@ -37,27 +37,26 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "utils.h"
 #include "username.h"
 
 struct hash_el {
-uid_t  uid;
+int  uid;
 char name[MAXLOGNAME];
 };
 
 #defineis_empty_hash(x)(hash_table[x].name[0] == 0)
 
 /* simple minded hashing function */
-#definehashit(i)   (i % Table_size)
+#definehashit(i)   (abs(i) % Table_size)
 
 /* K requires that statically declared tables be initialized to zero. */
 /* We depend on that for hash_table and YOUR compiler had BETTER do it! */
 static struct hash_el hash_table[Table_size];
 
 
-char *username(uid_t uid)
+char *username(int uid)
 {
 int hashindex;
 
@@ -70,7 +69,7 @@ char *username(uid_t uid)
 return(hash_table[hashindex].name);
 }
 
-uid_t userid(char username[])
+int userid(char username[])
 {
 struct passwd *pwd;
 
@@ -91,7 +90,7 @@ uid_t userid(char username[])
 }
 
 /* wecare 1 = enter it always, 0 = nice to have */
-int enter_user(uid_t uid, char name[], bool wecare)
+int enter_user(int uid, char name[], bool wecare)
 {
 int hashindex;
 
@@ -122,7 +121,7 @@ int enter_user(uid_t uid, char name[], bool wecare)
  */
 
 int
-get_user(uid_t uid)
+get_user(int uid)
 {
 struct passwd *pwd;
 

Modified: head/usr.bin/top/username.h
==
--- head/usr.bin/top/username.h Sun Jun  3 05:07:46 2018(r334552)
+++ head/usr.bin/top/username.h Sun Jun  3 05:20:11 2018(r334553)
@@ -12,13 +12,12 @@
 #define USERNAME_H
 
 #include 
-#include 
 
-int enter_user(uid_t uid, char *name, bool wecare);
-int get_user(uid_t uid);
+int enter_user(int uid, char *name, bool wecare);
+int get_user(int uid);
 voidinit_hash(void);
-char   *username(uid_t uid);
-uid_t   userid(char *username);
+char   *username(int uid);
+int userid(char *username);
 
 /*
  *  "Table_size" defines the size of the hash tables used to map uid to

Modified: head/usr.bin/top/utils.c
==
--- head/usr.bin/top/utils.cSun Jun  3 05:07:46 2018(r334552)
+++ head/usr.bin/top/utils.cSun Jun  3 05:20:11 2018(r334553)
@@ -89,12 +89,12 @@ char *itoa(unsigned int val)
 }
 
 /*
- *  itoa7(val) - like 

Re: svn commit: r334543 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
On 2 June 2018 at 16:56, Rodney W. Grimes
 wrote:
>> Author: eadler
>> Date: Sat Jun  2 22:06:27 2018
>> New Revision: 334543
>> URL: https://svnweb.freebsd.org/changeset/base/334543
>>
>> Log:
>>   top(1): chdir to / as init; remove unneeded comment
>>
>>   - chdir to / to allow unmounting of wd
>>   - remove warning about running top(1) as setuid. If this is a concern we
>>   should just drop privs instead.
>>
>> Modified:
>>   head/usr.bin/top/machine.c
>>   head/usr.bin/top/top.c
>>
>> Modified: head/usr.bin/top/machine.c
>> ==
>> --- head/usr.bin/top/machine.cSat Jun  2 21:50:00 2018
>> (r334542)
>> +++ head/usr.bin/top/machine.cSat Jun  2 22:06:27 2018
>> (r334543)
>> @@ -1613,11 +1613,6 @@ compare_ivcsw(const void *arg1, const void *arg2)
>>  /*
>>   * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
>>   *   the process does not exist.
>> - *   It is EXTREMELY IMPORTANT that this function work correctly.
>> - *   If top runs setuid root (as in SVR4), then this function
>> - *   is the only thing that stands in the way of a serious
>> - *   security problem.  It validates requests for the "kill"
>> - *   and "renice" commands.
>>   */
>>
>>  int
>>
>> Modified: head/usr.bin/top/top.c
>> ==
>> --- head/usr.bin/top/top.cSat Jun  2 21:50:00 2018(r334542)
>> +++ head/usr.bin/top/top.cSat Jun  2 22:06:27 2018(r334543)
>> @@ -260,6 +260,15 @@ main(int argc, char *argv[])
>>  #define CMD_order26
>>  #define CMD_pid  27
>>
>> +/*
>> + * Since top(1) is often long running and
>> + * doesn't typically care about where its running from
>> + * chdir to the root to allow unmounting of its
>> + * originall wd. Failure is alright as this is
>> + * just a courtesy for users.
>> + */
>> +chdir("/");
>> +
>
> Bad side effect of doing that is it is not hard to get a "core"
> from top when run as a user, as it is going to try to write
> to /, and it probably does not have permission for that.

Another person made the point that other similar applications don't do
this, so I just reverted it.

thanks!


-- 
Eitan Adler
Source, Ports, Doc committer
Bugmeister, Ports Security teams
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334552 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sun Jun  3 05:07:46 2018
New Revision: 334552
URL: https://svnweb.freebsd.org/changeset/base/334552

Log:
  top(1): remove chdir to /
  
  While this came out of a conversation in IRC, it turn out that some
  people don't like it. Since this was a courtesy feature, just remove it.

Modified:
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/top.c
==
--- head/usr.bin/top/top.c  Sun Jun  3 05:07:39 2018(r334551)
+++ head/usr.bin/top/top.c  Sun Jun  3 05:07:46 2018(r334552)
@@ -260,15 +260,6 @@ main(int argc, char *argv[])
 #define CMD_order  26
 #define CMD_pid27
 
-/*
- * Since top(1) is often long running and
- * doesn't typically care about where its running from
- * chdir to the root to allow unmounting of its
- * original wd. Failure is alright as this is
- * just a courtesy for users.
- */
-chdir("/");
-
 /* set the buffer for stdout */
 #ifdef DEBUG
 extern FILE *debug;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334551 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sun Jun  3 05:07:39 2018
New Revision: 334551
URL: https://svnweb.freebsd.org/changeset/base/334551

Log:
  top(1): use greater warnings
  
  One of the downsides of using numeric WARNS is that if we only have a
  single type of issue we get no protection from other changes.  For
  example, we got no warning for missing variable declaration, due to
  the issues with "const".
  
  For this utility, explicitly list out the warnings which are failing.
  They should still be fixed, so only reduce them to warning instead of
  error.
  
  Tested with: clang base (amd64, i386), gcc6, gcc7, gcc9, gcc base (mips)

Modified:
  head/usr.bin/top/Makefile
  head/usr.bin/top/machine.c

Modified: head/usr.bin/top/Makefile
==
--- head/usr.bin/top/Makefile   Sun Jun  3 03:53:11 2018(r334550)
+++ head/usr.bin/top/Makefile   Sun Jun  3 05:07:39 2018(r334551)
@@ -1,12 +1,22 @@
 # $FreeBSD$
 
+.include 
+
 PROG=  top
 SRCS=  commands.c display.c machine.c screen.c top.c \
username.c utils.c sigdesc.h
 CFLAGS+= -I ${.OBJDIR}
 MAN=   top.1
 
-WARNS?=3
+WARNS?=6
+
+.if ${COMPILER_TYPE} == "gcc" && ${COMPILER_VERSION} >= 5
+CFLAGS.gcc=-Wno-error=cast-align -Wno-error=cast-qual 
-Wno-error=discarded-qualifiers -Wno-error=incompatible-pointer-types \
+   -Wno-error=maybe-uninitialized
+.else #base gcc
+NO_WERROR=
+.endif
+CFLAGS.clang=-Wno-error=incompatible-pointer-types-discards-qualifiers 
-Wno-error=cast-qual -Wno-error=cast-align
 
 LIBADD=ncursesw m kvm jail
 

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sun Jun  3 03:53:11 2018(r334550)
+++ head/usr.bin/top/machine.c  Sun Jun  3 05:07:39 2018(r334551)
@@ -229,7 +229,7 @@ static int pageshift;   /* log base 2 of the 
pagesize *
 /*
  * Sorting orders.  The first element is the default.
  */
-char *ordernames[] = {
+static const char *ordernames[] = {
"cpu", "size", "res", "time", "pri", "threads",
"total", "read", "write", "fault", "vcsw", "ivcsw",
"jid", "swap", "pid", NULL
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334540 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
On 2 June 2018 at 21:14, Rodney W. Grimes
 wrote:
>> On 2 June 2018 at 16:53, Rodney W. Grimes
>>  wrote:
>> > [ Charset UTF-8 unsupported, converting... ]
>> >> Author: eadler
>> >> Date: Sat Jun  2 21:40:45 2018
>> >> New Revision: 334540
>> >> URL: https://svnweb.freebsd.org/changeset/base/334540
>> >>
>> >> Log:
>> >>   top(1): cleanup memory allocation and warnings
>> >>
>> >>   - Prefer calloc over malloc. This is more predicable and we're not in a
>> >>   performance sensitive context. [1]
>> >>   - Remove bogus comment (obsolete from prior commit). [2]
>> >>   - Remove void casts and type casts of NULL
>> >>   - Remove redundant declaration of 'quit'
>> >>   - Add additional const
>> >>
>> >>   Reported by:kib [1], vangyzen [2]
>> >>
>> >> Modified:
>> >>   head/usr.bin/top/display.c
>> >>   head/usr.bin/top/machine.c
>> >>   head/usr.bin/top/screen.c
>> >>   head/usr.bin/top/screen.h
>> >>   head/usr.bin/top/utils.c
>> > ...
>> >
>> >>
>> >> Modified: head/usr.bin/top/screen.c
>> >> ==
>> >> --- head/usr.bin/top/screen.c Sat Jun  2 21:16:20 2018(r334539)
>> >> +++ head/usr.bin/top/screen.c Sat Jun  2 21:40:45 2018(r334540)
>> >> @@ -3,7 +3,7 @@
>> >>   *  Version 3
>> >>   *
>> >>   *  This program may be freely redistributed,
>> >> - *  but this entire comment MUST remain intact.
>> >> + *  but this entire ceomment MUST remain intact.
>> >
>> > I know you have already fixed this spelling error,
>> > but I believe there are some other commits that actually
>> > removed either this string, or some part of "this entire"
>> > comment that is to "remain intact".
>>
>> I just went through my commits to top(1) and don't see any others. Did
>> I miss any?
>
> Index: commands.c
> ===
> --- commands.c  (revision 333898)
> +++ commands.c  (working copy)
> @@ -1,6 +1,5 @@
>  /*
>   *  Top users/processes display for Unix
> - *  Version 3
>   *
>   *  This program may be freely redistributed,
>   *  but this entire comment MUST remain intact.
>
> Found with a cd usr.bin/top; svn diff -r 333898 which is
> when you moved it to usr.bin.  Further investigation
> shows that this line was deleted at r333909.

I removed the version line, not the license line. Do you believe
"entire comment" includes the version information?



-- 
Eitan Adler
Source, Ports, Doc committer
Bugmeister, Ports Security teams
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334540 - head/usr.bin/top

2018-06-02 Thread Rodney W. Grimes
> On 2 June 2018 at 16:53, Rodney W. Grimes
>  wrote:
> > [ Charset UTF-8 unsupported, converting... ]
> >> Author: eadler
> >> Date: Sat Jun  2 21:40:45 2018
> >> New Revision: 334540
> >> URL: https://svnweb.freebsd.org/changeset/base/334540
> >>
> >> Log:
> >>   top(1): cleanup memory allocation and warnings
> >>
> >>   - Prefer calloc over malloc. This is more predicable and we're not in a
> >>   performance sensitive context. [1]
> >>   - Remove bogus comment (obsolete from prior commit). [2]
> >>   - Remove void casts and type casts of NULL
> >>   - Remove redundant declaration of 'quit'
> >>   - Add additional const
> >>
> >>   Reported by:kib [1], vangyzen [2]
> >>
> >> Modified:
> >>   head/usr.bin/top/display.c
> >>   head/usr.bin/top/machine.c
> >>   head/usr.bin/top/screen.c
> >>   head/usr.bin/top/screen.h
> >>   head/usr.bin/top/utils.c
> > ...
> >
> >>
> >> Modified: head/usr.bin/top/screen.c
> >> ==
> >> --- head/usr.bin/top/screen.c Sat Jun  2 21:16:20 2018(r334539)
> >> +++ head/usr.bin/top/screen.c Sat Jun  2 21:40:45 2018(r334540)
> >> @@ -3,7 +3,7 @@
> >>   *  Version 3
> >>   *
> >>   *  This program may be freely redistributed,
> >> - *  but this entire comment MUST remain intact.
> >> + *  but this entire ceomment MUST remain intact.
> >
> > I know you have already fixed this spelling error,
> > but I believe there are some other commits that actually
> > removed either this string, or some part of "this entire"
> > comment that is to "remain intact".
> 
> I just went through my commits to top(1) and don't see any others. Did
> I miss any?

Index: commands.c
===
--- commands.c  (revision 333898)
+++ commands.c  (working copy)
@@ -1,6 +1,5 @@
 /*
  *  Top users/processes display for Unix
- *  Version 3
  *
  *  This program may be freely redistributed,
  *  but this entire comment MUST remain intact.

Found with a cd usr.bin/top; svn diff -r 333898 which is
when you moved it to usr.bin.  Further investigation
shows that this line was deleted at r333909.



-- 
Rod Grimes rgri...@freebsd.org
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334550 - head/sys/cddl/dev/profile

2018-06-02 Thread Justin Hibbits
Author: jhibbits
Date: Sun Jun  3 03:53:11 2018
New Revision: 334550
URL: https://svnweb.freebsd.org/changeset/base/334550

Log:
  Revert r326083, it doesn't behave as expected.
  
  Even though there do appear to be more artificial frames, with 12, stack
  traces no longer list at all.  Revert until a better, more stable value can
  be determined.

Modified:
  head/sys/cddl/dev/profile/profile.c

Modified: head/sys/cddl/dev/profile/profile.c
==
--- head/sys/cddl/dev/profile/profile.c Sun Jun  3 02:58:53 2018
(r334549)
+++ head/sys/cddl/dev/profile/profile.c Sun Jun  3 03:53:11 2018
(r334550)
@@ -124,7 +124,7 @@
 /*
  * This value is bogus just to make module compilable on powerpc
  */
-#definePROF_ARTIFICIAL_FRAMES  12
+#definePROF_ARTIFICIAL_FRAMES  3
 #endif
 
 struct profile_probe_percpu;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334540 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
On 2 June 2018 at 16:53, Rodney W. Grimes
 wrote:
> [ Charset UTF-8 unsupported, converting... ]
>> Author: eadler
>> Date: Sat Jun  2 21:40:45 2018
>> New Revision: 334540
>> URL: https://svnweb.freebsd.org/changeset/base/334540
>>
>> Log:
>>   top(1): cleanup memory allocation and warnings
>>
>>   - Prefer calloc over malloc. This is more predicable and we're not in a
>>   performance sensitive context. [1]
>>   - Remove bogus comment (obsolete from prior commit). [2]
>>   - Remove void casts and type casts of NULL
>>   - Remove redundant declaration of 'quit'
>>   - Add additional const
>>
>>   Reported by:kib [1], vangyzen [2]
>>
>> Modified:
>>   head/usr.bin/top/display.c
>>   head/usr.bin/top/machine.c
>>   head/usr.bin/top/screen.c
>>   head/usr.bin/top/screen.h
>>   head/usr.bin/top/utils.c
> ...
>
>>
>> Modified: head/usr.bin/top/screen.c
>> ==
>> --- head/usr.bin/top/screen.c Sat Jun  2 21:16:20 2018(r334539)
>> +++ head/usr.bin/top/screen.c Sat Jun  2 21:40:45 2018(r334540)
>> @@ -3,7 +3,7 @@
>>   *  Version 3
>>   *
>>   *  This program may be freely redistributed,
>> - *  but this entire comment MUST remain intact.
>> + *  but this entire ceomment MUST remain intact.
>
> I know you have already fixed this spelling error,
> but I believe there are some other commits that actually
> removed either this string, or some part of "this entire"
> comment that is to "remain intact".

I just went through my commits to top(1) and don't see any others. Did
I miss any?

Eitan Adler
Source, Ports, Doc committer
Bugmeister, Ports Security teams
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334549 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sun Jun  3 02:58:53 2018
New Revision: 334549
URL: https://svnweb.freebsd.org/changeset/base/334549

Log:
  top(1): misc minor improvements
  
  - use bool instead of int [0]
  - use calloc correctly [0]
(this also caught an incorrect sizeof argument) [1]
  - use size_t over int [2]
  - correct style
  
  Reported by:  pfg [0], scan-build [1], gcc [2]

Modified:
  head/usr.bin/top/commands.c
  head/usr.bin/top/machine.c
  head/usr.bin/top/utils.c

Modified: head/usr.bin/top/commands.c
==
--- head/usr.bin/top/commands.c Sun Jun  3 00:42:36 2018(r334548)
+++ head/usr.bin/top/commands.c Sun Jun  3 02:58:53 2018(r334549)
@@ -43,7 +43,7 @@ struct errs   /* structure for a system-call error */
 
 static char *err_string(void);
 static int str_adderr(char *str, int len, int err);
-static int str_addarg(char *str, int len, char *arg, int first);
+static int str_addarg(char *str, int len, char *arg, bool first);
 
 /*
  *  show_help() - display the help screen; invoked in response to
@@ -199,9 +199,9 @@ static char err_listem[] = 
 char *err_string(void)
 {
 struct errs *errp;
-int  cnt = 0;
-int  first = true;
-int  currerr = -1;
+int cnt = 0;
+bool first = true;
+int currerr = -1;
 int stringlen; /* characters still available in "string" */
 static char string[STRMAX];
 
@@ -279,7 +279,7 @@ str_adderr(char *str, int len, int err)
  */
 
 static int
-str_addarg(char str[], int len, char arg[], int first)
+str_addarg(char str[], int len, char arg[], bool first)
 {
 int arglen;
 

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sun Jun  3 00:42:36 2018(r334548)
+++ head/usr.bin/top/machine.c  Sun Jun  3 02:58:53 2018(r334549)
@@ -381,8 +381,7 @@ machine_init(struct statics *statics)
cpumask = 0;
ncpus = 0;
GETSYSCTL("kern.smp.maxcpus", maxcpu);
-   size = sizeof(long) * maxcpu * CPUSTATES;
-   times = calloc(size, 1);
+   times = calloc(maxcpu * CPUSTATES, sizeof(long));
if (times == NULL)
err(1, "calloc %zu bytes", size);
if (sysctlbyname("kern.cp_times", times, , NULL, 0) == -1)
@@ -400,11 +399,10 @@ machine_init(struct statics *statics)
ncpus++;
}
}
-   size = sizeof(long) * ncpus * CPUSTATES;
-   assert(size > 0);
-   pcpu_cp_old = calloc(1, size);
-   pcpu_cp_diff = calloc(1, size);
-   pcpu_cpu_states = calloc(1, size);
+   assert(ncpus > 0);
+   pcpu_cp_old = calloc(ncpus * CPUSTATES, sizeof(long));
+   pcpu_cp_diff = calloc(ncpus * CPUSTATES, sizeof(long));
+   pcpu_cpu_states = calloc(ncpus * CPUSTATES, sizeof(int));
statics->ncpus = ncpus;
 
update_layout();

Modified: head/usr.bin/top/utils.c
==
--- head/usr.bin/top/utils.cSun Jun  3 00:42:36 2018(r334548)
+++ head/usr.bin/top/utils.cSun Jun  3 02:58:53 2018(r334549)
@@ -29,7 +29,7 @@
 int
 atoiwi(const char *str)
 {
-int len;
+size_t len;
 
 len = strlen(str);
 if (len != 0)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334543 - head/usr.bin/top

2018-06-02 Thread Rodney W. Grimes
> > Author: eadler
> > Date: Sat Jun  2 22:06:27 2018
> > New Revision: 334543
> > URL: https://svnweb.freebsd.org/changeset/base/334543
> > 
> > Log:
> >   top(1): chdir to / as init; remove unneeded comment
> >   
> >   - chdir to / to allow unmounting of wd
> >   - remove warning about running top(1) as setuid. If this is a concern we
> >   should just drop privs instead.
> > 
> > Modified:
> >   head/usr.bin/top/machine.c
> >   head/usr.bin/top/top.c
> > 
> > Modified: head/usr.bin/top/machine.c
> > ==
> > --- head/usr.bin/top/machine.c  Sat Jun  2 21:50:00 2018
> > (r334542)
> > +++ head/usr.bin/top/machine.c  Sat Jun  2 22:06:27 2018
> > (r334543)
> > @@ -1613,11 +1613,6 @@ compare_ivcsw(const void *arg1, const void *arg2)
> >  /*
> >   * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
> >   * the process does not exist.
> > - * It is EXTREMELY IMPORTANT that this function work correctly.
> > - * If top runs setuid root (as in SVR4), then this function
> > - * is the only thing that stands in the way of a serious
> > - * security problem.  It validates requests for the "kill"
> > - * and "renice" commands.
> >   */
> >  
> >  int
> > 
> > Modified: head/usr.bin/top/top.c
> > ==
> > --- head/usr.bin/top/top.c  Sat Jun  2 21:50:00 2018(r334542)
> > +++ head/usr.bin/top/top.c  Sat Jun  2 22:06:27 2018(r334543)
> > @@ -260,6 +260,15 @@ main(int argc, char *argv[])
> >  #define CMD_order  26
> >  #define CMD_pid27
> >  
> > +/*
> > + * Since top(1) is often long running and
> > + * doesn't typically care about where its running from
> > + * chdir to the root to allow unmounting of its
> > + * originall wd. Failure is alright as this is
> > + * just a courtesy for users.
> > + */
> > +chdir("/");
> > +
> 
> Bad side effect of doing that is it is not hard to get a "core"
 ^^^ now
> from top when run as a user, as it is going to try to write
> to /, and it probably does not have permission for that.
> 
> Better might be a cd to /tmp, or /var/tmp, which are usually
> hard to unmount for these reasons anyway.
> 
> >  /* set the buffer for stdout */
> >  #ifdef DEBUG
> >  extern FILE *debug;
> > 
> > 
> 
> -- 
> Rod Grimes rgri...@freebsd.org
> 
> 

-- 
Rod Grimes rgri...@freebsd.org
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334543 - head/usr.bin/top

2018-06-02 Thread Rodney W. Grimes
> Author: eadler
> Date: Sat Jun  2 22:06:27 2018
> New Revision: 334543
> URL: https://svnweb.freebsd.org/changeset/base/334543
> 
> Log:
>   top(1): chdir to / as init; remove unneeded comment
>   
>   - chdir to / to allow unmounting of wd
>   - remove warning about running top(1) as setuid. If this is a concern we
>   should just drop privs instead.
> 
> Modified:
>   head/usr.bin/top/machine.c
>   head/usr.bin/top/top.c
> 
> Modified: head/usr.bin/top/machine.c
> ==
> --- head/usr.bin/top/machine.cSat Jun  2 21:50:00 2018
> (r334542)
> +++ head/usr.bin/top/machine.cSat Jun  2 22:06:27 2018
> (r334543)
> @@ -1613,11 +1613,6 @@ compare_ivcsw(const void *arg1, const void *arg2)
>  /*
>   * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
>   *   the process does not exist.
> - *   It is EXTREMELY IMPORTANT that this function work correctly.
> - *   If top runs setuid root (as in SVR4), then this function
> - *   is the only thing that stands in the way of a serious
> - *   security problem.  It validates requests for the "kill"
> - *   and "renice" commands.
>   */
>  
>  int
> 
> Modified: head/usr.bin/top/top.c
> ==
> --- head/usr.bin/top/top.cSat Jun  2 21:50:00 2018(r334542)
> +++ head/usr.bin/top/top.cSat Jun  2 22:06:27 2018(r334543)
> @@ -260,6 +260,15 @@ main(int argc, char *argv[])
>  #define CMD_order26
>  #define CMD_pid  27
>  
> +/*
> + * Since top(1) is often long running and
> + * doesn't typically care about where its running from
> + * chdir to the root to allow unmounting of its
> + * originall wd. Failure is alright as this is
> + * just a courtesy for users.
> + */
> +chdir("/");
> +

Bad side effect of doing that is it is not hard to get a "core"
from top when run as a user, as it is going to try to write
to /, and it probably does not have permission for that.

Better might be a cd to /tmp, or /var/tmp, which are usually
hard to unmount for these reasons anyway.

>  /* set the buffer for stdout */
>  #ifdef DEBUG
>  extern FILE *debug;
> 
> 

-- 
Rod Grimes rgri...@freebsd.org
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r334540 - head/usr.bin/top

2018-06-02 Thread Rodney W. Grimes
[ Charset UTF-8 unsupported, converting... ]
> Author: eadler
> Date: Sat Jun  2 21:40:45 2018
> New Revision: 334540
> URL: https://svnweb.freebsd.org/changeset/base/334540
> 
> Log:
>   top(1): cleanup memory allocation and warnings
>   
>   - Prefer calloc over malloc. This is more predicable and we're not in a
>   performance sensitive context. [1]
>   - Remove bogus comment (obsolete from prior commit). [2]
>   - Remove void casts and type casts of NULL
>   - Remove redundant declaration of 'quit'
>   - Add additional const
>   
>   Reported by:kib [1], vangyzen [2]
> 
> Modified:
>   head/usr.bin/top/display.c
>   head/usr.bin/top/machine.c
>   head/usr.bin/top/screen.c
>   head/usr.bin/top/screen.h
>   head/usr.bin/top/utils.c
...

> 
> Modified: head/usr.bin/top/screen.c
> ==
> --- head/usr.bin/top/screen.c Sat Jun  2 21:16:20 2018(r334539)
> +++ head/usr.bin/top/screen.c Sat Jun  2 21:40:45 2018(r334540)
> @@ -3,7 +3,7 @@
>   *  Version 3
>   *
>   *  This program may be freely redistributed,
> - *  but this entire comment MUST remain intact.
> + *  but this entire ceomment MUST remain intact.

I know you have already fixed this spelling error,
but I believe there are some other commits that actually
removed either this string, or some part of "this entire"
comment that is to "remain intact".

Regards,
-- 
Rod Grimes rgri...@freebsd.org
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334547 - head/lib/libutil

2018-06-02 Thread Alan Somers
Author: asomers
Date: Sat Jun  2 22:40:16 2018
New Revision: 334547
URL: https://svnweb.freebsd.org/changeset/base/334547

Log:
  pty.3: Add a HISTORY section
  
  These functions were first added in 4.3 BSD-Reno, according to
  http://unix.superglobalmegacorp.com/ and the CSRG svn repository.
  
  Reviewed by:  bcr, bjk
  MFC after:2 weeks
  Differential Revision:https://reviews.freebsd.org/D15652

Modified:
  head/lib/libutil/pty.3

Modified: head/lib/libutil/pty.3
==
--- head/lib/libutil/pty.3  Sat Jun  2 22:37:53 2018(r334546)
+++ head/lib/libutil/pty.3  Sat Jun  2 22:40:16 2018(r334547)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\" "
-.Dd November 11, 2015
+.Dd June 2, 2018
 .Dt PTY 3
 .Os
 .Sh NAME
@@ -143,3 +143,18 @@ may set it to any value as described for
 .Xr pty 4 ,
 .Xr termios 4 ,
 .Xr group 5
+.Sh HISTORY
+The
+.Fn openpty
+and
+.Fn forkpty
+functions first appeared in
+.Bx 4.3 Reno.
+.Sh BUGS
+.Fn openpty
+writes the slave terminal's name to
+.Fa name ,
+but does not check that sufficient space is available.
+It is advisable to use
+.Xr ptsname 3
+instead.
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334546 - in head/sys: amd64/amd64 kern sys

2018-06-02 Thread Mateusz Guzik
Author: mjg
Date: Sat Jun  2 22:37:53 2018
New Revision: 334546
URL: https://svnweb.freebsd.org/changeset/base/334546

Log:
  Remove an unused argument to turnstile_unpend.
  
  PR:   228694
  Submitted by: Julian Pszczołowski 

Modified:
  head/sys/amd64/amd64/pmap.c
  head/sys/kern/kern_mutex.c
  head/sys/kern/kern_rmlock.c
  head/sys/kern/kern_rwlock.c
  head/sys/kern/subr_turnstile.c
  head/sys/sys/turnstile.h

Modified: head/sys/amd64/amd64/pmap.c
==
--- head/sys/amd64/amd64/pmap.c Sat Jun  2 22:20:09 2018(r334545)
+++ head/sys/amd64/amd64/pmap.c Sat Jun  2 22:37:53 2018(r334546)
@@ -513,7 +513,7 @@ pmap_delayed_invl_finished(void)
pmap_invl_gen = invl_gen->gen;
if (ts != NULL) {
turnstile_broadcast(ts, TS_SHARED_QUEUE);
-   turnstile_unpend(ts, TS_SHARED_LOCK);
+   turnstile_unpend(ts);
}
turnstile_chain_unlock(_gen_ts);
} else {

Modified: head/sys/kern/kern_mutex.c
==
--- head/sys/kern/kern_mutex.c  Sat Jun  2 22:20:09 2018(r334545)
+++ head/sys/kern/kern_mutex.c  Sat Jun  2 22:37:53 2018(r334546)
@@ -1029,7 +1029,7 @@ __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v)
 * This turnstile is now no longer associated with the mutex.  We can
 * unlock the chain lock so a new turnstile may take it's place.
 */
-   turnstile_unpend(ts, TS_EXCLUSIVE_LOCK);
+   turnstile_unpend(ts);
turnstile_chain_unlock(>lock_object);
 }
 

Modified: head/sys/kern/kern_rmlock.c
==
--- head/sys/kern/kern_rmlock.c Sat Jun  2 22:20:09 2018(r334545)
+++ head/sys/kern/kern_rmlock.c Sat Jun  2 22:37:53 2018(r334546)
@@ -494,7 +494,7 @@ _rm_unlock_hard(struct thread *td,struct rm_priotracke
ts = turnstile_lookup(>lock_object);
 
turnstile_signal(ts, TS_EXCLUSIVE_QUEUE);
-   turnstile_unpend(ts, TS_EXCLUSIVE_LOCK);
+   turnstile_unpend(ts);
turnstile_chain_unlock(>lock_object);
} else
mtx_unlock_spin(_spinlock);

Modified: head/sys/kern/kern_rwlock.c
==
--- head/sys/kern/kern_rwlock.c Sat Jun  2 22:20:09 2018(r334545)
+++ head/sys/kern/kern_rwlock.c Sat Jun  2 22:37:53 2018(r334546)
@@ -822,7 +822,7 @@ __rw_runlock_hard(struct rwlock *rw, struct thread *td
ts = turnstile_lookup(>lock_object);
MPASS(ts != NULL);
turnstile_broadcast(ts, queue);
-   turnstile_unpend(ts, TS_SHARED_LOCK);
+   turnstile_unpend(ts);
td->td_rw_rlocks--;
break;
}
@@ -1259,7 +1259,7 @@ __rw_wunlock_hard(volatile uintptr_t *c, uintptr_t v L
ts = turnstile_lookup(>lock_object);
MPASS(ts != NULL);
turnstile_broadcast(ts, queue);
-   turnstile_unpend(ts, TS_EXCLUSIVE_LOCK);
+   turnstile_unpend(ts);
turnstile_chain_unlock(>lock_object);
 }
 
@@ -1405,7 +1405,7 @@ __rw_downgrade_int(struct rwlock *rw LOCK_FILE_LINE_AR
 */
if (rwait && !wwait) {
turnstile_broadcast(ts, TS_SHARED_QUEUE);
-   turnstile_unpend(ts, TS_EXCLUSIVE_LOCK);
+   turnstile_unpend(ts);
} else
turnstile_disown(ts);
turnstile_chain_unlock(>lock_object);

Modified: head/sys/kern/subr_turnstile.c
==
--- head/sys/kern/subr_turnstile.c  Sat Jun  2 22:20:09 2018
(r334545)
+++ head/sys/kern/subr_turnstile.c  Sat Jun  2 22:37:53 2018
(r334546)
@@ -903,7 +903,7 @@ turnstile_broadcast(struct turnstile *ts, int queue)
  * chain locked.
  */
 void
-turnstile_unpend(struct turnstile *ts, int owner_type)
+turnstile_unpend(struct turnstile *ts)
 {
TAILQ_HEAD( ,thread) pending_threads;
struct turnstile *nts;

Modified: head/sys/sys/turnstile.h
==
--- head/sys/sys/turnstile.hSat Jun  2 22:20:09 2018(r334545)
+++ head/sys/sys/turnstile.hSat Jun  2 22:37:53 2018(r334546)
@@ -83,10 +83,6 @@ struct turnstile;
 #defineTS_EXCLUSIVE_QUEUE  0
 #defineTS_SHARED_QUEUE 1
 
-/* The type of lock currently held. */
-#defineTS_EXCLUSIVE_LOCK   TS_EXCLUSIVE_QUEUE
-#defineTS_SHARED_LOCK  TS_SHARED_QUEUE
-
 void   init_turnstiles(void);
 void   turnstile_adjust(struct thread *, u_char);
 struct turnstile *turnstile_alloc(void);
@@ -102,7 +98,7 @@ struct thread *turnstile_head(struct 

svn commit: r334545 - in head/sys: contrib/zstd/lib/freebsd kern netinet/libalias sys

2018-06-02 Thread Mateusz Guzik
Author: mjg
Date: Sat Jun  2 22:20:09 2018
New Revision: 334545
URL: https://svnweb.freebsd.org/changeset/base/334545

Log:
  malloc: try to use builtins for zeroing at the callsite
  
  Plenty of allocation sites pass M_ZERO and sizes which are small and known
  at compilation time. Handling them internally in malloc loses this information
  and results in avoidable calls to memset.
  
  Instead, let the compiler take the advantage of it whenever possible.
  
  Discussed with:   jeff

Modified:
  head/sys/contrib/zstd/lib/freebsd/stdlib.h
  head/sys/kern/kern_malloc.c
  head/sys/netinet/libalias/alias_mod.h
  head/sys/sys/malloc.h

Modified: head/sys/contrib/zstd/lib/freebsd/stdlib.h
==
--- head/sys/contrib/zstd/lib/freebsd/stdlib.h  Sat Jun  2 22:12:57 2018
(r334544)
+++ head/sys/contrib/zstd/lib/freebsd/stdlib.h  Sat Jun  2 22:20:09 2018
(r334545)
@@ -35,6 +35,7 @@
 
 MALLOC_DECLARE(M_ZSTD);
 
+#undef malloc
 #definemalloc(x)   (malloc)((x), M_ZSTD, M_WAITOK)
 #definefree(x) (free)((x), M_ZSTD)
 #definecalloc(a, b)(mallocarray)((a), (b), M_ZSTD, M_WAITOK | 
M_ZERO)

Modified: head/sys/kern/kern_malloc.c
==
--- head/sys/kern/kern_malloc.c Sat Jun  2 22:12:57 2018(r334544)
+++ head/sys/kern/kern_malloc.c Sat Jun  2 22:20:09 2018(r334545)
@@ -549,7 +549,7 @@ malloc_dbg(caddr_t *vap, size_t *sizep, struct malloc_
  * the allocation fails.
  */
 void *
-malloc(size_t size, struct malloc_type *mtp, int flags)
+(malloc)(size_t size, struct malloc_type *mtp, int flags)
 {
int indx;
caddr_t va;

Modified: head/sys/netinet/libalias/alias_mod.h
==
--- head/sys/netinet/libalias/alias_mod.h   Sat Jun  2 22:12:57 2018
(r334544)
+++ head/sys/netinet/libalias/alias_mod.h   Sat Jun  2 22:20:09 2018
(r334545)
@@ -41,6 +41,7 @@ MALLOC_DECLARE(M_ALIAS);
 
 /* Use kernel allocator. */
 #if defined(_SYS_MALLOC_H_)
+#undef malloc
 #definemalloc(x)   malloc(x, M_ALIAS, M_NOWAIT|M_ZERO)
 #definecalloc(n, x)mallocarray((n), (x), M_ALIAS, M_NOWAIT|M_ZERO)
 #definefree(x) free(x, M_ALIAS)

Modified: head/sys/sys/malloc.h
==
--- head/sys/sys/malloc.h   Sat Jun  2 22:12:57 2018(r334544)
+++ head/sys/sys/malloc.h   Sat Jun  2 22:20:09 2018(r334545)
@@ -38,6 +38,9 @@
 #define_SYS_MALLOC_H_
 
 #include 
+#ifdef _KERNEL
+#include 
+#endif
 #include 
 #include 
 #include 
@@ -183,6 +186,22 @@ void   free(void *addr, struct malloc_type *type);
 void   free_domain(void *addr, struct malloc_type *type);
 void   *malloc(size_t size, struct malloc_type *type, int flags) __malloc_like
__result_use_check __alloc_size(1);
+#ifdef _KERNEL
+#definemalloc(size, type, flags) ({
\
+   void *_malloc_item; \
+   size_t _size = (size);  \
+   if (__builtin_constant_p(size) && __builtin_constant_p(flags) &&\
+   ((flags) & M_ZERO)) {   \
+   _malloc_item = malloc(_size, type, (flags) &~ M_ZERO);  \
+   if (((flags) & M_WAITOK) || _malloc_item != NULL)   \
+   bzero(_malloc_item, _size); \
+   } else {\
+   _malloc_item = malloc(_size, type, flags);  \
+   }   \
+   _malloc_item;   \
+})
+#endif
+
 void   *malloc_domain(size_t size, struct malloc_type *type, int domain,
int flags) __malloc_like __result_use_check __alloc_size(1);
 void   *mallocarray(size_t nmemb, size_t size, struct malloc_type *type,
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334544 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sat Jun  2 22:12:57 2018
New Revision: 334544
URL: https://svnweb.freebsd.org/changeset/base/334544

Log:
  top(1): Fix two speeling errors I introduced

Modified:
  head/usr.bin/top/screen.c
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/screen.c
==
--- head/usr.bin/top/screen.c   Sat Jun  2 22:06:27 2018(r334543)
+++ head/usr.bin/top/screen.c   Sat Jun  2 22:12:57 2018(r334544)
@@ -3,7 +3,7 @@
  *  Version 3
  *
  *  This program may be freely redistributed,
- *  but this entire ceomment MUST remain intact.
+ *  but this entire comment MUST remain intact.
  *
  *  Copyright (c) 1984, 1989, William LeFebvre, Rice University
  *  Copyright (c) 1989, 1990, 1992, William LeFebvre, Northwestern University

Modified: head/usr.bin/top/top.c
==
--- head/usr.bin/top/top.c  Sat Jun  2 22:06:27 2018(r334543)
+++ head/usr.bin/top/top.c  Sat Jun  2 22:12:57 2018(r334544)
@@ -264,7 +264,7 @@ main(int argc, char *argv[])
  * Since top(1) is often long running and
  * doesn't typically care about where its running from
  * chdir to the root to allow unmounting of its
- * originall wd. Failure is alright as this is
+ * original wd. Failure is alright as this is
  * just a courtesy for users.
  */
 chdir("/");
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334543 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sat Jun  2 22:06:27 2018
New Revision: 334543
URL: https://svnweb.freebsd.org/changeset/base/334543

Log:
  top(1): chdir to / as init; remove unneeded comment
  
  - chdir to / to allow unmounting of wd
  - remove warning about running top(1) as setuid. If this is a concern we
  should just drop privs instead.

Modified:
  head/usr.bin/top/machine.c
  head/usr.bin/top/top.c

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sat Jun  2 21:50:00 2018(r334542)
+++ head/usr.bin/top/machine.c  Sat Jun  2 22:06:27 2018(r334543)
@@ -1613,11 +1613,6 @@ compare_ivcsw(const void *arg1, const void *arg2)
 /*
  * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
  * the process does not exist.
- * It is EXTREMELY IMPORTANT that this function work correctly.
- * If top runs setuid root (as in SVR4), then this function
- * is the only thing that stands in the way of a serious
- * security problem.  It validates requests for the "kill"
- * and "renice" commands.
  */
 
 int

Modified: head/usr.bin/top/top.c
==
--- head/usr.bin/top/top.c  Sat Jun  2 21:50:00 2018(r334542)
+++ head/usr.bin/top/top.c  Sat Jun  2 22:06:27 2018(r334543)
@@ -260,6 +260,15 @@ main(int argc, char *argv[])
 #define CMD_order  26
 #define CMD_pid27
 
+/*
+ * Since top(1) is often long running and
+ * doesn't typically care about where its running from
+ * chdir to the root to allow unmounting of its
+ * originall wd. Failure is alright as this is
+ * just a courtesy for users.
+ */
+chdir("/");
+
 /* set the buffer for stdout */
 #ifdef DEBUG
 extern FILE *debug;
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334540 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sat Jun  2 21:40:45 2018
New Revision: 334540
URL: https://svnweb.freebsd.org/changeset/base/334540

Log:
  top(1): cleanup memory allocation and warnings
  
  - Prefer calloc over malloc. This is more predicable and we're not in a
  performance sensitive context. [1]
  - Remove bogus comment (obsolete from prior commit). [2]
  - Remove void casts and type casts of NULL
  - Remove redundant declaration of 'quit'
  - Add additional const
  
  Reported by:  kib [1], vangyzen [2]

Modified:
  head/usr.bin/top/display.c
  head/usr.bin/top/machine.c
  head/usr.bin/top/screen.c
  head/usr.bin/top/screen.h
  head/usr.bin/top/utils.c

Modified: head/usr.bin/top/display.c
==
--- head/usr.bin/top/display.c  Sat Jun  2 21:16:20 2018(r334539)
+++ head/usr.bin/top/display.c  Sat Jun  2 21:40:45 2018(r334540)
@@ -148,8 +148,8 @@ display_resize(void)
 }
 
 /* now, allocate space for the screen buffer */
-screenbuf = malloc(lines * display_width);
-if (screenbuf == (char *)NULL)
+screenbuf = calloc(lines, display_width);
+if (screenbuf == NULL)
 {
/* oops! */
return(-1);
@@ -205,23 +205,23 @@ int display_init(struct statics * statics)
procstate_names = statics->procstate_names;
num_procstates = string_count(procstate_names);
assert(num_procstates > 0);
-   lprocstates = malloc(num_procstates * sizeof(int));
+   lprocstates = calloc(num_procstates, sizeof(int));
 
cpustate_names = statics->cpustate_names;
 
swap_names = statics->swap_names;
num_swap = string_count(swap_names);
assert(num_swap > 0);
-   lswap = malloc(num_swap * sizeof(int));
+   lswap = calloc(num_swap, sizeof(int));
num_cpustates = string_count(cpustate_names);
assert(num_cpustates > 0);
-   lcpustates = malloc(num_cpustates * sizeof(int) * statics->ncpus);
-   cpustate_columns = malloc(num_cpustates * sizeof(int));
+   lcpustates = calloc(num_cpustates * sizeof(int), statics->ncpus);
+   cpustate_columns = calloc(num_cpustates, sizeof(int));
 
memory_names = statics->memory_names;
num_memory = string_count(memory_names);
assert(num_memory > 0);
-   lmemory = malloc(num_memory * sizeof(int));
+   lmemory = calloc(num_memory, sizeof(int));
 
arc_names = statics->arc_names;
carc_names = statics->carc_names;
@@ -745,7 +745,7 @@ trim_header(char *text)
width = display_width;
header_length = strlen(text);
if (header_length >= width) {
-   s = malloc((width + 1) * sizeof(char));
+   s = calloc((width + 1), sizeof(char));
if (s == NULL)
return (NULL);
strncpy(s, text, width);

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sat Jun  2 21:16:20 2018(r334539)
+++ head/usr.bin/top/machine.c  Sat Jun  2 21:40:45 2018(r334540)
@@ -382,9 +382,9 @@ machine_init(struct statics *statics)
ncpus = 0;
GETSYSCTL("kern.smp.maxcpus", maxcpu);
size = sizeof(long) * maxcpu * CPUSTATES;
-   times = malloc(size);
+   times = calloc(size, 1);
if (times == NULL)
-   err(1, "malloc %zu bytes", size);
+   err(1, "calloc %zu bytes", size);
if (sysctlbyname("kern.cp_times", times, , NULL, 0) == -1)
err(1, "sysctlbyname kern.cp_times");
pcpu_cp_time = calloc(1, size);
@@ -779,11 +779,11 @@ get_process_info(struct system_info *si, struct proces
 */
if (previous_proc_count_max < nproc) {
free(previous_procs);
-   previous_procs = malloc(nproc * sizeof(*previous_procs));
+   previous_procs = calloc(nproc, sizeof(*previous_procs));
free(previous_pref);
-   previous_pref = malloc(nproc * sizeof(*previous_pref));
+   previous_pref = calloc(nproc, sizeof(*previous_pref));
if (previous_procs == NULL || previous_pref == NULL) {
-   (void) fprintf(stderr, "top: Out of memory.\n");
+   fprintf(stderr, "top: Out of memory.\n");
quit(TOP_EX_SYS_ERROR);
}
previous_proc_count_max = nproc;
@@ -996,9 +996,9 @@ format_next_process(caddr_t xhandle, char *(*get_useri
break;
}
 
-   cmdbuf = malloc(cmdlen + 1);
+   cmdbuf = calloc(cmdlen + 1, 1);
if (cmdbuf == NULL) {
-   warn("malloc(%d)", cmdlen + 1);
+   warn("calloc(%d)", cmdlen + 1);
return NULL;
}
 
@@ -1031,9 +1031,9 @@ format_next_process(caddr_t xhandle, char *(*get_useri
size_t len;
 
argbuflen = 

svn commit: r334538 - in head: sys/powerpc/powerpc sys/sys usr.bin/gcore

2018-06-02 Thread Justin Hibbits
Author: jhibbits
Date: Sat Jun  2 20:28:58 2018
New Revision: 334538
URL: https://svnweb.freebsd.org/changeset/base/334538

Log:
  Included VSX registers in powerpc core dumps
  
  Summary: Included VSX registers in powerpc core dumps (both kernel and gcore)
  
  Submitted by: Luis Pires
  Differential Revision: https://reviews.freebsd.org/D15512

Modified:
  head/sys/powerpc/powerpc/elf32_machdep.c
  head/sys/powerpc/powerpc/elf64_machdep.c
  head/sys/sys/elf_common.h
  head/usr.bin/gcore/elfcore.c

Modified: head/sys/powerpc/powerpc/elf32_machdep.c
==
--- head/sys/powerpc/powerpc/elf32_machdep.cSat Jun  2 20:14:43 2018
(r334537)
+++ head/sys/powerpc/powerpc/elf32_machdep.cSat Jun  2 20:28:58 2018
(r334538)
@@ -52,6 +52,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -171,19 +172,44 @@ elf32_dump_thread(struct thread *td, void *dst, size_t
 {
size_t len;
struct pcb *pcb;
+   uint64_t vshr[32];
+   uint64_t *vsr_dw1;
+   int vsr_idx;
 
len = 0;
pcb = td->td_pcb;
+
if (pcb->pcb_flags & PCB_VEC) {
save_vec_nodrop(td);
if (dst != NULL) {
len += elf32_populate_note(NT_PPC_VMX,
-   >pcb_vec, dst,
+   >pcb_vec, (char *)dst + len,
sizeof(pcb->pcb_vec), NULL);
} else
len += elf32_populate_note(NT_PPC_VMX, NULL, NULL,
sizeof(pcb->pcb_vec), NULL);
}
+
+   if (pcb->pcb_flags & PCB_VSX) {
+   save_fpu_nodrop(td);
+   if (dst != NULL) {
+   /*
+* Doubleword 0 of VSR0-VSR31 overlap with FPR0-FPR31 
and
+* VSR32-VSR63 overlap with VR0-VR31, so we only copy
+* the non-overlapping data, which is doubleword 1 of 
VSR0-VSR31.
+*/
+   for (vsr_idx = 0; vsr_idx < nitems(vshr); vsr_idx++) {
+   vsr_dw1 = (uint64_t 
*)>pcb_fpu.fpr[vsr_idx].vsr[2];
+   vshr[vsr_idx] = *vsr_dw1;
+   }
+   len += elf32_populate_note(NT_PPC_VSX,
+   vshr, (char *)dst + len,
+   sizeof(vshr), NULL);
+   } else
+   len += elf32_populate_note(NT_PPC_VSX, NULL, NULL,
+   sizeof(vshr), NULL);
+   }
+
*off = len;
 }
 

Modified: head/sys/powerpc/powerpc/elf64_machdep.c
==
--- head/sys/powerpc/powerpc/elf64_machdep.cSat Jun  2 20:14:43 2018
(r334537)
+++ head/sys/powerpc/powerpc/elf64_machdep.cSat Jun  2 20:28:58 2018
(r334538)
@@ -48,6 +48,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -234,19 +235,44 @@ elf64_dump_thread(struct thread *td, void *dst, size_t
 {
size_t len;
struct pcb *pcb;
+   uint64_t vshr[32];
+   uint64_t *vsr_dw1;
+   int vsr_idx;
 
len = 0;
pcb = td->td_pcb;
+
if (pcb->pcb_flags & PCB_VEC) {
save_vec_nodrop(td);
if (dst != NULL) {
len += elf64_populate_note(NT_PPC_VMX,
-   >pcb_vec, dst,
+   >pcb_vec, (char *)dst + len,
sizeof(pcb->pcb_vec), NULL);
} else
len += elf64_populate_note(NT_PPC_VMX, NULL, NULL,
sizeof(pcb->pcb_vec), NULL);
}
+
+   if (pcb->pcb_flags & PCB_VSX) {
+   save_fpu_nodrop(td);
+   if (dst != NULL) {
+   /*
+* Doubleword 0 of VSR0-VSR31 overlap with FPR0-FPR31 
and
+* VSR32-VSR63 overlap with VR0-VR31, so we only copy
+* the non-overlapping data, which is doubleword 1 of 
VSR0-VSR31.
+*/
+   for (vsr_idx = 0; vsr_idx < nitems(vshr); vsr_idx++) {
+   vsr_dw1 = (uint64_t 
*)>pcb_fpu.fpr[vsr_idx].vsr[2];
+   vshr[vsr_idx] = *vsr_dw1;
+   }
+   len += elf64_populate_note(NT_PPC_VSX,
+   vshr, (char *)dst + len,
+   sizeof(vshr), NULL);
+   } else
+   len += elf64_populate_note(NT_PPC_VSX, NULL, NULL,
+   sizeof(vshr), NULL);
+   }
+
*off = len;
 }
 

Modified: head/sys/sys/elf_common.h
==
--- head/sys/sys/elf_common.h   Sat Jun  2 20:14:43 2018

svn commit: r334537 - head/sys/amd64/amd64

2018-06-02 Thread Mateusz Guzik
Author: mjg
Date: Sat Jun  2 20:14:43 2018
New Revision: 334537
URL: https://svnweb.freebsd.org/changeset/base/334537

Log:
  amd64: add a mild depessimization to rep mov/stos users
  
  Currently all the primitives are waiting for a rewrite, tidy them up in the
  meantime.
  
  Vast majority of cases pass sizes which are multiple of 8. Which means the
  following rep stosb/movb has nothing to do. Turns out testing first if there
  is anything to do is a big win across the board (cpus with and without ERMS,
  Intel and AMD) while not pessimizing the case where there is work to do.
  
  Sample results for zeroing 64 bytes (ops/second):
  Ryzen Threadripper 1950X  91433212 -> 147265741
  Intel(R) Xeon(R) CPU X5675 @ 3.07GHz  90714044 -> 121992888
  
  bzero and bcopy are on their way out and were not modified. Nothing in the
  tree uses them.

Modified:
  head/sys/amd64/amd64/support.S

Modified: head/sys/amd64/amd64/support.S
==
--- head/sys/amd64/amd64/support.S  Sat Jun  2 20:11:28 2018
(r334536)
+++ head/sys/amd64/amd64/support.S  Sat Jun  2 20:14:43 2018
(r334537)
@@ -205,6 +205,11 @@ ENTRY(memmove)
movsq
movq%rdx,%rcx
andq$7,%rcx /* any bytes left? */
+   jne 2f
+   movq%r9,%rax
+   POP_FRAME_POINTER
+   ret
+2:
rep
movsb
movq%r9,%rax
@@ -248,6 +253,10 @@ ENTRY(memcpy)
movsq
movq%rdx,%rcx
andq$7,%rcx /* any bytes left? */
+   jne 1f
+   POP_FRAME_POINTER
+   ret
+1:
rep
movsb
POP_FRAME_POINTER
@@ -269,6 +278,11 @@ ENTRY(memset)
stosq
movq%rdx,%rcx
andq$7,%rcx
+   jne 1f
+   movq%r9,%rax
+   POP_FRAME_POINTER
+   ret
+1:
rep
stosb
movq%r9,%rax
@@ -358,6 +372,7 @@ ENTRY(copyout)
movsq
movb%dl,%cl
andb$7,%cl
+   je  done_copyout
rep
movsb
 
@@ -406,6 +421,7 @@ ENTRY(copyin)
movsq
movb%al,%cl
andb$7,%cl  /* copy remaining bytes */
+   je  done_copyin
rep
movsb
 
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334535 - in head: lib/libc/sys sys/powerpc/include sys/powerpc/powerpc

2018-06-02 Thread Justin Hibbits
Author: jhibbits
Date: Sat Jun  2 19:17:11 2018
New Revision: 334535
URL: https://svnweb.freebsd.org/changeset/base/334535

Log:
  Added ptrace support for reading/writing powerpc VSX registers
  
  Summary:
  Added ptrace support for getting/setting the remaining part of the VSX 
registers
  (the part that's not already covered by FPR or VR registers).
  
  This is necessary to add support for VSX registers in debuggers.
  
  Submitted by: Luis Pires
  Differential Revision: https://reviews.freebsd.org/D15458

Modified:
  head/lib/libc/sys/ptrace.2
  head/sys/powerpc/include/fpu.h
  head/sys/powerpc/include/ptrace.h
  head/sys/powerpc/powerpc/fpu.c
  head/sys/powerpc/powerpc/ptrace_machdep.c

Modified: head/lib/libc/sys/ptrace.2
==
--- head/lib/libc/sys/ptrace.2  Sat Jun  2 18:03:35 2018(r334534)
+++ head/lib/libc/sys/ptrace.2  Sat Jun  2 19:17:11 2018(r334535)
@@ -2,7 +2,7 @@
 .\"$NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $
 .\"
 .\" This file is in the public domain.
-.Dd May 22, 2018
+.Dd June 2, 2018
 .Dt PTRACE 2
 .Os
 .Sh NAME
@@ -934,6 +934,24 @@ argument is ignored.
 Set the thread's
 .Dv ALTIVEC
 machine state from the buffer pointed to by
+.Fa addr .
+.Pp
+The
+.Fa data
+argument is ignored.
+.It Dv PT_GETVSRREGS
+Return doubleword 1 of the thread's
+.Dv VSX
+registers VSR0-VSR31 in the buffer pointed to by
+.Fa addr .
+.Pp
+The
+.Fa data
+argument is ignored.
+.It Dv PT_SETVSRREGS
+Set doubleword 1 of the thread's
+.Dv VSX
+registers VSR0-VSR31 from the buffer pointed to by
 .Fa addr .
 .Pp
 The

Modified: head/sys/powerpc/include/fpu.h
==
--- head/sys/powerpc/include/fpu.h  Sat Jun  2 18:03:35 2018
(r334534)
+++ head/sys/powerpc/include/fpu.h  Sat Jun  2 19:17:11 2018
(r334535)
@@ -74,6 +74,7 @@
 
 voidenable_fpu(struct thread *);
 voidsave_fpu(struct thread *);
+voidsave_fpu_nodrop(struct thread *);
 
 #endif /* _KERNEL */
 

Modified: head/sys/powerpc/include/ptrace.h
==
--- head/sys/powerpc/include/ptrace.h   Sat Jun  2 18:03:35 2018
(r334534)
+++ head/sys/powerpc/include/ptrace.h   Sat Jun  2 19:17:11 2018
(r334535)
@@ -39,5 +39,7 @@
 
 #define PT_GETVRREGS   (PT_FIRSTMACH + 0)
 #define PT_SETVRREGS   (PT_FIRSTMACH + 1)
+#define PT_GETVSRREGS  (PT_FIRSTMACH + 2)
+#define PT_SETVSRREGS  (PT_FIRSTMACH + 3)
 
 #endif

Modified: head/sys/powerpc/powerpc/fpu.c
==
--- head/sys/powerpc/powerpc/fpu.c  Sat Jun  2 18:03:35 2018
(r334534)
+++ head/sys/powerpc/powerpc/fpu.c  Sat Jun  2 19:17:11 2018
(r334535)
@@ -45,6 +45,60 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 
+static void
+save_fpu_int(struct thread *td)
+{
+   int msr;
+   struct  pcb *pcb;
+
+   pcb = td->td_pcb;
+
+   /*
+* Temporarily re-enable floating-point during the save
+*/
+   msr = mfmsr();
+   if (pcb->pcb_flags & PCB_VSX)
+   mtmsr(msr | PSL_FP | PSL_VSX);
+   else
+   mtmsr(msr | PSL_FP);
+
+   /*
+* Save the floating-point registers and FPSCR to the PCB
+*/
+   if (pcb->pcb_flags & PCB_VSX) {
+   #define SFP(n)   __asm ("stxvw4x " #n ", 0,%0" \
+   :: "b"(>pcb_fpu.fpr[n]));
+   SFP(0); SFP(1); SFP(2); SFP(3);
+   SFP(4); SFP(5); SFP(6); SFP(7);
+   SFP(8); SFP(9); SFP(10);SFP(11);
+   SFP(12);SFP(13);SFP(14);SFP(15);
+   SFP(16);SFP(17);SFP(18);SFP(19);
+   SFP(20);SFP(21);SFP(22);SFP(23);
+   SFP(24);SFP(25);SFP(26);SFP(27);
+   SFP(28);SFP(29);SFP(30);SFP(31);
+   #undef SFP
+   } else {
+   #define SFP(n)   __asm ("stfd " #n ", 0(%0)" \
+   :: "b"(>pcb_fpu.fpr[n]));
+   SFP(0); SFP(1); SFP(2); SFP(3);
+   SFP(4); SFP(5); SFP(6); SFP(7);
+   SFP(8); SFP(9); SFP(10);SFP(11);
+   SFP(12);SFP(13);SFP(14);SFP(15);
+   SFP(16);SFP(17);SFP(18);SFP(19);
+   SFP(20);SFP(21);SFP(22);SFP(23);
+   SFP(24);SFP(25);SFP(26);SFP(27);
+   SFP(28);SFP(29);SFP(30);SFP(31);
+   #undef SFP
+   }
+   __asm __volatile ("mffs 0; stfd 0,0(%0)" :: "b"(>pcb_fpu.fpscr));
+
+   /*
+* Disable floating-point 

svn commit: r334534 - in head/sys: dev/cx libkern sys

2018-06-02 Thread Mateusz Guzik
Author: mjg
Date: Sat Jun  2 18:03:35 2018
New Revision: 334534
URL: https://svnweb.freebsd.org/changeset/base/334534

Log:
  Use __builtin for various mem* and b* (e.g. bzero) routines.
  
  Some of the routines were using artificially limited builtin already,
  drop the explicit limit.
  
  The use of builtins allows quite often allows the compiler to elide the call
  or most zeroing to begin with. For instance, if the target object is 32 bytes
  in size and gets zeroed + has 16 bytes initialized, the compiler can just
  add code to zero out the rest.
  
  Note not all the primites have asm variants and some of the existing ones
  are not optimized. Maintaines are strongly encourage to take a look
  (regardless of this change).

Modified:
  head/sys/dev/cx/machdep.h
  head/sys/libkern/bcmp.c
  head/sys/libkern/memcmp.c
  head/sys/libkern/memset.c
  head/sys/sys/libkern.h
  head/sys/sys/systm.h
  head/sys/sys/zutil.h

Modified: head/sys/dev/cx/machdep.h
==
--- head/sys/dev/cx/machdep.h   Sat Jun  2 17:57:09 2018(r334533)
+++ head/sys/dev/cx/machdep.h   Sat Jun  2 18:03:35 2018(r334534)
@@ -73,7 +73,6 @@
 #   include 
 #   include 
 #   include 
-#   define memset(a,b,c)   bzero (a,c)
 #   define port_t int
 
 #ifndef _SYS_CDEFS_H_

Modified: head/sys/libkern/bcmp.c
==
--- head/sys/libkern/bcmp.c Sat Jun  2 17:57:09 2018(r334533)
+++ head/sys/libkern/bcmp.c Sat Jun  2 18:03:35 2018(r334534)
@@ -44,7 +44,7 @@ typedef const unsigned long   *culp;
  * bcmp -- vax cmpc3 instruction
  */
 int
-bcmp(const void *b1, const void *b2, size_t length)
+(bcmp)(const void *b1, const void *b2, size_t length)
 {
 #if BYTE_ORDER == LITTLE_ENDIAN
/*

Modified: head/sys/libkern/memcmp.c
==
--- head/sys/libkern/memcmp.c   Sat Jun  2 17:57:09 2018(r334533)
+++ head/sys/libkern/memcmp.c   Sat Jun  2 18:03:35 2018(r334534)
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
  * Compare memory regions.
  */
 int
-memcmp(const void *s1, const void *s2, size_t n)
+(memcmp)(const void *s1, const void *s2, size_t n)
 {
if (n != 0) {
const unsigned char *p1 = s1, *p2 = s2;

Modified: head/sys/libkern/memset.c
==
--- head/sys/libkern/memset.c   Sat Jun  2 17:57:09 2018(r334533)
+++ head/sys/libkern/memset.c   Sat Jun  2 18:03:35 2018(r334534)
@@ -33,7 +33,7 @@ __FBSDID("$FreeBSD$");
 #include 
 
 void *
-memset(void *b, int c, size_t len)
+(memset)(void *b, int c, size_t len)
 {
char *bb;
 

Modified: head/sys/sys/libkern.h
==
--- head/sys/sys/libkern.h  Sat Jun  2 17:57:09 2018(r334533)
+++ head/sys/sys/libkern.h  Sat Jun  2 18:03:35 2018(r334534)
@@ -128,7 +128,6 @@ struct malloc_type;
 uint32_t arc4random(void);
 voidarc4random_buf(void *, size_t);
 voidarc4rand(void *, u_int, int);
-int bcmp(const void *, const void *, size_t);
 int timingsafe_bcmp(const void *, const void *, size_t);
 void   *bsearch(const void *, const void *, size_t,
size_t, int (*)(const void *, const void *));
@@ -160,7 +159,6 @@ int  fnmatch(const char *, const char *, int);
 int locc(int, char *, u_int);
 void   *memchr(const void *s, int c, size_t n);
 void   *memcchr(const void *s, int c, size_t n);
-int memcmp(const void *b1, const void *b2, size_t len);
 void   *memmem(const void *l, size_t l_len, const void *s, size_t s_len);
 voidqsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

Modified: head/sys/sys/systm.h
==
--- head/sys/sys/systm.hSat Jun  2 17:57:09 2018(r334533)
+++ head/sys/sys/systm.hSat Jun  2 18:03:35 2018(r334534)
@@ -259,25 +259,21 @@ void  hexdump(const void *ptr, int length, const char 
*
 
 #define ovbcopy(f, t, l) bcopy((f), (t), (l))
 void   bcopy(const void * _Nonnull from, void * _Nonnull to, size_t len);
-#define bcopy(from, to, len) ({\
-   if (__builtin_constant_p(len) && (len) <= 64)   \
-   __builtin_memmove((to), (from), (len)); \
-   else\
-   bcopy((from), (to), (len)); \
-})
+#define bcopy(from, to, len) __builtin_memmove((to), (from), (len))
 void   bzero(void * _Nonnull buf, size_t len);
-#define bzero(buf, len) ({ \
-   if (__builtin_constant_p(len) && (len) <= 64)   \
-   __builtin_memset((buf), 0, (len));  \
-   else   

svn commit: r334533 - in head/sys: libkern sys

2018-06-02 Thread Mateusz Guzik
Author: mjg
Date: Sat Jun  2 17:57:09 2018
New Revision: 334533
URL: https://svnweb.freebsd.org/changeset/base/334533

Log:
  libkern: tidy up memset
  
  1. Remove special-casing of 0 as it just results in an extra function call.
  This is clearly pessimal.
  2. Drop the inline stuff. For the most part it is much better served with
  __builtin_memset (coming later).
  3. Move the declaration to systm.h to match other funcs.
  
  Archs are encouraged to implement the variant for their own platform so that
  this implementation can be dropped.

Modified:
  head/sys/libkern/memset.c
  head/sys/sys/libkern.h
  head/sys/sys/systm.h

Modified: head/sys/libkern/memset.c
==
--- head/sys/libkern/memset.c   Sat Jun  2 16:28:10 2018(r334532)
+++ head/sys/libkern/memset.c   Sat Jun  2 17:57:09 2018(r334533)
@@ -37,10 +37,7 @@ memset(void *b, int c, size_t len)
 {
char *bb;
 
-   if (c == 0)
-   (bzero)(b, len);
-   else
-   for (bb = (char *)b; len--; )
-   *bb++ = c;
+   for (bb = (char *)b; len--; )
+   *bb++ = c;
return (b);
 }

Modified: head/sys/sys/libkern.h
==
--- head/sys/sys/libkern.h  Sat Jun  2 16:28:10 2018(r334532)
+++ head/sys/sys/libkern.h  Sat Jun  2 17:57:09 2018(r334533)
@@ -224,23 +224,6 @@ uint32_t armv8_crc32c(uint32_t, const unsigned char *,
 #endif
 #endif
 
-
-LIBKERN_INLINE void *memset(void *, int, size_t);
-#ifdef LIBKERN_BODY
-LIBKERN_INLINE void *
-memset(void *b, int c, size_t len)
-{
-   char *bb;
-
-   if (c == 0)
-   bzero(b, len);
-   else
-   for (bb = (char *)b; len--; )
-   *bb++ = c;
-   return (b);
-}
-#endif
-
 static __inline char *
 index(const char *p, int ch)
 {

Modified: head/sys/sys/systm.h
==
--- head/sys/sys/systm.hSat Jun  2 16:28:10 2018(r334532)
+++ head/sys/sys/systm.hSat Jun  2 17:57:09 2018(r334533)
@@ -274,6 +274,7 @@ voidbzero(void * _Nonnull buf, size_t len);
 })
 void   explicit_bzero(void * _Nonnull, size_t);
 
+void   *memset(void * _Nonnull buf, int c, size_t len);
 void   *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len);
 #define memcpy(to, from, len) __builtin_memcpy(to, from, len)
 void   *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334532 - head/sys/netinet

2018-06-02 Thread Michael Tuexen
Author: tuexen
Date: Sat Jun  2 16:28:10 2018
New Revision: 334532
URL: https://svnweb.freebsd.org/changeset/base/334532

Log:
  Don't overflow a buffer if we receive an INIT or INIT-ACK chunk
  without a RANDOM parameter but with a CHUNKS or HMAC-ALGO parameter.
  Please note that sending this combination violates the specification.
  
  Thnanks to Ronald E. Crane for reporting the issue for the userland
  stack.
  
  MFC after:3 days

Modified:
  head/sys/netinet/sctp_auth.c
  head/sys/netinet/sctp_pcb.c

Modified: head/sys/netinet/sctp_auth.c
==
--- head/sys/netinet/sctp_auth.cSat Jun  2 15:52:18 2018
(r334531)
+++ head/sys/netinet/sctp_auth.cSat Jun  2 16:28:10 2018
(r334532)
@@ -1504,6 +1504,8 @@ sctp_auth_get_cookie_params(struct sctp_tcb *stcb, str
if (p_random != NULL) {
keylen = sizeof(*p_random) + random_len;
memcpy(new_key->key, p_random, keylen);
+   } else {
+   keylen = 0;
}
/* append in the AUTH chunks */
if (chunks != NULL) {

Modified: head/sys/netinet/sctp_pcb.c
==
--- head/sys/netinet/sctp_pcb.c Sat Jun  2 15:52:18 2018(r334531)
+++ head/sys/netinet/sctp_pcb.c Sat Jun  2 16:28:10 2018(r334532)
@@ -6704,6 +6704,8 @@ next_param:
if (p_random != NULL) {
keylen = sizeof(*p_random) + random_len;
memcpy(new_key->key, p_random, keylen);
+   } else {
+   keylen = 0;
}
/* append in the AUTH chunks */
if (chunks != NULL) {
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334531 - head/usr.bin/top

2018-06-02 Thread Roman Bogorodskiy
Author: novel (ports committer)
Date: Sat Jun  2 15:52:18 2018
New Revision: 334531
URL: https://svnweb.freebsd.org/changeset/base/334531

Log:
  top: add -p option and p command to only show a single process
  
  Allow to show only a single process specified by PID. This could
  be done either by running top like 'top -p PID' or using the 'p' command
  inside top.
  
  Reviewed by:  eadler
  Approved by:  eadler
  Obtained from:OpenBSD
  Differential Revision:https://reviews.freebsd.org/D15501

Modified:
  head/usr.bin/top/commands.c
  head/usr.bin/top/machine.c
  head/usr.bin/top/machine.h
  head/usr.bin/top/top.1
  head/usr.bin/top/top.c
  head/usr.bin/top/top.h
  head/usr.bin/top/utils.c
  head/usr.bin/top/utils.h

Modified: head/usr.bin/top/commands.c
==
--- head/usr.bin/top/commands.c Sat Jun  2 14:07:27 2018(r334530)
+++ head/usr.bin/top/commands.c Sat Jun  2 15:52:18 2018(r334531)
@@ -92,6 +92,7 @@ o   - specify sort order (pri, size, res, cpu, tim
 o   - specify sort order (vcsw, ivcsw, read, write, fault, total, jid, 
pid)\n",
stdout);
fputs("\
+p   - display one process (+ selects all processes)\n\
 P   - toggle the displaying of per-CPU statistics\n\
 r   - renice a process\n\
 s   - change number of seconds to delay between updates\n\

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sat Jun  2 14:07:27 2018(r334530)
+++ head/usr.bin/top/machine.c  Sat Jun  2 15:52:18 2018(r334531)
@@ -764,6 +764,7 @@ get_process_info(struct system_info *si, struct proces
int show_self;
int show_system;
int show_uid;
+   int show_pid;
int show_kidle;
 
/*
@@ -783,7 +784,7 @@ get_process_info(struct system_info *si, struct proces
previous_pref = malloc(nproc * sizeof(*previous_pref));
if (previous_procs == NULL || previous_pref == NULL) {
(void) fprintf(stderr, "top: Out of memory.\n");
-   quit(23);
+   quit(TOP_EX_SYS_ERROR);
}
previous_proc_count_max = nproc;
}
@@ -822,7 +823,7 @@ get_process_info(struct system_info *si, struct proces
}
if (pref == NULL || pbase == NULL || pcpu == NULL) {
(void) fprintf(stderr, "top: Out of memory.\n");
-   quit(23);
+   quit(TOP_EX_SYS_ERROR);
}
/* get a pointer to the states summary array */
si->procstates = process_states;
@@ -833,6 +834,7 @@ get_process_info(struct system_info *si, struct proces
show_self = sel->self == -1;
show_system = sel->system;
show_uid = sel->uid[0] != -1;
+   show_pid = sel->pid != -1;
show_kidle = sel->kidle;
 
/* count up process states and get pointers to interesting procs */
@@ -894,6 +896,9 @@ get_process_info(struct system_info *si, struct proces
/* skip proc. that don't belong to the selected UID */
continue;
 
+   if (show_pid && pp->ki_pid != sel->pid)
+   continue;
+
*prefp++ = pp;
active_procs++;
}
@@ -1177,12 +1182,12 @@ getsysctl(const char *name, void *ptr, size_t len)
if (sysctlbyname(name, ptr, , NULL, 0) == -1) {
fprintf(stderr, "top: sysctl(%s...) failed: %s\n", name,
strerror(errno));
-   quit(23);
+   quit(TOP_EX_SYS_ERROR);
}
if (nlen != len) {
fprintf(stderr, "top: sysctl(%s...) expected %lu, got %lu\n",
name, (unsigned long)len, (unsigned long)nlen);
-   quit(23);
+   quit(TOP_EX_SYS_ERROR);
}
 }
 

Modified: head/usr.bin/top/machine.h
==
--- head/usr.bin/top/machine.h  Sat Jun  2 14:07:27 2018(r334530)
+++ head/usr.bin/top/machine.h  Sat Jun  2 15:52:18 2018(r334531)
@@ -69,6 +69,7 @@ struct process_select
 int jail;  /* show jail ID */
 int swap;  /* show swap usage */
 int kidle; /* show per-CPU idle threads */
+pid_t pid; /* only this pid (unless pid == -1) */
 char *command; /* only this command (unless == NULL) */
 };
 

Modified: head/usr.bin/top/top.1
==
--- head/usr.bin/top/top.1  Sat Jun  2 14:07:27 2018(r334530)
+++ head/usr.bin/top/top.1  Sat Jun  2 15:52:18 2018(r334531)
@@ -15,6 +15,11 @@ top \- display and update information about the top cp
 .BI \-m io | cpu
 ] [
 .BI \-o field
+]
+.br
+.ti +4
+[
+.BI \-p pid
 ] [
 .BI \-s time
 ] [
@@ 

svn commit: r334530 - in head: share/man/man4 sys/conf sys/dev/syscons

2018-06-02 Thread Bruce Evans
Author: bde
Date: Sat Jun  2 14:07:27 2018
New Revision: 334530
URL: https://svnweb.freebsd.org/changeset/base/334530

Log:
  Improve defaults for per-CPU kernel console colors, especially with 2
  or 4 CPUs.  Add a compile-time option SC_KERNEL_CONS_ATTRS to control the
  defaults.
  
  Default to color numbers in reverse order to CPU numbers (instead of
  in the same order with white first and wrapping to dark grey), so that
  the brightest bright colors are used first.  Don't use dark grey at all;
  replace it by dark green.
  
  Syscons has too many compile-time options, but this one is needed in
  in case the defaults give something like white on white, or the user
  really hates this feature and can't wait to turn it off in rc.
  
  MFC after:next release?

Modified:
  head/share/man/man4/syscons.4
  head/sys/conf/NOTES
  head/sys/conf/options
  head/sys/dev/syscons/syscons.c

Modified: head/share/man/man4/syscons.4
==
--- head/share/man/man4/syscons.4   Sat Jun  2 10:36:30 2018
(r334529)
+++ head/share/man/man4/syscons.4   Sat Jun  2 14:07:27 2018
(r334530)
@@ -26,7 +26,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd June 21, 2016
+.Dd June 2, 2018
 .Dt SYSCONS 4
 .Os
 .Sh NAME
@@ -53,6 +53,7 @@
 .Cd "options SC_NORM_ATTR=_attribute_"
 .Cd "options SC_NORM_REV_ATTR=_attribute_"
 .Cd "options SC_KERNEL_CONS_ATTR=_attribute_"
+.Cd "options SC_KERNEL_CONS_ATTRS=_attributes_"
 .Cd "options SC_KERNEL_CONS_REV_ATTR=_attribute_"
 .Cd "options SC_DFLT_FONT"
 .Cd "makeoptions SC_DFLT_FONT=_font_name_"
@@ -341,6 +342,7 @@ above.
 .It Dv SC_NORM_ATTR=_attribute_
 .It Dv SC_NORM_REV_ATTR=_attribute_
 .It Dv SC_KERNEL_CONS_ATTR=_attribute_
+.It Dv SC_KERNEL_CONS_ATTRS=_attributes_
 .It Dv SC_KERNEL_CONS_REV_ATTR=_attribute_
 These options will set the default colors.
 Available colors are defined in
@@ -348,6 +350,11 @@ Available colors are defined in
 See
 .Sx EXAMPLES
 below.
+.Dv SC_KERNEL_CONS_ATTRS
+is a character string giving a sequence of attributes in binary format.
+The sequence will be repeated up to the number of CPUs.
+Beware that the string must not be null,
+since the kernel divides by its length.
 .It Dv SC_DFLT_FONT
 This option will specify the default font.
 Available fonts are: iso, iso2, koi8-r, koi8-u, cp437, cp850, cp865,
@@ -538,6 +545,23 @@ The reversed message will be black on red background.
 .Pp
 .Dl "options SC_KERNEL_CONS_ATTR=(FG_LIGHTRED|BG_BLACK)"
 .Dl "options SC_KERNEL_CONS_REV_ATTR=(FG_BLACK|BG_RED)"
+.Pp
+Provided
+.Dv SC_KERNEL_CONS_ATTR
+is not set, or is set to its default of bright white on black,
+the following line will set 4 red-ish colors
+for printing kernel messages in colors depending on the CPU.
+.Pp
+.Dl options SC_KERNEL_CONS_ATTRS=\e"\ex0c\ex04\ex40\ex0e\e"
+.Pp
+The default scheme is probably better for up to 8 CPUs.
+Use a long string to get unique colors for more than 8 CPUs.
+.Pp
+To turn off all per-CPU coloring of kernel messages,
+set SC_KERNEL_CONS_ATTR to a non-default value,
+or use the default in a pattern of length 1.
+.Pp
+.Dl options SC_KERNEL_CONS_ATTRS=\e"\ex0f\e"
 .Pp
 The following example adds the font files
 .Pa cp850-8x16.fnt ,

Modified: head/sys/conf/NOTES
==
--- head/sys/conf/NOTES Sat Jun  2 10:36:30 2018(r334529)
+++ head/sys/conf/NOTES Sat Jun  2 14:07:27 2018(r334530)
@@ -1474,6 +1474,7 @@ options   SC_PIXEL_MODE   # add support for the 
raster t
 optionsSC_NORM_ATTR=(FG_GREEN|BG_BLACK)
 optionsSC_NORM_REV_ATTR=(FG_YELLOW|BG_GREEN)
 optionsSC_KERNEL_CONS_ATTR=(FG_RED|BG_BLACK)
+optionsSC_KERNEL_CONS_ATTRS=\"\x0c\x0d\x0e\x0f\x02\x09\x0a\x0b\"
 optionsSC_KERNEL_CONS_REV_ATTR=(FG_BLACK|BG_RED)
 
 # The following options will let you change the default behavior of

Modified: head/sys/conf/options
==
--- head/sys/conf/options   Sat Jun  2 10:36:30 2018(r334529)
+++ head/sys/conf/options   Sat Jun  2 14:07:27 2018(r334530)
@@ -774,6 +774,7 @@ SC_DISABLE_KDBKEY   opt_syscons.h
 SC_DISABLE_REBOOT  opt_syscons.h
 SC_HISTORY_SIZEopt_syscons.h
 SC_KERNEL_CONS_ATTRopt_syscons.h
+SC_KERNEL_CONS_ATTRS   opt_syscons.h
 SC_KERNEL_CONS_REV_ATTRopt_syscons.h
 SC_MOUSE_CHAR  opt_syscons.h
 SC_NO_CUTPASTE opt_syscons.h

Modified: head/sys/dev/syscons/syscons.c
==
--- head/sys/dev/syscons/syscons.c  Sat Jun  2 10:36:30 2018
(r334529)
+++ head/sys/dev/syscons/syscons.c  Sat Jun  2 14:07:27 2018
(r334530)
@@ -3153,6 +3153,17 @@ scinit(int unit, int flags)
 static u_char font_16[256*16];
 #endif
 
+#ifdef SC_KERNEL_CONS_ATTRS
+static const u_char dflt_kattrtab[] = 

Re: svn commit: r334515 - head/usr.bin/top

2018-06-02 Thread Konstantin Belousov
On Sat, Jun 02, 2018 at 03:31:14AM +, Eitan Adler wrote:
> Author: eadler
> Date: Sat Jun  2 03:31:14 2018
> New Revision: 334515
> URL: https://svnweb.freebsd.org/changeset/base/334515
> 
> Log:
>   top(1): avoid casting malloc
> 
> Modified:
>   head/usr.bin/top/display.c
>   head/usr.bin/top/machine.c
> 
> Modified: head/usr.bin/top/display.c
> ==
> --- head/usr.bin/top/display.cSat Jun  2 03:25:15 2018
> (r334514)
> +++ head/usr.bin/top/display.cSat Jun  2 03:31:14 2018
> (r334515)
> @@ -147,7 +147,7 @@ display_resize(void)
>  }
>  
>  /* now, allocate space for the screen buffer */
> -screenbuf = (char *)malloc(lines * display_width);
> +screenbuf = malloc(lines * display_width);
>  if (screenbuf == (char *)NULL)
>  {
>   /* oops! */
> @@ -203,20 +203,20 @@ int display_init(struct statics * statics)
>   /* save pointers and allocate space for names */
>   procstate_names = statics->procstate_names;
>   num_procstates = string_count(procstate_names);
> - lprocstates = (int *)malloc(num_procstates * sizeof(int));
> + lprocstates = malloc(num_procstates * sizeof(int));
It seems that this and other changed mallocs() better be spelled as
calloc(3).

>  
>   cpustate_names = statics->cpustate_names;
>  
>   swap_names = statics->swap_names;
>   num_swap = string_count(swap_names);
> - lswap = (int *)malloc(num_swap * sizeof(int));
> + lswap = malloc(num_swap * sizeof(int));
>   num_cpustates = string_count(cpustate_names);
> - lcpustates = (int *)malloc(num_cpustates * sizeof(int) * 
> statics->ncpus);
> - cpustate_columns = (int *)malloc(num_cpustates * sizeof(int));
> + lcpustates = malloc(num_cpustates * sizeof(int) * statics->ncpus);
> + cpustate_columns = malloc(num_cpustates * sizeof(int));
>  
>   memory_names = statics->memory_names;
>   num_memory = string_count(memory_names);
> - lmemory = (int *)malloc(num_memory * sizeof(int));
> + lmemory = malloc(num_memory * sizeof(int));
>  
>   arc_names = statics->arc_names;
>   carc_names = statics->carc_names;
> 
> Modified: head/usr.bin/top/machine.c
> ==
> --- head/usr.bin/top/machine.cSat Jun  2 03:25:15 2018
> (r334514)
> +++ head/usr.bin/top/machine.cSat Jun  2 03:31:14 2018
> (r334515)
> @@ -990,7 +990,7 @@ format_next_process(caddr_t xhandle, char *(*get_useri
>   break;
>   }
>  
> - cmdbuf = (char *)malloc(cmdlen + 1);
> + cmdbuf = malloc(cmdlen + 1);
>   if (cmdbuf == NULL) {
>   warn("malloc(%d)", cmdlen + 1);
>   return NULL;
> @@ -1025,7 +1025,7 @@ format_next_process(caddr_t xhandle, char *(*get_useri
>   size_t len;
>  
>   argbuflen = cmdlen * 4;
> - argbuf = (char *)malloc(argbuflen + 1);
> + argbuf = malloc(argbuflen + 1);
>   if (argbuf == NULL) {
>   warn("malloc(%zu)", argbuflen + 1);
>   free(cmdbuf);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334529 - head/sys/dev/syscons

2018-06-02 Thread Bruce Evans
Author: bde
Date: Sat Jun  2 10:36:30 2018
New Revision: 334529
URL: https://svnweb.freebsd.org/changeset/base/334529

Log:
  Use per-CPU attributes earlier.
  
  The per-CPU ts is not initialized early, so the global kernel ts is used
  early, but it ony has 1 (normal) attribute.  Switch this to the per-CPU
  attribute.
  
  The difference is most visible with EARLY_AP_STARTUP.
  
  Change to using the curcpu macro instead of PCPU_GET(cpuid) in 2 places for
  the above and in 1 other place in my old code in syscons.  The function-like
  spelling is perhaps better for indicating that curcpu is volatile (unlike
  curthread), but for CPU attributes volatility is a feature.

Modified:
  head/sys/dev/syscons/syscons.c

Modified: head/sys/dev/syscons/syscons.c
==
--- head/sys/dev/syscons/syscons.c  Sat Jun  2 09:59:27 2018
(r334528)
+++ head/sys/dev/syscons/syscons.c  Sat Jun  2 10:36:30 2018
(r334529)
@@ -2023,18 +2023,27 @@ sc_cnputc(struct consdev *cd, int c)
sizeof(sc_cnputc_log))
continue;
/* Console output has a per-CPU "input" state.  Switch for it. */
-   oldtsw = scp->tsw;
-   oldts = scp->ts;
-   ts = sc_kts[PCPU_GET(cpuid)];
+   ts = sc_kts[curcpu];
if (ts != NULL) {
+   oldtsw = scp->tsw;
+   oldts = scp->ts;
scp->tsw = sc_ktsw;
scp->ts = ts;
(*scp->tsw->te_sync)(scp);
+   } else {
+   /* Only 1 tsw early.  Switch only its attr. */
+   (*scp->tsw->te_default_attr)(scp, sc_kattrtab[curcpu],
+SC_KERNEL_CONS_REV_ATTR);
}
sc_puts(scp, buf, 1);
-   scp->tsw = oldtsw;
-   scp->ts = oldts;
-   (*scp->tsw->te_sync)(scp);
+   if (ts != NULL) {
+   scp->tsw = oldtsw;
+   scp->ts = oldts;
+   (*scp->tsw->te_sync)(scp);
+   } else {
+   (*scp->tsw->te_default_attr)(scp, SC_KERNEL_CONS_ATTR,
+SC_KERNEL_CONS_REV_ATTR);
+   }
 }
 
 s = spltty();  /* block sckbdevent and scrn_timer */
@@ -4177,7 +4186,7 @@ sc_kattr(void)
 {
 if (sc_console == NULL)
return (SC_KERNEL_CONS_ATTR);   /* for very early, before pcpu */
-return (sc_kattrtab[PCPU_GET(cpuid) % nitems(sc_kattrtab)]);
+return (sc_kattrtab[curcpu % nitems(sc_kattrtab)]);
 }
 
 static void
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334528 - head/sys/i386/include

2018-06-02 Thread Bruce Evans
Author: bde
Date: Sat Jun  2 09:59:27 2018
New Revision: 334528
URL: https://svnweb.freebsd.org/changeset/base/334528

Log:
  Oops, the last minute reduction in the clobber list for i386
  MCOUNT_OVERHEAD() in r334522 was too agressive.  Only mcount exit
  preserves %eax and %edx.

Modified:
  head/sys/i386/include/profile.h

Modified: head/sys/i386/include/profile.h
==
--- head/sys/i386/include/profile.h Sat Jun  2 08:46:09 2018
(r334527)
+++ head/sys/i386/include/profile.h Sat Jun  2 09:59:27 2018
(r334528)
@@ -64,7 +64,7 @@
__asm __volatile("pushl %0; call __mcount; popl %%ecx"  \
 :  \
 : "i" (label)  \
-: "cx", "memory")
+: "ax", "dx", "cx", "memory")
 #defineMEXITCOUNT_OVERHEAD()   
\
__asm __volatile("call .mexitcount; 1:" \
 : :\
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334527 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sat Jun  2 08:46:09 2018
New Revision: 334527
URL: https://svnweb.freebsd.org/changeset/base/334527

Log:
  Use stpcpy instead of home grown solution

Modified:
  head/usr.bin/top/display.c
  head/usr.bin/top/utils.c
  head/usr.bin/top/utils.h

Modified: head/usr.bin/top/display.c
==
--- head/usr.bin/top/display.c  Sat Jun  2 08:38:59 2018(r334526)
+++ head/usr.bin/top/display.c  Sat Jun  2 08:46:09 2018(r334527)
@@ -822,7 +822,7 @@ i_process(int line, char *thisline)
 
 /* copy it in to our buffer */
 base = smart_terminal ? screenbuf + lineindex(line) : screenbuf;
-p = strecpy(base, thisline);
+p = stpcpy(base, thisline);
 
 /* zero fill the rest of it */
 bzero(p, display_width - (p - base));
@@ -861,7 +861,7 @@ u_process(int line, char *newline)
fputs(newline, stdout);
 
/* copy it in to the buffer */
-   optr = strecpy(bufferline, newline);
+   optr = stpcpy(bufferline, newline);
 
/* zero fill the rest of it */
bzero(optr, display_width - (optr - bufferline));
@@ -1110,30 +1110,30 @@ static void summary_format(char *str, int *numbers, ch
if (thisname[0] == 'K')
{
/* yes: format it as a memory value */
-   p = strecpy(p, format_k(num));
+   p = stpcpy(p, format_k(num));
 
/* skip over the K, since it was included by format_k */
-   p = strecpy(p, thisname+1);
+   p = stpcpy(p, thisname+1);
}
/* is this number a ratio? */
else if (thisname[0] == ':')
{
(void) snprintf(rbuf, sizeof(rbuf), "%.2f", 
(float)*(numbers - 2) / (float)num);
-   p = strecpy(p, rbuf);
-   p = strecpy(p, thisname);
+   p = stpcpy(p, rbuf);
+   p = stpcpy(p, thisname);
}
else
{
-   p = strecpy(p, itoa(num));
-   p = strecpy(p, thisname);
+   p = stpcpy(p, itoa(num));
+   p = stpcpy(p, thisname);
}
}
 
/* ignore negative numbers, but display corresponding string */
else if (num < 0)
{
-   p = strecpy(p, thisname);
+   p = stpcpy(p, thisname);
}
 }
 

Modified: head/usr.bin/top/utils.c
==
--- head/usr.bin/top/utils.cSat Jun  2 08:38:59 2018(r334526)
+++ head/usr.bin/top/utils.cSat Jun  2 08:46:09 2018(r334527)
@@ -131,18 +131,6 @@ int digits(int val)
 }
 
 /*
- *  strecpy(to, from) - copy string "from" into "to" and return a pointer
- * to the END of the string "to".
- */
-
-char *
-strecpy(char *to, const char *from)
-{
-while ((*to++ = *from++) != '\0');
-return(--to);
-}
-
-/*
  * string_index(string, array) - find string in array and return index
  */
 
@@ -393,7 +381,7 @@ char *format_k(int amt)
}
 }
 
-p = strecpy(p, itoa(amt));
+p = stpcpy(p, itoa(amt));
 *p++ = tag;
 *p = '\0';
 
@@ -423,7 +411,7 @@ format_k2(unsigned long long amt)
}
 }
 
-p = strecpy(p, itoa((int)amt));
+p = stpcpy(p, itoa((int)amt));
 *p++ = tag;
 *p = '\0';
 

Modified: head/usr.bin/top/utils.h
==
--- head/usr.bin/top/utils.hSat Jun  2 08:38:59 2018(r334526)
+++ head/usr.bin/top/utils.hSat Jun  2 08:46:09 2018(r334527)
@@ -14,7 +14,6 @@ int atoiwi(const char *);
 char *itoa(unsigned int);
 char *itoa7(unsigned int);
 int digits(int);
-char *strecpy(char *, const char *);
 char **argparse(char *, int *);
 long percentages(int, int *, long *, long *, long *);
 char *format_time(long);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334526 - head/sys/dev/syscons

2018-06-02 Thread Bruce Evans
Author: bde
Date: Sat Jun  2 08:38:59 2018
New Revision: 334526
URL: https://svnweb.freebsd.org/changeset/base/334526

Log:
  Fix low-level locking during panics.
  
  The SCHEDULER_STOPPED() hack breaks locking generally, and
  mtx_trylock_*() especially.  When mtx_trylock_*() returns nonzero,
  naive code version here trusts it to have worked.  But when
  SCHEDULER_STOPPED() is true, mtx_trylock_*() returns 1 without doing
  anything.  Then mtx_unlock_*() crashes especially badly attempting to
  unlock iff the error is detected, since mutex unlocking functions don't
  check SCHEDULER_STOPPED().
  
  syscons already didn't trust mtx_trylock_spin(), but it was missing the
  logic to turn on sp->kdb_locked when turning off sp->mtx_locked during
  panics.  It also used panicstr instead of SCHEDULER_LOCKED because I
  thought that panicstr was more fragile.  They only differ for a window
  of lines in panic(), and in broken cases where stop_cpus_hard() in panic()
  didn't work.

Modified:
  head/sys/dev/syscons/syscons.c

Modified: head/sys/dev/syscons/syscons.c
==
--- head/sys/dev/syscons/syscons.c  Sat Jun  2 07:44:53 2018
(r334525)
+++ head/sys/dev/syscons/syscons.c  Sat Jun  2 08:38:59 2018
(r334526)
@@ -1807,13 +1807,19 @@ sccnscrlock(sc_softc_t *sc, struct sc_cnstate *sp)
  * enough to ignore the protection even in the kdb_active case.
  */
 if (kdb_active) {
-   sp->kdb_locked = sc->video_mtx.mtx_lock == MTX_UNOWNED || panicstr;
+   sp->kdb_locked = sc->video_mtx.mtx_lock == MTX_UNOWNED ||
+SCHEDULER_STOPPED();
sp->mtx_locked = FALSE;
 } else {
sp->kdb_locked = FALSE;
for (retries = 0; retries < 1000; retries++) {
sp->mtx_locked = mtx_trylock_spin_flags(>video_mtx,
-   MTX_QUIET) != 0 || panicstr;
+   MTX_QUIET) != 0;
+   if (SCHEDULER_STOPPED()) {
+   sp->kdb_locked = TRUE;
+   sp->mtx_locked = FALSE;
+   break;
+   }
if (sp->mtx_locked)
break;
DELAY(1);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334525 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sat Jun  2 07:44:53 2018
New Revision: 334525
URL: https://svnweb.freebsd.org/changeset/base/334525

Log:
  top(1): remove wrapper around putchar
  
  This appears to have been written for portability which we no longer
  need.

Modified:
  head/usr.bin/top/screen.c
  head/usr.bin/top/screen.h

Modified: head/usr.bin/top/screen.c
==
--- head/usr.bin/top/screen.c   Sat Jun  2 07:44:50 2018(r334524)
+++ head/usr.bin/top/screen.c   Sat Jun  2 07:44:53 2018(r334525)
@@ -323,11 +323,3 @@ go_home(void)
putcap(home);
 }
 }
-
-/* This has to be defined as a subroutine for tputs (instead of a macro) */
-
-int
-putstdout(int ch)
-{
-return putchar(ch);
-}

Modified: head/usr.bin/top/screen.h
==
--- head/usr.bin/top/screen.h   Sat Jun  2 07:44:50 2018(r334524)
+++ head/usr.bin/top/screen.h   Sat Jun  2 07:44:53 2018(r334525)
@@ -7,7 +7,7 @@
  *  $FreeBSD$
  */
 
-#define TCputs(str)tputs(str, 1, putstdout)
+#define TCputs(str)tputs(str, 1, putchar)
 #define putcap(str)(void)((str) != NULL ? TCputs(str) : 0)
 #define Move_to(x, y)  TCputs(tgoto(cursor_motion, x, y))
 
@@ -26,7 +26,6 @@ extern int  screen_length;
 extern int  screen_width;
 
 /* a function that puts a single character on stdout */
-intputstdout(int ch);
 intclear_eol(int len);
 void   top_standout(char *msg);
 void   top_clear(void);
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r334524 - head/usr.bin/top

2018-06-02 Thread Eitan Adler
Author: eadler
Date: Sat Jun  2 07:44:50 2018
New Revision: 334524
URL: https://svnweb.freebsd.org/changeset/base/334524

Log:
  top(1): const poison part 2
  
  Further reduce the number of warnings emitted by gcc.

Modified:
  head/usr.bin/top/display.c
  head/usr.bin/top/display.h
  head/usr.bin/top/machine.c

Modified: head/usr.bin/top/display.c
==
--- head/usr.bin/top/display.c  Sat Jun  2 06:40:15 2018(r334523)
+++ head/usr.bin/top/display.c  Sat Jun  2 07:44:50 2018(r334524)
@@ -945,7 +945,7 @@ display_header(int t)
 }
 
 void
-new_message(int type, char *msgfmt, ...)
+new_message(int type, const char *msgfmt, ...)
 {
 va_list args;
 size_t i;

Modified: head/usr.bin/top/display.h
==
--- head/usr.bin/top/display.h  Sat Jun  2 06:40:15 2018(r334523)
+++ head/usr.bin/top/display.h  Sat Jun  2 07:44:50 2018(r334524)
@@ -1,8 +1,6 @@
 /* $FreeBSD$ */
 /* constants needed for display.c */
 
-/* "type" argument for new_message function */
-
 #define  MT_standout  1
 #define  MT_delayed   2
 
@@ -26,7 +24,7 @@ void   i_procstates(int total, int *brkdn);
 voidi_swap(int *stats);
 voidi_timeofday(time_t *tod);
 voidi_uptime(struct timeval *bt, time_t *tod);
-voidnew_message(int type, char *msgfmt, ...);
+voidnew_message(int type, const char *msgfmt, ...);
 int readline(char *buffer, int size, int numeric);
 char   *trim_header(char *text);
 voidu_arc(int *stats);

Modified: head/usr.bin/top/machine.c
==
--- head/usr.bin/top/machine.c  Sat Jun  2 06:40:15 2018(r334523)
+++ head/usr.bin/top/machine.c  Sat Jun  2 07:44:50 2018(r334524)
@@ -119,7 +119,7 @@ static char up_header_tid_only[] =
 /* the extra nulls in the string "run" are for adding a slash and
the processor number when needed */
 
-static char *state_abbrev[] = {
+static const char *state_abbrev[] = {
"", "START", "RUN\0\0\0", "SLEEP", "STOP", "ZOMB", "WAIT", "LOCK"
 };
 
@@ -1354,8 +1354,8 @@ static int sorted_state[] = {
 static int
 compare_cpu(const void *arg1, const void *arg2)
 {
-   struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
-   struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+   const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1;
+   const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2;
 
ORDERKEY_PCTCPU(p1, p2);
ORDERKEY_CPTICKS(p1, p2);
@@ -1408,8 +1408,8 @@ int (*compares[])(const void *arg1, const void *arg2) 
 int
 compare_size(const void *arg1, const void *arg2)
 {
-   struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
-   struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+   const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1;
+   const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2;
 
ORDERKEY_MEM(p1, p2);
ORDERKEY_RSSIZE(p1, p2);
@@ -1426,8 +1426,8 @@ compare_size(const void *arg1, const void *arg2)
 int
 compare_res(const void *arg1, const void *arg2)
 {
-   struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
-   struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+   const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1;
+   const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2;
 
ORDERKEY_RSSIZE(p1, p2);
ORDERKEY_MEM(p1, p2);
@@ -1444,8 +1444,8 @@ compare_res(const void *arg1, const void *arg2)
 int
 compare_time(const void *arg1, const void *arg2)
 {
-   struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
-   struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+   const struct kinfo_proc *p1 = *(const struct kinfo_proc * const  *)arg1;
+   const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *) arg2;
 
ORDERKEY_CPTICKS(p1, p2);
ORDERKEY_PCTCPU(p1, p2);
@@ -1462,8 +1462,8 @@ compare_time(const void *arg1, const void *arg2)
 int
 compare_prio(const void *arg1, const void *arg2)
 {
-   struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
-   struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+   const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1;
+   const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2;
 
ORDERKEY_PRIO(p1, p2);
ORDERKEY_CPTICKS(p1, p2);
@@ -1479,8 +1479,8 @@ compare_prio(const void *arg1, const void *arg2)
 static int
 compare_threads(const void *arg1, const void *arg2)
 {
-   struct kinfo_proc *p1 = *(struct kinfo_proc **)arg1;
-   struct kinfo_proc *p2 = *(struct kinfo_proc **)arg2;
+   const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1;
+   const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2;
 

svn commit: r334523 - in head/sys: amd64/conf conf i386/conf

2018-06-02 Thread Bruce Evans
Author: bde
Date: Sat Jun  2 06:40:15 2018
New Revision: 334523
URL: https://svnweb.freebsd.org/changeset/base/334523

Log:
  Finish COMPAT_AOUT support for amd64.  It wasn't in any amd64 or MI
  file in /sys/conf, so was unavailable in configurations that don't use
  modules, and was not testable or notable in NOTES.  Its normal
  configuration (not using a module) is still silently deprecated in
  aout(4) by not mentioning it there.
  
  Update i386 NOTES for COMPAT_AOUT.  It is not i386-only, or even very MD.
  Sort its entry better.
  
  Finish gzip configuration (but not support) for amd64.  gzip is really
  gzipped aout.  It is currently broken even for i386 (a call to vm fails).
  amd64 has always attempted to configure and test it, but it depends on
  COMPAT_AOUT (as noted).  The bug that it depends on unconfigured files
  was not detected since it is configured as a device.  All other optional
  image activators are configured properly using an option.

Modified:
  head/sys/amd64/conf/NOTES
  head/sys/conf/files.amd64
  head/sys/conf/options.amd64
  head/sys/i386/conf/NOTES

Modified: head/sys/amd64/conf/NOTES
==
--- head/sys/amd64/conf/NOTES   Sat Jun  2 05:48:44 2018(r334522)
+++ head/sys/amd64/conf/NOTES   Sat Jun  2 06:40:15 2018(r334523)
@@ -632,6 +632,9 @@ options COMPAT_FREEBSD32
 # Emulate spx device for client side of SVR3 local X interface
 #XXX#options   SPX_HACK
 
+# Enable (32-bit) a.out binary support
+optionsCOMPAT_AOUT
+
 # Enable 32-bit runtime support for CloudABI binaries.
 optionsCOMPAT_CLOUDABI32
 

Modified: head/sys/conf/files.amd64
==
--- head/sys/conf/files.amd64   Sat Jun  2 05:48:44 2018(r334522)
+++ head/sys/conf/files.amd64   Sat Jun  2 06:40:15 2018(r334523)
@@ -617,6 +617,8 @@ dev/isci/scil/scif_sas_timer.c  
optional isci
 isa/syscons_isa.c  optionalsc
 isa/vga_isa.c  optionalvga
 kern/kern_clocksource.cstandard
+kern/imgact_aout.c optional compat_aout
+kern/imgact_gzip.c optional gzip
 kern/link_elf_obj.cstandard
 libkern/x86/crc32_sse42.c  standard
 #

Modified: head/sys/conf/options.amd64
==
--- head/sys/conf/options.amd64 Sat Jun  2 05:48:44 2018(r334522)
+++ head/sys/conf/options.amd64 Sat Jun  2 06:40:15 2018(r334523)
@@ -14,6 +14,7 @@ PV_STATS  opt_pmap.h
 # Options for emulators.  These should only be used at config time, so
 # they are handled like options for static filesystems
 # (see src/sys/conf/options), except for broken debugging options.
+COMPAT_AOUTopt_dontuse.h
 COMPAT_FREEBSD32   opt_global.h
 #IBCS2 opt_dontuse.h
 #COMPAT_LINUX  opt_dontuse.h

Modified: head/sys/i386/conf/NOTES
==
--- head/sys/i386/conf/NOTESSat Jun  2 05:48:44 2018(r334522)
+++ head/sys/i386/conf/NOTESSat Jun  2 06:40:15 2018(r334523)
@@ -913,14 +913,14 @@ options   NKPT=31
 # Emulate spx device for client side of SVR3 local X interface
 optionsSPX_HACK
 
+# Enable (32-bit) a.out binary support
+optionsCOMPAT_AOUT
+
 # Enable 32-bit runtime support for CloudABI binaries.
 optionsCOMPAT_CLOUDABI32
 
 # Enable Linux ABI emulation
 optionsCOMPAT_LINUX
-
-# Enable i386 a.out binary support
-optionsCOMPAT_AOUT
 
 # Enable the linux-like proc filesystem support (requires COMPAT_LINUX
 # and PSEUDOFS)
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"