kern/54094: [patch] make signedness of kg_nice and ki_nice explicit
Stefan Farfeleder
stefan at fafoe.narf.at
Fri Jul 4 07:30:17 PDT 2003
>Number: 54094
>Category: kern
>Synopsis: [patch] make signedness of kg_nice and ki_nice explicit
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Fri Jul 04 07:30:15 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Stefan Farfeleder
>Release: FreeBSD 5.1-CURRENT i386
>Organization:
>Environment:
System: FreeBSD frog.fafoe.narf.at 5.1-CURRENT FreeBSD 5.1-CURRENT #19: Fri Jul 4 14:44:41 CEST 2003 freebsd at frog.fafoe.narf.at:/freebsd/frog/obj/freebsd/frog/src/sys/FROG i386
>Description:
The members kg_nice of struct ksegrp and ki_nice of struct kinfo_proc hold nice
values which can be negative. The C language doesn't specify whether plain
char is signed or unsigned, both choices are allowed. Thus using char to store
negative values is a bad idea. FreeBSD/PowerPC currently cannot use unsigned
char for char because of bugs like this.
>How-To-Repeat:
>Fix:
Originally I wanted to use signed char for k{g,i}_nice but tjr@ suggested using
int8_t.
--- nice.diff begins here ---
Index: src/bin/ps/keyword.c
===================================================================
RCS file: /usr/home/ncvs/src/bin/ps/keyword.c,v
retrieving revision 1.63
diff -u -r1.63 keyword.c
--- src/bin/ps/keyword.c 12 Apr 2003 10:39:56 -0000 1.63
+++ src/bin/ps/keyword.c 4 Jul 2003 11:37:16 -0000
@@ -116,7 +116,7 @@
LONG, "ld", 0},
{"mwchan", "MWCHAN", NULL, LJUST, mwchan, NULL, 6, 0, CHAR, NULL, 0},
{"ni", "", "nice", 0, NULL, NULL, 0, 0, CHAR, NULL, 0},
- {"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d",
+ {"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), INT8_T, "d",
0},
{"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw),
LONG, "ld", 0},
Index: src/bin/ps/print.c
===================================================================
RCS file: /usr/home/ncvs/src/bin/ps/print.c,v
retrieving revision 1.82
diff -u -r1.82 print.c
--- src/bin/ps/print.c 15 Apr 2003 18:49:20 -0000 1.82
+++ src/bin/ps/print.c 4 Jul 2003 11:33:33 -0000
@@ -690,6 +690,9 @@
case UCHAR:
(void)printf(ofmt, v->width, *(u_char *)bp);
break;
+ case INT8_T:
+ (void)printf(ofmt, v->width, *(int8_t *)bp);
+ break;
case SHORT:
(void)printf(ofmt, v->width, *(short *)bp);
break;
Index: src/bin/ps/ps.h
===================================================================
RCS file: /usr/home/ncvs/src/bin/ps/ps.h,v
retrieving revision 1.16
diff -u -r1.16 ps.h
--- src/bin/ps/ps.h 12 Apr 2003 10:39:56 -0000 1.16
+++ src/bin/ps/ps.h 4 Jul 2003 11:34:01 -0000
@@ -35,7 +35,8 @@
*/
#define UNLIMITED 0 /* unlimited terminal width */
-enum type { CHAR, UCHAR, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR, PGTOK };
+enum type { CHAR, UCHAR, INT8_T, SHORT, USHORT, INT, UINT, LONG, ULONG, KPTR,
+ PGTOK };
typedef struct kinfo {
struct kinfo_proc *ki_p; /* kinfo_proc structure */
Index: src/sys/sys/proc.h
===================================================================
RCS file: /usr/home/ncvs/src/sys/sys/proc.h,v
retrieving revision 1.339
diff -u -r1.339 proc.h
--- src/sys/sys/proc.h 28 Jun 2003 08:29:04 -0000 1.339
+++ src/sys/sys/proc.h 4 Jul 2003 10:53:48 -0000
@@ -498,7 +498,7 @@
#define kg_startcopy kg_endzero
u_char kg_pri_class; /* (j) Scheduling class. */
u_char kg_user_pri; /* (j) User pri from estcpu and nice. */
- char kg_nice; /* (c + j) Process "nice" value. */
+ int8_t kg_nice; /* (c + j) Process "nice" value. */
#define kg_endcopy kg_numthreads
int kg_numthreads; /* (j) Num threads in total */
int kg_kses; /* (j) Num KSEs in group. */
Index: src/sys/sys/user.h
===================================================================
RCS file: /usr/home/ncvs/src/sys/sys/user.h,v
retrieving revision 1.53
diff -u -r1.53 user.h
--- src/sys/sys/user.h 13 May 2003 20:36:02 -0000 1.53
+++ src/sys/sys/user.h 4 Jul 2003 10:55:29 -0000
@@ -143,7 +143,7 @@
long ki_kiflag; /* KI_* flags (below) */
int ki_traceflag; /* Kernel trace points */
char ki_stat; /* S* process status */
- char ki_nice; /* Process "nice" value */
+ int8_t ki_nice; /* Process "nice" value */
char ki_lock; /* Process lock (prevent swap) count */
char ki_rqindex; /* Run queue index */
u_char ki_oncpu; /* Which cpu we are on */
--- nice.diff ends here ---
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list