pax_global_header00006660000000000000000000000064146512457500014523gustar00rootroot0000000000000052 comment=b7e7a6c48de810f6e34a82336c8497f4ccd1f2e0 prctl-1.7/000077500000000000000000000000001465124575000125165ustar00rootroot00000000000000prctl-1.7/BUILD000066400000000000000000000002411465124575000132750ustar00rootroot00000000000000Steps to build -------------- - Autoconfigure with "autoreconf -i" - Run configuration script - "./configure" - Build with "make" - Install with "make install" prctl-1.7/ChangeLog000066400000000000000000000030661465124575000142750ustar00rootroot00000000000000V1.7: Fri Jul 26 15:55:24 MDT 2024 Khalid Aziz (khalid@gonehiking.org) * Added missing defines to Makefile.in * Replace pre-generated configure with configure.ac * Added missing function types in prctl.c --------------------------- V1.6: Wed Feb 26 10:39:10 MST 2014 Khalid Aziz (khalid.aziz@oracle.com) * Improved messages and suppressed unnecessary error messages * Added support for PR_MCE_KILL --------------------------- V1.5: Thu May 18 10:46:10 MDT 2006 Khalid Aziz (khalid_aziz@hp.com) * Updated man page location in Makefile.in * Better error message in case kernel does not support prctl operations. --------------------------- Wed Mar 5 11:49:58 MST 2003 Khalid Aziz (khalid_aziz@hp.com) * Added "always-signal" option to --unaligned for ia64. Wed Oct 17 16:11:59 MDT 2001 Khalid Aziz (khalid_aziz@hp.com) * Added option to set floating point emulation behavior. Mon Jun 4 17:02:18 MDT 2001 Khalid Aziz (khalid_aziz@hp.com) * Bug fix: Did not recognize "--unaligned=default" as a valid command. Fri Jan 12 10:39:21 MST 2001 Khalid Aziz (khalid_aziz@hp.com) * Removed post-install warning from spec file. Added the removed warning to NOTES section of man page. Thu Nov 9 15:09:26 MST 2000 Khalid Aziz (khalid_aziz@hp.com) * Bug fix: If invoked as "prctl --unaligned=signal ./foo -b -a -r bletch", options -b, -a and -r are interpreted as options to prctl as opposed to options to foo. Thu Sep 21 10:22:50 MDT 2000 Khalid Aziz (khalid_aziz@hp.com) * Initial release of prctl with support for unaligned memory access behavior control. prctl-1.7/Makefile.in000066400000000000000000000054111465124575000145640ustar00rootroot00000000000000# Makefile for prctl # Copyright (c) 2000 Hewlett Packard Co # Copyright (c) 2000 Khalid Aziz "\|>" .RB "[\|" \c .I command\c \|] .P where \fB\fP are: .P .RB "\|" --unaligned=[silent|signal|always-signal|default] "\|" .P .RB "\|" --fpemu=[silent|signal|default] "\|" .P .RB "\|" --mcekill=[early|late|default] "\|" .SH DESCRIPTION \fBprctl\fP allows you to query or control certain process behavior. Supported options are: .P \fBUnaligned memory access:\fP When a process performs an unaligned memory access, by default the kernel would emulate the unaligned access correctly and log the unaligned access in syslog. This behavior can be changed so the kernel could either emulate the unaligned access correctly without logging an error ("silent") or send SIGBUS to the process ("signal" and "always-signal"). "always-signal" is available on ia64 only. .P \fBFloating point assistance faults:\fP when a process encounters a floating point assist fault, kernel would invoke floating point emulator and log the floating point assist fault. This behavior can be changed so the kernel could either emulate floating point operation without logging an error ("silent") or send SIGFPE to the offending process ("signal"). .P \fBMachine check memory corruption kill policy:\fP If a hardware memeory corruption is detected inside a thread's address space, mmemory corruption kill policy determines whether the thread received SIGBUS as soon as corruption is detected ("early"), when it accesses corrupted memory ("late"), or use system wide default. .P \fBprctl\fP can optionally be followed by a command. If a command is specified, \fBprctl\fP will exec the command with the processor behavior set to as specified by the options. If a command is not specified, \fBprctl\fP will fork a new shell unless the command only queried the current settings. The shell started by prctl will be as defined by the environment variable SHELL. If environment variable SHELL is not defined, shell in the password entry for the user will be started. If a shell is not found in the password entry, bash will be started. .SS OPTIONS .TP \fI-v\fP Verbose mode. In verbose mode, any new settings are confirmed with a message on stdout. .TP \fI--help\fP Print usage information and exit. .TP \fI--version\fP Print software version and exit. .TP \fI-q\fP Query the current settings for the process options controllable by prctl. .TP \fI--unaligned=[silent|signal|always-signal|default]]\fP Set unaligned memory access behavior to not log the access (\fBsilent\fP), send SIGBUS to the process (\fBsignal\fP), or do the default (\fBdefault\fP). On IA-64 architecture an additional value \fBalways-signal\fP is supported which causes a SIGBUS to be generated every time an unaligned access occurs. Refer to the section titled "Memory Datum Alignment and Atomicity" in "Intel IA-64 Architecture Software Developer's Manual: Volume 2" for details on when an unaligned access would not generate signal normally. If a value is not specified after "=", current setting is returned. .TP \fI--fpemu=[silent|signal|default]]\fP Set floating point assist fault behavior to not log the faulti (\fBsilent\fP), send SIGFPE to the process (\fBsignal\fP), or do the default (\fBdefault\fP). If a value is not specified after "=", current setting is returned. .TP If an option is specified multiple times, the last one takes effect. .SH EXAMPLES .TP .B prctl --unaligned=signal starts up a shell (as defined by the environment variable SHELL) and sets up any process running under this shell to be sent SIGBUS upon an unaligned memory access. .TP .B prctl --unaligned=signal gdb tst starts up a gdb session for the program "tst" with the process set to receive SIGBUS upon unligned memory access. .TP .B prctl --unaligned= displays the current setting for unaligned memory access handling. .TP .B prctl --unaligned= gdb tst displays the current setting for unaligned memory access handling and starts up a gdb session for the program "tst". .SH NOTES prctl works on 2.4.0 and above kernels only. .P --fpemu= option is specific to IPF (Itanium Processor Family, previously known as IA-64) and is supported on kernels 2.4.11 and above. Other architectures and kernels may return "Invalid argument" error. .SH SEE ALSO .BR prctl(2) .SH AUTHOR Khalid Aziz .SH LICENSE This software is made available under the GNU General Public License (GPL) Version 2.\" gpl.html# This software comes with NO WARRANTY.\" gpl.html#nowarr prctl-1.7/prctl.c000066400000000000000000000243331465124575000140130ustar00rootroot00000000000000/* * prctl - a tool to set process options * * Copyright (C) 2000 Hewlett-Packard Co * Copyright (C) 2000 Khalid Aziz * Copyright (C) 2014 Khalid Aziz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License Version 2 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #include #include #include #include #include /* Version */ #define VERSION "1.7" /* Shell to fall back on if no other shell can be found */ #define DEFAULT_SHELL "/bin/bash" #define PSR_UC 0x08 /* Command line options */ struct option longopts[] = { {"unaligned", 1, (int *)0, 'u'}, {"fpemu", 1, (int *)0, 'f'}, {"mcekill", 1, (int *)0, 'm'}, {"version", 0, (int *)0, 'V'}, {"help", 0, (int *)0, 'h'}, {0, 0, (int *)0, 0} }; /* Verbose mode */ int verbose=0; void print_version(char *progname) { printf("%s version %s\n", progname, VERSION); } void usage(char *progname) { print_version(progname); printf("Usage: %s [-v] [-h|--help] [--version]\n", progname); printf(" <-q|> [command]\n"); printf(" Options:\n"); #ifdef __ia64__ printf(" --unaligned=[silent|signal|always-signal|default]\n"); #else printf(" --unaligned=[silent|signal|default]\n"); #endif printf(" --fpemu=[silent|signal|default]\n"); printf(" --mcekill=[early|late|default]\n"); } int set_unaligned(int prctl_val) { int alignval, retval; int umask; /* * Check if we need to display the value or set it. */ if (prctl_val == -1) { if ((retval = prctl(PR_GET_UNALIGN, &alignval)) != -1) { printf("%-13s= ", "unaligned"); switch (alignval) { case 0: printf("default\n"); break; case PR_UNALIGN_NOPRINT: printf("silent\n"); break; case PR_UNALIGN_SIGBUS: #ifdef __ia64__ /* Get user mask */ __asm__ __volatile__ ("mov %0=psr.um;;": "=r"(umask) :: "memory"); if (umask & PSR_UC) printf("always-"); #endif printf("signal\n"); break; } } } else { if ((retval = prctl(PR_SET_UNALIGN, prctl_val)) != -1) { if (verbose) { printf("Set \"unaligned\" to "); switch (prctl_val) { case 0: printf("\"default\"\n"); break; case PR_UNALIGN_NOPRINT: printf("\"silent\"\n"); break; case PR_UNALIGN_SIGBUS: printf("\"signal\"\n"); break; } } } } if (retval == -1) { if (errno == EINVAL) { /* * print an error message only if we were trying * to set this value. */ if (prctl_val != -1) fprintf(stderr, "ERROR: This platform does not implement set_unaligned prctl feature.\n"); } else { fprintf(stderr, "Failed to %s \"unalign\" value: %s\n", ((prctl_val==-1)?"get":"set"),strerror(errno)); } } return(retval); } int set_fpemu(int prctl_val) { int fpemuval, retval; /* * Check if we need to display the value or set it. */ if (prctl_val == -1) { if ((retval = prctl(PR_GET_FPEMU, &fpemuval)) != -1) { printf("%-13s= ", "FP emulation"); switch (fpemuval) { case 0: printf("default\n"); break; case PR_FPEMU_NOPRINT: printf("silent\n"); break; case PR_FPEMU_SIGFPE: printf("signal\n"); break; } } } else { if ((retval = prctl(PR_SET_FPEMU, prctl_val)) != -1) { if (verbose) { printf("Set \"fpemu\" to "); switch (prctl_val) { case 0: printf("\"default\"\n"); break; case PR_FPEMU_NOPRINT: printf("\"silent\"\n"); break; case PR_FPEMU_SIGFPE: printf("\"signal\"\n"); break; } } } } /* * If this was a PR_GET_FPEMU operation and the error is EINVAL, * this platform does not implement PR_GET_FPEMU (It may be * implemented only on IA64 platforms). */ if (retval == -1) { if (errno == EINVAL) { /* * print an error message only if we were trying * to set this value. */ if (prctl_val != -1) fprintf(stderr, "ERROR: This platform does not implement set_fpemu prctl feature.\n"); } else { fprintf(stderr, "Failed to %s \"fpemu\" value: %s\n", ((prctl_val==-1)?"get":"set"),strerror(errno)); } } return(retval); } int set_mcekill(int prctl_val) { int killval, retval; int umask; /* * Check if we need to display the value or set it. */ if (prctl_val == -1) { killval = prctl(PR_MCE_KILL_GET, 0, 0, 0, 0); printf("%-13s= ", "mcekill"); switch (killval) { case PR_MCE_KILL_DEFAULT: printf("default\n"); break; case PR_MCE_KILL_EARLY: printf("early\n"); break; case PR_MCE_KILL_LATE: printf("late\n"); break; } } else { if ((retval = prctl(PR_MCE_KILL, PR_MCE_KILL_SET, prctl_val, 0, 0)) != -1) { if (verbose) { printf("Set \"mcekill\" to "); switch (prctl_val) { case PR_MCE_KILL_DEFAULT: printf("\"default\"\n"); break; case PR_MCE_KILL_EARLY: printf("\"early\"\n"); break; case PR_MCE_KILL_LATE: printf("\"late\"\n"); break; } } } } if (retval == -1) { if (errno == EINVAL) { /* * print an error message only if we were trying * to set this value. */ if (prctl_val != -1) fprintf(stderr, "ERROR: This platform does not implement set_mce_kill prctl feature.\n"); } else { fprintf(stderr, "Failed to %s \"mcekill\" value: %s\n", ((prctl_val==-1)?"get":"set"),strerror(errno)); } } return(retval); } int main(int argc, char **argv) { int opt, cmd_start; char *progname; char fullpath[512]; char shellname[128]; int unaligned_val = -99; int fpemu_val = -99; int mcekill_val = -99; int always_signal = 0; int display = 0; int display_all = 0; int umask; strcpy(fullpath, argv[0]); if ((progname = strrchr(fullpath, '/')) != NULL) { progname++; } else { progname = fullpath; } /* * Parse command line options */ if (argc == 1) { usage(progname); exit(1); } opterr = 0; while ((opt = getopt_long(argc, argv, "+qhv", longopts, (int *) NULL)) != EOF) { switch (opt) { case 'u': if (strcmp(optarg, "silent") == 0) { unaligned_val = PR_UNALIGN_NOPRINT; } else if (strcmp(optarg, "signal") == 0) { unaligned_val = PR_UNALIGN_SIGBUS; #ifdef __ia64__ } else if (strcmp(optarg, "always-signal") == 0) { unaligned_val = PR_UNALIGN_SIGBUS; always_signal = 1; #endif } else if (strcmp(optarg, "default") == 0) { unaligned_val = 0; } else if (optarg[0] == 0) { unaligned_val = -1; display = 1; } else { usage(progname); exit(1); } break; case 'f': if (strcmp(optarg, "silent") == 0) { fpemu_val = PR_FPEMU_NOPRINT; } else if (strcmp(optarg, "signal") == 0) { fpemu_val = PR_FPEMU_SIGFPE; } else if (strcmp(optarg, "default") == 0) { fpemu_val = 0; } else if (optarg[0] == 0) { fpemu_val = -1; display = 1; } else { usage(progname); exit(1); } break; case 'm': if (strcmp(optarg, "early") == 0) { mcekill_val = PR_MCE_KILL_EARLY; } else if (strcmp(optarg, "late") == 0) { mcekill_val = PR_MCE_KILL_LATE; } else if (strcmp(optarg, "default") == 0) { mcekill_val = PR_MCE_KILL_DEFAULT; } else if (optarg[0] == 0) { mcekill_val = -1; display = 1; } else { usage(progname); exit(1); } break; case 'q': display_all = 1; display = 1; break; case 'h': usage(progname); exit(0); break; case 'v': verbose = 1; break; case 'V': print_version(progname); exit(0); break; case '?': fprintf(stderr, "%s: invalid option - %c\n", progname, optopt); exit(1); break; } } /* * Is there a command on the command line? If there is, there * there should be atleast one other option on the line and it * should be something other than -v. */ cmd_start = optind; if ((cmd_start == 1) || ((cmd_start == 2) && (verbose))) { usage(progname); exit(1); } /* * If -q option was given, we will ignore all other options * and simply display current settings. */ if (display_all) { printf("Current settings for supported prctl operations:\n"); set_unaligned(-1); set_fpemu(-1); set_mcekill(-1); printf("\n"); exit(0); } else { /* * Now set the correct prctl options if needed */ if (unaligned_val != -99) { if (set_unaligned(unaligned_val) == -1) { exit(1); } #ifdef __ia64__ if (always_signal) { /* Set alignment check in user mask */ __asm__ __volatile__ ("sum psr.ac;;"::: "memory"); } #endif } if (fpemu_val != -99) { if (set_fpemu(fpemu_val) == -1) { exit(1); } } if (mcekill_val != -99) { if (set_mcekill(mcekill_val) == -1) { exit(1); } } } /* * Check if we need to run a command or start a new shell. * * If the command line options asked to display any of the values * and a command was not given on the command line, we will not * start a shell. * */ if (argv[cmd_start] == 0) { if (display) { exit(0); } printf("Starting a shell\n"); strcpy(shellname, getenv("SHELL")); /* * Make sure SHELL environment variable is not unset. If it * is, start bash. */ if (shellname[0] == 0) { struct passwd *pwd_entry; pwd_entry = getpwuid(getuid()); if (pwd_entry == NULL) { strcpy(shellname, DEFAULT_SHELL); } else { if (pwd_entry->pw_shell != NULL) { strcpy(shellname, pwd_entry->pw_shell); } else { strcpy(shellname, DEFAULT_SHELL); } } } /* * Now exec the shell */ if (execlp(shellname, (char *)shellname, (char *) 0) == -1) { fprintf(stderr, "Failed to exec the shell: %s\n", strerror(errno)); exit(1); } } else { /* * Now exec the user command */ if (execvp(argv[cmd_start], argv+cmd_start) == -1) { fprintf(stderr, "Failed to exec command \"%s\": %s\n", argv[cmd_start], strerror(errno)); exit(1); } } exit(0); } prctl-1.7/prctl.spec000066400000000000000000000035521465124575000145230ustar00rootroot00000000000000%define version 1.6 Summary: Utility to perform process operations Name: prctl Version: %{version} Release: 1 Copyright: GPL Group: Applications/System Source: ftp://linux.hpl.hp.com/pub/linux-ia64/prctl-%{version}.tar.gz Buildroot: /var/tmp/%{name}-root ExclusiveOS: linux %description The prctl utility allows a user to control certain process behavior in the runtime environment. This utility works on Linux 2.4 and higher kernels only. %prep %setup %build ./configure make %clean rm -rf $RPM_BUILD_ROOT %install rm -rf $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT/usr/local/man make install prefix=$RPM_BUILD_ROOT/usr/local %post %preun %files %doc /usr/local/bin/prctl /usr/local/man/man1/prctl.1 %changelog * Wed Feb 26 2014 Khalid Aziz (khalid.aziz@oracle.com) - Improved messages and suppressed unnecessary error messages - Added support for PR_MCE_KILL * Thu May 18 2006 Khalid Aziz (khalid_aziz@hp.com) - Updated man page location in Makefile.in - Better error message in case kernel does not support prctl operations. * Wed Mar 5 2003 Khalid Aziz (khalid_aziz@hp.com) - Added "always-signal" option to --unaligned for ia64. * Wed Oct 17 2001 Khalid Aziz (khalid_aziz@hp.com) - Added option to set floating point emulation behavior. * Mon Jun 4 2001 Khalid Aziz (khalid_aziz@hp.com) - Bug fix: Did not recognize "--unaligned=default" as a valid command. * Fri Jan 12 2001 Khalid Aziz (khalid_aziz@hp.com) - Removed post-install warning from spec file. Added the removed warning to NOTES section of man page. * Thu Nov 9 2000 Khalid Aziz (khalid_aziz@hp.com) - Bug fix: If invoked as "prctl --unaligned=signal ./foo -b -a -r bletch", options -b, -a and -r are interpreted as options to prctl as opposed to options to foo. * Thu Sep 21 2000 Khalid Aziz (khalid_aziz@hp.com) - Initial release of prctl with support for unaligned memory access behavior control.