Path: utzoo!mnetor!uunet!husc6!mailrus!ames!pasteur!ucbvax!miro.Berkeley.EDU!gregc From: gregc@miro.Berkeley.EDU.berkeley.edu (Greg Couch) Newsgroups: comp.sys.hp Subject: Re: existence of getrusage(2) call Message-ID: <23974@ucbvax.BERKELEY.EDU> Date: 8 May 88 01:17:48 GMT References: <12480@sri-spam.istc.sri.com> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: gregc@miro.Berkeley.EDU.UUCP (Greg Couch) Organization: University of California, Berkeley Lines: 371 Enclosed is a very unofficial, but extremely useful way of adding 4.2 system calls to hp-ux 5.x and 6.0. You may need to put some of the include files from /etc/conf/h in /usr/include/sys (e.g. resource.h), or grab them from a BSD system. I added getdtablesiz, getpagesize, getpriority, setpriority, setregid, setreuid, getrusage, getrlimit, and setrlimit. If you only add the system calls I did, you should be able to use the Makefile's as is. Read sys/hpux-patchinfo to get an idea of how the patching works and some caveats. - Greg Couch gregc@miro.Berkeley.EDU gregc@Berkeley.EDU ----- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by gregc at ebi on Sat May 7 17:56:40 1988 # # This archive contains: # libc sys # LANG=""; export LANG echo mkdir - libc mkdir libc echo x - libc/setreuid.s cat >libc/setreuid.s <<'@EOF' define(`SYSCALL_NAME', setreuid)dnl define(`SYSCALL_NUMBER', 0x7e)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/setreuid.s echo x - libc/getpagesize.s cat >libc/getpagesize.s <<'@EOF' define(`SYSCALL_NAME', getpagesize)dnl define(`SYSCALL_NUMBER', 0x40)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/getpagesize.s echo x - libc/Makefile cat >libc/Makefile <<'@EOF' # # Create system call stubs for libc and libc_p # SHELL = /bin/sh LIBC = /lib/libc.a LIBC_P = /lib/libc_p.a OBJS = getdtablesiz.o getpagesize.o getpriority.o setpriority.o \ setregid.o setreuid.o getrusage.o getrlimit.o setrlimit.o .s.o: m4 -DPROFILE $*.s | ${AS} -o profiled/$*.o m4 $*.s | ${AS} -o $*.o all: ${OBJS} install: all ar ru ${LIBC} ${OBJS} cd profiled; ar ru ${LIBC_P} ${OBJS} clean: rm -f ${OBJS} cd profiled; rm -f ${OBJS} # ${OBJS}: SYS.m4 @EOF chmod 444 libc/Makefile echo x - libc/getdtablesiz.s cat >libc/getdtablesiz.s <<'@EOF' define(`SYSCALL_NAME', getdtablesize)dnl define(`SYSCALL_NUMBER', 0x59)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/getdtablesiz.s echo x - libc/getpriority.s cat >libc/getpriority.s <<'@EOF' define(`SYSCALL_NAME', getpriority)dnl define(`SYSCALL_NUMBER', 0x64)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/getpriority.s echo x - libc/setpriority.s cat >libc/setpriority.s <<'@EOF' define(`SYSCALL_NAME', setpriority)dnl define(`SYSCALL_NUMBER', 0x60)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/setpriority.s echo x - libc/SYS.m4 cat >libc/SYS.m4 <<'@EOF' define(concat,$1$2$3$4$5$6$7$8$9)dnl allow_p1sub global concat(_, SYSCALL_NAME) global __cerror concat(_, SYSCALL_NAME): ifdef(`PROFILE', ` global mcount mov.l &Lcount, %a0 jsr mcount ')dnl ifelse(eval(SYSCALL_NUMBER/128), 0, ` movq &SYSCALL_NUMBER, %d0 ',` mov.l &SYSCALL_NUMBER, %d0 ')dnl trap &0x0 bcc.b L11 jmp __cerror L11: rts ifdef(`PROFILE', data lalign 4 Lcount: space 4 )dnl @EOF chmod 444 libc/SYS.m4 echo x - libc/getrusage.s cat >libc/getrusage.s <<'@EOF' define(`SYSCALL_NAME', getrusage)dnl define(`SYSCALL_NUMBER', 0x75)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/getrusage.s echo x - libc/setregid.s cat >libc/setregid.s <<'@EOF' define(`SYSCALL_NAME', setregid)dnl define(`SYSCALL_NUMBER', 0x7f)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/setregid.s echo x - libc/getrlimit.s cat >libc/getrlimit.s <<'@EOF' define(`SYSCALL_NAME', getrlimit)dnl define(`SYSCALL_NUMBER', 0x90)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/getrlimit.s echo x - libc/setrlimit.s cat >libc/setrlimit.s <<'@EOF' define(`SYSCALL_NAME', setrlimit)dnl define(`SYSCALL_NUMBER', 0x91)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/setrlimit.s echo x - libc/PROTO.s cat >libc/PROTO.s <<'@EOF' define(`SYSCALL_NAME', NAME)dnl define(`SYSCALL_NUMBER', NUMBER)dnl include(`SYS.m4')dnl @EOF chmod 444 libc/PROTO.s echo mkdir - libc/profiled mkdir libc/profiled chmod 755 libc/profiled chmod 755 libc echo mkdir - sys mkdir sys echo x - sys/syscall.instal cat >sys/syscall.instal <<'@EOF' /^#/ { next } { printf "sysent+(%s*8)?W %s\n", $2, $3 printf "sysent+(%s*8)+4?W %s\n", $2, $1 } END { print "$q" } @EOF chmod 444 sys/syscall.instal echo x - sys/Makefile cat >sys/Makefile <<'@EOF' # # Install new system calls in kernel # SHELL=/bin/sh syscall: awk -f syscall.check < syscall.stubs | adb /hp-ux /dev/kmem @echo "" @echo "every line should have been:" @echo " sysent+offset: 0x0 _nosys '# system-call-name'" @echo "if not," @echo " edit the syscall.stubs file to use different system call #'s" @echo "if so," @echo " make syscall-install" syscall-install: awk -f syscall.install < syscall.stubs | adb -w /hp-ux /dev/kmem @echo /etc/reboot the system to see change version: @ver=`uname -v` ; \ if [ $$ver = A ] ; then echo single-user system ; \ elif [ $$ver = B ] ; then echo 16-user system ; \ elif [ $$ver = C ] ; then echo 32-user system ; \ elif [ $$ver = D ] ; then echo 64-user system ; \ elif [ $$ver = U ] ; then echo unlimited-number-of-users system ; fi ; version-install: # use 4100 for a single-user system, 4200 for 16-user, # 4300 for 32-user, 4400 for 64-user, and 5500 for unlimited. # the 0x1b offset is from the version field offset inecho "utsname+0x1b?w 0x4200" | adb -w /hp-ux /dev/kmem @echo /etc/reboot the system to see change nobody-install: # set the nfs nobody value which controls what uid a remote root # has on our exported filesystems. Here we only export to trusted # hosts. echo "nobody?W 0" | adb -w /hp-ux /dev/kmem @echo /etc/reboot the system to see change @EOF chmod 644 sys/Makefile echo x - sys/syscall.check cat >sys/syscall.check <<'@EOF' /^#/ { next } { printf "sysent+(%s*8)/Xp\"'%s %s'\"\n", $2, $3, $1 } END { print "$q" } @EOF chmod 444 sys/syscall.check echo x - sys/hpux-patchinfo sed 's/^@//' >sys/hpux-patchinfo <<'@EOF' @From chris@ic.Berkeley.EDU Wed Jan 20 23:53:16 1988 Received: from ic.Berkeley.EDU by degas.Berkeley.EDU (5.58/1.26) id AA26174; Wed, 20 Jan 88 23:53:12 PST Received: by ic.Berkeley.EDU (5.57/1.26) id AA07726; Wed, 20 Jan 88 23:55:48 PST Date: Wed, 20 Jan 88 23:55:48 PST @From: chris@ic.Berkeley.EDU (Chris Guthrie) Message-Id: <8801210755.AA07726@ic.Berkeley.EDU> To: gregc@degas.Berkeley.EDU Subject: Re: hpux and rdist Status: RO Here's an old note I did on it. A systematic way to recover the Berkeley System calls from HP-UX HP-UX is based on a 4.2 bsd kernel. Unfortunately, HP decided overlay this kernel with a system five compatible interface. Often, this meant chopping out useful 4.2 system calls. Fortunately, someone with a bit of UNIX experience (and access to Berkeley source) can put back some of these system calls in the following manner: 1) Choose a needed system call. For example, we will use getpriority() which has two arguments. 2) You will need to adb the kernel: adb -w /hp-ux /dev/kmem 3) Collect the following information: Arguments: 2 Handler location in kernel: 0x58a8 (this can be had be typing getpriority=X in adb) syscall number 0x64 (100 base 10) (This comes out of sysent.c in the 4.2 source) sysent table location in kernel: 0x320 (this is equal to the syscall number * 0x8) 4) Check the sysent to make sure it hasn't been used for something else: in adb: sysent+320?Xp should give: sysent+0x320: 0x0 _nosys 5) Now, use adb to fill these numbers in. First the argument count: sysent+320?W 0x2 sysent+320/W 0x2 Then the handler location: sysent+324?W 0x58a8 sysent+324/W 0x58a8 Your kernel is now modified. 6) Now, for a user entry to this syscall, modify the following assembly entry in getpriority.s, and compile it with your program: global __cerror; err: jmp __cerror; global _getpriority; _getpriority: movq &0x64,%d0; trap &0x0; bcc.b _getpriority+0xC; jmp __cerror; rts; Note that the 0x64 represents the syscall number. It must be changed for other syscalls as should the label "getpriority." With most syscalls, this should work. Caveats: If you cannot find a handler for the syscall, you can't patch it in. For instance (sadly) rename doesn't exist. I have only installed getpriority, setpriority, and setreuid on my machines. I add them as I need them. Since I don't have HP-UX source (yet), I can never be sure that they work until I try them. Even then, there might be unseen problems. Finally, this hacking no doubt qualifies as non-standard software as far as the software response center is concerned. @EOF chmod 444 sys/hpux-patchinfo echo x - sys/syscall.stubs cat >sys/syscall.stubs <<'@EOF' # call number must be in hex for adb # name call # # args getdtablesize 0x59 0 getpagesize 0x40 0 getpriority 0x64 2 setpriority 0x60 3 setregid 0x7f 2 setreuid 0x7e 2 getrusage 0x75 2 getrlimit 0x90 2 setrlimit 0x91 2 @EOF chmod 444 sys/syscall.stubs chmod 755 sys exit 0