Jim needs restrictions
This commit is contained in:
29
ps/common.h
29
ps/common.h
@@ -12,6 +12,7 @@
|
||||
#ifndef PROCPS_PS_H
|
||||
#define PROCPS_PS_H
|
||||
|
||||
#include "../proc/procps.h"
|
||||
#include "../proc/readproc.h"
|
||||
#include <asm/page.h> /* looks safe for glibc, we need PAGE_SIZE */
|
||||
|
||||
@@ -54,23 +55,18 @@
|
||||
#define SOE 10 /* IBM's S/390 OpenEdition */
|
||||
|
||||
/*
|
||||
* Must not overflow the output buffer:
|
||||
* Try not to overflow the output buffer:
|
||||
* 32 pages for env+cmd
|
||||
* 8 kB pages on the Alpha
|
||||
* 5 chars for "\001 "
|
||||
* 64 kB pages on IA-64
|
||||
* 4 chars for "\377"
|
||||
* plus some slack for other stuff
|
||||
* That is about 1.3 MB on the Alpha
|
||||
*
|
||||
* This isn't good enough for setuid. If anyone cares, mmap() over the
|
||||
* last page with something unwriteable.
|
||||
* That is about 8.5 MB on IA-64, or 0.6 MB on i386
|
||||
*/
|
||||
|
||||
/* maximum escape expansion is 6, for " */
|
||||
#define ESC_STRETCH 6
|
||||
/* maximum escape expansion is 4, for \377 */
|
||||
#define ESC_STRETCH 4
|
||||
/* output buffer size */
|
||||
#define OUTBUF_SIZE (32*PAGE_SIZE*ESC_STRETCH + 8*PAGE_SIZE)
|
||||
/* spaces used to right-justify things */
|
||||
#define SPACE_AMOUNT (int)(PAGE_SIZE)
|
||||
|
||||
/******************* PS DEFINE *******************/
|
||||
|
||||
@@ -223,15 +219,15 @@ typedef struct sf_node {
|
||||
/*********************** GENERAL GLOBALS *************************/
|
||||
|
||||
/* escape.c */
|
||||
extern int escape_strlist(char *dst, const char **src, size_t n);
|
||||
extern int escape_str(char *dst, const char *src, size_t n);
|
||||
extern int octal_escape_str(char *dst, const char *src, size_t n);
|
||||
extern int simple_escape_str(char *dst, const char *src, size_t n);
|
||||
extern int escape_strlist(char *restrict dst, const char *restrict const *restrict src, size_t n);
|
||||
extern int escape_str(char *restrict dst, const char *restrict src, size_t n);
|
||||
extern int octal_escape_str(char *restrict dst, const char *restrict src, size_t n);
|
||||
extern int simple_escape_str(char *restrict dst, const char *restrict src, size_t n);
|
||||
|
||||
/********************* UNDECIDED GLOBALS **************/
|
||||
|
||||
/* output.c */
|
||||
extern void show_one_proc(proc_t* p);
|
||||
extern void show_one_proc(const proc_t *restrict const p);
|
||||
extern void print_format_specifiers(void);
|
||||
extern const aix_struct *search_aix_array(const int findme);
|
||||
extern const shortsort_struct *search_shortsort_array(const int findme);
|
||||
@@ -265,6 +261,7 @@ extern int lines_to_next_header;
|
||||
extern int max_line_width;
|
||||
extern const char *namelist_file;
|
||||
extern int negate_selection;
|
||||
extern int page_size; // "int" for math reasons?
|
||||
extern unsigned personality;
|
||||
extern int prefer_bsd_defaults;
|
||||
extern int running_only;
|
||||
|
@@ -48,7 +48,7 @@ static void signal_handler(int signo){
|
||||
_exit(signo+128);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
#undef DEBUG
|
||||
#ifdef DEBUG
|
||||
void init_stack_trace(char *prog_name);
|
||||
@@ -153,6 +153,7 @@ static void arg_show(void){
|
||||
}
|
||||
|
||||
#endif
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/***** check the header */
|
||||
@@ -376,7 +377,7 @@ not_root:
|
||||
/***** sorted or forest */
|
||||
static void fancy_spew(void){
|
||||
proc_t *retbuf = NULL;
|
||||
PROCTAB* ptp;
|
||||
PROCTAB *restrict ptp;
|
||||
int n = 0; /* number of processes & index into array */
|
||||
ptp = openproc(needs_for_format | needs_for_sort);
|
||||
if(!ptp) {
|
||||
|
16
ps/escape.c
16
ps/escape.c
@@ -9,14 +9,16 @@
|
||||
* GNU Library General Public License for more details.
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include "../proc/procps.h"
|
||||
#include "common.h"
|
||||
|
||||
/* sanitize a string, without the nice BSD library function: */
|
||||
/* strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH) */
|
||||
int octal_escape_str(char *dst, const char *src, size_t n){
|
||||
int octal_escape_str(char *restrict dst, const char *restrict src, size_t n){
|
||||
unsigned char c;
|
||||
char d;
|
||||
size_t i;
|
||||
const char *codes =
|
||||
const char codes[] =
|
||||
"Z------abtnvfr-------------e----"
|
||||
" *******************************" /* better: do not print any space */
|
||||
"****************************\\***"
|
||||
@@ -57,10 +59,10 @@ leave:
|
||||
}
|
||||
|
||||
/* sanitize a string via one-way mangle */
|
||||
int simple_escape_str(char *dst, const char *src, size_t n){
|
||||
int simple_escape_str(char *restrict dst, const char *restrict src, size_t n){
|
||||
unsigned char c;
|
||||
size_t i;
|
||||
const char *codes =
|
||||
const char codes[] =
|
||||
"Z-------------------------------"
|
||||
"********************************"
|
||||
"********************************"
|
||||
@@ -90,16 +92,16 @@ leave:
|
||||
}
|
||||
|
||||
/* escape a string as desired */
|
||||
int escape_str(char *dst, const char *src, size_t n){
|
||||
int escape_str(char *restrict dst, const char *restrict src, size_t n){
|
||||
return simple_escape_str(dst, src, n);
|
||||
}
|
||||
|
||||
/* escape an argv or environment string array */
|
||||
int escape_strlist(char *dst, const char **src, size_t n){
|
||||
int escape_strlist(char *restrict dst, const char *restrict const *restrict src, size_t n){
|
||||
size_t i = 0;
|
||||
while(*src){
|
||||
i += simple_escape_str(dst+i, *src, n-i);
|
||||
if((n-i > 1) && (*(src+1))) dst[i++] = ' ';
|
||||
if((n-i > 1) && src[1]) dst[i++] = ' ';
|
||||
src++;
|
||||
}
|
||||
return i;
|
||||
|
16
ps/global.c
16
ps/global.c
@@ -47,7 +47,7 @@ int bsd_c_option = -1;
|
||||
int bsd_e_option = -1;
|
||||
uid_t cached_euid = -1;
|
||||
dev_t cached_tty = -1;
|
||||
char forest_prefix[4 * 32*1024 + 100];
|
||||
char forest_prefix[4 * 32*1024 + 100]; // FIXME
|
||||
int forest_type = -1;
|
||||
unsigned format_flags = 0xffffffff; /* -l -f l u s -j... */
|
||||
format_node *format_list = (format_node *)0xdeadbeef; /* digested formatting options */
|
||||
@@ -59,6 +59,7 @@ int lines_to_next_header = -1;
|
||||
const char *namelist_file = (const char *)0xdeadbeef;
|
||||
int negate_selection = -1;
|
||||
int running_only = -1;
|
||||
int page_size = -1; // "int" for math reasons?
|
||||
unsigned personality = 0xffffffff;
|
||||
int prefer_bsd_defaults = -1;
|
||||
int screen_cols = -1;
|
||||
@@ -335,6 +336,7 @@ void reset_global(void){
|
||||
lines_to_next_header = 1;
|
||||
namelist_file = NULL;
|
||||
negate_selection = 0;
|
||||
page_size = getpagesize();
|
||||
running_only = 0;
|
||||
seconds_since_boot = uptime(0,0);
|
||||
selection_list = NULL;
|
||||
@@ -388,14 +390,14 @@ void self_info(void){
|
||||
screen_cols, screen_rows
|
||||
);
|
||||
|
||||
/* open_psdb(namelist_file); */
|
||||
fprintf(stderr,
|
||||
"personality=0x%08x (from \"%s\")\n"
|
||||
"EUID=%d TTY=%d,%d Hertz=%Ld\n"
|
||||
/* "namelist_file=\"%s\"\n" */
|
||||
,
|
||||
"EUID=%d TTY=%d,%d Hertz=%Ld PAGE_SIZE=%d page_size=%d\n",
|
||||
personality, saved_personality_text,
|
||||
cached_euid, (int)major(cached_tty), (int)minor(cached_tty), Hertz /* ,
|
||||
namelist_file?namelist_file:"<no System.map file>" */
|
||||
cached_euid, (int)major(cached_tty), (int)minor(cached_tty), Hertz,
|
||||
(int)(PAGE_SIZE), (int)(page_size)
|
||||
);
|
||||
|
||||
open_psdb(namelist_file);
|
||||
fprintf(stderr,"namelist_file=\"%s\"\n",namelist_file?namelist_file:"<no System.map file>");
|
||||
}
|
||||
|
55
ps/output.c
55
ps/output.c
@@ -80,9 +80,8 @@
|
||||
|
||||
#define COLWID 240 /* satisfy snprintf, which is faster than sprintf */
|
||||
|
||||
static char whitespace_and_outbuf[OUTBUF_SIZE + SPACE_AMOUNT + PAGE_SIZE*2];
|
||||
static char *outbuf = whitespace_and_outbuf+SPACE_AMOUNT;
|
||||
static char *whitespace = whitespace_and_outbuf;
|
||||
static char *outbuf;
|
||||
|
||||
static unsigned max_rightward = 0x12345678; /* space for RIGHT stuff */
|
||||
static unsigned max_leftward = 0x12345678; /* space for LEFT stuff */
|
||||
|
||||
@@ -100,7 +99,7 @@ static unsigned max_leftward = 0x12345678; /* space for LEFT stuff */
|
||||
|
||||
static int wide_signals; /* true if we have room */
|
||||
|
||||
static proc_t *pp; /* the process being printed */
|
||||
static const proc_t *pp; /* the process being printed */
|
||||
|
||||
static unsigned long seconds_since_1970;
|
||||
static unsigned long time_of_boot;
|
||||
@@ -1146,7 +1145,7 @@ static int sr_context ( const proc_t* P, const proc_t* Q ) {
|
||||
/* temporary hack -- mark new stuff grabbed from Debian ps */
|
||||
#define LNx LNX
|
||||
|
||||
/* there are about 195 listed */
|
||||
/* there are about 211 listed */
|
||||
|
||||
/* Many of these are placeholders for unsupported options. */
|
||||
static const format_struct format_array[] = {
|
||||
@@ -1605,7 +1604,7 @@ static void check_header_width(void){
|
||||
|
||||
|
||||
/********** show one process (NULL proc prints header) **********/
|
||||
void show_one_proc(proc_t* p){
|
||||
void show_one_proc(const proc_t *restrict const p){
|
||||
/* unknown: maybe set correct & actual to 1, remove +/- 1 below */
|
||||
int correct = 0; /* screen position we should be at */
|
||||
int actual = 0; /* screen position we are at */
|
||||
@@ -1614,7 +1613,7 @@ void show_one_proc(proc_t* p){
|
||||
int space = 0; /* amount of space we actually need to print */
|
||||
int dospace = 0; /* previous column determined that we need a space */
|
||||
int legit = 0; /* legitimately stolen extra space */
|
||||
format_node *fmt = format_list;
|
||||
const format_node *restrict fmt = format_list;
|
||||
static int did_stuff = 0; /* have we ever printed anything? */
|
||||
|
||||
if(-1==(long)p){ /* true only once, at the end */
|
||||
@@ -1724,7 +1723,7 @@ void show_one_proc(proc_t* p){
|
||||
*/
|
||||
space = correct - actual + leftpad;
|
||||
if(space<1) space=dospace;
|
||||
if(space>SPACE_AMOUNT) space=SPACE_AMOUNT;
|
||||
if(space>page_size) space=page_size; // only have so much available
|
||||
|
||||
/* print data, set x position stuff */
|
||||
amount = strlen(outbuf); /* post-chop data width */
|
||||
@@ -1759,6 +1758,7 @@ void show_one_proc(proc_t* p){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef TESTING
|
||||
static void sanity_check(void){
|
||||
format_struct *fs = format_array;
|
||||
@@ -1769,19 +1769,11 @@ static void sanity_check(void){
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void init_output(void){
|
||||
memset(whitespace, ' ', PAGE_SIZE);
|
||||
#if 0
|
||||
mprotect(whitespace, PAGE_SIZE, PROT_READ); /* FIXME may fail if unaligned */
|
||||
mprotect(
|
||||
(void *)((unsigned long)(whitespace_and_outbuf-PAGE_SIZE) &~ (PAGE_SIZE-1)),
|
||||
PAGE_SIZE, PROT_NONE
|
||||
);
|
||||
#endif
|
||||
seconds_since_1970 = time(NULL);
|
||||
time_of_boot = seconds_since_1970 - seconds_since_boot;
|
||||
meminfo();
|
||||
switch(getpagesize()){
|
||||
int outbuf_pages;
|
||||
|
||||
switch(page_size){
|
||||
case 65536: page_shift = 16; break;
|
||||
case 32768: page_shift = 15; break;
|
||||
case 16384: page_shift = 14; break;
|
||||
@@ -1791,5 +1783,28 @@ void init_output(void){
|
||||
case 2048: page_shift = 11; break;
|
||||
case 1024: page_shift = 10; break;
|
||||
}
|
||||
|
||||
outbuf_pages = OUTBUF_SIZE/page_size+1; // round up
|
||||
outbuf = mmap(
|
||||
0,
|
||||
page_size * (1+1+outbuf_pages+1),
|
||||
PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANONYMOUS,
|
||||
-1,
|
||||
0
|
||||
);
|
||||
mprotect(outbuf, page_size, PROT_NONE); // gaurd page
|
||||
outbuf += page_size;
|
||||
memset(outbuf, ' ', page_size);
|
||||
mprotect(outbuf, page_size, PROT_READ); // space page
|
||||
outbuf += page_size;
|
||||
// now outbuf points where we want it
|
||||
mprotect(outbuf + page_size * outbuf_pages, page_size, PROT_NONE); // gaurd page
|
||||
|
||||
seconds_since_1970 = time(NULL);
|
||||
time_of_boot = seconds_since_1970 - seconds_since_boot;
|
||||
|
||||
meminfo();
|
||||
|
||||
check_header_width();
|
||||
}
|
||||
|
Reference in New Issue
Block a user