diff --git a/.cdtproject b/.cdtproject
deleted file mode 100644
index 64882f1..0000000
--- a/.cdtproject
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
-
-
-
--
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--
-
-
-
-
-
-
diff --git a/.cproject b/.cproject
deleted file mode 100644
index 86d0083..0000000
--- a/.cproject
+++ /dev/null
@@ -1,71 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.cvsignore b/.cvsignore
index 9235365..d31d286 100644
--- a/.cvsignore
+++ b/.cvsignore
@@ -5,4 +5,3 @@
ne2k.raw
ne2k.txt
snapshot.txt
-ne2k-pktlog.txt
diff --git a/.externalToolBuilders/org.eclipse.cdt.make.core.ScannerConfigBuilder.launch b/.externalToolBuilders/org.eclipse.cdt.make.core.ScannerConfigBuilder.launch
deleted file mode 100644
index 9d5ba23..0000000
--- a/.externalToolBuilders/org.eclipse.cdt.make.core.ScannerConfigBuilder.launch
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/.externalToolBuilders/org.eclipse.cdt.make.core.makeBuilder.launch b/.externalToolBuilders/org.eclipse.cdt.make.core.makeBuilder.launch
deleted file mode 100644
index 1eb3ac6..0000000
--- a/.externalToolBuilders/org.eclipse.cdt.make.core.makeBuilder.launch
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs
deleted file mode 100644
index 7347476..0000000
--- a/.settings/org.eclipse.cdt.core.prefs
+++ /dev/null
@@ -1,9 +0,0 @@
-#Thu Jun 18 07:39:49 EDT 2009
-eclipse.preferences.version=1
-indexer/filesToParseUpFront=stdarg.h, stddef.h, sys/types.h
-indexer/indexAllFiles=true
-indexer/indexerId=org.eclipse.cdt.core.fastIndexer
-indexer/skipMacroReferences=false
-indexer/skipReferences=false
-indexer/skipTypeReferences=false
-indexerId=org.eclipse.cdt.core.fastIndexer
diff --git a/BUGS b/BUGS
index 3d0c282..f2dedf8 100644
--- a/BUGS
+++ b/BUGS
@@ -2,17 +2,4 @@
Bugs:
-06/12/12 - Only Works With GCC34
-
-06/17/09 - Need to free pageDir page
-
-10/27/06 - NEED TO IMPLIMENT ENV!!!!
-
-10/12/06 -
- Tempermental Keyboard Driver
-
-10/12/06 -
- UFS is hacked to get correct file size
-
-10/12/06 -
- usrland ld.so forces path sys:/lib/ must make more automated
+New bug appeared now login when started directly and not forked accesses memory it shouldn't touch....
\ No newline at end of file
diff --git a/ChangeLog b/ChangeLog
deleted file mode 100644
index 4740e9c..0000000
--- a/ChangeLog
+++ /dev/null
@@ -1,5 +0,0 @@
-2007-01-25 Christopher Olsen
- Cleaning up the ne2k driver for future network support.
-
- Previous version of UbixOS had LwIP functioning, I hope this will be true in this case.
-
diff --git a/FIX b/FIX
deleted file mode 100644
index 0b4bf17..0000000
--- a/FIX
+++ /dev/null
@@ -1 +0,0 @@
-libc __swbuf
diff --git a/Makefile b/Makefile
index 83ae1f5..b6856ea 100644
--- a/Makefile
+++ b/Makefile
@@ -1,24 +1,12 @@
# $Id$
# The System Makefile (C) 2002 The UbixOS Project
-all: kernel tools ubix_api libc_old ubix csu libc libcpp libutil bin
+all: kernel libc_old ubix libcpp bin sbin tools
# depend kernel tools
-csu: src
- (cd src/lib/csu;make)
-
-ubix_api: src
- (cd src/lib/ubix_api;make)
-
libc_old: src
(cd src/lib/libc_old;make)
-libc_a: src
- (cd src/lib/libc;make LIBPATH=${.CURDIR} lib.a)
-
-libc: src
- (cd src/lib/libc;make LIBPATH=${.CURDIR})
-
objgfx40: src
(cd src/lib/objgfx40;make)
@@ -31,12 +19,12 @@
libcpp: src
(cd src/lib/libcpp;make)
-libutil: src
- (cd src/lib/libutil;make)
-
depend: src
(cd src/lib/ubix;make)
+sbin: src
+ (cd src/sbin;make)
+
bin: src
(cd src/bin;make)
@@ -54,13 +42,11 @@
clean:
(cd src/sys;make clean)
- (cd src/lib/csu;make clean)
- (cd src/lib/ubix_api;make clean)
(cd src/lib/libc_old;make clean)
- (cd src/lib/libc;make clean)
- (cd src/lib/libutil;make clean)
+ (cd src/sbin;make clean)
(cd src/bin;make clean)
(cd src/lib/ubix;make clean)
+ (cd src/lib/objgfx40;make clean)
(cd src/lib/libcpp;make clean)
(cd src/lib/views/sunlight;make clean)
(cd src/lib/libstdc++;make clean)
diff --git a/README b/README
index 4c019e4..f2675cc 100644
--- a/README
+++ b/README
@@ -1,10 +1,3 @@
-$Id$
-
-2007-11-26
-As of REL_2 UbixOS is now using the UFS/FFS filesystem.. UbixFS is currently depreciated..
-
-
-
Installation:
make all install <- This will build the kernel and components and put them onto a floppy
@@ -17,3 +10,6 @@
2) cd ../boot2;make
3) cat boot1 boot2 > /dev/fd0
4) gcc -o test test.c;./test /dev/fd0 1;rm ./test
+
+This tree is no longer valid
+or is it?
diff --git a/RELEASE b/RELEASE
deleted file mode 100644
index 9258c10..0000000
--- a/RELEASE
+++ /dev/null
@@ -1,3 +0,0 @@
-$Id$
-
-Release V3.0
diff --git a/TODO b/TODO
index c9d134e..16a4f5e 100644
--- a/TODO
+++ b/TODO
@@ -1,22 +1,37 @@
$Id$
-11-28-06 - Make Web Site
+Brush up VMM
+Create VFS
+Remove old networking support
+Brush up drive subsystem
-10-12-06 -
- Wow a year later and now I'm working on it
- Finish fdisk
+pre: July 2005
- Work On Installer
+IMPORTANT FIRST THINGS TO DO
- Put Close File Into VFS....
+Kernel Modules - Start on this for drivers and the like
+ld.so loader - Share the ld.so read only pages to all applications
+find out why ld.so includes all of the libc.so
- Fix File Descriptor Structure!!
+Bring in ufs to kernel
+Set up an installer
+Make sure libc works
+Get gcc running
+Make VI work
+Make bash/tcsh work
+Make GDB work
+Make ld work
+Make ftp work
+Make smb work
+Make SATA work
+Make NIC work
-10-11-05
-Refamiliarize myself with all the code.
-Take out current ip/stack
-Clean up driver system
-Look into Ubix resource management
-Work on libc
-Enhance shared libraries
+Less Important
+
+Convert system calls to messages
+Finish up standard c library
+Make VMM 64Bit
+Finish PCI system
+Improve Driver Model
+RouteNG
\ No newline at end of file
diff --git a/doc/ELF_Format.pdf b/doc/ELF_Format.pdf
deleted file mode 100644
index 34b9e8c..0000000
--- a/doc/ELF_Format.pdf
+++ /dev/null
Binary files differ
diff --git a/doc/sample_driver.c b/doc/sample_driver.c
new file mode 100644
index 0000000..108bfcf
--- /dev/null
+++ b/doc/sample_driver.c
@@ -0,0 +1,98 @@
+/*****************************************************************************************
+ Copyright (c) 2002 The UbixOS Project
+ All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of
+conditions, the following disclaimer and the list of authors. Redistributions in binary
+form must reproduce the above copyright notice, this list of conditions, the following
+disclaimer and the list of authors in the documentation and/or other materials provided
+with the distribution. Neither the name of the UbixOS Project nor the names of its
+contributors may be used to endorse or promote products derived from this software
+without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ $Log$
+ Revision 1.1 2004/04/27 12:04:24 reddawg
+ Sample driver for isa interface
+
+
+
+ $Id$
+
+*****************************************************************************************/
+
+/********************************************************
+ This sample driver is good for an ISA device you can
+ either probe or hand set irq and ioAddr information if
+ ********************************************************/
+
+#include
+
+struct devInfo {
+ int irq;
+ int ioAddr;
+ }
+
+static struct devInfo sampleInfo;
+
+void sampleRegister() {
+ int sampleMajor = 0; /* Major ID */
+ int sampleMinor = 0; /* Minor ID */
+
+ deviceAdd(sampleMajor,sampleMinor,"c",sampleRead,sampleWrite,sampleReset,sampleInit,sampleIoctl,sampleStop,sampleStart,sampleStandby,sampleInfo)
+ }
+
+
+int sampleRead(struct deviceNode *dev,void *ptr,uInt32 offset,uInt32 length) {
+ /* Read From Device */
+ return(0);
+ }
+
+int sampleWrite(struct deviceNode *dev,void *ptr,uInt32 offset,uInt32 length) {
+ /* WritE to Device */
+ return(0);
+ }
+
+int sampleReset(struct deviceNode *dev) {
+ /* Device Reset */
+ return(0);
+ }
+
+int sampleInit(struct deviceNode *dev) {
+ /* Device Initialization */
+ /* Also Set Device Size If IT Is A Character Device */
+ dev->size = 1024;
+ return(0);
+ }
+
+int sampleIoctl(struct deviceNode *dev) {
+ /* Device IO Control */
+ return(0);
+ }
+
+int sampleStop(struct deviceNode *dev) {
+ /* Stop this device */
+ return(0);
+ }
+
+int sampleStart(struct deviceNode *dev) {
+ /* Start This Device */
+ return(0);
+ }
+
+int sampleStandby(struct deviceNode *dev) {
+ /* Do all things needed to allow this device to go into standby mode */
+ return(0);
+ }
diff --git a/doc/vfs.txt b/doc/vfs.txt
deleted file mode 100644
index 450b494..0000000
--- a/doc/vfs.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-$Id$
-
-fd offset -
-This will be adjusted by the read and write calls inside the FS module
-
-Unless you call lseek which stays in the VFS layer and this will adjust the offset
-
-Potential bug: we do not lock the fd... but lseek should not be called on the descriptor while the descirptor is in read/write
diff --git a/doc/vmm.txt b/doc/vmm.txt
new file mode 100644
index 0000000..debb245
--- /dev/null
+++ b/doc/vmm.txt
@@ -0,0 +1,34 @@
+This document goes over the UbixOS VMM
+
+
+1. Memory Layout -
+
+ Each application has its own private 4gb memory area the first 1mb is mapped 1:1 against the systems memory and is shared between all of the proccess
+ on the system it include bios information video buffers and the kernel code.
+
+ From 0x100000 - 3gb this memory region is available for the task itself for its code data and anything else it may need it for
+
+ The top 1gb is reserved and shared across every application this is the os memory region not readable by the application unless it is in a syscall
+
+ at 0x100000 the applications page directory is stored and page 0x768 is all the pagetable listed in the page dir specified at 0x100000
+
+2. Functions -
+
+ vmmInit:
+ This function initializes our memory map and paging system if either fail this returns a failure.
+
+ vmmMemMapInit:
+ This initializes our memory map, it is a linked list of available pages it keeps track of COW (copy on write) as well as ownership and status
+
+ vmmPagingInit:
+ This initializes our paging system sets up default memory area for kernel and remaps the memory map into the top 1GB this builds the memory foundation
+ for each application to follow
+
+ vmmCreateVirtualSpace:
+ This creates a new virtual space for a process it takes on arg pidType pid and returns the base address of the new page directory
+ This has the shared lower 1 mb and top 1GB everything inbetween is available for the process
+
+ vmmCopyVirtualSpace:
+ This copies the current virtual space for the process specified by the arg pidType pid passed in. This copy sets all the pages for 2mb -3gb COW and no
+ memory is physically copied when the program attempts to write to this region a page fault happens then the memory is physically copied
+
diff --git a/foo.txt b/foo.txt
new file mode 100644
index 0000000..c833fd0
--- /dev/null
+++ b/foo.txt
@@ -0,0 +1,242 @@
+#include
+#include
+
+#define IN
+#define STATUS_FAILURE -1
+#define STATUS_SUCCESS 0
+
+typedef struct _item_t Item_t;
+typedef struct _list_t List_t;
+struct _item_t
+{
+ Item_t *Previous;
+ Item_t *Next;
+};
+
+struct _list_t
+{
+ Item_t *First;
+ Item_t *Last;
+};
+
+
+/* checked */
+List_t *
+InitializeList()
+{
+ List_t * TList;
+
+ TList = malloc(sizeof *TList);
+ TList->First = NULL;
+ TList->Last = NULL;
+ return TList;
+}
+
+/* checked */
+Item_t *
+CreateItem()
+{
+ Item_t * p;
+ p = malloc(sizeof *p);
+ p->Next = NULL;
+ p->Previous = NULL;
+ p->Priority = 0;
+ return p;
+}
+
+
+/* checked */
+int
+InsertItemAtFront( IN List_t * TList,
+ IN Item_t * kItem)
+{
+ if(TList->First == NULL)
+ {
+ TList->First = kItem;
+ TList->Last = kItem;
+ kItem->Previous = NULL;
+ kItem->Next = NULL;
+ }
+ else
+ {
+ Item_t * FirstItem;
+
+ FirstItem = TList->First;
+ kItem->Next = FirstItem;
+ TList->First = kItem;
+ FirstItem->Previous = kItem;
+
+
+ }
+ return STATUS_SUCCESS;
+}
+
+
+
+/* checked */
+int
+SetItemPriority( IN Item_t * kItem,
+ IN PRIORITY Priority)
+{
+ kItem->Priority = Priority;
+ return STATUS_SUCCESS;
+}
+
+
+/* checked */
+int
+InsertItemBetweenItems( IN List_t * TList,
+ IN Item_t * Previous,
+ IN Item_t * Next,
+ IN Item_t * Insert)
+{
+
+ if(Previous == NULL || Next == NULL)
+ return STATUS_FAILURE;
+ else
+ {
+ Previous->Next = Insert;
+ Next->Previous = Insert;
+ Insert->Previous = Previous;
+ Insert->Next = Next;
+
+ }
+
+ return STATUS_SUCCESS;
+}
+
+
+/* checked */
+int
+RemoveItem( IN List_t * TList,
+ IN Item_t * kItem)
+{
+ kItem->Previous->Next = kItem->Next;
+ kItem->Next->Previous = kItem->Previous;
+ kItem->Previous = NULL;
+ kItem->Next = NULL;
+ return STATUS_SUCCESS;
+}
+
+/* checked */
+int
+DestroyItemsInList(IN List_t * ItemList)
+{
+ Item_t * z, tmp;
+
+ z = ItemList->Last;
+ while(z != NULL)
+ {
+ tmp = z->Previous;
+ MmFreeFromNonPagedPool(z);
+ z = tmp;
+ }
+ ItemList->First = NULL;
+ ItemList->Last = NULL;
+
+ return STATUS_SUCCESS;
+}
+
+
+
+NTSTATUS
+DestroyItemList(IN List_t * ItemList)
+{
+ MmFreeFromNonPagedPool(ItemList);
+ return STATUS_SUCCESS;
+}
+
+/* checked */
+Item_t *
+GetFirstItem(IN List_t * kItem)
+{
+ return kItem->First;
+}
+
+/* checked */
+Item_t *
+GetLastItem(IN List_t * kItem)
+{
+ return kItem->Last;
+}
+
+/* checked */
+List_t *
+RemoveItemListBetweenItems( IN Item_t * Previous,
+ IN Item_t * Next)
+{
+ List_t * NewList;
+
+ NewList = InitializeList();
+
+ NewList->First = Previous->Next;
+ NewList->Last = Next->Previous;
+
+ NewList->First->Previous = NULL;
+ NewList->Last->Next = NULL;
+
+ Previous->Next = Next;
+ Next->Previous = Previous;
+
+ return NewList;
+}
+
+
+/* checked */
+void
+InsertItemListBetweenItems( IN Item_t * Previous,
+ IN Item_t * Next,
+ IN List_t * Insert)
+{
+ assert(Previous != NULL);
+ assert(Next != NULL);
+
+ Previous->Next = Insert->First;
+ Next->Previous = Insert->Last;
+ Insert->First->Previous = Previous;
+ Insert->Last->Next = Next;
+ return STATUS_SUCCESS;
+}
+
+
+
+int
+main()
+{
+ List_t * High;
+ Item_t * a,b,c,d,e,z;
+
+ High = InitializeList();
+
+ a = CreateItem();
+ b = CreateItem();
+ c = CreateItem();
+ d = CreateItem();
+ e = CreateItem();
+
+ SetItemPriority(a, 1);
+ SetItemPriority(b, 2);
+ SetItemPriority(c, 3);
+ SetItemPriority(d, 4);
+ SetItemPriority(e, 5);
+
+ InsertItemAtFront(High, a);
+ InsertItemAtFront(High, b);
+ InsertItemAtFront(High, c);
+ InsertItemAtFront(High, d);
+ InsertItemAtFront(High, e);
+
+
+ z = High->Last;
+ while(z != NULL)
+ {
+ printf("Priority! equals %d\n", z->Priority);
+ z = z->Previous;
+ }
+
+
+
+
+
+ return 0;
+}
diff --git a/src/Makefile.inc b/src/Makefile.inc
index e51a3fe..d37383f 100644
--- a/src/Makefile.inc
+++ b/src/Makefile.inc
@@ -3,8 +3,10 @@
# allow you to change your default compiler without affecting your other work
CFLAGS =
-CC = gcc34
+CC = gcc
CXX = g++
LD = ld
AR = ar
REMOVE = rm -rf
+
+FD_DEVICE = /dev/fd0
diff --git a/src/README b/src/README
index 74148ed..ed58e06 100644
--- a/src/README
+++ b/src/README
@@ -4,4 +4,4 @@
include - Include files to build anything userland
lib - Userland libraries
sys - Kernel code
- tools - Tool kit required to build and install UbixOS
+ tools - Tool kit required to build and install UbixOS
\ No newline at end of file
diff --git a/src/bin/Makefile b/src/bin/Makefile
index e2c0aa9..70629ba 100644
--- a/src/bin/Makefile
+++ b/src/bin/Makefile
@@ -1,8 +1,8 @@
# $Id$
# The System Makefile (C) 2002 The UbixOS Project
-all: init-bin login-bin shell-bin clock-bin cp-bin fdisk-bin format-bin disklabel-bin ubistry-bin edit-bin ld-bin ttyd-bin stat-bin cat-bin rtld-elf-bin tcc-bin ls-bin
-# test-bin pwd-bin cat-bin de-bin goofball-bin mount-bin
+all: init-bin login-bin shell-bin ls-bin clock-bin cp-bin edit-bin ld-bin stat-bin cat-bin
+# test-bin pwd-bin cat-bin de-bin goofball-bin
init-bin: init
(cd init;make)
@@ -34,64 +34,31 @@
muffin-bin: muffin
(cd muffin;make)
-goofball-bin: goofball
- (cd goofball;make)
-
clock-bin: clock
(cd clock;make)
-fdisk-bin: fdisk
- (cd fdisk;make)
-
cp-bin: cp
(cd cp;make)
-format-bin: format
- (cd format;make)
-
-disklabel-bin: disklabel
- (cd disklabel;make)
launcher-bin: launcher
(cd launcher;make)
-ubistry-bin: ubistry
- (cd ubistry;make)
-
edit-bin: edit
(cd edit;make)
-ttyd-bin: ttyd
- (cd ttyd;make)
-
stat-bin: stat
(cd stat;make)
-mount-bin: mount
- (cd mount;make)
-
-rtld-elf-bin: rtld-elf
- (cd rtld-elf;make)
-
-tcc-bin: tcc
- (cd tcc;make)
-
clean:
(cd cp;make clean)
- (cd fdisk;make clean)
(cd init;make clean)
(cd shell;make clean)
(cd ls;make clean)
(cd login;make clean)
(cd clock;make clean)
(cd muffin;make clean)
- (cd format;make clean)
- (cd disklabel;make clean)
- (cd ubistry;make clean)
(cd ld;make clean)
(cd edit;make clean)
- (cd ttyd;make clean)
(cd stat;make clean)
- (cd mount;make clean)
- (cd rtld-elf;make clean)
- (cd tcc;make clean)
+ (cd cat; make clean)
diff --git a/src/bin/Makefile.inc b/src/bin/Makefile.inc
index e4a0946..8f7dae0 100644
--- a/src/bin/Makefile.inc
+++ b/src/bin/Makefile.inc
@@ -1,11 +1,9 @@
# 'bin' options
-CFLAGS = -nostdlib -nostdinc -fno-builtin -O2
+CFLAGS = -nostdlib -nostdinc -fno-builtin
INCLUDES = -I../../include
-#LIBRARIES = ../../lib/libc_old/math/*.o ../../lib/libc_old/quad/*.o ../../lib/libc_old/stdio/*.o ../../lib/libc_old/stdlib/*.o ../../lib/libc_old/sys/*.o ../../lib/libc_old/string/*.o ../../lib/libc_old/locale/*.o ../../lib/libc_old/gen/*.o ../../lib/libc_old/generic/*.o ../../lib/libc_old/*/*.o
-
-LIBRARIES = ../../lib/libc_old/*/*.o
+LIBRARIES = ../../lib/libc_old/math/*.o ../../lib/libc_old/quad/*.o ../../lib/libc_old/stdio/*.o ../../lib/libc_old/stdlib/*.o ../../lib/libc_old/sys/*.o ../../lib/libc_old/string/*.o ../../lib/libc_old/locale/*.o ../../lib/libc_old/gen/*.o ../../lib/libc_old/generic/*.o
STARTUP = ../../lib/ubix/*.o
diff --git a/src/bin/cat/Makefile b/src/bin/cat/Makefile
old mode 100644
new mode 100755
index 5affcdf..3b37181
--- a/src/bin/cat/Makefile
+++ b/src/bin/cat/Makefile
@@ -15,20 +15,19 @@
REMOVE = rm -f
#Objects
-OBJS = cat.o
+OBJS = main.o
-INCLUDES = -I../../include.new
-
-LIBRARIES = ../../lib/libc/libc.so
-
-STARTUP = ../../lib/csu/*.o
+LIBRARIES = ../../lib/libc_old/libc_old.so
# Link The Binary
$(BINARY) : $(OBJS)
$(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- #strip $(BINARY)
+ strip $(BINARY)
# Compile the source files
+.cpp.o:
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
.cc.o:
$(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
diff --git a/src/bin/cat/cat b/src/bin/cat/cat
deleted file mode 100755
index 56da348..0000000
--- a/src/bin/cat/cat
+++ /dev/null
Binary files differ
diff --git a/src/bin/cat/cat.c b/src/bin/cat/cat.c
deleted file mode 100644
index 443b222..0000000
--- a/src/bin/cat/cat.c
+++ /dev/null
@@ -1,318 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Kevin Fall.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char const copyright[] =
-"@(#) Copyright (c) 1989, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-#endif
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
-#endif
-#endif /* not lint */
-#include
-__FBSDID("$FreeBSD: src/bin/cat/cat.c,v 1.32 2005/01/10 08:39:20 imp Exp $");
-
-#include
-#include
-#ifndef NO_UDOM_SUPPORT
-#include
-#include
-#include
-#endif
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-int bflag, eflag, nflag, sflag, tflag, vflag;
-int rval;
-const char *filename;
-
-static void usage(void);
-static void scanfiles(char *argv[], int cooked);
-static void cook_cat(FILE *);
-static void raw_cat(int);
-
-#ifndef NO_UDOM_SUPPORT
-static int udom_open(const char *path, int flags);
-#endif
-
-int
-main(int argc, char *argv[])
-{
- int ch;
-printf("argc: [%i]\n",argc);
- setlocale(LC_CTYPE, "");
-//printf("optind: [0x%X:%i]\n",&optind,optind);
- while ((ch = getopt(argc, argv, "benstuv")) != -1)
- switch (ch) {
- case 'b':
- bflag = nflag = 1; /* -b implies -n */
- break;
- case 'e':
- eflag = vflag = 1; /* -e implies -v */
- break;
- case 'n':
- nflag = 1;
- break;
- case 's':
- sflag = 1;
- break;
- case 't':
- tflag = vflag = 1; /* -t implies -v */
- break;
- case 'u':
- setbuf(stdout, NULL);
- break;
- case 'v':
- vflag = 1;
- break;
- default:
- usage();
- }
-//printf("optind: [%i]\n",optind);
-asm("nop");
- argv += optind;
-asm("nop");
-// printf("optind: [%i]",optind);
- if (bflag || eflag || nflag || sflag || tflag || vflag)
- scanfiles(argv, 1);
- else
- scanfiles(argv, 0);
- if (fclose(stdout))
- err(1, "stdout");
- exit(rval);
- /* NOTREACHED */
-}
-
-static void
-usage(void)
-{
- fprintf(stderr, "usage: cat [-benstuv] [file ...]\n");
- exit(1);
- /* NOTREACHED */
-}
-
-static void
-scanfiles(char *argv[], int cooked)
-{
- int i = 0;
- char *path;
- FILE *fp;
-
- while ((path = argv[i]) != NULL || i == 0) {
- int fd;
-
- if (path == NULL || strcmp(path, "-") == 0) {
- filename = "stdin";
- fd = STDIN_FILENO;
- } else {
- filename = path;
- fd = open(path, O_RDONLY);
-printf("A");
-#ifndef NO_UDOM_SUPPORT
- if (fd < 0 && errno == EOPNOTSUPP)
- fd = udom_open(path, O_RDONLY);
-#endif
- }
- if (fd < 0) {
- warn("%s", path);
- rval = 1;
- } else if (cooked) {
- if (fd == STDIN_FILENO)
- cook_cat(stdin);
- else {
- fp = fdopen(fd, "r");
- cook_cat(fp);
- fclose(fp);
- }
- } else {
- raw_cat(fd);
- if (fd != STDIN_FILENO)
- close(fd);
- }
- if (path == NULL)
- break;
- ++i;
- }
-}
-
-static void
-cook_cat(FILE *fp)
-{
- int ch, gobble, line, prev;
-
- /* Reset EOF condition on stdin. */
- if (fp == stdin && feof(stdin))
- clearerr(stdin);
-
- line = gobble = 0;
- for (prev = '\n'; (ch = getc(fp)) != EOF; prev = ch) {
- if (prev == '\n') {
- if (sflag) {
- if (ch == '\n') {
- if (gobble)
- continue;
- gobble = 1;
- } else
- gobble = 0;
- }
- if (nflag && (!bflag || ch != '\n')) {
- (void)fprintf(stdout, "%6d\t", ++line);
- if (ferror(stdout))
- break;
- }
- }
- if (ch == '\n') {
- if (eflag && putchar('$') == EOF)
- break;
- } else if (ch == '\t') {
- if (tflag) {
- if (putchar('^') == EOF || putchar('I') == EOF)
- break;
- continue;
- }
- } else if (vflag) {
- if (!isascii(ch) && !isprint(ch)) {
- if (putchar('M') == EOF || putchar('-') == EOF)
- break;
- ch = toascii(ch);
- }
- if (iscntrl(ch)) {
- if (putchar('^') == EOF ||
- putchar(ch == '\177' ? '?' :
- ch | 0100) == EOF)
- break;
- continue;
- }
- }
- if (putchar(ch) == EOF)
- break;
- }
- if (ferror(fp)) {
- warn("%s", filename);
- rval = 1;
- clearerr(fp);
- }
- if (ferror(stdout))
- err(1, "stdout");
-}
-
-static void
-raw_cat(int rfd)
-{
- int off, wfd;
- ssize_t nr, nw;
- static size_t bsize;
- static char *buf = NULL;
- struct stat sbuf;
-
- wfd = fileno(stdout);
- if (buf == NULL) {
- if (fstat(wfd, &sbuf))
- err(1, "%s", filename);
- bsize = MAX(sbuf.st_blksize, 1024);
- if ((buf = malloc(bsize)) == NULL)
- err(1, "buffer");
- }
- while ((nr = read(rfd, buf, bsize)) > 0)
- for (off = 0; nr; nr -= nw, off += nw)
- if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
- err(1, "stdout");
- if (nr < 0) {
- warn("%s", filename);
- rval = 1;
- }
-}
-
-#ifndef NO_UDOM_SUPPORT
-
-static int
-udom_open(const char *path, int flags)
-{
- struct sockaddr_un sou;
- int fd;
- unsigned int len;
-
- bzero(&sou, sizeof(sou));
-
- /*
- * Construct the unix domain socket address and attempt to connect
- */
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd >= 0) {
- sou.sun_family = AF_UNIX;
- if ((len = strlcpy(sou.sun_path, path,
- sizeof(sou.sun_path))) >= sizeof(sou.sun_path)) {
- errno = ENAMETOOLONG;
- return (-1);
- }
- len = offsetof(struct sockaddr_un, sun_path[len+1]);
-
- if (connect(fd, (void *)&sou, len) < 0) {
- close(fd);
- fd = -1;
- }
- }
-
- /*
- * handle the open flags by shutting down appropriate directions
- */
- if (fd >= 0) {
- switch(flags & O_ACCMODE) {
- case O_RDONLY:
- if (shutdown(fd, SHUT_WR) == -1)
- warn(NULL);
- break;
- case O_WRONLY:
- if (shutdown(fd, SHUT_RD) == -1)
- warn(NULL);
- break;
- default:
- break;
- }
- }
- return(fd);
-}
-
-#endif
diff --git a/src/bin/cat/main.c b/src/bin/cat/main.c
new file mode 100644
index 0000000..0ef45d9
--- /dev/null
+++ b/src/bin/cat/main.c
@@ -0,0 +1,30 @@
+#include
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2)
+ {
+ printf("Usage: %s \n", argv[0]);
+ return 1;
+ }
+ else
+ {
+ FILE *fd;
+ char buffer[4096];
+
+ fd = fopen(argv[1], "rb");
+ if(fd == NULL)
+ {
+ printf("Usage: %s \n", argv[0]);
+ return 1;
+ }
+ while(feof(fd) == 0)
+ {
+ fread(buffer, 4096, 1, fd);
+ printf("%s", buffer);
+ }
+ fclose(fd);
+
+ }
+ return 0;
+}
diff --git a/src/bin/clock/main.c b/src/bin/clock/main.c
index 45dcb2e..57f9fe6 100644
--- a/src/bin/clock/main.c
+++ b/src/bin/clock/main.c
@@ -38,7 +38,6 @@
#define HOUR (60*MINUTE)
#define DAY (24*HOUR)
#define YEAR (365*DAY)
-extern const char *__progname;
static int monthSecs[12] = {
@@ -91,10 +90,7 @@
sysTime -= (min*MINUTE);
sec = sysTime;
- printf("[%s][%02d/%02d/%i, %02d:%02d.%02d]\n",argv[0],month,day,year,hour,min,sec);
- for (i = 0x0;i < argc;i++) {
- printf("argv[%i](0x%X:%s),__progrname(%s), argc: %i\n",i,argv[i],argv[i],__progname,argc);
- }
+ printf("[%02d/%02d/%i, %02d:%02d.%02d]\n",month,day,year,hour,min,sec);
return(0);
}
diff --git a/src/bin/cp/main.c b/src/bin/cp/main.c
index fddae81..f04e3f6 100644
--- a/src/bin/cp/main.c
+++ b/src/bin/cp/main.c
@@ -29,36 +29,48 @@
#include
#include
+//#include
-int main(int argc,char **argv) {
- int i = 0x0;
- char *buffer = (char *)malloc(0x2000);
- FILE *in = 0x0;
- FILE *out = 0x0;
- in = fopen(argv[1],"rb");
- out = fopen(argv[2],"wb");
- /*
- while (!feof(in)) {
- */
- for (i=0;i<21;i++) {
- fread(buffer,0x1000,1,in);
- fwrite(buffer,0x1000,1,out);
- }
- fclose(in);
- fclose(out);
- return(0x0);
- }
+int main(int argc,char **argv)
+{
+ int i = 0x0, z = 0x0;
+ char *buffer = (char *)malloc(4096);
+ FILE *in = 0x0;
+ FILE *out = 0x0;
+
+ //printf("fsqrt(4) = %f\n", fsqrt(4));
+
+ if(argc != 3)
+ {
+ printf("usage: cp \n");
+ return 0;
+ }
+
+ in = fopen(argv[1],"rb");
+ out = fopen(argv[2],"wb");
+
+ if(in == NULL || out == NULL)
+ {
+ printf("unable to open file(s) for i/o\n");
+ return 1;
+ }
+ while (!feof(in))
+ {
+ i = fread(buffer,4096,1,in);
+ z = fwrite(buffer,4096,1,out);
+ }
+ if(i != z)
+ printf("Out of disk space\n");
+ fclose(in);
+ fclose(out);
+ return(0x0);
+}
/***
$Log$
- Revision 1.1.1.1 2006/06/01 12:46:09 reddawg
- ubix2
+ Revision 1.4 2005/08/05 09:43:57 fsdfs
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:13:57 reddawg
- no message
+ code clean up, performance tuning
Revision 1.3 2004/05/24 13:40:35 reddawg
Clean Up
diff --git a/src/bin/disklabel/Makefile b/src/bin/disklabel/Makefile
deleted file mode 100644
index 427a0c3..0000000
--- a/src/bin/disklabel/Makefile
+++ /dev/null
@@ -1,45 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-#Linker
-LD = ld
-
-#Binary File Name
-BINARY = disklabel
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = main.o
-
-LIBRARIES = ../../lib/libc_old/libc_old.so
-
-# Link The Binary
-$(BINARY) : $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- strip $(BINARY)
-
-# Compile the source files
-.cc.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/disklabel/main.c b/src/bin/disklabel/main.c
deleted file mode 100644
index d79c52c..0000000
--- a/src/bin/disklabel/main.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*****************************************************************************************
- Copyright (c) 2002-2004 The UbixOS Project
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification, are
- permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this list of
- conditions, the following disclaimer and the list of authors. Redistributions in binary
- form must reproduce the above copyright notice, this list of conditions, the following
- disclaimer and the list of authors in the documentation and/or other materials provided
- with the distribution. Neither the name of the UbixOS Project nor the names of its
- contributors may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- $Id$
-
-*****************************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-
-#include "ubixfs.h"
-
-
-int main(int argc,char **argv) {
- FILE *fd;
- struct ubixDiskLabel *d = (struct ubixDiskLabel *)malloc(512);
- int i = 0x0;
- char buf[256];
-
- printf("Ubix Disk Label Editor Version 1.0\n");
- printf("(c) 2004 Ubix Corp \n\n");
-
- if (argc >= 2) {
- printf("Drive Info (%s):\n",argv[1]);
- fd = fopen(argv[1],"rb");
- }
- else {
- printf("Drive Info (hd0):\n");
- fd = fopen("hd0@devfs","rb");
- }
- fseek(fd,512,0);
- fread(d,512,1,fd);
-
- if (argc >= 3) {
- i = atoi(argv[2]);
- printf("d->partitions[%i].p_size = %i, ",i,d->partitions[i].p_size);
- printf("New Value: ");
- gets((char *)&buf);
- d->partitions[i].p_size = atoi(buf);
- printf("d->partitions[%i].p_offset = %i, ",i,d->partitions[i].p_offset);
- printf("New Value: ");
- gets((char *)&buf);
- d->partitions[i].p_offset = atoi(buf);
- printf("d->partitions[%i].p_fstype = %i, ",i,d->partitions[i].p_fstype);
- printf("New Value: ");
- gets((char *)&buf);
- d->partitions[i].p_fstype = atoi(buf);
- printf("d->partitions[%i].p_bsize = %i, ",i,d->partitions[i].p_bsize);
- printf("New Value: ");
- gets((char *)&buf);
- d->partitions[i].p_bsize = atoi(buf);
- printf("\n");
- printf("d->partitions[%i].p_size = %i\n",i,d->partitions[i].p_size);
- printf("d->partitions[%i].p_offset = %i\n",i,d->partitions[i].p_offset);
- printf("d->partitions[%i].p_fstype = %i\n",i,d->partitions[i].p_fstype);
- printf("d->partitions[%i].p_bsize = %i\n",i,d->partitions[i].p_bsize);
- fseek(fd,512,0);
- fwrite(d,512,1,fd);
- }
- else {
- for (i=0;i<4;i++) {
- if (d->partitions[i].p_fstype != 0x0) {
- printf("d->partitions[%i].p_size = %i\n",i,d->partitions[i].p_size);
- printf("d->partitions[%i].p_offset = %i\n",i,d->partitions[i].p_offset);
- printf("d->partitions[%i].p_fstype = 0x%X\n",i,d->partitions[i].p_fstype);
- printf("d->partitions[%i].p_bsize = 0x%X\n",i,d->partitions[i].p_bsize);
- }
- }
- }
-
- fclose(fd);
-
- return(0);
- }
-
-/***
- $Log$
- Revision 1.1.1.1 2006/06/01 12:46:09 reddawg
- ubix2
-
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:13:58 reddawg
- no message
-
- Revision 1.3 2004/06/01 01:30:43 reddawg
- No more warnings and organized make files
-
- Revision 1.2 2004/05/24 13:42:29 reddawg
- Clean Up
-
-
- END
- ***/
diff --git a/src/bin/disklabel/ubixfs.h b/src/bin/disklabel/ubixfs.h
deleted file mode 100644
index d19f452..0000000
--- a/src/bin/disklabel/ubixfs.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*****************************************************************************************
- Copyright (c) 2002-2004 The UbixOS Project
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification, are
- permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this list of
- conditions, the following disclaimer and the list of authors. Redistributions in binary
- form must reproduce the above copyright notice, this list of conditions, the following
- disclaimer and the list of authors in the documentation and/or other materials provided
- with the distribution. Neither the name of the UbixOS Project nor the names of its
- contributors may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- $Id$
-
-*****************************************************************************************/
-
-#include
-
-#define DOSPTYP_UBX 0x2A /* UbixFS partition type */
-#define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */
-#define MAXUBIXPARTITIONS 16
-#define UBIXFSMAGIC ((uInt32)0x69) /* The File System Magic Number */
-
-struct ubixDiskLabel {
- uInt32 magicNum;
- uInt32 magicNum2;
- uInt16 driveType;
- uInt16 numPartitions;
- struct ubixPartitions { /* the partition table */
- uInt32 p_size; /* number of sectors in partition */
- uInt32 p_offset; /* starting sector */
- uInt32 p_fsize; /* filesystem basic fragment size */
- uInt32 p_bsize; /* BAT size */
- uInt8 p_fstype; /* filesystem type, see below */
- uInt8 p_frag; /* filesystem fragments per block */
- } partitions[MAXUBIXPARTITIONS];
- };
-
-//Block Allocation Table Entry
-struct blockAllocationTableEntry {
- long attributes; //Block Attributes
- long realSector; //Real Sector
- long nextBlock; //Sector Of Next Block
- long reserved; //Reserved
- };
-
-
-struct directoryEntry {
- uInt32 startCluster; //Starting Cluster Of File
- uInt32 size; //Size Of File
- uInt32 creationDate; //Date Created
- uInt32 lastModified; //Date Last Modified
- uInt32 uid; //UID Of Owner
- uInt32 gid; //GID Of Owner
- uInt16 attributes; //Files Attributes
- uInt16 permissions; //Files Permissions
- char fileName[256]; //File Name
- };
-
-/***
- $Log$
- Revision 1.2 2006/10/26 23:52:26 reddawg
- Fixens
-
- Revision 1.1.1.1 2006/06/01 12:46:09 reddawg
- ubix2
-
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:13:59 reddawg
- no message
-
- Revision 1.2 2004/05/24 13:54:52 reddawg
- Clean Up
-
-
- END
- ***/
diff --git a/src/bin/edit/Makefile b/src/bin/edit/Makefile
index 0664542..190abb4 100644
--- a/src/bin/edit/Makefile
+++ b/src/bin/edit/Makefile
@@ -9,7 +9,7 @@
LD = ld
#Binary File Name
-BINARY = edit
+BINARY = init
#Delete Program
REMOVE = rm -f
@@ -17,13 +17,7 @@
#Objects
OBJS = main.o
-INCLUDES = -I../../include.new
-
-LIBRARIES = ../../lib/libc/libc.so
-
-STARTUP = ../../lib/csu/*.o
-
-CFLAGS += -ggdb
+LIBRARIES = ../../lib/libc_old/libc_old.so
# Link The Binary
$(BINARY) : $(OBJS)
@@ -38,7 +32,7 @@
$(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
.c.o:
- $(CC) -Wall -O -ggdb $(CFLAGS) $(INCLUDES) -c -o $@ $<
+ $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
.c.s:
$(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
diff --git a/src/bin/edit/main.c b/src/bin/edit/main.c
index e79c04d..f026e6e 100644
--- a/src/bin/edit/main.c
+++ b/src/bin/edit/main.c
@@ -28,51 +28,13 @@
*****************************************************************************************/
#include
-#include
int main(int argc,char **argv) {
- char *a,*b;
- FILE *out;
- char buf[8192];
- int fd;
- int len = -1;
printf("UbixOS Text Editor\n");
- printf("V1.0\n");
-
- //out = fopen("/test.txt","r");
-
- if (argc > 1)
- fd = open(argv[1]);
- else
- fd = open("/usr/include/stdio.h");
-
- printf("FD: %i\n",fd);
-
- //while (!feof(out)) {
- while (len != 0) {
- len = read(fd,&buf,8192);
- printf("[%i](%c%c%c%c)\n",len,buf[0],buf[1],buf[2],buf[3]);
- //printf("%c",fgetc(out));
- }
-
- //fclose(out);
-
- printf("argc: [%i]\n",argc);
-
- a = malloc(512);
- b = malloc(512);
-
- printf("[0x%X]\n",a);
- printf("[0x%X]\n",b);
- free(a);
- a = malloc(512);
- printf("[0x%X]\n",a);
- putchar('A');
-
return(0);
}
/***
+ $Log$
END
***/
-
diff --git a/src/bin/fdisk/Makefile b/src/bin/fdisk/Makefile
deleted file mode 100644
index 0f7b18c..0000000
--- a/src/bin/fdisk/Makefile
+++ /dev/null
@@ -1,45 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-#Linker
-LD = ld
-
-#Binary File Name
-BINARY = fdisk
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = main.o
-
-LIBRARIES = ../../lib/libc_old/libc_old.so
-
-# Link The Binary
-$(BINARY) : $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- strip $(BINARY)
-
-# Compile the source files
-.cc.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/fdisk/main.c b/src/bin/fdisk/main.c
deleted file mode 100644
index 5db9701..0000000
--- a/src/bin/fdisk/main.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/*****************************************************************************************
- Copyright (c) 2002-2004 The UbixOS Project
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification, are
- permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this list of
- conditions, the following disclaimer and the list of authors. Redistributions in binary
- form must reproduce the above copyright notice, this list of conditions, the following
- disclaimer and the list of authors in the documentation and/or other materials provided
- with the distribution. Neither the name of the UbixOS Project nor the names of its
- contributors may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- $Id$
-
-*****************************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-
-#include "ubixfs.h"
-
-struct dos_partition {
- unsigned char dp_flag; /* bootstrap flags */
- unsigned char dp_shd; /* starting head */
- unsigned char dp_ssect; /* starting sector */
- unsigned char dp_scyl; /* starting cylinder */
- unsigned char dp_type; /* partition type */
- unsigned char dp_ehd; /* end head */
- unsigned char dp_esect; /* end sector */
- unsigned char dp_ecyl; /* end cylinder */
- uInt32 dp_start; /* absolute starting sector number */
- uInt32 dp_size; /* partition size in sectors */
-};
-
-
-int main(int argc,char **argv) {
- FILE *fd;
- FILE *mbr;
- struct dos_partition *d = 0x0;
- char *data = (char *)malloc(512);
- int i = 0x0;
- char buf[256];
-
- d = (struct dos_partition *)(data + 0x1BE);
-
- printf("Ubix Disk Editor Version 1.0\n");
- printf("(c) 2004 Ubix Corp \n\n");
-
- if (argc >= 2) {
- printf("Drive Info (%s):\n",argv[1]);
- fd = fopen(argv[1],"rb");
- }
- else {
- printf("Drive Info (ad0):\n");
- fd = fopen("devfs:ad0","rb");
- }
- if (fd->size == 0x0) {
- printf("Invalid Device\n");
- exit(0x1);
- }
-
- fseek(fd,0,0);
- fread(data,512,1,fd);
-
- if (argc >= 3) {
- i = atoi(argv[2]);
- if (i == 0) {
- mbr = fopen("sys:mrb","rb");
- fseek(mbr,0,0);
- fread(data,512,1,mbr);
- printf("Installing Ubix MBR\n");
- }
- else {
- i--;
- printf("d[%i].dp_type = %i, ",i,d[i].dp_type);
- printf("New Value: ");
- gets((char *)&buf);
- d[i].dp_type = atoi(buf);
- printf("d[%i].dp_start: %i, ",i,d[i].dp_start);
- printf("New Value: ");
- gets((char *)&buf);
- d[i].dp_start = atoi(buf);
- printf("d[%i].dp_size: %i, ",i,d[i].dp_size);
- printf("New Value: ");
- gets((char *)&buf);
- d[i].dp_size = atoi(buf);
- printf("d[%i].dp_type: 0x%X\n",i,d[i].dp_type);
- printf("d[%i].dp_start: %i\n",i,d[i].dp_start);
- printf("d[%i].dp_size: %i\n",i,d[i].dp_size);
- }
- fseek(fd,0,0);
- fwrite(data,512,1,fd);
- }
- else {
- printf("Partition Table:\n");
- for (i=0;i<4;i++) {
- if (d[i].dp_type != 0x0) {
- printf("d[%i].dp_type: 0x%X\n",i,d[i].dp_type);
- printf("d[%i].dp_start: %i\n",i,d[i].dp_start);
- printf("d[%i].dp_size: %i\n",i,d[i].dp_size);
- }
- }
- }
-
- fclose(fd);
-
- return(0);
- }
-
-/***
- $Log$
- Revision 1.2 2006/10/12 15:00:26 reddawg
- More changes
-
- Revision 1.1.1.1 2006/06/01 12:46:09 reddawg
- ubix2
-
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:13:58 reddawg
- no message
-
- Revision 1.9 2004/08/15 00:33:02 reddawg
- Wow the ide driver works again
-
- Revision 1.8 2004/06/01 01:30:43 reddawg
- No more warnings and organized make files
-
- Revision 1.7 2004/05/24 13:54:52 reddawg
- Clean Up
-
-
- END
- ***/
diff --git a/src/bin/fdisk/ubixfs.h b/src/bin/fdisk/ubixfs.h
deleted file mode 100644
index d19f452..0000000
--- a/src/bin/fdisk/ubixfs.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*****************************************************************************************
- Copyright (c) 2002-2004 The UbixOS Project
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification, are
- permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this list of
- conditions, the following disclaimer and the list of authors. Redistributions in binary
- form must reproduce the above copyright notice, this list of conditions, the following
- disclaimer and the list of authors in the documentation and/or other materials provided
- with the distribution. Neither the name of the UbixOS Project nor the names of its
- contributors may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- $Id$
-
-*****************************************************************************************/
-
-#include
-
-#define DOSPTYP_UBX 0x2A /* UbixFS partition type */
-#define UBIXDISKMAGIC ((uInt32)0x45) /* The disk magic number */
-#define MAXUBIXPARTITIONS 16
-#define UBIXFSMAGIC ((uInt32)0x69) /* The File System Magic Number */
-
-struct ubixDiskLabel {
- uInt32 magicNum;
- uInt32 magicNum2;
- uInt16 driveType;
- uInt16 numPartitions;
- struct ubixPartitions { /* the partition table */
- uInt32 p_size; /* number of sectors in partition */
- uInt32 p_offset; /* starting sector */
- uInt32 p_fsize; /* filesystem basic fragment size */
- uInt32 p_bsize; /* BAT size */
- uInt8 p_fstype; /* filesystem type, see below */
- uInt8 p_frag; /* filesystem fragments per block */
- } partitions[MAXUBIXPARTITIONS];
- };
-
-//Block Allocation Table Entry
-struct blockAllocationTableEntry {
- long attributes; //Block Attributes
- long realSector; //Real Sector
- long nextBlock; //Sector Of Next Block
- long reserved; //Reserved
- };
-
-
-struct directoryEntry {
- uInt32 startCluster; //Starting Cluster Of File
- uInt32 size; //Size Of File
- uInt32 creationDate; //Date Created
- uInt32 lastModified; //Date Last Modified
- uInt32 uid; //UID Of Owner
- uInt32 gid; //GID Of Owner
- uInt16 attributes; //Files Attributes
- uInt16 permissions; //Files Permissions
- char fileName[256]; //File Name
- };
-
-/***
- $Log$
- Revision 1.2 2006/10/26 23:52:26 reddawg
- Fixens
-
- Revision 1.1.1.1 2006/06/01 12:46:09 reddawg
- ubix2
-
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:13:59 reddawg
- no message
-
- Revision 1.2 2004/05/24 13:54:52 reddawg
- Clean Up
-
-
- END
- ***/
diff --git a/src/bin/format/Makefile b/src/bin/format/Makefile
deleted file mode 100644
index f27ed98..0000000
--- a/src/bin/format/Makefile
+++ /dev/null
@@ -1,45 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-#Linker
-LD = ld
-
-#Binary File Name
-BINARY = format
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = main.o
-
-LIBRARIIES = ../../lib/libc/libc.so
-
-# Link The Binary
-$(BINARY) : $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- strip $(BINARY)
-
-# Compile the source files
-.cc.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/format/main.c b/src/bin/format/main.c
deleted file mode 100644
index b147a23..0000000
--- a/src/bin/format/main.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*****************************************************************************************
- Copyright (c) 2002-2004 The UbixOS Project
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without modification, are
- permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this list of
- conditions, the following disclaimer and the list of authors. Redistributions in binary
- form must reproduce the above copyright notice, this list of conditions, the following
- disclaimer and the list of authors in the documentation and/or other materials provided
- with the distribution. Neither the name of the UbixOS Project nor the names of its
- contributors may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
- THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
- TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- $Id$
-
-*****************************************************************************************/
-
-#include
-#include
-#include
-#include
-#include
-
-
-int main(int argc,char **argv) {
- printf("UbixOS Format V1.0\n");
- return(0);
- }
-
-/***
- $Log$
- Revision 1.1.1.1 2006/06/01 12:46:08 reddawg
- ubix2
-
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:13:59 reddawg
- no message
-
- Revision 1.4 2004/06/01 01:30:43 reddawg
- No more warnings and organized make files
-
- Revision 1.3 2004/05/24 14:09:20 reddawg
- Clean Up
-
-
- END
- ***/
diff --git a/src/bin/init/main.c b/src/bin/init/main.c
index 56f6863..080ae17 100644
--- a/src/bin/init/main.c
+++ b/src/bin/init/main.c
@@ -1,5 +1,5 @@
/*****************************************************************************************
- Copyright (c) 2002-2004,2007,2008, 2012 The UbixOS Project
+ Copyright (c) 2002-2004 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
@@ -32,19 +32,9 @@
#include
#include
#include
-#include
int main(int argc,char **argv) {
int i=0x0;
- mpi_message_t myMsg;
-
- printf("A");
-
- /* Create a mailbox for this task */
- if (mpi_createMbox("init") != 0x0) {
- printf("Error: Failed to creating mail box: init\n");
- exit(0x1);
- }
/* Make sure we have superuser permissions if not exit */
if ((getuid() != 0x0) && (getgid() != 0x0)) {
@@ -52,69 +42,131 @@
exit(0x1);
}
- printf("Initializing uBixOS\n");
+ printf("INIT: Loading System Processes and configuration\n");
-#if 0
/* Start TTYD */
- i = fork();
+ //i = fork();
- if (0x0 == i) {
- exec("sys:/ttyd",0x0);
- printf("Error: Could not start TTYD\n");
- exit(0x0);
- }
+ //if (0x0 == i) {
+ // printf("ttyd: Starting ... ");
+ // exec("sys:/ttyd",0x0,0x0);
+ // printf("OK\n");
+ // printf("Error: Could not start TTYD\n");
+ // exit(0x0);
- while (pidStatus(i) > 0x0)
- sched_yield();
-#endif
-
-#if 0
- i = fork();
- if (0x0 == i) {
- printf("Starting Ubix Registry (ubistry)\n");
- exec("sys:/ubistry",0x0);
- printf("Error: Error Starting ubistry\n");
- exit(0x0);
- }
- while (pidStatus(i) > 0x0) {
- sched_yield();
- }
-#endif
+ //i = fork();
+ //if (0x0 == i) {
+ printf("ubistry: Starting ... ");
+ exec("sys:/ubistry",0x0,0x0);
+ printf("OK\n");
+ //printf("Error: Error Starting ubistry\n");
+ // exit(0x0);
+ // }
+
+ //while (pidStatus(i) > 0x0) {
+ // sched_yield();
+ // }
startup:
- i = fork();
+ //i = fork();
+ //if (0 == i) {
+ printf("Starting Login Daemon... ");
+ exec("sys:/login",0x0,0x0);
+ printf("OK\n");
+ // printf("Error Starting System\n");
+ // exit(0x0);
+ // }
- if (0 == i) {
- printf("Starting Login Daemon.\n");
- exec("sys:/bin/login",0x0,0x0);
- printf("Error Starting System\n");
- exit(0x0);
- }
-
- while (pidStatus(i) > 0x0) {
- fetchAgain:
- if (mpi_fetchMessage("init",&myMsg) == 0x0) {
- switch (myMsg.header) {
- case 10:
- printf("Exec: (%s)\n",myMsg.data);
- break;
- default:
- printf("MailBox: init Received Message %i:%s\n",myMsg.header,myMsg.data);
- break;
- }
- goto fetchAgain;
- }
- sched_yield();
- }
-
- printf("Error: login exited!");
-
- goto startup;
-
+
return(0x0);
}
/***
+ $Log$
+ Revision 1.27 2004/09/11 12:26:07 reddawg
+ We now initialize all needed daemons
+
+ Revision 1.26 2004/09/11 12:11:11 reddawg
+ Cleaning up the VFS more changes to follow...
+
+ Revision 1.25 2004/09/08 23:19:58 reddawg
+ hmm
+
+ Revision 1.24 2004/08/25 22:02:41 reddawg
+ task switching - We now are using software switching to be consistant with the rest of the world because all of this open source freaks gave me a hard time about something I liked. There doesn't seem to be any gain in performance but it is working fine and flawlessly
+
+ Revision 1.23 2004/08/24 23:33:45 reddawg
+ Fixed
+
+ Revision 1.22 2004/08/24 05:24:36 reddawg
+ TCA Is A BONER!!!!
+
+ Revision 1.21 2004/08/21 23:47:50 reddawg
+ *** empty log message ***
+
+ Revision 1.20 2004/08/21 20:21:20 reddawg
+ *** empty log message ***
+
+ Revision 1.19 2004/08/14 11:29:42 reddawg
+ ok
+
+ Revision 1.17 2004/08/14 11:23:02 reddawg
+ Changes
+
+ Revision 1.16 2004/08/01 20:47:59 reddawg
+ Minor changes
+
+ Revision 1.15 2004/07/28 17:07:25 reddawg
+ MPI: moved the syscalls
+
+ Revision 1.14 2004/07/28 00:17:05 reddawg
+ Major:
+ Disconnected page 0x0 from the system... Unfortunately this broke many things
+ all of which have been fixed. This was good because nothing deferences NULL
+ any more.
+
+ Things affected:
+ malloc,kmalloc,getfreepage,getfreevirtualpage,pagefault,fork,exec,ld,ld.so,exec,file
+
+ Revision 1.13 2004/07/17 18:16:45 reddawg
+ Hmm
+
+ Revision 1.12 2004/06/28 23:12:59 reddawg
+ file format now container:/path/to/file
+
+ Revision 1.11 2004/06/04 13:29:56 reddawg
+ libc: modified mkdir(); interface
+ kpanic: kPanic(); now says kPanic: %s
+ system: now reboots when receives message for reboot
+ also when command start sde is received by system the STD is started
+
+ Revision 1.10 2004/05/26 13:11:41 reddawg
+ Makefile: adjust all the Makefile to strip binaries to conserve floppy space
+
+ Revision 1.9 2004/05/26 12:19:19 reddawg
+ init: init now starts the ubix registry system
+
+ Revision 1.8 2004/05/25 22:44:59 reddawg
+ Test code
+
+ Revision 1.7 2004/05/25 22:32:58 reddawg
+ We turned back on GUI
+
+ Revision 1.6 2004/05/25 18:38:00 reddawg
+ The system INIT task now responds to messages it is the root process for the OS
+
+ Revision 1.5 2004/05/25 15:43:44 reddawg
+ Tests for MPI
+
+ Revision 1.4 2004/05/23 23:40:37 reddawg
+ Cleanup
+
+ Revision 1.3 2004/05/21 21:15:56 reddawg
+ Cleaned up initialized program
+
+ Revision 1.2 2004/05/21 15:43:58 reddawg
+ Fixed the the bootup ordering in userland initialization
+
END
***/
diff --git a/src/bin/ld/Makefile b/src/bin/ld/Makefile
index e77cfb3..8038f81 100644
--- a/src/bin/ld/Makefile
+++ b/src/bin/ld/Makefile
@@ -8,8 +8,6 @@
#Linker
LD = ld
-CFLAGS = -Wall -nostdlib -nostdinc -fno-builtin -O -fpic
-
#Binary File Name
OUTPUT = ld.so
@@ -21,21 +19,21 @@
# Link The Binary
$(OUTPUT) : $(OBJS)
- $(CC) -O -fpic -nostdlib -shared -Wl,-soname,$(OUTPUT) -e _ld -o $(OUTPUT) $(OBJS) $(LIBRARIES) $(SUBS)
+ $(CC) -nostdlib -shared -Wl,-soname,$(OUTPUT) -e _ld -o $(OUTPUT) $(OBJS) $(LIBRARIES) $(SUBS)
# strip $(OUTPUT)
# Compile the source files
.cpp.o:
- $(CXX) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $<
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
.cc.o:
- $(CXX) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $<
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
.cc.s:
- $(CXX) -Wall $(CFLAGS) $(INCLUDES) -S -o $@ $<
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
.c.o:
- $(CC) -Wall $(CFLAGS) $(INCLUDES) -c -o $@ $<
+ $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
.c.s:
$(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
diff --git a/src/bin/ld/addlibrary.c b/src/bin/ld/addlibrary.c
index 7b652cd..71eec3b 100644
--- a/src/bin/ld/addlibrary.c
+++ b/src/bin/ld/addlibrary.c
@@ -7,37 +7,28 @@
int x = 0x0;
int rel = 0x0;
uInt32 *reMap = 0x0;
- uInt32 *funcPtr = 0x0;
char *newLoc = 0x0;
FILE *linkerFd = 0x0;
- char tmpFile[1024];
ldLibrary *tmpLib = 0x0;
if ((tmpLib = (ldLibrary *)malloc(sizeof(ldLibrary))) == 0x0) {
printf("malloc failed: tmpLib\n");
exit(0x1);
}
+
if (tmpLib->output == 0x0) {
- /* Hack because we have no ld path set */
- sprintf(tmpFile,"sys:/lib/%s",lib);
- printf("tmpFile: [%s]\n",tmpFile);
- linkerFd = fopen(tmpFile,"rb");
+ linkerFd = fopen(lib,"rb");
if (linkerFd->fd == 0x0) {
printf("Could not open library: %s\n",lib);
exit(-1);
}
- //if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) {
- //if ((tmpLib->output = (char *)malloc(0x111000)) == 0x0) {
-//HELP FOOKIN SIZE NEED
- if ((tmpLib->output = (char *)getPage((0x0FF000/0x1000),2)) == 0x0) {
+ if ((tmpLib->output = (char *)malloc((linkerFd->size+0x4000))) == 0x0) {
printf("malloc failed: tmpLib->output\n");
exit(0x1);
}
sprintf(tmpLib->name,lib);
}
- #ifdef DEBUG
- printf("Base: {0x%X}\n",tmpLib->output);
- #endif
+
if (tmpLib->linkerHeader == 0x0) {
fseek(linkerFd,0x0,0x0);
if ((tmpLib->linkerHeader = (elfHeader *)malloc(sizeof(elfHeader))) == 0x0) {
@@ -46,6 +37,7 @@
}
fread(tmpLib->linkerHeader,sizeof(elfHeader),1,linkerFd);
}
+
if (tmpLib->linkerProgramHeader == 0x0) {
if ((tmpLib->linkerProgramHeader = (elfProgramHeader *)malloc(sizeof(elfProgramHeader)*tmpLib->linkerHeader->ePhnum)) == 0x0) {
printf("malloc failed: tmpLib->linkerProgramHeader\n");
@@ -65,14 +57,13 @@
case PT_GNU_STACK:
/* Tells us if the stack should be executable. Failsafe to
executable until we add checking */
- printf("NOT DEF1\n");
break;
case PT_PAX_FLAGS:
/* Not sure... */
- printf("NOT DEF2\n");
break;
default:
- printf("Unhandled Header (ld.so) : %08x\n", tmpLib->linkerProgramHeader[i].phType);
+ printf("Unhandled Header : %08x\n",
+ tmpLib->linkerProgramHeader[i].phType);
break;
}
}
@@ -92,7 +83,7 @@
fread(tmpLib->linkerShStr,tmpLib->linkerSectionHeader[tmpLib->linkerHeader->eShstrndx].shSize,1,linkerFd);
}
- for (i = 0x0;i < tmpLib->linkerHeader->eShnum;i++) {
+ for (i=0x0;ilinkerHeader->eShnum;i++) {
switch (tmpLib->linkerSectionHeader[i].shType) {
case 3:
if (!strcmp((tmpLib->linkerShStr + tmpLib->linkerSectionHeader[i].shName),".dynstr")) {
@@ -127,16 +118,8 @@
case R_386_RELATIVE:
*reMap += (uInt32)tmpLib->output;
break;
- case R_386_JMP_SLOT:
- *reMap = ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue);
- //*reMap += (uInt32)tmpLib->output;
- break;
- case R_386_GLOB_DAT:
- *reMap = ((uInt32)tmpLib->output + tmpLib->linkerRelSymTab[rel].dynValue);
- break;
default:
- printf("Unhandled sym: [0x%X]\n", ELF32_R_TYPE(tmpLib->linkerElfRel[x].pltInfo));
- while (1);
+ printf("Unhandled sym\n");
break;
}
}
@@ -153,37 +136,6 @@
}
}
}
-//printf("Looking For Environ: [%i]\n\n",tmpLib->linkerSectionHeader[tmpLib->sym].shSize/sizeof(elfDynSym));
- /* Sync environ __progname */
- for (i=0x0;ilinkerSectionHeader[tmpLib->sym].shSize/sizeof(elfDynSym);i++) {
- if (!strcmp("environ",(tmpLib->linkerDynStr + tmpLib->linkerRelSymTab[i].dynName))) {
- funcPtr = (uInt32 *)((uInt32)(tmpLib->linkerRelSymTab[i].dynValue) + (uInt32)tmpLib->output);
- //printf("[envion:0x%X:0x%X]\n",funcPtr,*funcPtr);
- for (x = 0x0;x < binarySectionHeader[binarySym].shSize/sizeof(elfDynSym);x++) {
- if (!strcmp("environ",(binaryDynStr + binaryRelSymTab[x].dynName))) {
- *funcPtr = (uInt32 *)((uInt32)(binaryRelSymTab[x].dynValue));// + (uInt32)tmpLib->output);
- //printf("[envion:0x%X:0x%X]\n",funcPtr,*funcPtr);
- }
- }
- //break;
- }
- }
-
-//printf("Looking For __progname: [%i]\n\n",tmpLib->linkerSectionHeader[tmpLib->sym].shSize/sizeof(elfDynSym));
- /* Sync environ __progname */
- for (i=0x0;ilinkerSectionHeader[tmpLib->sym].shSize/sizeof(elfDynSym);i++) {
- if (!strcmp("__progname",(tmpLib->linkerDynStr + tmpLib->linkerRelSymTab[i].dynName))) {
- funcPtr = (uInt32 *)((uInt32)(tmpLib->linkerRelSymTab[i].dynValue) + (uInt32)tmpLib->output);
- //printf("[__progname:0x%X:0x%X]\n",funcPtr,*funcPtr);
- for (x = 0x0;x < binarySectionHeader[binarySym].shSize/sizeof(elfDynSym);x++) {
- if (!strcmp("__progname",(binaryDynStr + binaryRelSymTab[x].dynName))) {
- *funcPtr = (uInt32 *)((uInt32)(binaryRelSymTab[x].dynValue));// + (uInt32)tmpLib->output);
- //printf("[__progname:0x%X:0x%X]\n",funcPtr,*funcPtr);
- }
- }
- //break;
- }
- }
if (libs != 0x0)
libs->prev = tmpLib;
@@ -194,5 +146,6 @@
if (linkerFd) {
fclose(linkerFd);
}
+
return(tmpLib);
}
diff --git a/src/bin/ld/elf.h b/src/bin/ld/elf.h
index 1499bf1..919bf80 100644
--- a/src/bin/ld/elf.h
+++ b/src/bin/ld/elf.h
@@ -146,7 +146,6 @@
uInt32 dynPtr;
} elfDynamic;
-
char *elfGetShType(int);
char *elfGetPhType(int);
char *elfGetRelType(int);
@@ -155,32 +154,5 @@
#define ELF32_R_TYPE(i) ((unsigned char)(i))
#define ELF32_R_INFO(s, t) ((s)<<8+(unsigned char)(t))
-/* New Stuff */
-#define SHT_NULL 0
-#define SHT_PROGBITS 1
-#define SHT_SYMTAB 2
-#define SHT_STRTAB 3
-#define SHT_RELA 4
-#define SHT_HASH 5
-#define SHT_DYNAMIC 6
-#define SHT_NOTE 7
-#define SHT_NOBITS 8
-#define SHT_REL 9
-#define SHT_SHLIB 10
-#define SHT_DYNSYM 11
-#define SHT_LOPROC 0x70000000
-#define SHT_HIPROC 0x7fffffff
-#define SHT_LOUSER 0x80000000
-#define SHT_HIUSER 0xffffffff
-
-typedef struct {
- long d_tag;
- union {
- uInt32 d_val;
- uInt32 d_ptr;
- } d_un;
- } Elf32_Dyn;
-
-
#endif
diff --git a/src/bin/ld/entry.S b/src/bin/ld/entry.S
index eace1a2..6dd34e6 100644
--- a/src/bin/ld/entry.S
+++ b/src/bin/ld/entry.S
@@ -39,19 +39,6 @@
/***
$Log$
- Revision 1.1.1.1 2006/06/01 12:46:09 reddawg
- ubix2
-
- Revision 1.2 2005/10/12 00:13:28 reddawg
- Removed
-
- Revision 1.1.1.1 2005/09/26 17:14:00 reddawg
- no message
-
- Revision 1.1 2004/06/17 11:58:10 reddawg
- ld.so: Made a few changes to the way it functions hopefully it will
- improve some of its performance.
-
END
***/
diff --git a/src/bin/ld/findfunc.c b/src/bin/ld/findfunc.c
index 4b1f1db..74794ee 100644
--- a/src/bin/ld/findfunc.c
+++ b/src/bin/ld/findfunc.c
@@ -4,34 +4,21 @@
uInt32 ldFindFunc(const char *func,const char *lib) {
int i = 0x0;
- int x = 0x0;
uInt32 *funcPtr = 0x0;
ldLibrary *libPtr = 0x0;
- for (x = 0; x < lib_c;x++) {
- libPtr = ldFindLibrary(lib + lib_s[x]);
- if (libPtr == 0x0) {
- //printf("[%s][%s]\n",func,lib);
- libPtr = ldAddLibrary(lib + lib_s[x]);
- }
-
- //printf("str: [0x%X]\n",libPtr->linkerDynStr);
- //printf("func: [%s]",func);
-
- for (i=0x0;ilinkerSectionHeader[libPtr->sym].shSize/sizeof(elfDynSym);i++) {
- // printf("Func: [%s]\n",func);
- if (!strcmp(func,(libPtr->linkerDynStr + libPtr->linkerRelSymTab[i].dynName))) {
- funcPtr = (uInt32 *)((uInt32)(libPtr->linkerRelSymTab[i].dynValue) + (uInt32)libPtr->output);
- if (funcPtr == 0x0) {
- printf("[%s:0x%X]\n",func,(uInt32)funcPtr);
- }
- return((uInt32)funcPtr);
- break;
- }
+ libPtr = ldFindLibrary(lib);
+ if (libPtr == 0x0) {
+ libPtr = ldAddLibrary(lib);
+ }
+
+ for (i=0x0;ilinkerSectionHeader[libPtr->sym].shSize/sizeof(elfDynSym);i++) {
+ if (!strcmp(func,(libPtr->linkerDynStr + libPtr->linkerRelSymTab[i].dynName))) {
+ funcPtr = (uInt32 *)((uInt32)(libPtr->linkerRelSymTab[i].dynValue) + (uInt32)libPtr->output);
+ break;
}
}
- printf("ERROR COULDN'T FIND FUNCTION: %s:%s\n",func,lib);
- return(0x0);
+ return((uInt32)funcPtr);
}
diff --git a/src/bin/ld/ld.h b/src/bin/ld/ld.h
index 9159bbf..aa6e698 100644
--- a/src/bin/ld/ld.h
+++ b/src/bin/ld/ld.h
@@ -18,18 +18,22 @@
} ldLibrary;
extern ldLibrary *libs;
-extern int lib_c;
-extern int lib_s[10];
-extern int binarySym;
-extern elfSectionHeader *binarySectionHeader;
-extern char *binaryDynStr;
-extern elfDynSym *binaryRelSymTab;
uInt32 ldFindFunc(const char *,const char *);
ldLibrary *ldFindLibrary(const char *);
ldLibrary *ldAddLibrary(const char *);
/***
+ $Log$
+ Revision 1.3 2004/06/17 02:58:49 reddawg
+ Cleaned Out Dead Code
+
+ Revision 1.2 2004/06/17 01:52:54 reddawg
+ Maybe?
+
+ Revision 1.1 2004/06/16 23:11:34 reddawg
+ ld.so: now adds librarys it is a little more efficient does the lazy binding
+
END
***/
diff --git a/src/bin/ld/main.c b/src/bin/ld/main.c
index 199cbd9..25b284f 100644
--- a/src/bin/ld/main.c
+++ b/src/bin/ld/main.c
@@ -1,5 +1,5 @@
/*****************************************************************************************
- Copyright (c) 2002-2004, 2008 The UbixOS Project
+ Copyright (c) 2002-2004 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
@@ -32,25 +32,21 @@
#include
#include "ld.h"
-ldLibrary *libs = 0x0;
-int lib_c = 0x0;
-int lib_s[10];
-int binarySym = 0x0;
-static elfHeader *binaryHeader = 0x0;
-elfSectionHeader *binarySectionHeader = 0x0;
-static char *binaryShStr = 0x0;
-char *binaryDynStr = 0x0;
-elfDynSym *binaryRelSymTab = 0x0;
-static Elf32_Dyn *binaryElf32_Dyn = 0x0;
-static elfPltInfo *binaryElfRel = 0x0;
+ldLibrary *libs = 0x0;
+
+static elfHeader *binaryHeader = 0x0;
+static elfSectionHeader *binarySectionHeader = 0x0;
+static char *binaryShStr = 0x0;
+static char *binaryDynStr = 0x0;
+static elfDynSym *binaryRelSymTab = 0x0;
+static elfPltInfo *binaryElfRel = 0x0;
uInt32 ld(uInt32 got2,uInt32 entry) {
- int i = 0x0;
- int x = 0x0;
- int rel = 0x0;
- uInt32 *reMap = 0x0;
- FILE *binaryFd = 0x0;
-
+ int i = 0x0;
+ int x = 0x0;
+ int rel = 0x0;
+ uInt32 *reMap = 0x0;
+ FILE *binaryFd = 0x0;
if (binaryHeader == 0x0) {
binaryFd = malloc(sizeof(FILE));
@@ -65,11 +61,11 @@
fseek(binaryFd,binaryHeader->eShoff,0);
fread(binarySectionHeader,sizeof(elfSectionHeader),binaryHeader->eShnum,binaryFd);
- if (binaryShStr == 0x0) {
- binaryShStr = (char *)malloc(binarySectionHeader[binaryHeader->eShstrndx].shSize);
- fseek(binaryFd,binarySectionHeader[binaryHeader->eShstrndx].shOffset,0);
- fread(binaryShStr,binarySectionHeader[binaryHeader->eShstrndx].shSize,1,binaryFd);
- }
+ if (binaryShStr == 0x0) {
+ binaryShStr = (char *)malloc(binarySectionHeader[binaryHeader->eShstrndx].shSize);
+ fseek(binaryFd,binarySectionHeader[binaryHeader->eShstrndx].shOffset,0);
+ fread(binaryShStr,binarySectionHeader[binaryHeader->eShstrndx].shSize,1,binaryFd);
+ }
for (i=0x0;ieShnum;i++) {
switch (binarySectionHeader[i].shType) {
@@ -82,73 +78,83 @@
}
}
break;
- case SHT_DYNAMIC:
- binaryElf32_Dyn = (Elf32_Dyn *)malloc(binarySectionHeader[i].shSize);
- fseek(binaryFd,binarySectionHeader[i].shOffset,0);
- fread(binaryElf32_Dyn,binarySectionHeader[i].shSize,1,binaryFd);
- for (x = 0;x < binarySectionHeader[i].shSize / sizeof(Elf32_Dyn);x++) {
- if (binaryElf32_Dyn[x].d_tag == 1) {
- lib_s[lib_c] = binaryElf32_Dyn[x].d_un.d_ptr;
- lib_c++;
- }
- }
- break;
- case SHT_REL:
- // if (!strcmp(binaryShStr + binarySectionHeader[i].shName,".rel.dyn"))
- // relDyn = i;
- // else
- rel = i;
+ case 9:
+ rel = i;
break;
case 11:
if (binaryRelSymTab == 0x0) {
binaryRelSymTab = (elfDynSym *)malloc(binarySectionHeader[i].shSize);
fseek(binaryFd,binarySectionHeader[i].shOffset,0);
fread(binaryRelSymTab,binarySectionHeader[i].shSize,1,binaryFd);
- binarySym = i;
}
break;
}
}
}
- /*
- if ((binaryElfRelDyn == 0x0) && (relDyn != 0)) {
- binaryElfRelDyn = (elfPltInfo *)malloc(binarySectionHeader[i].shSize);
- fseek(binaryFd,binarySectionHeader[relDyn].shOffset,0x0);
- fread(binaryElfRelDyn,binarySectionHeader[relDyn].shSize,1,binaryFd);
-
- for (x = 0;x < binarySectionHeader[relDyn].shSize / sizeof(elfPltInfo);x++) {
- switch (ELF32_R_TYPE(binaryElfRelDyn[x].pltInfo)) {
- case R_386_COPY:
- printf("COPY");
- reMap = (uInt32 *)binaryElfRelDyn[x].pltOffset;
- *reMap = 0x1;
- break;
- default:
- //printf("UNHANDLED THING");
- break;
- }
- printf("y: [%i:0x%X]",y,binaryElfRelDyn[x].pltOffset);
- }
- }
- */
-
-
if (binaryElfRel == 0x0) {
- binaryElfRel = (elfPltInfo *)malloc(binarySectionHeader[rel].shSize);
fseek(binaryFd,binarySectionHeader[rel].shOffset,0x0);
+ binaryElfRel = (elfPltInfo *)malloc(binarySectionHeader[rel].shSize);
fread(binaryElfRel,binarySectionHeader[rel].shSize,1,binaryFd);
}
-
i = (entry/sizeof(elfPltInfo));
x = ELF32_R_SYM(binaryElfRel[i].pltInfo);
reMap = (uInt32 *)binaryElfRel[i].pltOffset;
- *reMap = ldFindFunc(binaryDynStr + binaryRelSymTab[x].dynName,binaryDynStr);
+ *reMap = ldFindFunc(binaryDynStr + binaryRelSymTab[x].dynName,(char *)(binaryDynStr + 1));
+
+ if (binaryFd) {
+ fclose(binaryFd);
+ }
return(*reMap);
}
/***
+ $Log$
+ Revision 1.12 2004/06/17 14:14:44 reddawg
+ Fixed some potential problems
+
+ Revision 1.11 2004/06/17 13:05:14 reddawg
+ dynamic linking: fixed int6 issue problem was multiple rel's
+
+ Revision 1.10 2004/06/17 12:32:11 reddawg
+ the machine should just hlt
+
+ Revision 1.9 2004/06/17 11:58:10 reddawg
+ ld.so: Made a few changes to the way it functions hopefully it will
+ improve some of its performance.
+
+ Revision 1.8 2004/06/17 02:58:49 reddawg
+ Cleaned Out Dead Code
+
+ Revision 1.7 2004/06/17 01:09:24 reddawg
+ TCA: cvs update make and give me output
+
+ Revision 1.6 2004/06/16 23:11:34 reddawg
+ ld.so: now adds librarys it is a little more efficient does the lazy binding
+
+ Revision 1.5 2004/06/16 18:04:15 reddawg
+ Fixed typo printf <--> kprintf
+
+ Revision 1.4 2004/06/16 16:31:58 reddawg
+ ld.so: the dynamic linker works and has been tested
+
+ Revision 1.3 2004/06/16 13:52:51 reddawg
+ Start of userland LD
+
+ Revision 1.2 2004/06/01 01:30:43 reddawg
+ No more warnings and organized make files
+
+ Revision 1.1 2004/04/26 21:16:03 reddawg
+ Initial addition of the ubix LD
+
+ Revision 1.2 2004/04/26 13:20:42 reddawg
+ Turn off muffin
+
+ Revision 1.1 2004/04/26 13:13:25 reddawg
+ Initial Introduction of the UbixOS Format Utility into the source tree
+
END
***/
+
diff --git a/src/bin/login/main.c b/src/bin/login/main.c
index c76ffd8..d703d4e 100644
--- a/src/bin/login/main.c
+++ b/src/bin/login/main.c
@@ -1,5 +1,5 @@
/**************************************************************************************
- Copyright (c) 2002,2008 The UbixOS Project
+ Copyright (c) 2002 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -63,8 +63,10 @@
char passWord[32];
char *data2 = 0x0;
struct passwd *data = 0x0;
+ int foo;
+
if ((getuid() != 0x0) && (getgid() != 0x0)) {
printf("This Application Must Be Run As Root.\n");
exit(-1);
@@ -74,14 +76,23 @@
exit(0x1);
}
- fd = fopen("sys:/etc/userdb","r");
+
+ fd = fopen("sys:/userdb","r");
if (fd->fd == 0x0) {
- printf("Missing User Database.\n");
+ printf("file not found!!!\n");
exit(0x1);
}
-
+/*
+ if (!(fd = fopen("sys:/userdb","r"))) {
+ printf("Error Opening File");
+ memcpy(data[0].username,"root",4);
+ memcpy(data[0].password,"user",4);
+ memcpy(data[0].shell,"sys:/shell", 10);
+*/
fread(data,0x1000,0x1,fd);
fclose(fd);
+
+
if ((data2 = (char *)malloc(384)) == 0x0) {
printf("Malloc Failed\n");
@@ -89,13 +100,6 @@
}
/* we need to move this into the libc for getpwent(), etc */
-/*
- foo = auth("root", "user");
- if(foo != -1)
- printf("yay\n");
- else
- printf("damn\n");
-*/
login:
printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)");
@@ -103,6 +107,48 @@
gets((char *)&userName);
printf("Password: ");
pgets((char *)&passWord);
+
+if(auth(userName, passWord) != -1)
+{
+ shellPid = fork();
+ if (shellPid == 0x0)
+ {
+ if (setuid(data[i].uid) != 0x0)
+ printf("Set UID Failed\n");
+ if (setgid(data[i].gid) != 0x0)
+ printf("Set GID Failed\n");
+ if ((fd = fopen("sys:/motd","r")) == 0x0)
+ printf("No MOTD");
+ else {
+ fread(data2,384,1,fd);
+ printf("%s\n",data2);
+ fclose(fd);
+ //chdir(data[i].path);
+ chdir("sys:/");
+ exec(data[i].shell,0x0,0x0);
+ printf("Error: Problem Starting Shell\n");
+ exit(-1);
+ }
+ }
+ else
+ while (pidStatus(shellPid) > 0) {
+ sched_yield();
+ }
+
+ }
+ else
+ {
+ printf("Incorrect Login\n");
+ goto login;
+}
+
+return 0x0;
+
+}
+
+
+
+/*
for (i=0x0;i<(4096/sizeof(struct passwd));i++) {
if (0x0 == strcmp(userName,data[i].username)) {
if (0x0 == strcmp(passWord,data[i].password)) {
@@ -114,10 +160,7 @@
if (setgid(data[i].gid) != 0x0) {
printf("Set GID Failed\n");
}
- fd = 0x0;
- fd = fopen("sys:/etc/motd","r");
- //if ((fd = fopen("sys:/motd","r")) == 0x0) {
- if (fd == 0x0) {
+ if ((fd = fopen("sys:/motd","r")) == 0x0) {
printf("No MOTD");
}
else {
@@ -126,8 +169,7 @@
}
fclose(fd);
//chdir(data[i].path);
- chdir("sys:/bin/");
- printf("[%s]\n",data[i].shell);
+ chdir("sys:/");
exec(data[i].shell,0x0,0x0);
printf("Error: Problem Starting Shell\n");
exit(-1);
@@ -144,5 +186,6 @@
printf("Login Incorrect!\n");
goto login;
return(0x0);
- }
+
+*/
diff --git a/src/bin/login2/Makefile b/src/bin/login2/Makefile
deleted file mode 100644
index b5fa30e..0000000
--- a/src/bin/login2/Makefile
+++ /dev/null
@@ -1,56 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-#Linker
-LD = ld
-
-#Binary File Name
-BINARY = login
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = main.o
-
-#LIBRARIES = ../../lib/libc/libc.so
-
-INCLUDES = -I../../include.new
-
-LIBRARIES = ../../lib/libc/libc.so ../../lib/ubix_api/ubix_api.so
-
-STARTUP = ../../lib/csu/*.o
-
-
-
-# Link The Binary
-$(BINARY) : $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
-# strip $(BINARY)
-
-# Compile the source files
-.cpp.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/login2/main.c b/src/bin/login2/main.c
deleted file mode 100644
index d764542..0000000
--- a/src/bin/login2/main.c
+++ /dev/null
@@ -1,152 +0,0 @@
-/**************************************************************************************
- Copyright (c) 2002 The UbixOS Project
- All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
-Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
-Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
-in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
-contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
-GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
-OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
-OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- $Id$
-
-**************************************************************************************/
-
-#include
-#include
-#include
-//#include
-#include
-//#include
-#include
-
-struct passwd {
- char username[32];
- char password[32];
- int uid;
- int gid;
- char shell[128];
- char realname[256];
- char path[256];
- };
-
-static char *pgets(char *string) {
- int count=0,ch=0;
- while (1) {
- ch = fgetc(stdin);
- if(ch == 10) {
- printf("\n");
- break;
- }
- else if(ch == 8 && count > 0) count-=2;
- else if(ch == 0) count--;
- else string[count] = ch;
- if (ch != 8) printf("*");
- count++;
- }
- string[count] = '\0';
- return(string);
- }
-
-int main() {
- FILE *fd;
- int shellPid = 0,i = 0x0;
- char userName[32];
- char passWord[32];
- char *data2 = 0x0;
- struct passwd *data = 0x0;
-
-
- if ((getuid() != 0x0) && (getgid() != 0x0)) {
- printf("This Application Must Be Run As Root.\n");
- exit(-1);
- }
- if ((data = (struct passwd *)malloc(0x1000)) == 0x0) {
- printf("Malloc Failed\n");
- exit(0x1);
- }
-
- fd = fopen("sys:/etc/userdb","r");
- if (fd == 0x0) {
- printf("Missing User Database.\n");
- exit(0x1);
- }
-
- fread(data,0x1000,0x1,fd);
- fclose(fd);
-
- if ((data2 = (char *)malloc(384)) == 0x0) {
- printf("Malloc Failed\n");
- exit(0x1);
- }
-
-/* we need to move this into the libc for getpwent(), etc */
-/*
- foo = auth("root", "user");
- if(foo != -1)
- printf("yay\n");
- else
- printf("damn\n");
-*/
-
- login:
- printf("\nUbixOS/IA-32 (devel.ubixos.com) (console)");
- printf("\n\nLogin: ");
- printf("Test: [%i]\n",ubix_test());
- gets((char *)&userName);
- printf("Password: ");
- gets((char *)&passWord);
- //pgets((char *)&passWord);
- for (i=0x0;i<(4096/sizeof(struct passwd));i++) {
- if (0x0 == strcmp(userName,data[i].username)) {
- if (0x0 == strcmp(passWord,data[i].password)) {
- shellPid = old_fork();
- if (shellPid == 0x0) {
- if (setuid(data[i].uid) != 0x0) {
- printf("Set UID Failed\n");
- }
- if (setgid(data[i].gid) != 0x0) {
- printf("Set GID Failed\n");
- }
- fd = 0x0;
- fd = fopen("sys:/etc/motd","r");
- //if ((fd = fopen("sys:/motd","r")) == 0x0) {
- if (fd == 0x0) {
- printf("No MOTD");
- }
- else {
- fread(data2,384,1,fd);
- printf("%s\n",data2);
- }
- fclose(fd);
- //chdir(data[i].path);
- chdir("sys:/bin/");
- // exec(data[i].shell,0x0);
- printf("Error: Problem Starting Shell\n");
- exit(-1);
- }
- else {
-/*
- while (pidStatus(shellPid) > 0) {
- sched_yield();
- }
-*/
- goto login;
- }
- }
- }
- }
- printf("Login Incorrect!\n");
- goto login;
- return(0x0);
- }
-
diff --git a/src/bin/ls/Makefile b/src/bin/ls/Makefile
index 24360c2..70dd9a4 100644
--- a/src/bin/ls/Makefile
+++ b/src/bin/ls/Makefile
@@ -15,22 +15,19 @@
REMOVE = rm -f
#Objects
-OBJS = cmp.o util.o print.o ls.o
+OBJS = main.o
-INCLUDES = -I../../include.new
-
-LIBRARIES = ../../lib/libc/libc.so ../../lib/libutil/libutil.so
-
-STARTUP = ../../lib/csu/*.o
-
-CFLAGS += -fno-strict-aliasing -pipe
+LIBRARIES = ../../lib/libc_old/libc_old.so
# Link The Binary
$(BINARY) : $(OBJS)
$(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- #strip $(BINARY)
+ strip $(BINARY)
# Compile the source files
+.cpp.o:
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
.cc.o:
$(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
@@ -38,7 +35,7 @@
$(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
.c.o:
- $(CC) -Wall -O -ggdb $(CFLAGS) $(INCLUDES) -c -o $@ $<
+ $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
.c.s:
$(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
diff --git a/src/bin/ls/cmp.c b/src/bin/ls/cmp.c
deleted file mode 100644
index f9d0086..0000000
--- a/src/bin/ls/cmp.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Fischbein.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
-#endif /* not lint */
-#endif
-#include
-__FBSDID("$FreeBSD: src/bin/ls/cmp.c,v 1.18 2006/03/24 16:38:02 jhb Exp $");
-
-
-#include
-#include
-
-#include
-#include
-
-#include "ls.h"
-#include "extern.h"
-
-int
-namecmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (strcoll(a->fts_name, b->fts_name));
-}
-
-int
-revnamecmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (strcoll(b->fts_name, a->fts_name));
-}
-
-int
-modcmp(const FTSENT *a, const FTSENT *b)
-{
-
- if (b->fts_statp->st_mtimespec.tv_sec >
- a->fts_statp->st_mtimespec.tv_sec)
- return (1);
- if (b->fts_statp->st_mtimespec.tv_sec <
- a->fts_statp->st_mtimespec.tv_sec)
- return (-1);
- if (b->fts_statp->st_mtimespec.tv_nsec >
- a->fts_statp->st_mtimespec.tv_nsec)
- return (1);
- if (b->fts_statp->st_mtimespec.tv_nsec <
- a->fts_statp->st_mtimespec.tv_nsec)
- return (-1);
- return (strcoll(a->fts_name, b->fts_name));
-}
-
-int
-revmodcmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (modcmp(b, a));
-}
-
-int
-acccmp(const FTSENT *a, const FTSENT *b)
-{
-
- if (b->fts_statp->st_atimespec.tv_sec >
- a->fts_statp->st_atimespec.tv_sec)
- return (1);
- if (b->fts_statp->st_atimespec.tv_sec <
- a->fts_statp->st_atimespec.tv_sec)
- return (-1);
- if (b->fts_statp->st_atimespec.tv_nsec >
- a->fts_statp->st_atimespec.tv_nsec)
- return (1);
- if (b->fts_statp->st_atimespec.tv_nsec <
- a->fts_statp->st_atimespec.tv_nsec)
- return (-1);
- return (strcoll(a->fts_name, b->fts_name));
-}
-
-int
-revacccmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (acccmp(b, a));
-}
-
-int
-birthcmp(const FTSENT *a, const FTSENT *b)
-{
-
- if (b->fts_statp->st_birthtimespec.tv_sec >
- a->fts_statp->st_birthtimespec.tv_sec)
- return (1);
- if (b->fts_statp->st_birthtimespec.tv_sec <
- a->fts_statp->st_birthtimespec.tv_sec)
- return (-1);
- if (b->fts_statp->st_birthtimespec.tv_nsec >
- a->fts_statp->st_birthtimespec.tv_nsec)
- return (1);
- if (b->fts_statp->st_birthtimespec.tv_nsec <
- a->fts_statp->st_birthtimespec.tv_nsec)
- return (-1);
- return (strcoll(a->fts_name, b->fts_name));
-}
-
-int
-revbirthcmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (birthcmp(b, a));
-}
-
-int
-statcmp(const FTSENT *a, const FTSENT *b)
-{
-
- if (b->fts_statp->st_ctimespec.tv_sec >
- a->fts_statp->st_ctimespec.tv_sec)
- return (1);
- if (b->fts_statp->st_ctimespec.tv_sec <
- a->fts_statp->st_ctimespec.tv_sec)
- return (-1);
- if (b->fts_statp->st_ctimespec.tv_nsec >
- a->fts_statp->st_ctimespec.tv_nsec)
- return (1);
- if (b->fts_statp->st_ctimespec.tv_nsec <
- a->fts_statp->st_ctimespec.tv_nsec)
- return (-1);
- return (strcoll(a->fts_name, b->fts_name));
-}
-
-int
-revstatcmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (statcmp(b, a));
-}
-
-int
-sizecmp(const FTSENT *a, const FTSENT *b)
-{
-
- if (b->fts_statp->st_size > a->fts_statp->st_size)
- return (1);
- if (b->fts_statp->st_size < a->fts_statp->st_size)
- return (-1);
- return (strcoll(a->fts_name, b->fts_name));
-}
-
-int
-revsizecmp(const FTSENT *a, const FTSENT *b)
-{
-
- return (sizecmp(b, a));
-}
diff --git a/src/bin/ls/extern.h b/src/bin/ls/extern.h
deleted file mode 100644
index f6e674b..0000000
--- a/src/bin/ls/extern.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * Copyright (c) 1991, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)extern.h 8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/ls/extern.h,v 1.25 2006/03/24 16:38:02 jhb Exp $
- */
-
-int acccmp(const FTSENT *, const FTSENT *);
-int revacccmp(const FTSENT *, const FTSENT *);
-int birthcmp(const FTSENT *, const FTSENT *);
-int revbirthcmp(const FTSENT *, const FTSENT *);
-int modcmp(const FTSENT *, const FTSENT *);
-int revmodcmp(const FTSENT *, const FTSENT *);
-int namecmp(const FTSENT *, const FTSENT *);
-int revnamecmp(const FTSENT *, const FTSENT *);
-int statcmp(const FTSENT *, const FTSENT *);
-int revstatcmp(const FTSENT *, const FTSENT *);
-int sizecmp(const FTSENT *, const FTSENT *);
-int revsizecmp(const FTSENT *, const FTSENT *);
-
-void printcol(const DISPLAY *);
-void printlong(const DISPLAY *);
-int printname(const char *);
-void printscol(const DISPLAY *);
-void printstream(const DISPLAY *);
-void usage(void);
-int prn_normal(const char *);
-size_t len_octal(const char *, int);
-int prn_octal(const char *);
-int prn_printable(const char *);
-#ifdef COLORLS
-void parsecolors(const char *cs);
-void colorquit(int);
-
-extern char *ansi_fgcol;
-extern char *ansi_bgcol;
-extern char *ansi_coloff;
-extern char *attrs_off;
-extern char *enter_bold;
-#endif
-extern int termwidth;
diff --git a/src/bin/ls/ls.c b/src/bin/ls/ls.c
deleted file mode 100644
index 8d515a6..0000000
--- a/src/bin/ls/ls.c
+++ /dev/null
@@ -1,879 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Fischbein.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1989, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n";
-#endif /* not lint */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)ls.c 8.5 (Berkeley) 4/2/94";
-#endif /* not lint */
-#endif
-#include
-__FBSDID("$FreeBSD: src/bin/ls/ls.c,v 1.85 2006/03/24 17:09:03 jhb Exp $");
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#ifdef COLORLS
-#include
-#include
-#endif
-
-#include "ls.h"
-#include "extern.h"
-
-/*
- * Upward approximation of the maximum number of characters needed to
- * represent a value of integral type t as a string, excluding the
- * NUL terminator, with provision for a sign.
- */
-#define STRBUF_SIZEOF(t) (1 + CHAR_BIT * sizeof(t) / 3 + 1)
-
-/*
- * MAKENINES(n) turns n into (10**n)-1. This is useful for converting a width
- * into a number that wide in decimal.
- * XXX: Overflows are not considered.
- */
-#define MAKENINES(n) \
- do { \
- intmax_t i; \
- \
- /* Use a loop as all values of n are small. */ \
- for (i = 1; n > 0; i *= 10) \
- n--; \
- n = i - 1; \
- } while(0)
-
-static void display(const FTSENT *, FTSENT *, int);
-static int mastercmp(const FTSENT * const *, const FTSENT * const *);
-static void traverse(int, char **, int);
-
-static void (*printfcn)(const DISPLAY *);
-static int (*sortfcn)(const FTSENT *, const FTSENT *);
-
-long blocksize; /* block size units */
-int termwidth = 80; /* default terminal width */
-
-/* flags */
- int f_accesstime; /* use time of last access */
- int f_birthtime; /* use time of birth */
- int f_flags; /* show flags associated with a file */
- int f_humanval; /* show human-readable file sizes */
- int f_inode; /* print inode */
-static int f_kblocks; /* print size in kilobytes */
-static int f_listdir; /* list actual directory, not contents */
-static int f_listdot; /* list files beginning with . */
-static int f_noautodot; /* do not automatically enable -A for root */
- int f_longform; /* long listing format */
- int f_nonprint; /* show unprintables as ? */
-static int f_nosort; /* don't sort output */
- int f_notabs; /* don't use tab-separated multi-col output */
-static int f_numericonly; /* don't convert uid/gid to name */
- int f_octal; /* show unprintables as \xxx */
- int f_octal_escape; /* like f_octal but use C escapes if possible */
-static int f_recursive; /* ls subdirectories also */
-static int f_reversesort; /* reverse whatever sort is used */
- int f_sectime; /* print the real time for all files */
-static int f_singlecol; /* use single column output */
- int f_size; /* list size in short listing */
- int f_slash; /* similar to f_type, but only for dirs */
- int f_sortacross; /* sort across rows, not down columns */
- int f_statustime; /* use time of last mode change */
-static int f_stream; /* stream the output, separate with commas */
-static int f_timesort; /* sort by time vice name */
-static int f_sizesort;
- int f_type; /* add type character for non-regular files */
-static int f_whiteout; /* show whiteout entries */
- int f_label; /* show MAC label */
-#ifdef COLORLS
- int f_color; /* add type in color for non-regular files */
-
-char *ansi_bgcol; /* ANSI sequence to set background colour */
-char *ansi_fgcol; /* ANSI sequence to set foreground colour */
-char *ansi_coloff; /* ANSI sequence to reset colours */
-char *attrs_off; /* ANSI sequence to turn off attributes */
-char *enter_bold; /* ANSI sequence to set color to bold mode */
-#endif
-
-static int rval;
-
-int
-main(int argc, char *argv[])
-{
- static char dot[] = ".", *dotav[] = {dot, NULL};
- struct winsize win;
- int ch, fts_options, notused;
- char *p;
-#ifdef COLORLS
- char termcapbuf[1024]; /* termcap definition buffer */
- char tcapbuf[512]; /* capability buffer */
- char *bp = tcapbuf;
-#endif
-
- (void)setlocale(LC_ALL, "");
-
- /* Terminal defaults to -Cq, non-terminal defaults to -1. */
- if (isatty(STDOUT_FILENO)) {
- termwidth = 80;
- if ((p = getenv("COLUMNS")) != NULL && *p != '\0')
- termwidth = atoi(p);
- else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) != -1 &&
- win.ws_col > 0)
- termwidth = win.ws_col;
- f_nonprint = 1;
- } else {
- f_singlecol = 1;
- /* retrieve environment variable, in case of explicit -C */
- p = getenv("COLUMNS");
- if (p)
- termwidth = atoi(p);
- }
-
- printf("termwidth: %i\n",termwidth);
-
- fts_options = FTS_PHYSICAL;
- while ((ch = getopt(argc, argv,
- "1ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx")) != -1) {
- switch (ch) {
- /*
- * The -1, -C, -x and -l options all override each other so
- * shell aliasing works right.
- */
- case '1':
- f_singlecol = 1;
- f_longform = 0;
- f_stream = 0;
- break;
- case 'B':
- f_nonprint = 0;
- f_octal = 1;
- f_octal_escape = 0;
- break;
- case 'C':
- f_sortacross = f_longform = f_singlecol = 0;
- break;
- case 'l':
- f_longform = 1;
- f_singlecol = 0;
- f_stream = 0;
- break;
- case 'x':
- f_sortacross = 1;
- f_longform = 0;
- f_singlecol = 0;
- break;
- /* The -c, -u, and -U options override each other. */
- case 'c':
- f_statustime = 1;
- f_accesstime = 0;
- f_birthtime = 0;
- break;
- case 'u':
- f_accesstime = 1;
- f_statustime = 0;
- f_birthtime = 0;
- break;
- case 'U':
- f_birthtime = 1;
- f_accesstime = 0;
- f_statustime = 0;
- break;
- case 'F':
- f_type = 1;
- f_slash = 0;
- break;
- case 'H':
- fts_options |= FTS_COMFOLLOW;
- break;
- case 'G':
- setenv("CLICOLOR", "", 1);
- break;
- case 'L':
- fts_options &= ~FTS_PHYSICAL;
- fts_options |= FTS_LOGICAL;
- break;
- case 'P':
- fts_options &= ~FTS_COMFOLLOW;
- fts_options &= ~FTS_LOGICAL;
- fts_options |= FTS_PHYSICAL;
- break;
- case 'R':
- f_recursive = 1;
- break;
- case 'a':
- fts_options |= FTS_SEEDOT;
- /* FALLTHROUGH */
- case 'A':
- f_listdot = 1;
- break;
- case 'I':
- f_noautodot = 1;
- break;
- /* The -d option turns off the -R option. */
- case 'd':
- f_listdir = 1;
- f_recursive = 0;
- break;
- case 'f':
- f_nosort = 1;
- break;
- case 'g': /* Compatibility with 4.3BSD. */
- break;
- case 'h':
- f_humanval = 1;
- break;
- case 'i':
- f_inode = 1;
- break;
- case 'k':
- f_humanval = 0;
- f_kblocks = 1;
- break;
- case 'm':
- f_stream = 1;
- f_singlecol = 0;
- f_longform = 0;
- break;
- case 'n':
- f_numericonly = 1;
- break;
- case 'o':
- f_flags = 1;
- break;
- case 'p':
- f_slash = 1;
- f_type = 1;
- break;
- case 'q':
- f_nonprint = 1;
- f_octal = 0;
- f_octal_escape = 0;
- break;
- case 'r':
- f_reversesort = 1;
- break;
- case 's':
- f_size = 1;
- break;
- case 'T':
- f_sectime = 1;
- break;
- /* The -t and -S options override each other. */
- case 't':
- f_timesort = 1;
- f_sizesort = 0;
- break;
- case 'S':
- f_sizesort = 1;
- f_timesort = 0;
- break;
- case 'W':
- f_whiteout = 1;
- break;
- case 'b':
- f_nonprint = 0;
- f_octal = 0;
- f_octal_escape = 1;
- break;
- case 'w':
- f_nonprint = 0;
- f_octal = 0;
- f_octal_escape = 0;
- break;
- case 'Z':
- f_label = 1;
- break;
- default:
- case '?':
- usage();
- }
- }
- argc -= optind;
- argv += optind;
-
- /* Root is -A automatically unless -I. */
- if (!f_listdot && getuid() == (uid_t)0 && !f_noautodot)
- f_listdot = 1;
-
- /* Enabling of colours is conditional on the environment. */
- if (getenv("CLICOLOR") &&
- (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE")))
-#ifdef COLORLS
- if (tgetent(termcapbuf, getenv("TERM")) == 1) {
- ansi_fgcol = tgetstr("AF", &bp);
- ansi_bgcol = tgetstr("AB", &bp);
- attrs_off = tgetstr("me", &bp);
- enter_bold = tgetstr("md", &bp);
-
- /* To switch colours off use 'op' if
- * available, otherwise use 'oc', or
- * don't do colours at all. */
- ansi_coloff = tgetstr("op", &bp);
- if (!ansi_coloff)
- ansi_coloff = tgetstr("oc", &bp);
- if (ansi_fgcol && ansi_bgcol && ansi_coloff)
- f_color = 1;
- }
-#else
- warnx("color support not compiled in");
-#endif /*COLORLS*/
-
-#ifdef COLORLS
- if (f_color) {
- /*
- * We can't put tabs and color sequences together:
- * column number will be incremented incorrectly
- * for "stty oxtabs" mode.
- */
- f_notabs = 1;
- (void)signal(SIGINT, colorquit);
- (void)signal(SIGQUIT, colorquit);
- parsecolors(getenv("LSCOLORS"));
- }
-#endif
-
- /*
- * If not -F, -i, -l, -s, -S or -t options, don't require stat
- * information, unless in color mode in which case we do
- * need this to determine which colors to display.
- */
- if (!f_inode && !f_longform && !f_size && !f_timesort &&
- !f_sizesort && !f_type
-#ifdef COLORLS
- && !f_color
-#endif
- )
- fts_options |= FTS_NOSTAT;
-
- /*
- * If not -F, -d or -l options, follow any symbolic links listed on
- * the command line.
- */
- if (!f_longform && !f_listdir && !f_type)
- fts_options |= FTS_COMFOLLOW;
-
- /*
- * If -W, show whiteout entries
- */
-#ifdef FTS_WHITEOUT
- if (f_whiteout)
- fts_options |= FTS_WHITEOUT;
-#endif
-
- /* If -l or -s, figure out block size. */
- if (f_longform || f_size) {
- if (f_kblocks)
- blocksize = 2;
- else {
- (void)getbsize(¬used, &blocksize);
- blocksize /= 512;
- }
- }
- /* Select a sort function. */
- if (f_reversesort) {
- if (!f_timesort && !f_sizesort)
- sortfcn = revnamecmp;
- else if (f_sizesort)
- sortfcn = revsizecmp;
- else if (f_accesstime)
- sortfcn = revacccmp;
- else if (f_birthtime)
- sortfcn = revbirthcmp;
- else if (f_statustime)
- sortfcn = revstatcmp;
- else /* Use modification time. */
- sortfcn = revmodcmp;
- } else {
- if (!f_timesort && !f_sizesort)
- sortfcn = namecmp;
- else if (f_sizesort)
- sortfcn = sizecmp;
- else if (f_accesstime)
- sortfcn = acccmp;
- else if (f_birthtime)
- sortfcn = birthcmp;
- else if (f_statustime)
- sortfcn = statcmp;
- else /* Use modification time. */
- sortfcn = modcmp;
- }
-
- /* Select a print function. */
- if (f_singlecol)
- printfcn = printscol;
- else if (f_longform)
- printfcn = printlong;
- else if (f_stream)
- printfcn = printstream;
- else
- printfcn = printcol;
-
- if (argc)
- traverse(argc, argv, fts_options);
- else
- traverse(1, dotav, fts_options);
- printf("EXITING: [%i]\n",rval);
- exit(rval);
-}
-
-static int output; /* If anything output. */
-
-/*
- * Traverse() walks the logical directory structure specified by the argv list
- * in the order specified by the mastercmp() comparison function. During the
- * traversal it passes linked lists of structures to display() which represent
- * a superset (may be exact set) of the files to be displayed.
- */
-static void
-traverse(int argc, char *argv[], int options)
-{
- FTS *ftsp;
- FTSENT *p, *chp;
- int ch_options;
-
- if ((ftsp =
- fts_open(argv, options, f_nosort ? NULL : mastercmp)) == NULL)
- err(1, "fts_open");
-
- /*
- * We ignore errors from fts_children here since they will be
- * replicated and signalled on the next call to fts_read() below.
- */
- chp = fts_children(ftsp, 0);
- if (chp != NULL)
- display(NULL, chp, options);
- if (f_listdir)
- return;
-
- /*
- * If not recursing down this tree and don't need stat info, just get
- * the names.
- */
- ch_options = !f_recursive && !f_label &&
- options & FTS_NOSTAT ? FTS_NAMEONLY : 0;
-
- while ((p = fts_read(ftsp)) != NULL)
- switch (p->fts_info) {
- case FTS_DC:
- warnx("%s: directory causes a cycle", p->fts_name);
- break;
- case FTS_DNR:
- case FTS_ERR:
- warnx("%s: %s", p->fts_name, strerror(p->fts_errno));
- rval = 1;
- break;
- case FTS_D:
- if (p->fts_level != FTS_ROOTLEVEL &&
- p->fts_name[0] == '.' && !f_listdot)
- break;
-
- /*
- * If already output something, put out a newline as
- * a separator. If multiple arguments, precede each
- * directory with its name.
- */
- if (output) {
- putchar('\n');
- (void)printname(p->fts_path);
- puts(":");
- } else if (argc > 1) {
- (void)printname(p->fts_path);
- puts(":");
- output = 1;
- }
- chp = fts_children(ftsp, ch_options);
- display(p, chp, options);
-
- if (!f_recursive && chp != NULL)
- (void)fts_set(ftsp, p, FTS_SKIP);
- break;
- default:
- break;
- }
- if (errno)
- err(1, "fts_read");
-}
-
-/*
- * Display() takes a linked list of FTSENT structures and passes the list
- * along with any other necessary information to the print function. P
- * points to the parent directory of the display list.
- */
-static void
-display(const FTSENT *p, FTSENT *list, int options)
-{
- struct stat *sp;
- DISPLAY d;
- FTSENT *cur;
- NAMES *np;
- off_t maxsize;
- long maxblock;
- u_long btotal, labelstrlen, maxinode, maxlen, maxnlink;
- u_long maxlabelstr;
- int bcfile, maxflags;
- gid_t maxgroup;
- uid_t maxuser;
- size_t flen, ulen, glen;
- char *initmax;
- int entries, needstats;
- const char *user, *group;
- char *flags, *labelstr = NULL;
- char buf[STRBUF_SIZEOF(u_quad_t) + 1];
- char ngroup[STRBUF_SIZEOF(uid_t) + 1];
- char nuser[STRBUF_SIZEOF(gid_t) + 1];
-
- needstats = f_inode || f_longform || f_size;
- flen = 0;
- btotal = 0;
- initmax = getenv("LS_COLWIDTHS");
- /* Fields match -lios order. New ones should be added at the end. */
- maxlabelstr = maxblock = maxinode = maxlen = maxnlink =
- maxuser = maxgroup = maxflags = maxsize = 0;
- if (initmax != NULL && *initmax != '\0') {
- char *initmax2, *jinitmax;
- int ninitmax;
-
- /* Fill-in "::" as "0:0:0" for the sake of scanf. */
- jinitmax = malloc(strlen(initmax) * 2 + 2);
- if (jinitmax == NULL)
- err(1, "malloc");
- initmax2 = jinitmax;
- if (*initmax == ':')
- strcpy(initmax2, "0:"), initmax2 += 2;
- else
- *initmax2++ = *initmax, *initmax2 = '\0';
- for (initmax++; *initmax != '\0'; initmax++) {
- if (initmax[-1] == ':' && initmax[0] == ':') {
- *initmax2++ = '0';
- *initmax2++ = initmax[0];
- initmax2[1] = '\0';
- } else {
- *initmax2++ = initmax[0];
- initmax2[1] = '\0';
- }
- }
- if (initmax2[-1] == ':')
- strcpy(initmax2, "0");
-
- ninitmax = sscanf(jinitmax,
- " %lu : %ld : %lu : %u : %u : %i : %jd : %lu : %lu ",
- &maxinode, &maxblock, &maxnlink, &maxuser,
- &maxgroup, &maxflags, &maxsize, &maxlen, &maxlabelstr);
- f_notabs = 1;
- switch (ninitmax) {
- case 0:
- maxinode = 0;
- /* FALLTHROUGH */
- case 1:
- maxblock = 0;
- /* FALLTHROUGH */
- case 2:
- maxnlink = 0;
- /* FALLTHROUGH */
- case 3:
- maxuser = 0;
- /* FALLTHROUGH */
- case 4:
- maxgroup = 0;
- /* FALLTHROUGH */
- case 5:
- maxflags = 0;
- /* FALLTHROUGH */
- case 6:
- maxsize = 0;
- /* FALLTHROUGH */
- case 7:
- maxlen = 0;
- /* FALLTHROUGH */
- case 8:
- maxlabelstr = 0;
- /* FALLTHROUGH */
-#ifdef COLORLS
- if (!f_color)
-#endif
- f_notabs = 0;
- /* FALLTHROUGH */
- default:
- break;
- }
- MAKENINES(maxinode);
- MAKENINES(maxblock);
- MAKENINES(maxnlink);
- MAKENINES(maxsize);
- free(jinitmax);
- }
- bcfile = 0;
- flags = NULL;
- for (cur = list, entries = 0; cur; cur = cur->fts_link) {
- if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) {
- warnx("%s: %s",
- cur->fts_name, strerror(cur->fts_errno));
- cur->fts_number = NO_PRINT;
- rval = 1;
- continue;
- }
- /*
- * P is NULL if list is the argv list, to which different rules
- * apply.
- */
- if (p == NULL) {
- /* Directories will be displayed later. */
- if (cur->fts_info == FTS_D && !f_listdir) {
- cur->fts_number = NO_PRINT;
- continue;
- }
- } else {
- /* Only display dot file if -a/-A set. */
- if (cur->fts_name[0] == '.' && !f_listdot) {
- cur->fts_number = NO_PRINT;
- continue;
- }
- }
- if (cur->fts_namelen > maxlen)
- maxlen = cur->fts_namelen;
- if (f_octal || f_octal_escape) {
- u_long t = len_octal(cur->fts_name, cur->fts_namelen);
-
- if (t > maxlen)
- maxlen = t;
- }
- if (needstats) {
- sp = cur->fts_statp;
- if (sp->st_blocks > maxblock)
- maxblock = sp->st_blocks;
- if (sp->st_ino > maxinode)
- maxinode = sp->st_ino;
- if (sp->st_nlink > maxnlink)
- maxnlink = sp->st_nlink;
- if (sp->st_size > maxsize)
- maxsize = sp->st_size;
-
- btotal += sp->st_blocks;
- if (f_longform) {
- if (f_numericonly) {
- (void)snprintf(nuser, sizeof(nuser),
- "%u", sp->st_uid);
- (void)snprintf(ngroup, sizeof(ngroup),
- "%u", sp->st_gid);
- user = nuser;
- group = ngroup;
- } else {
- user = user_from_uid(sp->st_uid, 0);
- group = group_from_gid(sp->st_gid, 0);
- }
- if ((ulen = strlen(user)) > maxuser)
- maxuser = ulen;
- if ((glen = strlen(group)) > maxgroup)
- maxgroup = glen;
- if (f_flags) {
- flags = fflagstostr(sp->st_flags);
- if (flags != NULL && *flags == '\0') {
- free(flags);
- flags = strdup("-");
- }
- if (flags == NULL)
- err(1, "fflagstostr");
- flen = strlen(flags);
- if (flen > (size_t)maxflags)
- maxflags = flen;
- } else
- flen = 0;
- labelstr = NULL;
- if (f_label) {
- char name[PATH_MAX + 1];
- mac_t label;
- int error;
-
- error = mac_prepare_file_label(&label);
- if (error == -1) {
- warn("MAC label for %s/%s",
- cur->fts_parent->fts_path,
- cur->fts_name);
- goto label_out;
- }
-
- if (cur->fts_level == FTS_ROOTLEVEL)
- snprintf(name, sizeof(name),
- "%s", cur->fts_name);
- else
- snprintf(name, sizeof(name),
- "%s/%s", cur->fts_parent->
- fts_accpath, cur->fts_name);
-
- if (options & FTS_LOGICAL)
- error = mac_get_file(name,
- label);
- else
- error = mac_get_link(name,
- label);
- if (error == -1) {
- warn("MAC label for %s/%s",
- cur->fts_parent->fts_path,
- cur->fts_name);
- mac_free(label);
- goto label_out;
- }
-
- error = mac_to_text(label,
- &labelstr);
- if (error == -1) {
- warn("MAC label for %s/%s",
- cur->fts_parent->fts_path,
- cur->fts_name);
- mac_free(label);
- goto label_out;
- }
- mac_free(label);
-label_out:
- if (labelstr == NULL)
- labelstr = strdup("-");
- labelstrlen = strlen(labelstr);
- if (labelstrlen > maxlabelstr)
- maxlabelstr = labelstrlen;
- } else
- labelstrlen = 0;
-
- if ((np = malloc(sizeof(NAMES) + labelstrlen +
- ulen + glen + flen + 4)) == NULL)
- err(1, "malloc");
-
- np->user = &np->data[0];
- (void)strcpy(np->user, user);
- np->group = &np->data[ulen + 1];
- (void)strcpy(np->group, group);
-
- if (S_ISCHR(sp->st_mode) ||
- S_ISBLK(sp->st_mode))
- bcfile = 1;
-
- if (f_flags) {
- np->flags = &np->data[ulen + glen + 2];
- (void)strcpy(np->flags, flags);
- free(flags);
- }
- if (f_label) {
- np->label = &np->data[ulen + glen + 2
- + (f_flags ? flen + 1 : 0)];
- (void)strcpy(np->label, labelstr);
- free(labelstr);
- }
- cur->fts_pointer = np;
- }
- }
- ++entries;
- }
-
- /*
- * If there are no entries to display, we normally stop right
- * here. However, we must continue if we have to display the
- * total block count. In this case, we display the total only
- * on the second (p != NULL) pass.
- */
- if (!entries && (!(f_longform || f_size) || p == NULL))
- return;
-
- d.list = list;
- d.entries = entries;
- d.maxlen = maxlen;
- if (needstats) {
- d.bcfile = bcfile;
- d.btotal = btotal;
- (void)snprintf(buf, sizeof(buf), "%lu", maxblock);
- d.s_block = strlen(buf);
- d.s_flags = maxflags;
- d.s_label = maxlabelstr;
- d.s_group = maxgroup;
- (void)snprintf(buf, sizeof(buf), "%lu", maxinode);
- d.s_inode = strlen(buf);
- (void)snprintf(buf, sizeof(buf), "%lu", maxnlink);
- d.s_nlink = strlen(buf);
- (void)snprintf(buf, sizeof(buf), "%ju", maxsize);
- d.s_size = strlen(buf);
- d.s_user = maxuser;
- }
- printfcn(&d);
- output = 1;
-
- if (f_longform)
- for (cur = list; cur; cur = cur->fts_link)
- free(cur->fts_pointer);
-}
-
-/*
- * Ordering for mastercmp:
- * If ordering the argv (fts_level = FTS_ROOTLEVEL) return non-directories
- * as larger than directories. Within either group, use the sort function.
- * All other levels use the sort function. Error entries remain unsorted.
- */
-static int
-mastercmp(const FTSENT * const *a, const FTSENT * const *b)
-{
- int a_info, b_info;
-
- a_info = (*a)->fts_info;
- if (a_info == FTS_ERR)
- return (0);
- b_info = (*b)->fts_info;
- if (b_info == FTS_ERR)
- return (0);
-
- if (a_info == FTS_NS || b_info == FTS_NS)
- return (namecmp(*a, *b));
-
- if (a_info != b_info &&
- (*a)->fts_level == FTS_ROOTLEVEL && !f_listdir) {
- if (a_info == FTS_D)
- return (1);
- if (b_info == FTS_D)
- return (-1);
- }
- return (sortfcn(*a, *b));
-}
diff --git a/src/bin/ls/ls.h b/src/bin/ls/ls.h
deleted file mode 100644
index 8a7537c..0000000
--- a/src/bin/ls/ls.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Fischbein.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)ls.h 8.1 (Berkeley) 5/31/93
- * $FreeBSD: src/bin/ls/ls.h,v 1.22 2006/03/24 16:38:02 jhb Exp $
- */
-
-#define NO_PRINT 1
-
-extern long blocksize; /* block size units */
-
-extern int f_accesstime; /* use time of last access */
-extern int f_birthtime; /* use time of file creation */
-extern int f_flags; /* show flags associated with a file */
-extern int f_humanval; /* show human-readable file sizes */
-extern int f_label; /* show MAC label */
-extern int f_inode; /* print inode */
-extern int f_longform; /* long listing format */
-extern int f_octal; /* print unprintables in octal */
-extern int f_octal_escape; /* like f_octal but use C escapes if possible */
-extern int f_nonprint; /* show unprintables as ? */
-extern int f_sectime; /* print the real time for all files */
-extern int f_size; /* list size in short listing */
-extern int f_slash; /* append a '/' if the file is a directory */
-extern int f_sortacross; /* sort across rows, not down columns */
-extern int f_statustime; /* use time of last mode change */
-extern int f_notabs; /* don't use tab-separated multi-col output */
-extern int f_type; /* add type character for non-regular files */
-#ifdef COLORLS
-extern int f_color; /* add type in color for non-regular files */
-#endif
-
-typedef struct {
- FTSENT *list;
- u_long btotal;
- int bcfile;
- int entries;
- int maxlen;
- u_int s_block;
- u_int s_flags;
- u_int s_label;
- u_int s_group;
- u_int s_inode;
- u_int s_nlink;
- u_int s_size;
- u_int s_user;
-} DISPLAY;
-
-typedef struct {
- char *user;
- char *group;
- char *flags;
- char *label;
- char data[1];
-} NAMES;
diff --git a/src/bin/ls/main.c b/src/bin/ls/main.c
new file mode 100644
index 0000000..cdfd2b3
--- /dev/null
+++ b/src/bin/ls/main.c
@@ -0,0 +1,132 @@
+/**************************************************************************************
+ Copyright (c) 2002 The UbixOS Project
+ All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions, the following disclaimer and the list of authors.
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions, the following disclaimer and the list of authors
+in the documentation and/or other materials provided with the distribution. Neither the name of the UbixOS Project nor the names of its
+contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ $Id$
+
+**************************************************************************************/
+
+#include
+#include
+#include
+
+
+#define permRead 0x8
+#define permWrite 0x4
+#define permExecute 0x2
+#define permHidden 0x1
+
+
+//UbixFS Directory Entry
+struct directoryEntry {
+ uInt32 startCluster; //Starting Cluster Of File
+ uInt32 size; //Size Of File
+ uInt32 creationDate; //Date Created
+ uInt32 lastModified; //Date Last Modified
+ uInt32 uid; //UID Of Owner
+ uInt32 gid; //GID Of Owner
+ uInt16 attributes; //Files Attributes
+ uInt16 permissions; //Files Permissions
+ char fileName[256]; //File Name
+ };
+
+#define typeFile 1
+#define typeContainer 2
+#define typeDirectory 4
+#define typeDeleted 8
+
+int main(int argc,char **argv) {
+ int i = 0x0,x = 0x0,tmpPerms = 0x0;
+ char *pwd = 0x0;
+ char *permsData = 0x0;
+ FILE *fd;
+ struct directoryEntry *dirEntry = 0x0;
+
+ pwd = (char *)malloc(256);
+ permsData = (char *)malloc(13);
+
+ if (argv == 0x0) {
+ getcwd(pwd,256);
+ if ((fd = fopen(pwd,"rb")) == 0x0) {
+ printf("Error: Reading Directory\n");
+ exit(1);
+ }
+ }
+ else if (argv[1] == 0x0) {
+ getcwd(pwd,256);
+ if ((fd = fopen(pwd,"rb")) == 0x0) {
+ printf("Error: Reading Directory\n");
+ exit(1);
+ }
+ }
+ else {
+ fd = fopen(argv[1],"rb");
+ if (fd->fd == 0x0) {
+ printf("Error: Reading Directory\n");
+ exit(1);
+ }
+ }
+ dirEntry = (struct directoryEntry *)malloc(fd->size);
+ fread(dirEntry,fd->size,1,fd);
+ pwd[0] = '/';
+ for (i=0;i<(fd->size/sizeof(struct directoryEntry));i++) {
+ if ((dirEntry[i].fileName[0] > 0) && (dirEntry[i].fileName[0] != '/')) {
+ for (x=0;x<12;x++) {
+ permsData[x] = '-';
+ }
+ if ((dirEntry[i].attributes & typeDeleted) == typeDeleted) {
+ permsData[0] = 'd';
+ goto next;
+ }
+ else if ((dirEntry[i].attributes & typeFile) == typeFile) {
+ permsData[0] = 'F';
+ }
+ else if ((dirEntry[i].attributes & typeDirectory) == typeDirectory) {
+ permsData[0] = 'D';
+ }
+ else if ((dirEntry[i].attributes & typeContainer) == typeContainer) {
+ permsData[0] = '@';
+ }
+ else {
+ permsData[0] = 'U';
+ }
+ tmpPerms = ((dirEntry[i].permissions & 0xF00) >> 8);
+ if ((tmpPerms & permRead) == permRead) permsData[1] = 'R';
+ if ((tmpPerms & permWrite) == permWrite) permsData[2] = 'W';
+ if ((tmpPerms & permExecute) == permExecute) permsData[3] = 'E';
+ if ((tmpPerms & permHidden) == permHidden) permsData[4] = 'H';
+ tmpPerms = ((dirEntry[i].permissions & 0x0F0) >> 4);
+ if ((tmpPerms & permRead) == permRead) permsData[5] = 'R';
+ if ((tmpPerms & permWrite) == permWrite) permsData[6] = 'W';
+ if ((tmpPerms & permExecute) == permExecute) permsData[7] = 'E';
+ if ((tmpPerms & permHidden) == permHidden) permsData[8] = 'H';
+ tmpPerms = ((dirEntry[i].permissions & 0x00F) >> 0);
+ if ((tmpPerms & permRead) == permRead) permsData[9] = 'R';
+ if ((tmpPerms & permWrite) == permWrite) permsData[10] = 'W';
+ if ((tmpPerms & permExecute) == permExecute) permsData[11] = 'E';
+ if ((tmpPerms & permHidden) == permHidden) permsData[12] = 'H';
+ printf("%s %i %i %i\t%s\n",permsData,(int)dirEntry[i].uid,(int)dirEntry[i].gid,(int)dirEntry[i].size,dirEntry[i].fileName);
+ next:
+ asm("nop");
+ }
+ }
+ if (fclose(fd) != 0x0) {
+ printf("Error Closing Directory\n");
+ }
+ return(0);
+ }
diff --git a/src/bin/ls/print.c b/src/bin/ls/print.c
deleted file mode 100644
index 5616b2b..0000000
--- a/src/bin/ls/print.c
+++ /dev/null
@@ -1,682 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Fischbein.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)print.c 8.4 (Berkeley) 4/17/94";
-#endif /* not lint */
-#endif
-#include
-__FBSDID("$FreeBSD: src/bin/ls/print.c,v 1.76 2006/10/18 10:58:27 ru Exp $");
-
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#ifdef COLORLS
-#include
-#include
-#include
-#endif
-
-#include "ls.h"
-#include "extern.h"
-
-static int printaname(const FTSENT *, u_long, u_long);
-static void printlink(const FTSENT *);
-static void printtime(time_t);
-static int printtype(u_int);
-static void printsize(size_t, off_t);
-#ifdef COLORLS
-static void endcolor(int);
-static int colortype(mode_t);
-#endif
-static void aclmode(char *, const FTSENT *, int *);
-
-#define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT)
-
-#ifdef COLORLS
-/* Most of these are taken from */
-typedef enum Colors {
- C_DIR, /* directory */
- C_LNK, /* symbolic link */
- C_SOCK, /* socket */
- C_FIFO, /* pipe */
- C_EXEC, /* executable */
- C_BLK, /* block special */
- C_CHR, /* character special */
- C_SUID, /* setuid executable */
- C_SGID, /* setgid executable */
- C_WSDIR, /* directory writeble to others, with sticky
- * bit */
- C_WDIR, /* directory writeble to others, without
- * sticky bit */
- C_NUMCOLORS /* just a place-holder */
-} Colors;
-
-static const char *defcolors = "exfxcxdxbxegedabagacad";
-
-/* colors for file types */
-static struct {
- int num[2];
- int bold;
-} colors[C_NUMCOLORS];
-#endif
-
-void
-printscol(const DISPLAY *dp)
-{
- FTSENT *p;
-
- for (p = dp->list; p; p = p->fts_link) {
- if (IS_NOPRINT(p))
- continue;
- (void)printaname(p, dp->s_inode, dp->s_block);
- (void)putchar('\n');
- }
-}
-
-/*
- * print name in current style
- */
-int
-printname(const char *name)
-{
-printf("printname\n");
- if (f_octal || f_octal_escape)
- return prn_octal(name);
- else if (f_nonprint)
- return prn_printable(name);
- else
- return prn_normal(name);
-}
-
-void
-printlong(const DISPLAY *dp)
-{
- struct stat *sp;
- FTSENT *p;
- NAMES *np;
- char buf[20];
-#ifdef COLORLS
- int color_printed = 0;
-#endif
- int haveacls;
- dev_t prevdev;
-
- printf("PRINTLONG\n");
-
- if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
- (f_longform || f_size)) {
- (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
- }
-
- haveacls = 1;
- prevdev = (dev_t)-1;
- for (p = dp->list; p; p = p->fts_link) {
- if (IS_NOPRINT(p))
- continue;
- sp = p->fts_statp;
- if (f_inode)
- (void)printf("%*lu ", dp->s_inode, (u_long)sp->st_ino);
- if (f_size)
- (void)printf("%*jd ",
- dp->s_block, howmany(sp->st_blocks, blocksize));
- strmode(sp->st_mode, buf);
- /*
- * Cache whether or not the filesystem supports ACL's to
- * avoid expensive syscalls. Try again when we change devices.
- */
- if (haveacls || sp->st_dev != prevdev) {
- aclmode(buf, p, &haveacls);
- prevdev = sp->st_dev;
- }
- np = p->fts_pointer;
- (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink,
- sp->st_nlink, dp->s_user, np->user, dp->s_group,
- np->group);
- if (f_flags)
- (void)printf("%-*s ", dp->s_flags, np->flags);
- if (f_label)
- (void)printf("%-*s ", dp->s_label, np->label);
- if (S_ISCHR(sp->st_mode) || S_ISBLK(sp->st_mode))
- if (minor(sp->st_rdev) > 255 || minor(sp->st_rdev) < 0)
- (void)printf("%3d, 0x%08x ",
- major(sp->st_rdev),
- (u_int)minor(sp->st_rdev));
- else
- (void)printf("%3d, %3d ",
- major(sp->st_rdev), minor(sp->st_rdev));
- else if (dp->bcfile)
- (void)printf("%*s%*jd ",
- 8 - dp->s_size, "", dp->s_size, sp->st_size);
- else
- printsize(dp->s_size, sp->st_size);
- if (f_accesstime)
- printtime(sp->st_atime);
- else if (f_birthtime)
- printtime(sp->st_birthtime);
- else if (f_statustime)
- printtime(sp->st_ctime);
- else
- printtime(sp->st_mtime);
-#ifdef COLORLS
- if (f_color)
- color_printed = colortype(sp->st_mode);
-#endif
- (void)printname(p->fts_name);
-#ifdef COLORLS
- if (f_color && color_printed)
- endcolor(0);
-#endif
- if (f_type)
- (void)printtype(sp->st_mode);
- if (S_ISLNK(sp->st_mode))
- printlink(p);
- (void)putchar('\n');
- }
-}
-
-void
-printstream(const DISPLAY *dp)
-{
- FTSENT *p;
- int chcnt;
-printf("printstream\n");
-
- for (p = dp->list, chcnt = 0; p; p = p->fts_link) {
- if (p->fts_number == NO_PRINT)
- continue;
- /* XXX strlen does not take octal escapes into account. */
- if (strlen(p->fts_name) + chcnt +
- (p->fts_link ? 2 : 0) >= (unsigned)termwidth) {
- putchar('\n');
- chcnt = 0;
- }
- chcnt += printaname(p, dp->s_inode, dp->s_block);
- if (p->fts_link) {
- printf(", ");
- chcnt += 2;
- }
- }
- if (chcnt)
- putchar('\n');
-}
-
-void
-printcol(const DISPLAY *dp)
-{
- static FTSENT **array;
- static int lastentries = -1;
- FTSENT *p;
- FTSENT **narray;
- int base;
- int chcnt;
- int cnt;
- int col;
- int colwidth;
- int endcol;
- int num;
- int numcols;
- int numrows;
- int row;
- int tabwidth;
-
-printf("printcol");
-
- if (f_notabs)
- tabwidth = 1;
- else
- tabwidth = 8;
-
- /*
- * Have to do random access in the linked list -- build a table
- * of pointers.
- */
- if (dp->entries > lastentries) {
- if ((narray =
- realloc(array, dp->entries * sizeof(FTSENT *))) == NULL) {
- warn(NULL);
- printscol(dp);
- return;
- }
- lastentries = dp->entries;
- array = narray;
- }
- for (p = dp->list, num = 0; p; p = p->fts_link)
- if (p->fts_number != NO_PRINT)
- array[num++] = p;
-
- colwidth = dp->maxlen;
- if (f_inode)
- colwidth += dp->s_inode + 1;
- if (f_size)
- colwidth += dp->s_block + 1;
- if (f_type)
- colwidth += 1;
-
- colwidth = (colwidth + tabwidth) & ~(tabwidth - 1);
- printf("colwidth: %i\n",colwidth);
- if (termwidth < 2 * colwidth) {
- printscol(dp);
- return;
- }
-
- printf("termwidth: %i\n",termwidth);
- numcols = termwidth / colwidth;
- numrows = num / numcols;
- if (num % numcols)
- ++numrows;
-
- if ((dp->list == NULL || dp->list->fts_level != FTS_ROOTLEVEL) &&
- (f_longform || f_size)) {
- (void)printf("total %lu\n", howmany(dp->btotal, blocksize));
- }
-
- base = 0;
- for (row = 0; row < numrows; ++row) {
- endcol = colwidth;
- if (!f_sortacross)
- base = row;
- for (col = 0, chcnt = 0; col < numcols; ++col) {
- chcnt += printaname(array[base], dp->s_inode,
- dp->s_block);
- if (f_sortacross)
- base++;
- else
- base += numrows;
- if (base >= num)
- break;
- while ((cnt = ((chcnt + tabwidth) & ~(tabwidth - 1)))
- <= endcol) {
- if (f_sortacross && col + 1 >= numcols)
- break;
- (void)putchar(f_notabs ? ' ' : '\t');
- chcnt = cnt;
- }
- endcol += colwidth;
- }
- (void)putchar('\n');
- }
-}
-
-/*
- * print [inode] [size] name
- * return # of characters printed, no trailing characters.
- */
-static int
-printaname(const FTSENT *p, u_long inodefield, u_long sizefield)
-{
- struct stat *sp;
- int chcnt;
-#ifdef COLORLS
- int color_printed = 0;
-#endif
-
-printf("printaname:\n");
-
- sp = p->fts_statp;
- chcnt = 0;
- if (f_inode)
- chcnt += printf("%*lu ", (int)inodefield, (u_long)sp->st_ino);
- if (f_size)
- chcnt += printf("%*jd ",
- (int)sizefield, howmany(sp->st_blocks, blocksize));
-
-printf("f_size: %i\n",f_size);
-#ifdef COLORLS
- if (f_color)
- color_printed = colortype(sp->st_mode);
-#endif
- chcnt += printname(p->fts_name);
-#ifdef COLORLS
- if (f_color && color_printed)
- endcolor(0);
-#endif
- if (f_type)
- chcnt += printtype(sp->st_mode);
- return (chcnt);
-}
-
-static void
-printtime(time_t ftime)
-{
- char longstring[80];
- static time_t now = 0;
- const char *format;
- static int d_first = -1;
-
-printf("printtime\n");
- if (d_first < 0)
- d_first = (*nl_langinfo(D_MD_ORDER) == 'd');
- if (now == 0)
- now = time(NULL);
-
-#define SIXMONTHS ((365 / 2) * 86400)
- if (f_sectime)
- /* mmm dd hh:mm:ss yyyy || dd mmm hh:mm:ss yyyy */
- format = d_first ? "%e %b %T %Y " : "%b %e %T %Y ";
- else if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS)
- /* mmm dd hh:mm || dd mmm hh:mm */
- format = d_first ? "%e %b %R " : "%b %e %R ";
- else
- /* mmm dd yyyy || dd mmm yyyy */
- format = d_first ? "%e %b %Y " : "%b %e %Y ";
- strftime(longstring, sizeof(longstring), format, localtime(&ftime));
- fputs(longstring, stdout);
-}
-
-static int
-printtype(u_int mode)
-{
-printf("printtype\n");
-
- if (f_slash) {
- if ((mode & S_IFMT) == S_IFDIR) {
- (void)putchar('/');
- return (1);
- }
- return (0);
- }
-
- switch (mode & S_IFMT) {
- case S_IFDIR:
- (void)putchar('/');
- return (1);
- case S_IFIFO:
- (void)putchar('|');
- return (1);
- case S_IFLNK:
- (void)putchar('@');
- return (1);
- case S_IFSOCK:
- (void)putchar('=');
- return (1);
- case S_IFWHT:
- (void)putchar('%');
- return (1);
- default:
- break;
- }
- if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
- (void)putchar('*');
- return (1);
- }
- return (0);
-}
-
-#ifdef COLORLS
-static int
-putch(int c)
-{
-printf("putch\n");
- (void)putchar(c);
- return 0;
-}
-
-static int
-writech(int c)
-{
- char tmp = (char)c;
-
-printf("writech\n");
-
- (void)write(STDOUT_FILENO, &tmp, 1);
- return 0;
-}
-
-static void
-printcolor(Colors c)
-{
- char *ansiseq;
-
- if (colors[c].bold)
- tputs(enter_bold, 1, putch);
-
- if (colors[c].num[0] != -1) {
- ansiseq = tgoto(ansi_fgcol, 0, colors[c].num[0]);
- if (ansiseq)
- tputs(ansiseq, 1, putch);
- }
- if (colors[c].num[1] != -1) {
- ansiseq = tgoto(ansi_bgcol, 0, colors[c].num[1]);
- if (ansiseq)
- tputs(ansiseq, 1, putch);
- }
-}
-
-static void
-endcolor(int sig)
-{
- tputs(ansi_coloff, 1, sig ? writech : putch);
- tputs(attrs_off, 1, sig ? writech : putch);
-}
-
-static int
-colortype(mode_t mode)
-{
- switch (mode & S_IFMT) {
- case S_IFDIR:
- if (mode & S_IWOTH)
- if (mode & S_ISTXT)
- printcolor(C_WSDIR);
- else
- printcolor(C_WDIR);
- else
- printcolor(C_DIR);
- return (1);
- case S_IFLNK:
- printcolor(C_LNK);
- return (1);
- case S_IFSOCK:
- printcolor(C_SOCK);
- return (1);
- case S_IFIFO:
- printcolor(C_FIFO);
- return (1);
- case S_IFBLK:
- printcolor(C_BLK);
- return (1);
- case S_IFCHR:
- printcolor(C_CHR);
- return (1);
- default:;
- }
- if (mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
- if (mode & S_ISUID)
- printcolor(C_SUID);
- else if (mode & S_ISGID)
- printcolor(C_SGID);
- else
- printcolor(C_EXEC);
- return (1);
- }
- return (0);
-}
-
-void
-parsecolors(const char *cs)
-{
- int i;
- int j;
- size_t len;
- char c[2];
- short legacy_warn = 0;
-
- if (cs == NULL)
- cs = ""; /* LSCOLORS not set */
- len = strlen(cs);
- for (i = 0; i < (int)C_NUMCOLORS; i++) {
- colors[i].bold = 0;
-
- if (len <= 2 * (size_t)i) {
- c[0] = defcolors[2 * i];
- c[1] = defcolors[2 * i + 1];
- } else {
- c[0] = cs[2 * i];
- c[1] = cs[2 * i + 1];
- }
- for (j = 0; j < 2; j++) {
- /* Legacy colours used 0-7 */
- if (c[j] >= '0' && c[j] <= '7') {
- colors[i].num[j] = c[j] - '0';
- if (!legacy_warn) {
- warnx("LSCOLORS should use "
- "characters a-h instead of 0-9 ("
- "see the manual page)");
- }
- legacy_warn = 1;
- } else if (c[j] >= 'a' && c[j] <= 'h')
- colors[i].num[j] = c[j] - 'a';
- else if (c[j] >= 'A' && c[j] <= 'H') {
- colors[i].num[j] = c[j] - 'A';
- colors[i].bold = 1;
- } else if (tolower((unsigned char)c[j]) == 'x')
- colors[i].num[j] = -1;
- else {
- warnx("invalid character '%c' in LSCOLORS"
- " env var", c[j]);
- colors[i].num[j] = -1;
- }
- }
- }
-}
-
-void
-colorquit(int sig)
-{
- endcolor(sig);
-
- (void)signal(sig, SIG_DFL);
- (void)kill(getpid(), sig);
-}
-
-#endif /* COLORLS */
-
-static void
-printlink(const FTSENT *p)
-{
- int lnklen;
- char name[MAXPATHLEN + 1];
- char path[MAXPATHLEN + 1];
-
- if (p->fts_level == FTS_ROOTLEVEL)
- (void)snprintf(name, sizeof(name), "%s", p->fts_name);
- else
- (void)snprintf(name, sizeof(name),
- "%s/%s", p->fts_parent->fts_accpath, p->fts_name);
- if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) {
- (void)fprintf(stderr, "\nls: %s: %s\n", name, strerror(errno));
- return;
- }
- path[lnklen] = '\0';
- (void)printf(" -> ");
- (void)printname(path);
-}
-
-static void
-printsize(size_t width, off_t bytes)
-{
-
- if (f_humanval) {
- char buf[5];
-
- humanize_number(buf, sizeof(buf), (int64_t)bytes, "",
- HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
- (void)printf("%5s ", buf);
- } else
- (void)printf("%*jd ", (u_int)width, bytes);
-}
-
-static void
-aclmode(char *buf, const FTSENT *p, int *haveacls)
-{
- char name[MAXPATHLEN + 1];
- int entries, ret;
- acl_t facl;
- acl_entry_t ae;
-
- /*
- * Add a + after the standard rwxrwxrwx mode if the file has an
- * extended ACL. strmode() reserves space at the end of the string.
- */
- if (p->fts_level == FTS_ROOTLEVEL)
- snprintf(name, sizeof(name), "%s", p->fts_name);
- else
- snprintf(name, sizeof(name), "%s/%s",
- p->fts_parent->fts_accpath, p->fts_name);
- /*
- * We have no way to tell whether a symbolic link has an ACL since
- * pathconf() and acl_get_file() both follow them. They also don't
- * support whiteouts.
- */
- if (S_ISLNK(p->fts_statp->st_mode) || S_ISWHT(p->fts_statp->st_mode)) {
- *haveacls = 1;
- return;
- }
- if ((ret = pathconf(name, _PC_ACL_EXTENDED)) <= 0) {
- if (ret < 0 && errno != EINVAL)
- warn("%s", name);
- else
- *haveacls = 0;
- return;
- }
- *haveacls = 1;
- if ((facl = acl_get_file(name, ACL_TYPE_ACCESS)) != NULL) {
- if (acl_get_entry(facl, ACL_FIRST_ENTRY, &ae) == 1) {
- entries = 1;
- while (acl_get_entry(facl, ACL_NEXT_ENTRY, &ae) == 1)
- if (++entries > 3)
- break;
- /*
- * POSIX.1e requires that ACLs of type ACL_TYPE_ACCESS
- * must have at least three entries (owner, group,
- * and other). So anything with more than 3 ACLs looks
- * interesting to us.
- */
- if (entries > 3)
- buf[10] = '+';
- }
- acl_free(facl);
- } else
- warn("%s", name);
-}
diff --git a/src/bin/ls/util.c b/src/bin/ls/util.c
deleted file mode 100644
index e3f6026..0000000
--- a/src/bin/ls/util.c
+++ /dev/null
@@ -1,234 +0,0 @@
-/*-
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Michael Fischbein.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if 0
-#ifndef lint
-static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94";
-#endif /* not lint */
-#endif
-#include
-__FBSDID("$FreeBSD: src/bin/ls/util.c,v 1.40 2006/03/24 16:38:02 jhb Exp $");
-
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "ls.h"
-#include "extern.h"
-
-int
-prn_normal(const char *s)
-{
- mbstate_t mbs;
- wchar_t wc;
- int i, n;
- size_t clen;
-
- memset(&mbs, 0, sizeof(mbs));
- n = 0;
- while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
- if (clen == (size_t)-2) {
- n += printf("%s", s);
- break;
- }
- if (clen == (size_t)-1) {
- memset(&mbs, 0, sizeof(mbs));
- putchar((unsigned char)*s);
- s++;
- n++;
- continue;
- }
- for (i = 0; i < (int)clen; i++)
- putchar((unsigned char)s[i]);
- s += clen;
- if (iswprint(wc))
- n += wcwidth(wc);
- }
- return (n);
-}
-
-int
-prn_printable(const char *s)
-{
- mbstate_t mbs;
- wchar_t wc;
- int i, n;
- size_t clen;
-
- memset(&mbs, 0, sizeof(mbs));
- n = 0;
- while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
- printf("CLEN: %i - %i - %i\n",clen,(size_t)-1,(size_t)-2);
- if (clen == (size_t)-1) {
- putchar('?');
- s++;
- n++;
- memset(&mbs, 0, sizeof(mbs));
- continue;
- }
- if (clen == (size_t)-2) {
- putchar('?');
- n++;
- break;
- }
- if (!iswprint(wc)) {
- printf("WTF?\n");
- putchar('?');
- s += clen;
- n++;
- continue;
- }
- printf("HERE?\n");
- for (i = 0; i < (int)clen; i++)
- putchar((unsigned char)s[i]);
- s += clen;
- n += wcwidth(wc);
- }
- return (n);
-}
-
-/*
- * The fts system makes it difficult to replace fts_name with a different-
- * sized string, so we just calculate the real length here and do the
- * conversion in prn_octal()
- *
- * XXX when using f_octal_escape (-b) rather than f_octal (-B), the
- * length computed by len_octal may be too big. I just can't be buggered
- * to fix this as an efficient fix would involve a lookup table. Same goes
- * for the rather inelegant code in prn_octal.
- *
- * DES 1998/04/23
- */
-
-size_t
-len_octal(const char *s, int len)
-{
- mbstate_t mbs;
- wchar_t wc;
- size_t clen, r;
-
- memset(&mbs, 0, sizeof(mbs));
- r = 0;
- while (len != 0 && (clen = mbrtowc(&wc, s, len, &mbs)) != 0) {
- if (clen == (size_t)-1) {
- r += 4;
- s++;
- len--;
- memset(&mbs, 0, sizeof(mbs));
- continue;
- }
- if (clen == (size_t)-2) {
- r += 4 * len;
- break;
- }
- if (iswprint(wc))
- r++;
- else
- r += 4 * clen;
- s += clen;
- }
- return (r);
-}
-
-int
-prn_octal(const char *s)
-{
- static const char esc[] = "\\\\\"\"\aa\bb\ff\nn\rr\tt\vv";
- const char *p;
- mbstate_t mbs;
- wchar_t wc;
- size_t clen;
- unsigned char ch;
- int goodchar, i, len, prtlen;
-
- memset(&mbs, 0, sizeof(mbs));
- len = 0;
- while ((clen = mbrtowc(&wc, s, MB_LEN_MAX, &mbs)) != 0) {
- goodchar = clen != (size_t)-1 && clen != (size_t)-2;
- if (goodchar && iswprint(wc) && wc != L'\"' && wc != L'\\') {
- for (i = 0; i < (int)clen; i++)
- putchar((unsigned char)s[i]);
- len += wcwidth(wc);
- } else if (goodchar && f_octal_escape && wc >= 0 &&
- wc <= (wchar_t)UCHAR_MAX &&
- (p = strchr(esc, (char)wc)) != NULL) {
- putchar('\\');
- putchar(p[1]);
- len += 2;
- } else {
- if (goodchar)
- prtlen = clen;
- else if (clen == (size_t)-1)
- prtlen = 1;
- else
- prtlen = strlen(s);
- for (i = 0; i < prtlen; i++) {
- ch = (unsigned char)s[i];
- putchar('\\');
- putchar('0' + (ch >> 6));
- putchar('0' + ((ch >> 3) & 7));
- putchar('0' + (ch & 7));
- len += 4;
- }
- }
- if (clen == (size_t)-2)
- break;
- if (clen == (size_t)-1) {
- memset(&mbs, 0, sizeof(mbs));
- s++;
- } else
- s += clen;
- }
- return (len);
-}
-
-void
-usage(void)
-{
- (void)fprintf(stderr,
-#ifdef COLORLS
- "usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwx1]"
-#else
- "usage: ls [-ABCFHILPRSTUWZabcdfghiklmnopqrstuwx1]"
-#endif
- " [file ...]\n");
- exit(1);
-}
diff --git a/src/bin/mount/Makefile b/src/bin/mount/Makefile
deleted file mode 100644
index f54faa5..0000000
--- a/src/bin/mount/Makefile
+++ /dev/null
@@ -1,45 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-#Linker
-LD = ld
-
-#Binary File Name
-BINARY = mount
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = main.o
-
-LIBRARIES = ../../lib/libc_old/libc_old.so
-
-# Link The Binary
-$(BINARY) : $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- strip $(BINARY)
-
-# Compile the source files
-.cc.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/mount/main.c b/src/bin/mount/main.c
deleted file mode 100644
index 75a03f1..0000000
--- a/src/bin/mount/main.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include
-#include
-
-void usage();
-
-int main(int argc,char * const argv[]) {
- int ch = 0x0;
- while ((ch = getopt(argc, argv, "adlF:fo:prwt:uv")) != -1) {
- printf("[%i]\n",ch);
- switch (ch) {
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
- }
- return(0x0);
- }
-
-void usage() {
-
- (void)printf("%s\n%s\n%s\n",
-"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
-" mount [-dfpruvw] special | node",
-" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node");
- exit(1);
-}
-
diff --git a/src/bin/mv/Makefile b/src/bin/mv/Makefile
new file mode 100755
index 0000000..8e71e7d
--- /dev/null
+++ b/src/bin/mv/Makefile
@@ -0,0 +1,45 @@
+# $Id$
+# Application Makefile (C) 2002-2004 The UbixOS Project
+
+# Include Global 'Source' Options
+include ../../Makefile.inc
+include ../Makefile.inc
+
+#Linker
+LD = ld
+
+#Binary File Name
+BINARY = mv
+
+#Delete Program
+REMOVE = rm -f
+
+#Objects
+OBJS = main.o
+
+LIBRARIES = ../../lib/libc_old/libc_old.so
+
+# Link The Binary
+$(BINARY) : $(OBJS)
+ $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
+ strip $(BINARY)
+
+# Compile the source files
+.cc.o:
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
+.cc.s:
+ $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
+
+.c.o:
+ $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
+
+.c.s:
+ $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
+
+.S.o:
+ $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
+
+# Clean Up The junk
+clean:
+ $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/mv/main.c b/src/bin/mv/main.c
new file mode 100755
index 0000000..c090151
--- /dev/null
+++ b/src/bin/mv/main.c
@@ -0,0 +1,52 @@
+#include
+#include
+#include
+
+int main(int argc,char **argv)
+{
+ int i = 0x0, z = 0x0;
+ char *buffer = (char *)malloc(4096);
+ FILE *in = 0x0;
+ FILE *out = 0x0;
+
+ if(argc != 3)
+ {
+ printf("usage: mv \n");
+ return 0;
+ }
+
+ in = fopen(argv[1],"rb");
+ out = fopen(argv[2],"wb");
+
+ if(in == NULL || out == NULL)
+ {
+ printf("unable to open file(s) for i/o\n");
+ return 1;
+ }
+ while (!feof(in))
+ {
+ i = fread(buffer,4096,1,in);
+ z = fwrite(buffer,4096,1,out);
+ }
+ fclose(in);
+ fclose(out);
+
+ if(i != z)
+ printf("mv: failed: out of disk space or kernel error\n");
+ else
+ unlink(argv[1]);
+ return(0x0);
+}
+
+/***
+ $Log$
+ Revision 1.4 2005/08/05 09:43:57 fsdfs
+
+ code clean up, performance tuning
+
+ Revision 1.3 2004/05/24 13:40:35 reddawg
+ Clean Up
+
+
+ END
+ ***/
diff --git a/src/bin/rtld-elf/Makefile b/src/bin/rtld-elf/Makefile
deleted file mode 100644
index 28e62e5..0000000
--- a/src/bin/rtld-elf/Makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-INCLUDES = -I../../include.new -I./
-
-#-Werror
-CFLAGS+= -Wall -DFREEBSD_ELF -DIN_RTLD -DPIC
-CFLAGS = -O -fpic -fno-strict-aliasing -pipe -Wall -DFREEBSD_ELF -DIN_RTLD -I./ -elf -DPIC -std=gnu99 -Wformat=2 -Wno-format-extra-args -DDEBUG
-
-
-#Linker
-LD = ld
-
-#Binary File Name
-OUTPUT = ld-elf.so.1
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = rtld_start.o reloc.o rtld.o rtld_lock.o map_object.o malloc.o xmalloc.o debug.o libmap.o
-
-LIBRARIES = #../../lib/libc/libc.so
-
-
-# Link The Binary
-$(OUTPUT) : $(OBJS)
-# $(CC) -fpic -nostdlib -shared -Wl,-soname,$(OUTPUT) -e .rtld_start -o $(OUTPUT) $(OBJS) $(LIBRARIES) $(SUBS)
-# $(CC) $(CFLAGS) -nostdlib -e .rtld_start -elf -shared -Wl,-Bsymbolic -o $(OUTPUT) $(OBJS) -lc_pic
-# $(CC) $(CFLAGS) -nostdlib -e .rtld_start -elf -shared -Wl,-Bsymbolic -o $(OUTPUT) $(OBJS) ./libc_pic.a #-lc_pic
- $(CC) $(CFLAGS) -nostdlib -e .rtld_start -elf -shared -Wl,-Bsymbolic -o $(OUTPUT) $(OBJS) ../../lib/libc/pic.a #-lc_pic
-# strip $(OUTPUT)
-
-# Compile the source files
-.cpp.o:
- $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.o:
- $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(OUTPUT)
diff --git a/src/bin/rtld-elf/debug.c b/src/bin/rtld-elf/debug.c
deleted file mode 100644
index 3a83b66..0000000
--- a/src/bin/rtld-elf/debug.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*-
- * Copyright 1996-1998 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/debug.c,v 1.4 2003/06/19 16:09:18 mdodd Exp $
- */
-
-/*
- * Support for printing debugging messages.
- */
-
-#include
-#include
-
-#include "debug.h"
-#include "rtld.h"
-
-static const char rel_header[] =
- " symbol name r_info r_offset st_value st_size address value\n"
- " ------------------------------------------------------------------------------\n";
-static const char rel_format[] = " %-25s %6lx %08lx %08lx %7d %10p %08lx\n";
-
-int debug = 0;
-
-void
-debug_printf(const char *format, ...)
-{
- if (debug) {
- va_list ap;
- va_start(ap, format);
-
- fflush(stdout);
- vfprintf(stderr, format, ap);
- putc('\n', stderr);
-
- va_end(ap);
- }
-}
-
-void
-dump_relocations (Obj_Entry *obj0)
-{
- Obj_Entry *obj;
-
- for (obj = obj0; obj != NULL; obj = obj->next) {
- dump_obj_relocations(obj);
- }
-}
-
-void
-dump_obj_relocations (Obj_Entry *obj)
-{
-
- printf("Object \"%s\", relocbase %p\n", obj->path, obj->relocbase);
-
- if (obj->relsize) {
- printf("Non-PLT Relocations: %ld\n",
- (obj->relsize / sizeof(Elf_Rel)));
- dump_Elf_Rel(obj, obj->rel, obj->relsize);
- }
-
- if (obj->relasize) {
- printf("Non-PLT Relocations with Addend: %ld\n",
- (obj->relasize / sizeof(Elf_Rela)));
- dump_Elf_Rela(obj, obj->rela, obj->relasize);
- }
-
- if (obj->pltrelsize) {
- printf("PLT Relocations: %ld\n",
- (obj->pltrelsize / sizeof(Elf_Rel)));
- dump_Elf_Rel(obj, obj->pltrel, obj->pltrelsize);
- }
-
- if (obj->pltrelasize) {
- printf("PLT Relocations with Addend: %ld\n",
- (obj->pltrelasize / sizeof(Elf_Rela)));
- dump_Elf_Rela(obj, obj->pltrela, obj->pltrelasize);
- }
-}
-
-void
-dump_Elf_Rel (Obj_Entry *obj, const Elf_Rel *rel0, u_long relsize)
-{
- const Elf_Rel *rel;
- const Elf_Rel *rellim;
- const Elf_Sym *sym;
- Elf_Addr *dstaddr;
-
- printf("%s", rel_header);
- rellim = (const Elf_Rel *)((const char *)rel0 + relsize);
- for (rel = rel0; rel < rellim; rel++) {
- dstaddr = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- sym = obj->symtab + ELF_R_SYM(rel->r_info);
- printf(rel_format,
- obj->strtab + sym->st_name,
- (u_long)rel->r_info, (u_long)rel->r_offset,
- (u_long)sym->st_value, (int)sym->st_size,
- dstaddr, (u_long)*dstaddr);
- }
- return;
-}
-
-void
-dump_Elf_Rela (Obj_Entry *obj, const Elf_Rela *rela0, u_long relasize)
-{
- const Elf_Rela *rela;
- const Elf_Rela *relalim;
- const Elf_Sym *sym;
- Elf_Addr *dstaddr;
-
- printf("%s", rel_header);
- relalim = (const Elf_Rela *)((const char *)rela0 + relasize);
- for (rela = rela0; rela < relalim; rela++) {
- dstaddr = (Elf_Addr *)(obj->relocbase + rela->r_offset);
- sym = obj->symtab + ELF_R_SYM(rela->r_info);
- printf(rel_format,
- obj->strtab + sym->st_name,
- (u_long)rela->r_info, (u_long)rela->r_offset,
- (u_long)sym->st_value, (int)sym->st_size,
- dstaddr, (u_long)*dstaddr);
- }
- return;
-}
diff --git a/src/bin/rtld-elf/debug.h b/src/bin/rtld-elf/debug.h
deleted file mode 100644
index 68faa0a..0000000
--- a/src/bin/rtld-elf/debug.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*-
- * Copyright 1996-1998 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/debug.h,v 1.6 2004/03/21 01:21:26 peter Exp $
- */
-
-/*
- * Support for printing debugging messages.
- */
-
-#ifndef DEBUG_H
-#define DEBUG_H 1
-
-#ifndef __GNUC__
-#error "This file must be compiled with GCC"
-#endif
-
-#include
-
-#include
-#include
-
-extern void debug_printf(const char *, ...) __printflike(1, 2);
-extern int debug;
-
-#ifdef DEBUG
-#define dbg(format, args...) debug_printf(format , ## args)
-#else
-#define dbg(format, args...) ((void) 0)
-#endif
-
-#ifndef COMPAT_32BIT
-#define _MYNAME "ld-elf.so.1"
-#else
-#define _MYNAME "ld-elf32.so.1"
-#endif
-
-#define assert(cond) ((cond) ? (void) 0 : \
- (msg(_MYNAME ": assert failed: " __FILE__ ":" \
- __XSTRING(__LINE__) "\n"), abort()))
-#define msg(s) write(STDOUT_FILENO, s, strlen(s))
-#define trace() msg(_MYNAME ": " __XSTRING(__LINE__) "\n")
-
-
-#endif /* DEBUG_H */
diff --git a/src/bin/rtld-elf/libmap.c b/src/bin/rtld-elf/libmap.c
deleted file mode 100644
index b78fe4c..0000000
--- a/src/bin/rtld-elf/libmap.c
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * $FreeBSD: src/libexec/rtld-elf/libmap.c,v 1.14 2005/02/04 02:46:41 mdodd Exp $
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "debug.h"
-#include "rtld.h"
-#include "libmap.h"
-
-#ifndef _PATH_LIBMAP_CONF
-#define _PATH_LIBMAP_CONF "/etc/libmap.conf"
-#endif
-
-#ifdef COMPAT_32BIT
-#undef _PATH_LIBMAP_CONF
-#define _PATH_LIBMAP_CONF "/etc/libmap32.conf"
-#endif
-
-TAILQ_HEAD(lm_list, lm);
-struct lm {
- char *f;
- char *t;
-
- TAILQ_ENTRY(lm) lm_link;
-};
-
-TAILQ_HEAD(lmp_list, lmp) lmp_head = TAILQ_HEAD_INITIALIZER(lmp_head);
-struct lmp {
- char *p;
- enum { T_EXACT=0, T_BASENAME, T_DIRECTORY } type;
- struct lm_list lml;
- TAILQ_ENTRY(lmp) lmp_link;
-};
-
-static int lm_count;
-
-static void lmc_parse (FILE *);
-static void lm_add (const char *, const char *, const char *);
-static void lm_free (struct lm_list *);
-static char * lml_find (struct lm_list *, const char *);
-static struct lm_list * lmp_find (const char *);
-static struct lm_list * lmp_init (char *);
-static const char * quickbasename (const char *);
-static int readstrfn (void * cookie, char *buf, int len);
-static int closestrfn (void * cookie);
-
-#define iseol(c) (((c) == '#') || ((c) == '\0') || \
- ((c) == '\n') || ((c) == '\r'))
-
-int
-lm_init (char *libmap_override)
-{
- FILE *fp;
-
- dbg("%s(\"%s\")", __func__, libmap_override);
-
- TAILQ_INIT(&lmp_head);
-
- fp = fopen(_PATH_LIBMAP_CONF, "r");
- if (fp) {
- lmc_parse(fp);
- fclose(fp);
- }
-
- if (libmap_override) {
- char *p;
- /* do some character replacement to make $LIBMAP look like a
- text file, then "open" it with funopen */
- libmap_override = xstrdup(libmap_override);
-
- for (p = libmap_override; *p; p++) {
- switch (*p) {
- case '=':
- *p = ' '; break;
- case ',':
- *p = '\n'; break;
- }
- }
- fp = funopen(libmap_override, readstrfn, NULL, NULL, closestrfn);
- if (fp) {
- lmc_parse(fp);
- fclose(fp);
- }
- }
-
- return (lm_count == 0);
-}
-
-static void
-lmc_parse (FILE *fp)
-{
- char *cp;
- char *f, *t, *c, *p;
- char prog[MAXPATHLEN];
- char line[MAXPATHLEN + 2];
-
- dbg("%s(%p)", __func__, fp);
-
- p = NULL;
- while ((cp = fgets(line, MAXPATHLEN + 1, fp)) != NULL) {
- t = f = c = NULL;
-
- /* Skip over leading space */
- while (isspace(*cp)) cp++;
-
- /* Found a comment or EOL */
- if (iseol(*cp)) continue;
-
- /* Found a constraint selector */
- if (*cp == '[') {
- cp++;
-
- /* Skip leading space */
- while (isspace(*cp)) cp++;
-
- /* Found comment, EOL or end of selector */
- if (iseol(*cp) || *cp == ']')
- continue;
-
- c = cp++;
- /* Skip to end of word */
- while (!isspace(*cp) && !iseol(*cp) && *cp != ']')
- cp++;
-
- /* Skip and zero out trailing space */
- while (isspace(*cp)) *cp++ = '\0';
-
- /* Check if there is a closing brace */
- if (*cp != ']') continue;
-
- /* Terminate string if there was no trailing space */
- *cp++ = '\0';
-
- /*
- * There should be nothing except whitespace or comment
- from this point to the end of the line.
- */
- while(isspace(*cp)) cp++;
- if (!iseol(*cp)) continue;
-
- strcpy(prog, c);
- p = prog;
- continue;
- }
-
- /* Parse the 'from' candidate. */
- f = cp++;
- while (!isspace(*cp) && !iseol(*cp)) cp++;
-
- /* Skip and zero out the trailing whitespace */
- while (isspace(*cp)) *cp++ = '\0';
-
- /* Found a comment or EOL */
- if (iseol(*cp)) continue;
-
- /* Parse 'to' mapping */
- t = cp++;
- while (!isspace(*cp) && !iseol(*cp)) cp++;
-
- /* Skip and zero out the trailing whitespace */
- while (isspace(*cp)) *cp++ = '\0';
-
- /* Should be no extra tokens at this point */
- if (!iseol(*cp)) continue;
-
- *cp = '\0';
- lm_add(p, f, t);
- }
-}
-
-static void
-lm_free (struct lm_list *lml)
-{
- struct lm *lm;
-
- dbg("%s(%p)", __func__, lml);
-
- while (!TAILQ_EMPTY(lml)) {
- lm = TAILQ_FIRST(lml);
- TAILQ_REMOVE(lml, lm, lm_link);
- free(lm->f);
- free(lm->t);
- free(lm);
- }
- return;
-}
-
-void
-lm_fini (void)
-{
- struct lmp *lmp;
-
- dbg("%s()", __func__);
-
- while (!TAILQ_EMPTY(&lmp_head)) {
- lmp = TAILQ_FIRST(&lmp_head);
- TAILQ_REMOVE(&lmp_head, lmp, lmp_link);
- free(lmp->p);
- lm_free(&lmp->lml);
- free(lmp);
- }
- return;
-}
-
-static void
-lm_add (const char *p, const char *f, const char *t)
-{
- struct lm_list *lml;
- struct lm *lm;
-
- if (p == NULL)
- p = "$DEFAULT$";
-
- dbg("%s(\"%s\", \"%s\", \"%s\")", __func__, p, f, t);
-
- if ((lml = lmp_find(p)) == NULL)
- lml = lmp_init(xstrdup(p));
-
- lm = xmalloc(sizeof(struct lm));
- lm->f = xstrdup(f);
- lm->t = xstrdup(t);
- TAILQ_INSERT_HEAD(lml, lm, lm_link);
- lm_count++;
-}
-
-char *
-lm_find (const char *p, const char *f)
-{
- struct lm_list *lml;
- char *t;
-
- dbg("%s(\"%s\", \"%s\")", __func__, p, f);
-
- if (p != NULL && (lml = lmp_find(p)) != NULL) {
- t = lml_find(lml, f);
- if (t != NULL) {
- /*
- * Add a global mapping if we have
- * a successful constrained match.
- */
- lm_add(NULL, f, t);
- return (t);
- }
- }
- lml = lmp_find("$DEFAULT$");
- if (lml != NULL)
- return (lml_find(lml, f));
- else
- return (NULL);
-}
-
-/* Given a libmap translation list and a library name, return the
- replacement library, or NULL */
-#ifdef COMPAT_32BIT
-char *
-lm_findn (const char *p, const char *f, const int n)
-{
- char pathbuf[64], *s, *t;
-
- if (n < sizeof(pathbuf) - 1) {
- memcpy(pathbuf, f, n);
- pathbuf[n] = '\0';
- s = pathbuf;
- } else {
- s = xmalloc(n + 1);
- strcpy(s, f);
- }
- t = lm_find(p, s);
- if (s != pathbuf)
- free(s);
- return (t);
-}
-#endif
-
-static char *
-lml_find (struct lm_list *lmh, const char *f)
-{
- struct lm *lm;
-
- dbg("%s(%p, \"%s\")", __func__, lmh, f);
-
- TAILQ_FOREACH(lm, lmh, lm_link)
- if (strcmp(f, lm->f) == 0)
- return (lm->t);
- return (NULL);
-}
-
-/* Given an executable name, return a pointer to the translation list or
- NULL if no matches */
-static struct lm_list *
-lmp_find (const char *n)
-{
- struct lmp *lmp;
-
- dbg("%s(\"%s\")", __func__, n);
-
- TAILQ_FOREACH(lmp, &lmp_head, lmp_link)
- if ((lmp->type == T_EXACT && strcmp(n, lmp->p) == 0) ||
- (lmp->type == T_DIRECTORY && strncmp(n, lmp->p, strlen(lmp->p)) == 0) ||
- (lmp->type == T_BASENAME && strcmp(quickbasename(n), lmp->p) == 0))
- return (&lmp->lml);
- return (NULL);
-}
-
-static struct lm_list *
-lmp_init (char *n)
-{
- struct lmp *lmp;
-
- dbg("%s(\"%s\")", __func__, n);
-
- lmp = xmalloc(sizeof(struct lmp));
- lmp->p = n;
- if (n[strlen(n)-1] == '/')
- lmp->type = T_DIRECTORY;
- else if (strchr(n,'/') == NULL)
- lmp->type = T_BASENAME;
- else
- lmp->type = T_EXACT;
- TAILQ_INIT(&lmp->lml);
- TAILQ_INSERT_HEAD(&lmp_head, lmp, lmp_link);
-
- return (&lmp->lml);
-}
-
-/* libc basename is overkill. Return a pointer to the character after the
- last /, or the original string if there are no slashes. */
-static const char *
-quickbasename (const char *path)
-{
- const char *p = path;
- for (; *path; path++) {
- if (*path == '/')
- p = path+1;
- }
- return (p);
-}
-
-static int
-readstrfn(void * cookie, char *buf, int len)
-{
- static char *current;
- static int left;
- int copied;
-
- copied = 0;
- if (!current) {
- current = cookie;
- left = strlen(cookie);
- }
- while (*current && left && len) {
- *buf++ = *current++;
- left--;
- len--;
- copied++;
- }
- return copied;
-}
-
-static int
-closestrfn(void * cookie)
-{
- free(cookie);
- return 0;
-}
diff --git a/src/bin/rtld-elf/libmap.h b/src/bin/rtld-elf/libmap.h
deleted file mode 100644
index 6b0991d..0000000
--- a/src/bin/rtld-elf/libmap.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * $FreeBSD: src/libexec/rtld-elf/libmap.h,v 1.4 2005/02/04 02:46:41 mdodd Exp $
- */
-
-int lm_init (char *);
-void lm_fini (void);
-char * lm_find (const char *, const char *);
-#ifdef COMPAT_32BIT
-char * lm_findn (const char *, const char *, const int);
-#endif
diff --git a/src/bin/rtld-elf/malloc.c b/src/bin/rtld-elf/malloc.c
deleted file mode 100644
index c8fa19e..0000000
--- a/src/bin/rtld-elf/malloc.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*-
- * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-/*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/
-static char *rcsid = "$FreeBSD: src/libexec/rtld-elf/malloc.c,v 1.10 2003/08/22 02:22:59 imp Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * malloc.c (Caltech) 2/21/82
- * Chris Kingsley, kingsley@cit-20.
- *
- * This is a very fast storage allocator. It allocates blocks of a small
- * number of different sizes, and keeps free lists of each size. Blocks that
- * don't exactly fit are passed up to the next larger size. In this
- * implementation, the available sizes are 2^n-4 (or 2^n-10) bytes long.
- * This is designed for use in a virtual memory environment.
- */
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#ifndef BSD
-#define MAP_COPY MAP_PRIVATE
-#define MAP_FILE 0
-#define MAP_ANON 0
-#endif
-
-#ifndef BSD /* Need do better than this */
-#define NEED_DEV_ZERO 1
-#endif
-
-static void morecore();
-static int findbucket();
-
-/*
- * Pre-allocate mmap'ed pages
- */
-#define NPOOLPAGES (32*1024/pagesz)
-static caddr_t pagepool_start, pagepool_end;
-static int morepages();
-
-/*
- * The overhead on a block is at least 4 bytes. When free, this space
- * contains a pointer to the next free block, and the bottom two bits must
- * be zero. When in use, the first byte is set to MAGIC, and the second
- * byte is the size index. The remaining bytes are for alignment.
- * If range checking is enabled then a second word holds the size of the
- * requested block, less 1, rounded up to a multiple of sizeof(RMAGIC).
- * The order of elements is critical: ov_magic must overlay the low order
- * bits of ov_next, and ov_magic can not be a valid ov_next bit pattern.
- */
-union overhead {
- union overhead *ov_next; /* when free */
- struct {
- u_char ovu_magic; /* magic number */
- u_char ovu_index; /* bucket # */
-#ifdef RCHECK
- u_short ovu_rmagic; /* range magic number */
- u_int ovu_size; /* actual block size */
-#endif
- } ovu;
-#define ov_magic ovu.ovu_magic
-#define ov_index ovu.ovu_index
-#define ov_rmagic ovu.ovu_rmagic
-#define ov_size ovu.ovu_size
-};
-
-#define MAGIC 0xef /* magic # on accounting info */
-#define RMAGIC 0x5555 /* magic # on range info */
-
-#ifdef RCHECK
-#define RSLOP sizeof (u_short)
-#else
-#define RSLOP 0
-#endif
-
-/*
- * nextf[i] is the pointer to the next free block of size 2^(i+3). The
- * smallest allocatable block is 8 bytes. The overhead information
- * precedes the data area returned to the user.
- */
-#define NBUCKETS 30
-static union overhead *nextf[NBUCKETS];
-
-static int pagesz; /* page size */
-static int pagebucket; /* page size bucket */
-
-#ifdef MSTATS
-/*
- * nmalloc[i] is the difference between the number of mallocs and frees
- * for a given block size.
- */
-static u_int nmalloc[NBUCKETS];
-#include
-#endif
-
-#if defined(MALLOC_DEBUG) || defined(RCHECK)
-#define ASSERT(p) if (!(p)) botch("p")
-#include
-static void
-botch(s)
- char *s;
-{
- fprintf(stderr, "\r\nassertion botched: %s\r\n", s);
- (void) fflush(stderr); /* just in case user buffered it */
- abort();
-}
-#else
-#define ASSERT(p)
-#endif
-
-/* Debugging stuff */
-static void xprintf(const char *, ...);
-#define TRACE() xprintf("TRACE %s:%d\n", __FILE__, __LINE__)
-
-void *
-malloc(nbytes)
- size_t nbytes;
-{
- register union overhead *op;
- register int bucket;
- register long n;
- register unsigned amt;
-
- /*
- * First time malloc is called, setup page size and
- * align break pointer so all data will be page aligned.
- */
- if (pagesz == 0) {
- pagesz = n = getpagesize();
- if (morepages(NPOOLPAGES) == 0)
- return NULL;
- op = (union overhead *)(pagepool_start);
- n = n - sizeof (*op) - ((long)op & (n - 1));
- if (n < 0)
- n += pagesz;
- if (n) {
- pagepool_start += n;
- }
- bucket = 0;
- amt = 8;
- while ((unsigned)pagesz > amt) {
- amt <<= 1;
- bucket++;
- }
- pagebucket = bucket;
- }
- /*
- * Convert amount of memory requested into closest block size
- * stored in hash buckets which satisfies request.
- * Account for space used per block for accounting.
- */
- if (nbytes <= (unsigned long)(n = pagesz - sizeof (*op) - RSLOP)) {
-#ifndef RCHECK
- amt = 8; /* size of first bucket */
- bucket = 0;
-#else
- amt = 16; /* size of first bucket */
- bucket = 1;
-#endif
- n = -(sizeof (*op) + RSLOP);
- } else {
- amt = pagesz;
- bucket = pagebucket;
- }
- while (nbytes > amt + n) {
- amt <<= 1;
- if (amt == 0)
- return (NULL);
- bucket++;
- }
- /*
- * If nothing in hash bucket right now,
- * request more memory from the system.
- */
- if ((op = nextf[bucket]) == NULL) {
- morecore(bucket);
- if ((op = nextf[bucket]) == NULL)
- return (NULL);
- }
- /* remove from linked list */
- nextf[bucket] = op->ov_next;
- op->ov_magic = MAGIC;
- op->ov_index = bucket;
-#ifdef MSTATS
- nmalloc[bucket]++;
-#endif
-#ifdef RCHECK
- /*
- * Record allocated size of block and
- * bound space with magic numbers.
- */
- op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1);
- op->ov_rmagic = RMAGIC;
- *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
-#endif
- return ((char *)(op + 1));
-}
-
-/*
- * Allocate more memory to the indicated bucket.
- */
-static void
-morecore(bucket)
- int bucket;
-{
- register union overhead *op;
- register int sz; /* size of desired block */
- int amt; /* amount to allocate */
- int nblks; /* how many blocks we get */
-
- /*
- * sbrk_size <= 0 only for big, FLUFFY, requests (about
- * 2^30 bytes on a VAX, I think) or for a negative arg.
- */
- sz = 1 << (bucket + 3);
-#ifdef MALLOC_DEBUG
- ASSERT(sz > 0);
-#else
- if (sz <= 0)
- return;
-#endif
- if (sz < pagesz) {
- amt = pagesz;
- nblks = amt / sz;
- } else {
- amt = sz + pagesz;
- nblks = 1;
- }
- if (amt > pagepool_end - pagepool_start)
- if (morepages(amt/pagesz + NPOOLPAGES) == 0)
- return;
- op = (union overhead *)pagepool_start;
- pagepool_start += amt;
-
- /*
- * Add new memory allocated to that on
- * free list for this hash bucket.
- */
- nextf[bucket] = op;
- while (--nblks > 0) {
- op->ov_next = (union overhead *)((caddr_t)op + sz);
- op = (union overhead *)((caddr_t)op + sz);
- }
-}
-
-void
-free(cp)
- void *cp;
-{
- register int size;
- register union overhead *op;
-
- if (cp == NULL)
- return;
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
-#ifdef MALLOC_DEBUG
- ASSERT(op->ov_magic == MAGIC); /* make sure it was in use */
-#else
- if (op->ov_magic != MAGIC)
- return; /* sanity */
-#endif
-#ifdef RCHECK
- ASSERT(op->ov_rmagic == RMAGIC);
- ASSERT(*(u_short *)((caddr_t)(op + 1) + op->ov_size) == RMAGIC);
-#endif
- size = op->ov_index;
- ASSERT(size < NBUCKETS);
- op->ov_next = nextf[size]; /* also clobbers ov_magic */
- nextf[size] = op;
-#ifdef MSTATS
- nmalloc[size]--;
-#endif
-}
-
-/*
- * When a program attempts "storage compaction" as mentioned in the
- * old malloc man page, it realloc's an already freed block. Usually
- * this is the last block it freed; occasionally it might be farther
- * back. We have to search all the free lists for the block in order
- * to determine its bucket: 1st we make one pass thru the lists
- * checking only the first block in each; if that fails we search
- * ``realloc_srchlen'' blocks in each list for a match (the variable
- * is extern so the caller can modify it). If that fails we just copy
- * however many bytes was given to realloc() and hope it's not huge.
- */
-int realloc_srchlen = 4; /* 4 should be plenty, -1 =>'s whole list */
-
-void *
-realloc(cp, nbytes)
- void *cp;
- size_t nbytes;
-{
- register u_int onb;
- register int i;
- union overhead *op;
- char *res;
- int was_alloced = 0;
-
- if (cp == NULL)
- return (malloc(nbytes));
- op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
- if (op->ov_magic == MAGIC) {
- was_alloced++;
- i = op->ov_index;
- } else {
- /*
- * Already free, doing "compaction".
- *
- * Search for the old block of memory on the
- * free list. First, check the most common
- * case (last element free'd), then (this failing)
- * the last ``realloc_srchlen'' items free'd.
- * If all lookups fail, then assume the size of
- * the memory block being realloc'd is the
- * largest possible (so that all "nbytes" of new
- * memory are copied into). Note that this could cause
- * a memory fault if the old area was tiny, and the moon
- * is gibbous. However, that is very unlikely.
- */
- if ((i = findbucket(op, 1)) < 0 &&
- (i = findbucket(op, realloc_srchlen)) < 0)
- i = NBUCKETS;
- }
- onb = 1 << (i + 3);
- if (onb < (u_int)pagesz)
- onb -= sizeof (*op) + RSLOP;
- else
- onb += pagesz - sizeof (*op) - RSLOP;
- /* avoid the copy if same size block */
- if (was_alloced) {
- if (i) {
- i = 1 << (i + 2);
- if (i < pagesz)
- i -= sizeof (*op) + RSLOP;
- else
- i += pagesz - sizeof (*op) - RSLOP;
- }
- if (nbytes <= onb && nbytes > (size_t)i) {
-#ifdef RCHECK
- op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1);
- *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC;
-#endif
- return(cp);
- } else
- free(cp);
- }
- if ((res = malloc(nbytes)) == NULL)
- return (NULL);
- if (cp != res) /* common optimization if "compacting" */
- bcopy(cp, res, (nbytes < onb) ? nbytes : onb);
- return (res);
-}
-
-/*
- * Search ``srchlen'' elements of each free list for a block whose
- * header starts at ``freep''. If srchlen is -1 search the whole list.
- * Return bucket number, or -1 if not found.
- */
-static int
-findbucket(freep, srchlen)
- union overhead *freep;
- int srchlen;
-{
- register union overhead *p;
- register int i, j;
-
- for (i = 0; i < NBUCKETS; i++) {
- j = 0;
- for (p = nextf[i]; p && j != srchlen; p = p->ov_next) {
- if (p == freep)
- return (i);
- j++;
- }
- }
- return (-1);
-}
-
-#ifdef MSTATS
-/*
- * mstats - print out statistics about malloc
- *
- * Prints two lines of numbers, one showing the length of the free list
- * for each size category, the second showing the number of mallocs -
- * frees for each size category.
- */
-mstats(s)
- char *s;
-{
- register int i, j;
- register union overhead *p;
- int totfree = 0,
- totused = 0;
-
- fprintf(stderr, "Memory allocation statistics %s\nfree:\t", s);
- for (i = 0; i < NBUCKETS; i++) {
- for (j = 0, p = nextf[i]; p; p = p->ov_next, j++)
- ;
- fprintf(stderr, " %d", j);
- totfree += j * (1 << (i + 3));
- }
- fprintf(stderr, "\nused:\t");
- for (i = 0; i < NBUCKETS; i++) {
- fprintf(stderr, " %d", nmalloc[i]);
- totused += nmalloc[i] * (1 << (i + 3));
- }
- fprintf(stderr, "\n\tTotal in use: %d, total free: %d\n",
- totused, totfree);
-}
-#endif
-
-
-static int
-morepages(n)
-int n;
-{
- int fd = -1;
- int offset;
-
-#ifdef NEED_DEV_ZERO
- fd = open(_PATH_DEVZERO, O_RDWR, 0);
- if (fd == -1)
- perror(_PATH_DEVZERO);
-#endif
-
- if (pagepool_end - pagepool_start > pagesz) {
- caddr_t addr = (caddr_t)
- (((long)pagepool_start + pagesz - 1) & ~(pagesz - 1));
- if (munmap(addr, pagepool_end - addr) != 0)
- warn("morepages: munmap %p", addr);
- }
-
- offset = (long)pagepool_start - ((long)pagepool_start & ~(pagesz - 1));
-
- if ((pagepool_start = mmap(0, n * pagesz,
- PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_COPY, fd, 0)) == (caddr_t)-1) {
- xprintf("Cannot map anonymous memory");
- return 0;
- }
- pagepool_end = pagepool_start + n * pagesz;
- pagepool_start += offset;
-
-#ifdef NEED_DEV_ZERO
- close(fd);
-#endif
- return n;
-}
-
-/*
- * Non-mallocing printf, for use by malloc itself.
- */
-static void
-xprintf(const char *fmt, ...)
-{
- char buf[256];
- va_list ap;
-
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- (void)write(STDOUT_FILENO, buf, strlen(buf));
- va_end(ap);
-}
diff --git a/src/bin/rtld-elf/map_object.c b/src/bin/rtld-elf/map_object.c
deleted file mode 100644
index 6734cc2..0000000
--- a/src/bin/rtld-elf/map_object.c
+++ /dev/null
@@ -1,377 +0,0 @@
-/*-
- * Copyright 1996-1998 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/map_object.c,v 1.16 2005/02/27 12:55:40 dfr Exp $
- */
-
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-
-#include "debug.h"
-#include "rtld.h"
-
-static Elf_Ehdr *get_elf_header (int, const char *);
-static int convert_prot(int); /* Elf flags -> mmap protection */
-static int convert_flags(int); /* Elf flags -> mmap flags */
-
-/*
- * Map a shared object into memory. The "fd" argument is a file descriptor,
- * which must be open on the object and positioned at its beginning.
- * The "path" argument is a pathname that is used only for error messages.
- *
- * The return value is a pointer to a newly-allocated Obj_Entry structure
- * for the shared object. Returns NULL on failure.
- */
-Obj_Entry *
-map_object(int fd, const char *path, const struct stat *sb)
-{
- Elf_Dyn *dynp = 0x0;
- Obj_Entry *obj;
- Elf_Ehdr *hdr;
- int i;
- Elf_Phdr *phdr;
- Elf_Phdr *phlimit;
- Elf_Phdr **segs;
- int nsegs;
- Elf_Phdr *phdyn;
- Elf_Phdr *phphdr;
- Elf_Phdr *phinterp;
- Elf_Phdr *phtls;
- caddr_t mapbase;
- size_t mapsize;
- Elf_Off base_offset;
- Elf_Addr base_vaddr;
- Elf_Addr base_vlimit;
- caddr_t base_addr;
- Elf_Off data_offset;
- Elf_Addr data_vaddr;
- Elf_Addr data_vlimit;
- caddr_t data_addr;
- int data_prot;
- int data_flags;
- Elf_Addr clear_vaddr;
- caddr_t clear_addr;
- caddr_t clear_page;
- size_t nclear;
- Elf_Addr bss_vaddr;
- Elf_Addr bss_vlimit;
- caddr_t bss_addr;
-
- hdr = get_elf_header(fd, path);
- if (hdr == NULL)
- return (NULL);
-
- /*
- * Scan the program header entries, and save key information.
- *
- * We rely on there being exactly two load segments, text and data,
- * in that order.
- */
- phdr = (Elf_Phdr *) ((char *)hdr + hdr->e_phoff);
- phlimit = phdr + hdr->e_phnum;
- nsegs = -1;
- phdyn = phphdr = phinterp = phtls = NULL;
- segs = alloca(sizeof(segs[0]) * hdr->e_phnum);
-dbg("SDF: %i",hdr->e_phnum);
-
- while (phdr < phlimit) {
- switch (phdr->p_type) {
-
- case PT_INTERP:
- phinterp = phdr;
- break;
-
- case PT_LOAD:
- segs[++nsegs] = phdr;
- if (segs[nsegs]->p_align < PAGE_SIZE) {
- _rtld_error("%s: PT_LOAD segment %d not page-aligned",
- path, nsegs);
- return NULL;
- }
- break;
-
- case PT_PHDR:
- phphdr = phdr;
- break;
-
- case PT_DYNAMIC:
- phdyn = phdr;
- break;
-
- case PT_TLS:
- phtls = phdr;
- break;
- }
-
- ++phdr;
- }
- if (phdyn == NULL) {
- _rtld_error("%s: object is not dynamically-linked", path);
- return NULL;
- }
-
- if (nsegs < 0) {
- _rtld_error("%s: too few PT_LOAD segments", path);
- return NULL;
- }
-
- /*
- * Map the entire address space of the object, to stake out our
- * contiguous region, and to establish the base address for relocation.
- */
- base_offset = trunc_page(segs[0]->p_offset);
- base_vaddr = trunc_page(segs[0]->p_vaddr);
- base_vlimit = round_page(segs[nsegs]->p_vaddr + segs[nsegs]->p_memsz);
- mapsize = base_vlimit - base_vaddr;
- base_addr = hdr->e_type == ET_EXEC ? (caddr_t) base_vaddr : NULL;
-
- mapbase = mmap(base_addr, mapsize, convert_prot(segs[0]->p_flags),
- convert_flags(segs[0]->p_flags), fd, base_offset);
- if (mapbase == (caddr_t) -1) {
- _rtld_error("%s: mmap of entire address space failed: %s",
- path, strerror(errno));
- return NULL;
- }
- if (base_addr != NULL && mapbase != base_addr) {
- _rtld_error("%s: mmap returned wrong address: wanted %p, got %p",
- path, base_addr, mapbase);
- munmap(mapbase, mapsize);
- return NULL;
- }
-
- for (i = 0; i <= nsegs; i++) {
- /* Overlay the segment onto the proper region. */
- data_offset = trunc_page(segs[i]->p_offset);
- data_vaddr = trunc_page(segs[i]->p_vaddr);
- data_vlimit = round_page(segs[i]->p_vaddr + segs[i]->p_filesz);
- data_addr = mapbase + (data_vaddr - base_vaddr);
- data_prot = convert_prot(segs[i]->p_flags);
- data_flags = convert_flags(segs[i]->p_flags) | MAP_FIXED;
- /* Do not call mmap on the first segment - this is redundant */
- if (i && mmap(data_addr, data_vlimit - data_vaddr, data_prot,
- data_flags, fd, data_offset) == (caddr_t) -1) {
- _rtld_error("%s: mmap of data failed: %s", path, strerror(errno));
- return NULL;
- }
-
- /* Clear any BSS in the last page of the segment. */
- clear_vaddr = segs[i]->p_vaddr + segs[i]->p_filesz;
- clear_addr = mapbase + (clear_vaddr - base_vaddr);
- clear_page = mapbase + (trunc_page(clear_vaddr) - base_vaddr);
- if ((nclear = data_vlimit - clear_vaddr) > 0) {
- /* Make sure the end of the segment is writable */
- if ((data_prot & PROT_WRITE) == 0 &&
- -1 == mprotect(clear_page, PAGE_SIZE, data_prot|PROT_WRITE)) {
- _rtld_error("%s: mprotect failed: %s", path,
- strerror(errno));
- return NULL;
- }
-
- memset(clear_addr, 0, nclear);
-
- /* Reset the data protection back */
- if ((data_prot & PROT_WRITE) == 0)
- mprotect(clear_page, PAGE_SIZE, data_prot);
- }
-
- /* Overlay the BSS segment onto the proper region. */
- bss_vaddr = data_vlimit;
- bss_vlimit = round_page(segs[i]->p_vaddr + segs[i]->p_memsz);
- bss_addr = mapbase + (bss_vaddr - base_vaddr);
- if (bss_vlimit > bss_vaddr) { /* There is something to do */
- if (mmap(bss_addr, bss_vlimit - bss_vaddr, data_prot,
- MAP_PRIVATE|MAP_FIXED|MAP_ANON, -1, 0) == (caddr_t) -1) {
- _rtld_error("%s: mmap of bss failed: %s", path,
- strerror(errno));
- return NULL;
- }
- }
- }
-
- obj = obj_new();
- if (sb != NULL) {
- obj->dev = sb->st_dev;
- obj->ino = sb->st_ino;
- }
- obj->mapbase = mapbase;
- obj->mapsize = mapsize;
- obj->textsize = round_page(segs[0]->p_vaddr + segs[0]->p_memsz) -
- base_vaddr;
- obj->vaddrbase = base_vaddr;
- obj->relocbase = mapbase - base_vaddr;
- obj->dynamic = (const Elf_Dyn *) (obj->relocbase + phdyn->p_vaddr);
- dynp = (Elf_Dyn *) (obj->relocbase + phdyn->p_vaddr);
- dbg("TEST: [0x%X:0x%X:0x%X]",dynp->d_tag,phdyn->p_vaddr,(u_int32_t)mapbase);
- if (hdr->e_entry != 0)
- obj->entry = (caddr_t) (obj->relocbase + hdr->e_entry);
- if (phphdr != NULL) {
- obj->phdr = (const Elf_Phdr *) (obj->relocbase + phphdr->p_vaddr);
- obj->phsize = phphdr->p_memsz;
- }
- if (phinterp != NULL)
- obj->interp = (const char *) (obj->relocbase + phinterp->p_vaddr);
- if (phtls != NULL) {
- tls_dtv_generation++;
- obj->tlsindex = ++tls_max_index;
- obj->tlssize = phtls->p_memsz;
- obj->tlsalign = phtls->p_align;
- obj->tlsinitsize = phtls->p_filesz;
- obj->tlsinit = mapbase + phtls->p_vaddr;
- }
- return obj;
-}
-
-static Elf_Ehdr *
-get_elf_header (int fd, const char *path)
-{
- static union {
- Elf_Ehdr hdr;
- char buf[PAGE_SIZE];
- } u;
- ssize_t nbytes;
-
- if ((nbytes = read(fd, u.buf, PAGE_SIZE)) == -1) {
- _rtld_error("%s: read error: %s", path, strerror(errno));
- return NULL;
- }
-
- /* Make sure the file is valid */
- if (nbytes < (ssize_t)sizeof(Elf_Ehdr) || !IS_ELF(u.hdr)) {
- _rtld_error("%s: invalid file format", path);
- return NULL;
- }
- if (u.hdr.e_ident[EI_CLASS] != ELF_TARG_CLASS
- || u.hdr.e_ident[EI_DATA] != ELF_TARG_DATA) {
- _rtld_error("%s: unsupported file layout", path);
- return NULL;
- }
- if (u.hdr.e_ident[EI_VERSION] != EV_CURRENT
- || u.hdr.e_version != EV_CURRENT) {
- _rtld_error("%s: unsupported file version", path);
- return NULL;
- }
- if (u.hdr.e_type != ET_EXEC && u.hdr.e_type != ET_DYN) {
- _rtld_error("%s: unsupported file type", path);
- return NULL;
- }
- if (u.hdr.e_machine != ELF_TARG_MACH) {
- _rtld_error("%s: unsupported machine", path);
- return NULL;
- }
-
- /*
- * We rely on the program header being in the first page. This is
- * not strictly required by the ABI specification, but it seems to
- * always true in practice. And, it simplifies things considerably.
- */
- if (u.hdr.e_phentsize != sizeof(Elf_Phdr)) {
- _rtld_error(
- "%s: invalid shared object: e_phentsize != sizeof(Elf_Phdr)", path);
- return NULL;
- }
- if (u.hdr.e_phoff + u.hdr.e_phnum * sizeof(Elf_Phdr) > (size_t)nbytes) {
- _rtld_error("%s: program header too large", path);
- return NULL;
- }
-
- return (&u.hdr);
-}
-
-void
-obj_free(Obj_Entry *obj)
-{
- Objlist_Entry *elm;
-
- if (obj->tls_done) {
- free_tls_offset(obj);
- }
- free(obj->path);
- while (obj->needed != NULL) {
- Needed_Entry *needed = obj->needed;
- obj->needed = needed->next;
- free(needed);
- }
- while (!STAILQ_EMPTY(&obj->dldags)) {
- elm = STAILQ_FIRST(&obj->dldags);
- STAILQ_REMOVE_HEAD(&obj->dldags, link);
- free(elm);
- }
- while (!STAILQ_EMPTY(&obj->dagmembers)) {
- elm = STAILQ_FIRST(&obj->dagmembers);
- STAILQ_REMOVE_HEAD(&obj->dagmembers, link);
- free(elm);
- }
- free(obj->origin_path);
- free(obj->priv);
- free(obj);
-}
-
-Obj_Entry *
-obj_new(void)
-{
- Obj_Entry *obj;
-
- obj = CNEW(Obj_Entry);
- STAILQ_INIT(&obj->dldags);
- STAILQ_INIT(&obj->dagmembers);
- return obj;
-}
-
-/*
- * Given a set of ELF protection flags, return the corresponding protection
- * flags for MMAP.
- */
-static int
-convert_prot(int elfflags)
-{
- int prot = 0;
- if (elfflags & PF_R)
- prot |= PROT_READ;
- if (elfflags & PF_W)
- prot |= PROT_WRITE;
- if (elfflags & PF_X)
- prot |= PROT_EXEC;
- return prot;
-}
-
-static int
-convert_flags(int elfflags)
-{
- int flags = MAP_PRIVATE; /* All mappings are private */
-
- /*
- * Readonly mappings are marked "MAP_NOCORE", because they can be
- * reconstructed by a debugger.
- */
- if (!(elfflags & PF_W))
- flags |= MAP_NOCORE;
- return flags;
-}
diff --git a/src/bin/rtld-elf/reloc.c b/src/bin/rtld-elf/reloc.c
deleted file mode 100644
index 16b0669..0000000
--- a/src/bin/rtld-elf/reloc.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*-
- * Copyright 1996, 1997, 1998, 1999 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/i386/reloc.c,v 1.18 2005/06/29 23:15:36 peter Exp $
- */
-
-/*
- * Dynamic linker for ELF.
- *
- * John Polstra .
- */
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "debug.h"
-#include "rtld.h"
-
-/*
- * Process the special R_386_COPY relocations in the main program. These
- * copy data from a shared object into a region in the main program's BSS
- * segment.
- *
- * Returns 0 on success, -1 on failure.
- */
-int
-do_copy_relocations(Obj_Entry *dstobj)
-{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
-
- assert(dstobj->mainprog); /* COPY relocations are invalid elsewhere */
-
- rellim = (const Elf_Rel *) ((caddr_t) dstobj->rel + dstobj->relsize);
- for (rel = dstobj->rel; rel < rellim; rel++) {
- if (ELF_R_TYPE(rel->r_info) == R_386_COPY) {
- void *dstaddr;
- const Elf_Sym *dstsym;
- const char *name;
- unsigned long hash;
- size_t size;
- const void *srcaddr;
- const Elf_Sym *srcsym;
- Obj_Entry *srcobj;
-
- dstaddr = (void *) (dstobj->relocbase + rel->r_offset);
- dstsym = dstobj->symtab + ELF_R_SYM(rel->r_info);
- name = dstobj->strtab + dstsym->st_name;
- hash = elf_hash(name);
- size = dstsym->st_size;
-
- for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next)
- if ((srcsym = symlook_obj(name, hash, srcobj, false)) != NULL)
- break;
-
- if (srcobj == NULL) {
- _rtld_error("Undefined symbol \"%s\" referenced from COPY"
- " relocation in %s", name, dstobj->path);
- return -1;
- }
-
- srcaddr = (const void *) (srcobj->relocbase + srcsym->st_value);
- memcpy(dstaddr, srcaddr, size);
- }
- }
-
- return 0;
-}
-
-/* Initialize the special GOT entries. */
-void
-init_pltgot(Obj_Entry *obj)
-{
- if (obj->pltgot != NULL) {
- obj->pltgot[1] = (Elf_Addr) obj;
- obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start;
- }
-}
-
-/* Process the non-PLT relocations. */
-int
-reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld)
-{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
- SymCache *cache;
- int bytes = obj->nchains * sizeof(SymCache);
- int r = -1;
-
- /*
- * The dynamic loader may be called from a thread, we have
- * limited amounts of stack available so we cannot use alloca().
- */
- cache = mmap(NULL, bytes, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0);
-
- if (cache == MAP_FAILED)
- cache = NULL;
-
- rellim = (const Elf_Rel *) ((caddr_t) obj->rel + obj->relsize);
- for (rel = obj->rel; rel < rellim; rel++) {
- Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rel->r_offset);
-
- switch (ELF_R_TYPE(rel->r_info)) {
-
- case R_386_NONE:
- break;
-
- case R_386_32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- false, cache);
-
- if (def == NULL)
- goto done;
- *where += (Elf_Addr) (defobj->relocbase + def->st_value);
- }
- break;
-
- case R_386_PC32:
- /*
- * I don't think the dynamic linker should ever see this
- * type of relocation. But the binutils-2.6 tools sometimes
- * generate it.
- */
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-//dbg("A.1");
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- false, cache);
-//dbg("A.2");
- if (def == NULL)
- goto done;
-
- *where +=
- (Elf_Addr) (defobj->relocbase + def->st_value) -
- (Elf_Addr) where;
- }
- break;
-
- case R_386_COPY:
- /*
- * These are deferred until all other relocations have
- * been done. All we do here is make sure that the COPY
- * relocation is not in a shared library. They are allowed
- * only in executable files.
- */
-//dbg("386_COPY");
- if (!obj->mainprog) {
- _rtld_error("%s: Unexpected R_386_COPY relocation"
- " in shared library", obj->path);
- goto done;
- }
- break;
-
- case R_386_GLOB_DAT:
- {
-//dbg("386_GD");
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- false, cache);
- if (def == NULL)
- goto done;
-
- *where = (Elf_Addr) (defobj->relocbase + def->st_value);
- }
- break;
-
- case R_386_RELATIVE:
- *where += (Elf_Addr) obj->relocbase;
- break;
-
- case R_386_TLS_TPOFF:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- false, cache);
- if (def == NULL)
- goto done;
-
- /*
- * We lazily allocate offsets for static TLS as we
- * see the first relocation that references the
- * TLS block. This allows us to support (small
- * amounts of) static TLS in dynamically loaded
- * modules. If we run out of space, we generate an
- * error.
- */
- if (!defobj->tls_done) {
- if (!allocate_tls_offset((Obj_Entry*) defobj)) {
- _rtld_error("%s: No space available for static "
- "Thread Local Storage", obj->path);
- goto done;
- }
- }
-
- *where += (Elf_Addr) (def->st_value - defobj->tlsoffset);
- }
- break;
-
- case R_386_TLS_DTPMOD32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- false, cache);
- if (def == NULL)
- goto done;
-
- *where += (Elf_Addr) defobj->tlsindex;
- }
- break;
-
- case R_386_TLS_DTPOFF32:
- {
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj,
- false, cache);
- if (def == NULL)
- goto done;
-
- *where += (Elf_Addr) def->st_value;
- }
- break;
-
- default:
- _rtld_error("%s: Unsupported relocation type %d"
- " in non-PLT relocations\n", obj->path,
- ELF_R_TYPE(rel->r_info));
- goto done;
- }
- }
- r = 0;
-done:
- if (cache)
- munmap(cache, bytes);
- return(r);
-}
-
-/* Process the PLT relocations. */
-int
-reloc_plt(Obj_Entry *obj)
-{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
-
- rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
- for (rel = obj->pltrel; rel < rellim; rel++) {
- Elf_Addr *where;
-
- assert(ELF_R_TYPE(rel->r_info) == R_386_JMP_SLOT);
-
- /* Relocate the GOT slot pointing into the PLT. */
- where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- *where += (Elf_Addr)obj->relocbase;
- }
- return 0;
-}
-
-/* Relocate the jump slots in an object. */
-int
-reloc_jmpslots(Obj_Entry *obj)
-{
- const Elf_Rel *rellim;
- const Elf_Rel *rel;
-
- if (obj->jmpslots_done)
- return 0;
- rellim = (const Elf_Rel *)((char *)obj->pltrel + obj->pltrelsize);
- for (rel = obj->pltrel; rel < rellim; rel++) {
- Elf_Addr *where, target;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
-
- assert(ELF_R_TYPE(rel->r_info) == R_386_JMP_SLOT);
- where = (Elf_Addr *)(obj->relocbase + rel->r_offset);
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true, NULL);
- if (def == NULL)
- return -1;
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
- reloc_jmpslot(where, target, defobj, obj, rel);
- }
- obj->jmpslots_done = true;
- return 0;
-}
-
-void
-allocate_initial_tls(Obj_Entry *objs)
-{
- void* tls;
-
- /*
- * Fix the size of the static TLS block by using the maximum
- * offset allocated so far and adding a bit for dynamic modules to
- * use.
- */
- tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
- tls = allocate_tls(objs, NULL, 2*sizeof(Elf_Addr), sizeof(Elf_Addr));
-dbg("tls: [0x%X]",(u_int32_t)tls);
- i386_set_gsbase(tls);
-}
-
-/* GNU ABI */
-__attribute__((__regparm__(1)))
-void *___tls_get_addr(tls_index *ti)
-{
- Elf_Addr** segbase;
- Elf_Addr* dtv;
-
- __asm __volatile("movl %%gs:0, %0" : "=r" (segbase));
- dtv = segbase[1];
-
- return tls_get_addr_common(&segbase[1], ti->ti_module, ti->ti_offset);
-}
-
-/* Sun ABI */
-void *__tls_get_addr(tls_index *ti)
-{
- Elf_Addr** segbase;
- Elf_Addr* dtv;
-
- __asm __volatile("movl %%gs:0, %0" : "=r" (segbase));
- dtv = segbase[1];
-
- return tls_get_addr_common(&segbase[1], ti->ti_module, ti->ti_offset);
-}
diff --git a/src/bin/rtld-elf/rtld.c b/src/bin/rtld-elf/rtld.c
deleted file mode 100644
index 2bc7ad4..0000000
--- a/src/bin/rtld-elf/rtld.c
+++ /dev/null
@@ -1,2848 +0,0 @@
-/*-
- * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra.
- * Copyright 2003 Alexander Kabaev .
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $Id$
- */
-
-/*
- * Dynamic linker for ELF.
- *
- * John Polstra .
- */
-
-#ifndef __GNUC__
-#error "GCC is needed to compile this file"
-#endif
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#include "debug.h"
-#include "rtld.h"
-#include "libmap.h"
-#include "rtld_tls.h"
-
-#ifndef COMPAT_32BIT
-#define PATH_RTLD "/libexec/ld-elf.so.1"
-#else
-#define PATH_RTLD "/libexec/ld-elf32.so.1"
-#endif
-
-/* Types. */
-typedef void (*func_ptr_type)();
-typedef void * (*path_enum_proc) (const char *path, size_t len, void *arg);
-
-/*
- * This structure provides a reentrant way to keep a list of objects and
- * check which ones have already been processed in some way.
- */
-typedef struct Struct_DoneList {
- const Obj_Entry **objs; /* Array of object pointers */
- unsigned int num_alloc; /* Allocated size of the array */
- unsigned int num_used; /* Number of array slots used */
-} DoneList;
-
-/*
- * Function declarations.
- */
-static const char *basename(const char *);
-static void die(void);
-static void digest_dynamic(Obj_Entry *, int);
-static Obj_Entry *digest_phdr(const Elf_Phdr *, int, caddr_t, const char *);
-static Obj_Entry *dlcheck(void *);
-static int do_search_info(const Obj_Entry *obj, int, struct dl_serinfo *);
-static bool donelist_check(DoneList *, const Obj_Entry *);
-static void errmsg_restore(char *);
-static char *errmsg_save(void);
-static void *fill_search_info(const char *, size_t, void *);
-static char *find_library(const char *, const Obj_Entry *);
-static const char *gethints(void);
-static void init_dag(Obj_Entry *);
-static void init_dag1(Obj_Entry *root, Obj_Entry *obj, DoneList *);
-static void init_rtld(caddr_t);
-static void initlist_add_neededs(Needed_Entry *needed, Objlist *list);
-static void initlist_add_objects(Obj_Entry *obj, Obj_Entry **tail,
- Objlist *list);
-static bool is_exported(const Elf_Sym *);
-static void linkmap_add(Obj_Entry *);
-static void linkmap_delete(Obj_Entry *);
-static int load_needed_objects(Obj_Entry *);
-static int load_preload_objects(void);
-static Obj_Entry *load_object(char *);
-static Obj_Entry *obj_from_addr(const void *);
-static void objlist_call_fini(Objlist *);
-static void objlist_call_init(Objlist *);
-static void objlist_clear(Objlist *);
-static Objlist_Entry *objlist_find(Objlist *, const Obj_Entry *);
-static void objlist_init(Objlist *);
-static void objlist_push_head(Objlist *, Obj_Entry *);
-static void objlist_push_tail(Objlist *, Obj_Entry *);
-static void objlist_remove(Objlist *, Obj_Entry *);
-static void objlist_remove_unref(Objlist *);
-static void *path_enumerate(const char *, path_enum_proc, void *);
-static int relocate_objects(Obj_Entry *, bool, Obj_Entry *);
-static int rtld_dirname(const char *, char *);
-static void rtld_exit(void);
-static char *search_library_path(const char *, const char *);
-static const void **get_program_var_addr(const char *name);
-static void set_program_var(const char *, const void *);
-static const Elf_Sym *symlook_default(const char *, unsigned long hash,
- const Obj_Entry *refobj, const Obj_Entry **defobj_out, bool in_plt);
-static const Elf_Sym *symlook_list(const char *, unsigned long,
- Objlist *, const Obj_Entry **, bool in_plt, DoneList *);
-static void trace_loaded_objects(Obj_Entry *obj);
-static void unlink_object(Obj_Entry *);
-static void unload_object(Obj_Entry *);
-static void unref_dag(Obj_Entry *);
-static void ref_dag(Obj_Entry *);
-
-void r_debug_state(struct r_debug*, struct link_map*);
-
-/*
- * Data declarations.
- */
-static char *error_message; /* Message for dlerror(), or NULL */
-struct r_debug r_debug; /* for GDB; */
-static bool libmap_disable; /* Disable libmap */
-static char *libmap_override; /* Maps to use in addition to libmap.conf */
-static bool trust; /* False for setuid and setgid programs */
-static bool dangerous_ld_env; /* True if environment variables have been
- used to affect the libraries loaded */
-static char *ld_bind_now; /* Environment variable for immediate binding */
-static char *ld_debug; /* Environment variable for debugging */
-static char *ld_library_path; /* Environment variable for search path */
-static char *ld_preload; /* Environment variable for libraries to
- load first */
-static char *ld_tracing; /* Called from ldd to print libs */
-static Obj_Entry *obj_list; /* Head of linked list of shared objects */
-static Obj_Entry **obj_tail; /* Link field of last object in list */
-static Obj_Entry *obj_main; /* The main program shared object */
-static Obj_Entry obj_rtld; /* The dynamic linker shared object */
-static unsigned int obj_count; /* Number of objects in obj_list */
-
-static Objlist list_global = /* Objects dlopened with RTLD_GLOBAL */
- STAILQ_HEAD_INITIALIZER(list_global);
-static Objlist list_main = /* Objects loaded at program startup */
- STAILQ_HEAD_INITIALIZER(list_main);
-static Objlist list_fini = /* Objects needing fini() calls */
- STAILQ_HEAD_INITIALIZER(list_fini);
-
-static Elf_Sym sym_zero; /* For resolving undefined weak refs. */
-
-#define GDB_STATE(s,m) r_debug.r_state = s; r_debug_state(&r_debug,m);
-
-extern Elf_Dyn _DYNAMIC;
-#pragma weak _DYNAMIC
-#ifndef RTLD_IS_DYNAMIC
-#define RTLD_IS_DYNAMIC() (&_DYNAMIC != NULL)
-#endif
-
-/*
- * These are the functions the dynamic linker exports to application
- * programs. They are the only symbols the dynamic linker is willing
- * to export from itself.
- */
-static func_ptr_type exports[] = {
- (func_ptr_type) &_rtld_error,
- (func_ptr_type) &dlclose,
- (func_ptr_type) &dlerror,
- (func_ptr_type) &dlopen,
- (func_ptr_type) &dlsym,
- (func_ptr_type) &dladdr,
- (func_ptr_type) &dllockinit,
- (func_ptr_type) &dlinfo,
- (func_ptr_type) &_rtld_thread_init,
-#ifdef __i386__
- (func_ptr_type) &___tls_get_addr,
-#endif
- (func_ptr_type) &__tls_get_addr,
- (func_ptr_type) &_rtld_allocate_tls,
- (func_ptr_type) &_rtld_free_tls,
- NULL
-};
-
-/*
- * Global declarations normally provided by crt1. The dynamic linker is
- * not built with crt1, so we have to provide them ourselves.
- */
-char *__progname;
-char **environ;
-
-/*
- * Globals to control TLS allocation.
- */
-size_t tls_last_offset; /* Static TLS offset of last module */
-size_t tls_last_size; /* Static TLS size of last module */
-size_t tls_static_space; /* Static TLS space allocated */
-int tls_dtv_generation = 1; /* Used to detect when dtv size changes */
-int tls_max_index = 1; /* Largest module index allocated */
-
-/*
- * Fill in a DoneList with an allocation large enough to hold all of
- * the currently-loaded objects. Keep this as a macro since it calls
- * alloca and we want that to occur within the scope of the caller.
- */
-#define donelist_init(dlp) \
- ((dlp)->objs = alloca(obj_count * sizeof (dlp)->objs[0]), \
- assert((dlp)->objs != NULL), \
- (dlp)->num_alloc = obj_count, \
- (dlp)->num_used = 0)
-
-/*
- * Main entry point for dynamic linking. The first argument is the
- * stack pointer. The stack is expected to be laid out as described
- * in the SVR4 ABI specification, Intel 386 Processor Supplement.
- * Specifically, the stack pointer points to a word containing
- * ARGC. Following that in the stack is a null-terminated sequence
- * of pointers to argument strings. Then comes a null-terminated
- * sequence of pointers to environment strings. Finally, there is a
- * sequence of "auxiliary vector" entries.
- *
- * The second argument points to a place to store the dynamic linker's
- * exit procedure pointer and the third to a place to store the main
- * program's object.
- *
- * The return value is the main program's entry point.
- */
-func_ptr_type
-_rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
-{
- Elf_Auxinfo *aux_info[AT_COUNT];
- int i;
- int argc;
- char **argv;
- char **env;
- Elf_Auxinfo *aux;
- Elf_Auxinfo *auxp;
- const char *argv0;
- Objlist_Entry *entry;
- Obj_Entry *obj;
- Obj_Entry **preload_tail;
- Objlist initlist;
- int lockstate;
-
- /*
- * On entry, the dynamic linker itself has not been relocated yet.
- * Be very careful not to reference any global data until after
- * init_rtld has returned. It is OK to reference file-scope statics
- * and string constants, and to call static and global functions.
- */
- /* Find the auxiliary vector on the stack. */
- argc = *sp++;
- argv = (char **) sp;
-
- sp += argc + 1; /* Skip over arguments and NULL terminator */
- env = (char **) sp;
-
- while (*sp++ != 0); /* Skip over environment, and NULL terminator */
-
- aux = (Elf_Auxinfo *) sp;
-
-
-
- /* Digest the auxiliary vector. */
- for (i = 0; i < AT_COUNT; i++)
- aux_info[i] = NULL;
-
- for (auxp = aux; auxp->a_type != AT_NULL; auxp++) {
- if (auxp->a_type < AT_COUNT) {
- aux_info[auxp->a_type] = auxp;
- }
- }
-
- /* Initialize and relocate ourselves. */
- assert(aux_info[AT_BASE] != NULL);
-
- if ((u_int32_t)aux_info[AT_BASE]->a_un.a_ptr != 0x1000000)
- while (1);
-
- init_rtld((caddr_t) aux_info[AT_BASE]->a_un.a_ptr);
-
- __progname = obj_rtld.path;
- argv0 = argv[0] != NULL ? argv[0] : "(null)";
- environ = env;
-
- trust = !issetugid();
-
- ld_bind_now = getenv(LD_ "BIND_NOW");
- if (trust) {
- ld_debug = getenv(LD_ "DEBUG");
- libmap_disable = getenv(LD_ "LIBMAP_DISABLE") != NULL;
- libmap_override = getenv(LD_ "LIBMAP");
- ld_library_path = "/lib";//getenv(LD_ "LIBRARY_PATH");
- ld_preload = getenv(LD_ "PRELOAD");
- dangerous_ld_env = libmap_disable || (libmap_override != NULL) ||
- (ld_library_path != NULL) || (ld_preload != NULL);
- } else
- dangerous_ld_env = 0;
- ld_tracing = getenv(LD_ "TRACE_LOADED_OBJECTS");
-
-
- if (ld_debug != NULL && *ld_debug != '\0')
- debug = 1;
-
-
- dbg("%s is initialized, base address = %p", __progname,
- (caddr_t) aux_info[AT_BASE]->a_un.a_ptr);
- dbg("RTLD dynamic = %p", obj_rtld.dynamic);
- dbg("RTLD pltgot = %p", obj_rtld.pltgot);
-
- /*
- * Load the main program, or process its program header if it is
- * already loaded.
- */
- if (aux_info[AT_EXECFD] != NULL) { /* Load the main program. */
- int fd = aux_info[AT_EXECFD]->a_un.a_val;
- dbg("loading main program");
- obj_main = map_object(fd, argv0, NULL);
- close(fd);
- if (obj_main == NULL)
- die();
- } else { /* Main program already loaded. */
- const Elf_Phdr *phdr;
- int phnum;
- caddr_t entry;
-
- dbg("processing main program's program header");
- assert(aux_info[AT_PHDR] != NULL);
- phdr = (const Elf_Phdr *) aux_info[AT_PHDR]->a_un.a_ptr;
- assert(aux_info[AT_PHNUM] != NULL);
- phnum = aux_info[AT_PHNUM]->a_un.a_val;
- assert(aux_info[AT_PHENT] != NULL);
- assert(aux_info[AT_PHENT]->a_un.a_val == sizeof(Elf_Phdr));
- assert(aux_info[AT_ENTRY] != NULL);
- entry = (caddr_t) aux_info[AT_ENTRY]->a_un.a_ptr;
- if ((obj_main = digest_phdr(phdr, phnum, entry, argv0)) == NULL)
- die();
- }
-
- obj_main->path = xstrdup(argv0);
- obj_main->mainprog = true;
-
- /*
- * Get the actual dynamic linker pathname from the executable if
- * possible. (It should always be possible.) That ensures that
- * gdb will find the right dynamic linker even if a non-standard
- * one is being used.
- */
- if (obj_main->interp != NULL &&
- strcmp(obj_main->interp, obj_rtld.path) != 0) {
- free(obj_rtld.path);
- obj_rtld.path = xstrdup(obj_main->interp);
- __progname = obj_rtld.path;
- }
-
-
- digest_dynamic(obj_main, 0);
-
- linkmap_add(obj_main);
- linkmap_add(&obj_rtld);
-
- /* Link the main program into the list of objects. */
- *obj_tail = obj_main;
- obj_tail = &obj_main->next;
- obj_count++;
- /* Make sure we don't call the main program's init and fini functions. */
- obj_main->init = obj_main->fini = (Elf_Addr)NULL;
-
- /* Initialize a fake symbol for resolving undefined weak references. */
- sym_zero.st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
- sym_zero.st_shndx = SHN_UNDEF;
-
- if (!libmap_disable)
- libmap_disable = (bool)lm_init(libmap_override);
-
- dbg("loading LD_PRELOAD libraries");
- if (load_preload_objects() == -1)
- die();
- preload_tail = obj_tail;
-debug = 1;
-
-
- dbg("loading needed objects");
- if (load_needed_objects(obj_main) == -1)
- die();
-
- /* Make a list of all objects loaded at startup. */
- for (obj = obj_list; obj != NULL; obj = obj->next) {
- objlist_push_tail(&list_main, obj);
- obj->refcount++;
- }
-
- if (ld_tracing) { /* We're done */
- trace_loaded_objects(obj_main);
- exit(0);
- }
-
- if (getenv(LD_ "DUMP_REL_PRE") != NULL) {
- dump_relocations(obj_main);
- exit (0);
- }
-
- /* setup TLS for main thread */
- dbg("initializing initial thread local storage");
- STAILQ_FOREACH(entry, &list_main, link) {
- /*
- * Allocate all the initial objects out of the static TLS
- * block even if they didn't ask for it.
- */
- allocate_tls_offset(entry->obj);
- }
-
- allocate_initial_tls(obj_list);
-
- if (relocate_objects(obj_main, ld_bind_now != NULL && *ld_bind_now != '\0', &obj_rtld) == -1)
- die();
-
- dbg("doing copy relocations");
- if (do_copy_relocations(obj_main) == -1)
- die();
-
- if (getenv(LD_ "DUMP_REL_POST") != NULL) {
- dump_relocations(obj_main);
- exit (0);
- }
-
- dbg("initializing key program variables");
- set_program_var("__progname", argv[0] != NULL ? basename(argv[0]) : "");
- set_program_var("environ", env);
-
- dbg("initializing thread locks");
- lockdflt_init();
-
- /* Make a list of init functions to call. */
- objlist_init(&initlist);
- initlist_add_objects(obj_list, preload_tail, &initlist);
-
- r_debug_state(NULL, &obj_main->linkmap); /* say hello to gdb! */
-
- objlist_call_init(&initlist);
- lockstate = wlock_acquire(rtld_bind_lock);
- objlist_clear(&initlist);
- wlock_release(rtld_bind_lock, lockstate);
-
- dbg("transferring control to program entry point = %p", obj_main->entry);
-
- /* Return the exit procedure and the program entry point. */
- *exit_proc = rtld_exit;
- *objp = obj_main;
- return (func_ptr_type) obj_main->entry;
-}
-
-Elf_Addr
-_rtld_bind(Obj_Entry *obj, Elf_Size reloff)
-{
- const Elf_Rel *rel;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- Elf_Addr *where;
- Elf_Addr target;
- int lockstate;
-
- lockstate = rlock_acquire(rtld_bind_lock);
- if (obj->pltrel)
- rel = (const Elf_Rel *) ((caddr_t) obj->pltrel + reloff);
- else
- rel = (const Elf_Rel *) ((caddr_t) obj->pltrela + reloff);
-
- where = (Elf_Addr *) (obj->relocbase + rel->r_offset);
- def = find_symdef(ELF_R_SYM(rel->r_info), obj, &defobj, true, NULL);
- if (def == NULL)
- die();
-
- target = (Elf_Addr)(defobj->relocbase + def->st_value);
-
- dbg("\"%s\" in \"%s\" ==> %p in \"%s\"",
- defobj->strtab + def->st_name, basename(obj->path),
- (void *)target, basename(defobj->path));
-
- /*
- * Write the new contents for the jmpslot. Note that depending on
- * architecture, the value which we need to return back to the
- * lazy binding trampoline may or may not be the target
- * address. The value returned from reloc_jmpslot() is the value
- * that the trampoline needs.
- */
- target = reloc_jmpslot(where, target, defobj, obj, rel);
- rlock_release(rtld_bind_lock, lockstate);
- return target;
-}
-
-/*
- * Error reporting function. Use it like printf. If formats the message
- * into a buffer, and sets things up so that the next call to dlerror()
- * will return the message.
- */
-void
-_rtld_error(const char *fmt, ...)
-{
- static char buf[512];
- va_list ap;
-
- va_start(ap, fmt);
- vsnprintf(buf, sizeof buf, fmt, ap);
- error_message = buf;
- va_end(ap);
-}
-
-/*
- * Return a dynamically-allocated copy of the current error message, if any.
- */
-static char *
-errmsg_save(void)
-{
- return error_message == NULL ? NULL : xstrdup(error_message);
-}
-
-/*
- * Restore the current error message from a copy which was previously saved
- * by errmsg_save(). The copy is freed.
- */
-static void
-errmsg_restore(char *saved_msg)
-{
- if (saved_msg == NULL)
- error_message = NULL;
- else {
- _rtld_error("%s", saved_msg);
- free(saved_msg);
- }
-}
-
-static const char *
-basename(const char *name)
-{
- const char *p = strrchr(name, '/');
- return p != NULL ? p + 1 : name;
-}
-
-static void
-die(void)
-{
- const char *msg = dlerror();
-
- if (msg == NULL)
- msg = "Fatal error";
- errx(1, "%s", msg);
-}
-
-/*
- * Process a shared object's DYNAMIC section, and save the important
- * information in its Obj_Entry structure.
- */
-static void
-digest_dynamic(Obj_Entry *obj, int early)
-{
- const Elf_Dyn *dynp;
- Needed_Entry **needed_tail = &obj->needed;
- const Elf_Dyn *dyn_rpath = NULL;
- int plttype = DT_REL;
-
- obj->bind_now = false;
- for (dynp = obj->dynamic; dynp->d_tag != DT_NULL; dynp++) {
- switch (dynp->d_tag) {
-
- case DT_REL:
- obj->rel = (const Elf_Rel *) (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_RELSZ:
- obj->relsize = dynp->d_un.d_val;
- break;
-
- case DT_RELENT:
- assert(dynp->d_un.d_val == sizeof(Elf_Rel));
- break;
-
- case DT_JMPREL:
- obj->pltrel = (const Elf_Rel *)
- (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_PLTRELSZ:
- obj->pltrelsize = dynp->d_un.d_val;
- break;
-
- case DT_RELA:
- obj->rela = (const Elf_Rela *) (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_RELASZ:
- obj->relasize = dynp->d_un.d_val;
- break;
-
- case DT_RELAENT:
- assert(dynp->d_un.d_val == sizeof(Elf_Rela));
- break;
-
- case DT_PLTREL:
- plttype = dynp->d_un.d_val;
- assert(dynp->d_un.d_val == DT_REL || plttype == DT_RELA);
- break;
-
- case DT_SYMTAB:
- obj->symtab = (const Elf_Sym *)
- (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_SYMENT:
- assert(dynp->d_un.d_val == sizeof(Elf_Sym));
- break;
-
- case DT_STRTAB:
- obj->strtab = (const char *) (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_STRSZ:
- obj->strsize = dynp->d_un.d_val;
- break;
-
- case DT_HASH:
- {
- const Elf_Hashelt *hashtab = (const Elf_Hashelt *)
- (obj->relocbase + dynp->d_un.d_ptr);
- obj->nbuckets = hashtab[0];
- obj->nchains = hashtab[1];
- obj->buckets = hashtab + 2;
- obj->chains = obj->buckets + obj->nbuckets;
- }
- break;
-
- case DT_NEEDED:
- if (!obj->rtld) {
- Needed_Entry *nep = NEW(Needed_Entry);
- nep->name = dynp->d_un.d_val;
- nep->obj = NULL;
- nep->next = NULL;
-
- *needed_tail = nep;
- needed_tail = &nep->next;
- }
- break;
-
- case DT_PLTGOT:
- obj->pltgot = (Elf_Addr *) (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_TEXTREL:
- obj->textrel = true;
- break;
-
- case DT_SYMBOLIC:
- obj->symbolic = true;
- break;
-
- case DT_RPATH:
- case DT_RUNPATH: /* XXX: process separately */
- /*
- * We have to wait until later to process this, because we
- * might not have gotten the address of the string table yet.
- */
- dyn_rpath = dynp;
- break;
-
- case DT_SONAME:
- /* Not used by the dynamic linker. */
- break;
-
- case DT_INIT:
- obj->init = (Elf_Addr) (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_FINI:
- obj->fini = (Elf_Addr) (obj->relocbase + dynp->d_un.d_ptr);
- break;
-
- case DT_DEBUG:
- /* XXX - not implemented yet */
- if (!early)
- dbg("Filling in DT_DEBUG entry");
- ((Elf_Dyn*)dynp)->d_un.d_ptr = (Elf_Addr) &r_debug;
- break;
-
- case DT_FLAGS:
- if (dynp->d_un.d_val & DF_ORIGIN) {
- obj->origin_path = xmalloc(PATH_MAX);
- if (rtld_dirname(obj->path, obj->origin_path) == -1)
- die();
- }
- if (dynp->d_un.d_val & DF_SYMBOLIC)
- obj->symbolic = true;
- if (dynp->d_un.d_val & DF_TEXTREL)
- obj->textrel = true;
- if (dynp->d_un.d_val & DF_BIND_NOW)
- obj->bind_now = true;
- if (dynp->d_un.d_val & DF_STATIC_TLS)
- ;
- break;
-
- default:
- if (!early) {
- dbg("Ignoring d_tag %ld = %#lx", (long)dynp->d_tag, (long)dynp->d_tag);
- }
- break;
- }
- }
-
- obj->traced = false;
-
- if (plttype == DT_RELA) {
- obj->pltrela = (const Elf_Rela *) obj->pltrel;
- obj->pltrel = NULL;
- obj->pltrelasize = obj->pltrelsize;
- obj->pltrelsize = 0;
- }
-
- if (dyn_rpath != NULL)
- obj->rpath = obj->strtab + dyn_rpath->d_un.d_val;
-}
-
-/*
- * Process a shared object's program header. This is used only for the
- * main program, when the kernel has already loaded the main program
- * into memory before calling the dynamic linker. It creates and
- * returns an Obj_Entry structure.
- */
-static Obj_Entry *
-digest_phdr(const Elf_Phdr *phdr, int phnum, caddr_t entry, const char *path)
-{
- Obj_Entry *obj;
- const Elf_Phdr *phlimit = phdr + phnum;
- const Elf_Phdr *ph;
- int nsegs = 0;
-
- obj = obj_new();
- for (ph = phdr; ph < phlimit; ph++) {
- switch (ph->p_type) {
-
- case PT_PHDR:
- if ((const Elf_Phdr *)ph->p_vaddr != phdr) {
- _rtld_error("%s: invalid PT_PHDR", path);
- return NULL;
- }
- obj->phdr = (const Elf_Phdr *) ph->p_vaddr;
- obj->phsize = ph->p_memsz;
- break;
-
- case PT_INTERP:
- obj->interp = (const char *) ph->p_vaddr;
- break;
-
- case PT_LOAD:
- if (nsegs == 0) { /* First load segment */
- obj->vaddrbase = trunc_page(ph->p_vaddr);
- obj->mapbase = (caddr_t) obj->vaddrbase;
- obj->relocbase = obj->mapbase - obj->vaddrbase;
- obj->textsize = round_page(ph->p_vaddr + ph->p_memsz) -
- obj->vaddrbase;
- } else { /* Last load segment */
- obj->mapsize = round_page(ph->p_vaddr + ph->p_memsz) -
- obj->vaddrbase;
- }
- nsegs++;
- break;
-
- case PT_DYNAMIC:
- obj->dynamic = (const Elf_Dyn *) ph->p_vaddr;
- break;
-
- case PT_TLS:
- obj->tlsindex = 1;
- obj->tlssize = ph->p_memsz;
- obj->tlsalign = ph->p_align;
- obj->tlsinitsize = ph->p_filesz;
- obj->tlsinit = (void*) ph->p_vaddr;
- break;
- }
- }
- if (nsegs < 1) {
- _rtld_error("%s: too few PT_LOAD segments", path);
- return NULL;
- }
-
- obj->entry = entry;
- return obj;
-}
-
-static Obj_Entry *
-dlcheck(void *handle)
-{
- Obj_Entry *obj;
-
- for (obj = obj_list; obj != NULL; obj = obj->next)
- if (obj == (Obj_Entry *) handle)
- break;
-
- if (obj == NULL || obj->refcount == 0 || obj->dl_refcount == 0) {
- _rtld_error("Invalid shared object handle %p", handle);
- return NULL;
- }
- return obj;
-}
-
-/*
- * If the given object is already in the donelist, return true. Otherwise
- * add the object to the list and return false.
- */
-static bool
-donelist_check(DoneList *dlp, const Obj_Entry *obj)
-{
- unsigned int i;
-
- for (i = 0; i < dlp->num_used; i++)
- if (dlp->objs[i] == obj)
- return true;
- /*
- * Our donelist allocation should always be sufficient. But if
- * our threads locking isn't working properly, more shared objects
- * could have been loaded since we allocated the list. That should
- * never happen, but we'll handle it properly just in case it does.
- */
- if (dlp->num_used < dlp->num_alloc)
- dlp->objs[dlp->num_used++] = obj;
- return false;
-}
-
-/*
- * Hash function for symbol table lookup. Don't even think about changing
- * this. It is specified by the System V ABI.
- */
-unsigned long
-elf_hash(const char *name)
-{
- const unsigned char *p = (const unsigned char *) name;
- unsigned long h = 0;
- unsigned long g;
-
- while (*p != '\0') {
- h = (h << 4) + *p++;
- if ((g = h & 0xf0000000) != 0)
- h ^= g >> 24;
- h &= ~g;
- }
- return h;
-}
-
-/*
- * Find the library with the given name, and return its full pathname.
- * The returned string is dynamically allocated. Generates an error
- * message and returns NULL if the library cannot be found.
- *
- * If the second argument is non-NULL, then it refers to an already-
- * loaded shared object, whose library search path will be searched.
- *
- * The search order is:
- * LD_LIBRARY_PATH
- * rpath in the referencing file
- * ldconfig hints
- * /lib:/usr/lib
- */
-static char *
-find_library(const char *xname, const Obj_Entry *refobj)
-{
- char *pathname;
- char *name;
-
- if (strchr(xname, '/') != NULL) { /* Hard coded pathname */
- if (xname[0] != '/' && !trust) {
- _rtld_error("Absolute pathname required for shared object \"%s\"",
- xname);
- return NULL;
- }
- return xstrdup(xname);
- }
-
- if (libmap_disable || (refobj == NULL) ||
- (name = lm_find(refobj->path, xname)) == NULL)
- name = (char *)xname;
-
- dbg(" Searching for \"%s\"", name);
- if ((pathname = search_library_path(name, ld_library_path)) != NULL ||
- (refobj != NULL &&
- (pathname = search_library_path(name, refobj->rpath)) != NULL) ||
- (pathname = search_library_path(name, gethints())) != NULL ||
- (pathname = search_library_path(name, STANDARD_LIBRARY_PATH)) != NULL)
- return pathname;
-
- if(refobj != NULL && refobj->path != NULL) {
- _rtld_error("Shared object \"%s\" not found, required by \"%s\"",
- name, basename(refobj->path));
- } else {
- _rtld_error("Shared object \"%s\" not found", name);
- }
- return NULL;
-}
-
-/*
- * Given a symbol number in a referencing object, find the corresponding
- * definition of the symbol. Returns a pointer to the symbol, or NULL if
- * no definition was found. Returns a pointer to the Obj_Entry of the
- * defining object via the reference parameter DEFOBJ_OUT.
- */
-const Elf_Sym *
-find_symdef(unsigned long symnum, const Obj_Entry *refobj,
- const Obj_Entry **defobj_out, bool in_plt, SymCache *cache)
-{
- const Elf_Sym *ref;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- const char *name;
- unsigned long hash;
-
- /*
- * If we have already found this symbol, get the information from
- * the cache.
- */
- if (symnum >= refobj->nchains)
- return NULL; /* Bad object */
-
- if (cache != NULL && cache[symnum].sym != NULL) {
- *defobj_out = cache[symnum].obj;
- return cache[symnum].sym;
- }
-
- ref = refobj->symtab + symnum;
- name = refobj->strtab + ref->st_name;
- defobj = NULL;
-
- /*
- * We don't have to do a full scale lookup if the symbol is local.
- * We know it will bind to the instance in this load module; to
- * which we already have a pointer (ie ref). By not doing a lookup,
- * we not only improve performance, but it also avoids unresolvable
- * symbols when local symbols are not in the hash table. This has
- * been seen with the ia64 toolchain.
- */
- if (ELF_ST_BIND(ref->st_info) != STB_LOCAL) {
- if (ELF_ST_TYPE(ref->st_info) == STT_SECTION) {
- _rtld_error("%s: Bogus symbol table entry %lu", refobj->path,
- symnum);
- }
- hash = elf_hash(name);
- def = symlook_default(name, hash, refobj, &defobj, in_plt);
- } else {
- def = ref;
- defobj = refobj;
- }
-
- /*
- * If we found no definition and the reference is weak, treat the
- * symbol as having the value zero.
- */
- if (def == NULL && ELF_ST_BIND(ref->st_info) == STB_WEAK) {
- def = &sym_zero;
- defobj = obj_main;
- }
-
- if (def != NULL) {
- *defobj_out = defobj;
- /* Record the information in the cache to avoid subsequent lookups. */
- if (cache != NULL) {
- cache[symnum].sym = def;
- cache[symnum].obj = defobj;
- }
- } else {
- if (refobj != &obj_rtld)
- _rtld_error("%s: Undefined symbol \"%s\"", refobj->path, name);
- }
- return def;
-}
-
-/*
- * Return the search path from the ldconfig hints file, reading it if
- * necessary. Returns NULL if there are problems with the hints file,
- * or if the search path there is empty.
- */
-static const char *
-gethints(void)
-{
- static char *hints;
-
- if (hints == NULL) {
- int fd;
- struct elfhints_hdr hdr;
- char *p;
-
- /* Keep from trying again in case the hints file is bad. */
- hints = "";
-
- if ((fd = open(_PATH_ELF_HINTS, O_RDONLY)) == -1)
- return NULL;
- if (read(fd, &hdr, sizeof hdr) != sizeof hdr ||
- hdr.magic != ELFHINTS_MAGIC ||
- hdr.version != 1) {
- close(fd);
- return NULL;
- }
- p = xmalloc(hdr.dirlistlen + 1);
- if (lseek(fd, hdr.strtab + hdr.dirlist, SEEK_SET) == -1 ||
- read(fd, p, hdr.dirlistlen + 1) != (ssize_t)hdr.dirlistlen + 1) {
- free(p);
- close(fd);
- return NULL;
- }
- hints = p;
- close(fd);
- }
- return hints[0] != '\0' ? hints : NULL;
-}
-
-static void
-init_dag(Obj_Entry *root)
-{
- DoneList donelist;
-
- donelist_init(&donelist);
- init_dag1(root, root, &donelist);
-}
-
-static void
-init_dag1(Obj_Entry *root, Obj_Entry *obj, DoneList *dlp)
-{
- const Needed_Entry *needed;
-
- if (donelist_check(dlp, obj))
- return;
-
- obj->refcount++;
- objlist_push_tail(&obj->dldags, root);
- objlist_push_tail(&root->dagmembers, obj);
- for (needed = obj->needed; needed != NULL; needed = needed->next)
- if (needed->obj != NULL)
- init_dag1(root, needed->obj, dlp);
-}
-
-/*
- * Initialize the dynamic linker. The argument is the address at which
- * the dynamic linker has been mapped into memory. The primary task of
- * this function is to relocate the dynamic linker.
- */
-static void
-init_rtld(caddr_t mapbase)
-{
- Obj_Entry objtmp; /* Temporary rtld object */
-
- /*
- * Conjure up an Obj_Entry structure for the dynamic linker.
- *
- * The "path" member can't be initialized yet because string constatns
- * cannot yet be acessed. Below we will set it correctly.
- */
- memset(&objtmp, 0, sizeof(objtmp));
- objtmp.path = NULL;
- objtmp.rtld = true;
- objtmp.mapbase = mapbase;
-#ifdef PIC
- objtmp.relocbase = mapbase;
-#endif
- if (RTLD_IS_DYNAMIC()) {
- objtmp.dynamic = rtld_dynamic(&objtmp);
- digest_dynamic(&objtmp, 1);
- assert(objtmp.needed == NULL);
- assert(!objtmp.textrel);
-
- /*
- * Temporarily put the dynamic linker entry into the object list, so
- * that symbols can be found.
- */
-
- relocate_objects(&objtmp, true, &objtmp);
- }
-
- /* Initialize the object list. */
- obj_tail = &obj_list;
-
- /* Now that non-local variables can be accesses, copy out obj_rtld. */
- memcpy(&obj_rtld, &objtmp, sizeof(obj_rtld));
-
- /* Replace the path with a dynamically allocated copy. */
- obj_rtld.path = xstrdup(PATH_RTLD);
-
- r_debug.r_brk = r_debug_state;
- r_debug.r_state = RT_CONSISTENT;
-}
-
-/*
- * Add the init functions from a needed object list (and its recursive
- * needed objects) to "list". This is not used directly; it is a helper
- * function for initlist_add_objects(). The write lock must be held
- * when this function is called.
- */
-static void
-initlist_add_neededs(Needed_Entry *needed, Objlist *list)
-{
- /* Recursively process the successor needed objects. */
- if (needed->next != NULL)
- initlist_add_neededs(needed->next, list);
-
- /* Process the current needed object. */
- if (needed->obj != NULL)
- initlist_add_objects(needed->obj, &needed->obj->next, list);
-}
-
-/*
- * Scan all of the DAGs rooted in the range of objects from "obj" to
- * "tail" and add their init functions to "list". This recurses over
- * the DAGs and ensure the proper init ordering such that each object's
- * needed libraries are initialized before the object itself. At the
- * same time, this function adds the objects to the global finalization
- * list "list_fini" in the opposite order. The write lock must be
- * held when this function is called.
- */
-static void
-initlist_add_objects(Obj_Entry *obj, Obj_Entry **tail, Objlist *list)
-{
- if (obj->init_done)
- return;
- obj->init_done = true;
-
- /* Recursively process the successor objects. */
- if (&obj->next != tail)
- initlist_add_objects(obj->next, tail, list);
-
- /* Recursively process the needed objects. */
- if (obj->needed != NULL)
- initlist_add_neededs(obj->needed, list);
-
- /* Add the object to the init list. */
- if (obj->init != (Elf_Addr)NULL)
- objlist_push_tail(list, obj);
-
- /* Add the object to the global fini list in the reverse order. */
- if (obj->fini != (Elf_Addr)NULL)
- objlist_push_head(&list_fini, obj);
-}
-
-#ifndef FPTR_TARGET
-#define FPTR_TARGET(f) ((Elf_Addr) (f))
-#endif
-
-static bool
-is_exported(const Elf_Sym *def)
-{
- Elf_Addr value;
- const func_ptr_type *p;
-
- value = (Elf_Addr)(obj_rtld.relocbase + def->st_value);
- for (p = exports; *p != NULL; p++)
- if (FPTR_TARGET(*p) == value)
- return true;
- return false;
-}
-
-/*
- * Given a shared object, traverse its list of needed objects, and load
- * each of them. Returns 0 on success. Generates an error message and
- * returns -1 on failure.
- */
-static int load_needed_objects(Obj_Entry *first) {
- Obj_Entry *obj;
-
- for (obj = first; obj != NULL; obj = obj->next) {
- Needed_Entry *needed;
-
- for (needed = obj->needed; needed != NULL; needed = needed->next) {
- const char *name = obj->strtab + needed->name;
- char *path = find_library(name, obj);
-
- needed->obj = NULL;
-
- if (path == NULL && !ld_tracing)
- return -1;
-
- printf("\n\nPATH: [%s]\n",path);
-
- if (path) {
- needed->obj = load_object(path);
- if (needed->obj == NULL && !ld_tracing)
- return(-1); /* XXX - cleanup */
- }
- }
- }
-
- return 0;
- }
-
-static int
-load_preload_objects(void)
-{
- char *p = ld_preload;
- static const char delim[] = " \t:;";
-
- if (p == NULL)
- return 0;
-
- p += strspn(p, delim);
- while (*p != '\0') {
- size_t len = strcspn(p, delim);
- char *path;
- char savech;
-
- savech = p[len];
- p[len] = '\0';
- if ((path = find_library(p, NULL)) == NULL)
- return -1;
- if (load_object(path) == NULL)
- return -1; /* XXX - cleanup */
- p[len] = savech;
- p += len;
- p += strspn(p, delim);
- }
- return 0;
-}
-
-/*
- * Load a shared object into memory, if it is not already loaded. The
- * argument must be a string allocated on the heap. This function assumes
- * responsibility for freeing it when necessary.
- *
- * Returns a pointer to the Obj_Entry for the object. Returns NULL
- * on failure.
- */
-static Obj_Entry *
-load_object(char *path)
-{
- Obj_Entry *obj;
- int fd = -1;
- struct stat sb;
- struct statfs fs;
-
- for (obj = obj_list->next; obj != NULL; obj = obj->next)
- if (strcmp(obj->path, path) == 0)
- break;
-
- /*
- * If we didn't find a match by pathname, open the file and check
- * again by device and inode. This avoids false mismatches caused
- * by multiple links or ".." in pathnames.
- *
- * To avoid a race, we open the file and use fstat() rather than
- * using stat().
- */
- if (obj == NULL) {
- if ((fd = open(path, O_RDONLY)) == -1) {
- _rtld_error("Cannot open \"%s\"", path);
- return NULL;
- }
- if (fstat(fd, &sb) == -1) {
- _rtld_error("Cannot fstat \"%s\"", path);
- close(fd);
- return NULL;
- }
- for (obj = obj_list->next; obj != NULL; obj = obj->next) {
- if (obj->ino == sb.st_ino && obj->dev == sb.st_dev) {
- close(fd);
- break;
- }
- }
- }
-
- if (obj == NULL) { /* First use of this object, so we must map it in */
- /*
- * but first, make sure that environment variables haven't been
- * used to circumvent the noexec flag on a filesystem.
- */
- if (dangerous_ld_env) {
- if (fstatfs(fd, &fs) != 0) {
- _rtld_error("Cannot fstatfs \"%s\"", path);
- close(fd);
- return NULL;
- }
- if (fs.f_flags & MNT_NOEXEC) {
- _rtld_error("Cannot execute objects on %s\n", fs.f_mntonname);
- close(fd);
- return NULL;
- }
- }
- dbg("loading \"%s\"", path);
-
- obj = map_object(fd, path, &sb);
-
- printf("\nmapped object\n");
- close(fd);
- if (obj == NULL) {
- free(path);
- return NULL;
- }
-
- obj->path = path;
-
- digest_dynamic(obj, 0);
-//while(1);
-
- *obj_tail = obj;
- obj_tail = &obj->next;
- obj_count++;
- linkmap_add(obj); /* for GDB & dlinfo() */
-
- dbg(" %p .. %p: %s", obj->mapbase,
- obj->mapbase + obj->mapsize - 1, obj->path);
- if (obj->textrel)
- dbg(" WARNING: %s has impure text", obj->path);
- } else
- free(path);
-
- return obj;
-}
-
-static Obj_Entry *
-obj_from_addr(const void *addr)
-{
- Obj_Entry *obj;
-
- for (obj = obj_list; obj != NULL; obj = obj->next) {
- if (addr < (void *) obj->mapbase)
- continue;
- if (addr < (void *) (obj->mapbase + obj->mapsize))
- return obj;
- }
- return NULL;
-}
-
-/*
- * Call the finalization functions for each of the objects in "list"
- * which are unreferenced. All of the objects are expected to have
- * non-NULL fini functions.
- */
-static void
-objlist_call_fini(Objlist *list)
-{
- Objlist_Entry *elm;
- char *saved_msg;
-
- /*
- * Preserve the current error message since a fini function might
- * call into the dynamic linker and overwrite it.
- */
- saved_msg = errmsg_save();
- STAILQ_FOREACH(elm, list, link) {
- if (elm->obj->refcount == 0) {
- dbg("calling fini function for %s at %p", elm->obj->path,
- (void *)elm->obj->fini);
- call_initfini_pointer(elm->obj, elm->obj->fini);
- }
- }
- errmsg_restore(saved_msg);
-}
-
-/*
- * Call the initialization functions for each of the objects in
- * "list". All of the objects are expected to have non-NULL init
- * functions.
- */
-static void
-objlist_call_init(Objlist *list)
-{
- Objlist_Entry *elm;
- char *saved_msg;
-
- /*
- * Preserve the current error message since an init function might
- * call into the dynamic linker and overwrite it.
- */
- saved_msg = errmsg_save();
- STAILQ_FOREACH(elm, list, link) {
- dbg("calling init function for %s at %p", elm->obj->path,
- (void *)elm->obj->init);
- call_initfini_pointer(elm->obj, elm->obj->init);
- }
- errmsg_restore(saved_msg);
-}
-
-static void
-objlist_clear(Objlist *list)
-{
- Objlist_Entry *elm;
-
- while (!STAILQ_EMPTY(list)) {
- elm = STAILQ_FIRST(list);
- STAILQ_REMOVE_HEAD(list, link);
- free(elm);
- }
-}
-
-static Objlist_Entry *
-objlist_find(Objlist *list, const Obj_Entry *obj)
-{
- Objlist_Entry *elm;
-
- STAILQ_FOREACH(elm, list, link)
- if (elm->obj == obj)
- return elm;
- return NULL;
-}
-
-static void
-objlist_init(Objlist *list)
-{
- STAILQ_INIT(list);
-}
-
-static void
-objlist_push_head(Objlist *list, Obj_Entry *obj)
-{
- Objlist_Entry *elm;
-
- elm = NEW(Objlist_Entry);
- elm->obj = obj;
- STAILQ_INSERT_HEAD(list, elm, link);
-}
-
-static void
-objlist_push_tail(Objlist *list, Obj_Entry *obj)
-{
- Objlist_Entry *elm;
-
- elm = NEW(Objlist_Entry);
- elm->obj = obj;
- STAILQ_INSERT_TAIL(list, elm, link);
-}
-
-static void
-objlist_remove(Objlist *list, Obj_Entry *obj)
-{
- Objlist_Entry *elm;
-
- if ((elm = objlist_find(list, obj)) != NULL) {
- STAILQ_REMOVE(list, elm, Struct_Objlist_Entry, link);
- free(elm);
- }
-}
-
-/*
- * Remove all of the unreferenced objects from "list".
- */
-static void
-objlist_remove_unref(Objlist *list)
-{
- Objlist newlist;
- Objlist_Entry *elm;
-
- STAILQ_INIT(&newlist);
- while (!STAILQ_EMPTY(list)) {
- elm = STAILQ_FIRST(list);
- STAILQ_REMOVE_HEAD(list, link);
- if (elm->obj->refcount == 0)
- free(elm);
- else
- STAILQ_INSERT_TAIL(&newlist, elm, link);
- }
- *list = newlist;
-}
-
-/*
- * Relocate newly-loaded shared objects. The argument is a pointer to
- * the Obj_Entry for the first such object. All objects from the first
- * to the end of the list of objects are relocated. Returns 0 on success,
- * or -1 on failure.
- */
-static int
-relocate_objects(Obj_Entry *first, bool bind_now, Obj_Entry *rtldobj)
-{
- Obj_Entry *obj;
-
- for (obj = first; obj != NULL; obj = obj->next) {
- if (obj != rtldobj)
- dbg("relocating (\"%s\")", obj->path);
- if (obj->nbuckets == 0 || obj->nchains == 0 || obj->buckets == NULL ||
- obj->symtab == NULL || obj->strtab == NULL) {
- _rtld_error("%s: Shared object has no run-time symbol table",
- obj->path);
- return -1;
- }
-
- if (obj->textrel) {
- /* There are relocations to the write-protected text segment. */
- if (mprotect(obj->mapbase, obj->textsize,
- PROT_READ|PROT_WRITE|PROT_EXEC) == -1) {
- _rtld_error("%s: Cannot write-enable text segment: %s",
- obj->path, strerror(errno));
- return -1;
- }
- }
-
- /* Process the non-PLT relocations. */
- if (reloc_non_plt(obj, rtldobj))
- return -1;
-
- if (obj->textrel) { /* Re-protected the text segment. */
- if (mprotect(obj->mapbase, obj->textsize,
- PROT_READ|PROT_EXEC) == -1) {
- _rtld_error("%s: Cannot write-protect text segment: %s",
- obj->path, strerror(errno));
- return -1;
- }
- }
-
- /* Process the PLT relocations. */
- if (reloc_plt(obj) == -1)
- return -1;
-
- /* Relocate the jump slots if we are doing immediate binding. */
- if (obj->bind_now || bind_now)
- if (reloc_jmpslots(obj) == -1)
- return -1;
-
- /*
- * Set up the magic number and version in the Obj_Entry. These
- * were checked in the crt1.o from the original ElfKit, so we
- * set them for backward compatibility.
- */
- obj->magic = RTLD_MAGIC;
- obj->version = RTLD_VERSION;
-
- /* Set the special PLT or GOT entries. */
- init_pltgot(obj);
- }
-
- return 0;
-}
-
-/*
- * Cleanup procedure. It will be called (by the atexit mechanism) just
- * before the process exits.
- */
-static void
-rtld_exit(void)
-{
- Obj_Entry *obj;
-
- dbg("rtld_exit()");
- /* Clear all the reference counts so the fini functions will be called. */
- for (obj = obj_list; obj != NULL; obj = obj->next)
- obj->refcount = 0;
- objlist_call_fini(&list_fini);
- /* No need to remove the items from the list, since we are exiting. */
- if (!libmap_disable)
- lm_fini();
-}
-
-static void *
-path_enumerate(const char *path, path_enum_proc callback, void *arg)
-{
-#ifdef COMPAT_32BIT
- const char *trans;
-#endif
- if (path == NULL)
- return (NULL);
-
- path += strspn(path, ":;");
- while (*path != '\0') {
- size_t len;
- char *res;
-
- len = strcspn(path, ":;");
-#ifdef COMPAT_32BIT
- trans = lm_findn(NULL, path, len);
- if (trans)
- res = callback(trans, strlen(trans), arg);
- else
-#endif
- res = callback(path, len, arg);
-
- if (res != NULL)
- return (res);
-
- path += len;
- path += strspn(path, ":;");
- }
-
- return (NULL);
-}
-
-struct try_library_args {
- const char *name;
- size_t namelen;
- char *buffer;
- size_t buflen;
-};
-
-static void *
-try_library_path(const char *dir, size_t dirlen, void *param)
-{
- struct try_library_args *arg;
-
- arg = param;
- if (*dir == '/' || trust) {
- char *pathname;
-
- if (dirlen + 1 + arg->namelen + 1 > arg->buflen)
- return (NULL);
-
- pathname = arg->buffer;
- strncpy(pathname, dir, dirlen);
- pathname[dirlen] = '/';
- strcpy(pathname + dirlen + 1, arg->name);
-
- dbg(" Trying \"%s\"", pathname);
- if (access(pathname, F_OK) == 0) { /* We found it */
- pathname = xmalloc(dirlen + 1 + arg->namelen + 1);
- strcpy(pathname, arg->buffer);
- return (pathname);
- }
- }
- return (NULL);
-}
-
-static char *
-search_library_path(const char *name, const char *path)
-{
- char *p;
- struct try_library_args arg;
-
- if (path == NULL)
- return NULL;
-printf("name: [%s]\n",name);
- arg.name = name;
- arg.namelen = strlen(name);
- arg.buffer = xmalloc(PATH_MAX);
- arg.buflen = PATH_MAX;
-
- p = path_enumerate(path, try_library_path, &arg);
-
- free(arg.buffer);
-
- return (p);
-}
-
-int
-dlclose(void *handle)
-{
- Obj_Entry *root;
- int lockstate;
-
- lockstate = wlock_acquire(rtld_bind_lock);
- root = dlcheck(handle);
- if (root == NULL) {
- wlock_release(rtld_bind_lock, lockstate);
- return -1;
- }
-
- /* Unreference the object and its dependencies. */
- root->dl_refcount--;
-
- unref_dag(root);
-
- if (root->refcount == 0) {
- /*
- * The object is no longer referenced, so we must unload it.
- * First, call the fini functions with no locks held.
- */
- wlock_release(rtld_bind_lock, lockstate);
- objlist_call_fini(&list_fini);
- lockstate = wlock_acquire(rtld_bind_lock);
- objlist_remove_unref(&list_fini);
-
- /* Finish cleaning up the newly-unreferenced objects. */
- GDB_STATE(RT_DELETE,&root->linkmap);
- unload_object(root);
- GDB_STATE(RT_CONSISTENT,NULL);
- }
- wlock_release(rtld_bind_lock, lockstate);
- return 0;
-}
-
-const char *
-dlerror(void)
-{
- char *msg = error_message;
- error_message = NULL;
- return msg;
-}
-
-/*
- * This function is deprecated and has no effect.
- */
-void
-dllockinit(void *context,
- void *(*lock_create)(void *context),
- void (*rlock_acquire)(void *lock),
- void (*wlock_acquire)(void *lock),
- void (*lock_release)(void *lock),
- void (*lock_destroy)(void *lock),
- void (*context_destroy)(void *context))
-{
- static void *cur_context;
- static void (*cur_context_destroy)(void *);
-
- /* Just destroy the context from the previous call, if necessary. */
- if (cur_context_destroy != NULL)
- cur_context_destroy(cur_context);
- cur_context = context;
- cur_context_destroy = context_destroy;
-}
-
-void *
-dlopen(const char *name, int mode)
-{
- Obj_Entry **old_obj_tail;
- Obj_Entry *obj;
- Objlist initlist;
- int result, lockstate;
-
- ld_tracing = (mode & RTLD_TRACE) == 0 ? NULL : "1";
- if (ld_tracing != NULL)
- environ = (char **)*get_program_var_addr("environ");
-
- objlist_init(&initlist);
-
- lockstate = wlock_acquire(rtld_bind_lock);
- GDB_STATE(RT_ADD,NULL);
-
- old_obj_tail = obj_tail;
- obj = NULL;
- if (name == NULL) {
- obj = obj_main;
- obj->refcount++;
- } else {
- char *path = find_library(name, obj_main);
- if (path != NULL)
- obj = load_object(path);
- }
-
- if (obj) {
- obj->dl_refcount++;
- if (mode & RTLD_GLOBAL && objlist_find(&list_global, obj) == NULL)
- objlist_push_tail(&list_global, obj);
- mode &= RTLD_MODEMASK;
- if (*old_obj_tail != NULL) { /* We loaded something new. */
- assert(*old_obj_tail == obj);
-
- result = load_needed_objects(obj);
- if (result != -1 && ld_tracing)
- goto trace;
-
- if (result == -1 ||
- (init_dag(obj), relocate_objects(obj, mode == RTLD_NOW,
- &obj_rtld)) == -1) {
- obj->dl_refcount--;
- unref_dag(obj);
- if (obj->refcount == 0)
- unload_object(obj);
- obj = NULL;
- } else {
- /* Make list of init functions to call. */
- initlist_add_objects(obj, &obj->next, &initlist);
- }
- } else {
-
- /* Bump the reference counts for objects on this DAG. */
- ref_dag(obj);
-
- if (ld_tracing)
- goto trace;
- }
- }
-
- GDB_STATE(RT_CONSISTENT,obj ? &obj->linkmap : NULL);
-
- /* Call the init functions with no locks held. */
- wlock_release(rtld_bind_lock, lockstate);
- objlist_call_init(&initlist);
- lockstate = wlock_acquire(rtld_bind_lock);
- objlist_clear(&initlist);
- wlock_release(rtld_bind_lock, lockstate);
- return obj;
-trace:
- trace_loaded_objects(obj);
- wlock_release(rtld_bind_lock, lockstate);
- exit(0);
-}
-
-void *
-dlsym(void *handle, const char *name)
-{
- const Obj_Entry *obj;
- unsigned long hash;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- int lockstate;
-
- hash = elf_hash(name);
- def = NULL;
- defobj = NULL;
-
- lockstate = rlock_acquire(rtld_bind_lock);
- if (handle == NULL || handle == RTLD_NEXT ||
- handle == RTLD_DEFAULT || handle == RTLD_SELF) {
- void *retaddr;
-
- retaddr = __builtin_return_address(0); /* __GNUC__ only */
- if ((obj = obj_from_addr(retaddr)) == NULL) {
- _rtld_error("Cannot determine caller's shared object");
- rlock_release(rtld_bind_lock, lockstate);
- return NULL;
- }
- if (handle == NULL) { /* Just the caller's shared object. */
- def = symlook_obj(name, hash, obj, true);
- defobj = obj;
- } else if (handle == RTLD_NEXT || /* Objects after caller's */
- handle == RTLD_SELF) { /* ... caller included */
- if (handle == RTLD_NEXT)
- obj = obj->next;
- for (; obj != NULL; obj = obj->next) {
- if ((def = symlook_obj(name, hash, obj, true)) != NULL) {
- defobj = obj;
- break;
- }
- }
- } else {
- assert(handle == RTLD_DEFAULT);
- def = symlook_default(name, hash, obj, &defobj, true);
- }
- } else {
- if ((obj = dlcheck(handle)) == NULL) {
- rlock_release(rtld_bind_lock, lockstate);
- return NULL;
- }
-
- if (obj->mainprog) {
- DoneList donelist;
-
- /* Search main program and all libraries loaded by it. */
- donelist_init(&donelist);
- def = symlook_list(name, hash, &list_main, &defobj, true,
- &donelist);
- } else {
- /*
- * XXX - This isn't correct. The search should include the whole
- * DAG rooted at the given object.
- */
- def = symlook_obj(name, hash, obj, true);
- defobj = obj;
- }
- }
-
- if (def != NULL) {
- rlock_release(rtld_bind_lock, lockstate);
-
- /*
- * The value required by the caller is derived from the value
- * of the symbol. For the ia64 architecture, we need to
- * construct a function descriptor which the caller can use to
- * call the function with the right 'gp' value. For other
- * architectures and for non-functions, the value is simply
- * the relocated value of the symbol.
- */
- if (ELF_ST_TYPE(def->st_info) == STT_FUNC)
- return make_function_pointer(def, defobj);
- else
- return defobj->relocbase + def->st_value;
- }
-
- _rtld_error("Undefined symbol \"%s\"", name);
- rlock_release(rtld_bind_lock, lockstate);
- return NULL;
-}
-
-int
-dladdr(const void *addr, Dl_info *info)
-{
- const Obj_Entry *obj;
- const Elf_Sym *def;
- void *symbol_addr;
- unsigned long symoffset;
- int lockstate;
-
- lockstate = rlock_acquire(rtld_bind_lock);
- obj = obj_from_addr(addr);
- if (obj == NULL) {
- _rtld_error("No shared object contains address");
- rlock_release(rtld_bind_lock, lockstate);
- return 0;
- }
- info->dli_fname = obj->path;
- info->dli_fbase = obj->mapbase;
- info->dli_saddr = (void *)0;
- info->dli_sname = NULL;
-
- /*
- * Walk the symbol list looking for the symbol whose address is
- * closest to the address sent in.
- */
- for (symoffset = 0; symoffset < obj->nchains; symoffset++) {
- def = obj->symtab + symoffset;
-
- /*
- * For skip the symbol if st_shndx is either SHN_UNDEF or
- * SHN_COMMON.
- */
- if (def->st_shndx == SHN_UNDEF || def->st_shndx == SHN_COMMON)
- continue;
-
- /*
- * If the symbol is greater than the specified address, or if it
- * is further away from addr than the current nearest symbol,
- * then reject it.
- */
- symbol_addr = obj->relocbase + def->st_value;
- if (symbol_addr > addr || symbol_addr < info->dli_saddr)
- continue;
-
- /* Update our idea of the nearest symbol. */
- info->dli_sname = obj->strtab + def->st_name;
- info->dli_saddr = symbol_addr;
-
- /* Exact match? */
- if (info->dli_saddr == addr)
- break;
- }
- rlock_release(rtld_bind_lock, lockstate);
- return 1;
-}
-
-int
-dlinfo(void *handle, int request, void *p)
-{
- const Obj_Entry *obj;
- int error, lockstate;
-
- lockstate = rlock_acquire(rtld_bind_lock);
-
- if (handle == NULL || handle == RTLD_SELF) {
- void *retaddr;
-
- retaddr = __builtin_return_address(0); /* __GNUC__ only */
- if ((obj = obj_from_addr(retaddr)) == NULL)
- _rtld_error("Cannot determine caller's shared object");
- } else
- obj = dlcheck(handle);
-
- if (obj == NULL) {
- rlock_release(rtld_bind_lock, lockstate);
- return (-1);
- }
-
- error = 0;
- switch (request) {
- case RTLD_DI_LINKMAP:
- *((struct link_map const **)p) = &obj->linkmap;
- break;
- case RTLD_DI_ORIGIN:
- error = rtld_dirname(obj->path, p);
- break;
-
- case RTLD_DI_SERINFOSIZE:
- case RTLD_DI_SERINFO:
- error = do_search_info(obj, request, (struct dl_serinfo *)p);
- break;
-
- default:
- _rtld_error("Invalid request %d passed to dlinfo()", request);
- error = -1;
- }
-
- rlock_release(rtld_bind_lock, lockstate);
-
- return (error);
-}
-
-struct fill_search_info_args {
- int request;
- unsigned int flags;
- Dl_serinfo *serinfo;
- Dl_serpath *serpath;
- char *strspace;
-};
-
-static void *
-fill_search_info(const char *dir, size_t dirlen, void *param)
-{
- struct fill_search_info_args *arg;
-
- arg = param;
-
- if (arg->request == RTLD_DI_SERINFOSIZE) {
- arg->serinfo->dls_cnt ++;
- arg->serinfo->dls_size += sizeof(Dl_serpath) + dirlen + 1;
- } else {
- struct dl_serpath *s_entry;
-
- s_entry = arg->serpath;
- s_entry->dls_name = arg->strspace;
- s_entry->dls_flags = arg->flags;
-
- strncpy(arg->strspace, dir, dirlen);
- arg->strspace[dirlen] = '\0';
-
- arg->strspace += dirlen + 1;
- arg->serpath++;
- }
-
- return (NULL);
-}
-
-static int
-do_search_info(const Obj_Entry *obj, int request, struct dl_serinfo *info)
-{
- struct dl_serinfo _info;
- struct fill_search_info_args args;
-
- args.request = RTLD_DI_SERINFOSIZE;
- args.serinfo = &_info;
-
- _info.dls_size = __offsetof(struct dl_serinfo, dls_serpath);
- _info.dls_cnt = 0;
-
- path_enumerate(ld_library_path, fill_search_info, &args);
- path_enumerate(obj->rpath, fill_search_info, &args);
- path_enumerate(gethints(), fill_search_info, &args);
- path_enumerate(STANDARD_LIBRARY_PATH, fill_search_info, &args);
-
-
- if (request == RTLD_DI_SERINFOSIZE) {
- info->dls_size = _info.dls_size;
- info->dls_cnt = _info.dls_cnt;
- return (0);
- }
-
- if (info->dls_cnt != _info.dls_cnt || info->dls_size != _info.dls_size) {
- _rtld_error("Uninitialized Dl_serinfo struct passed to dlinfo()");
- return (-1);
- }
-
- args.request = RTLD_DI_SERINFO;
- args.serinfo = info;
- args.serpath = &info->dls_serpath[0];
- args.strspace = (char *)&info->dls_serpath[_info.dls_cnt];
-
- args.flags = LA_SER_LIBPATH;
- if (path_enumerate(ld_library_path, fill_search_info, &args) != NULL)
- return (-1);
-
- args.flags = LA_SER_RUNPATH;
- if (path_enumerate(obj->rpath, fill_search_info, &args) != NULL)
- return (-1);
-
- args.flags = LA_SER_CONFIG;
- if (path_enumerate(gethints(), fill_search_info, &args) != NULL)
- return (-1);
-
- args.flags = LA_SER_DEFAULT;
- if (path_enumerate(STANDARD_LIBRARY_PATH, fill_search_info, &args) != NULL)
- return (-1);
- return (0);
-}
-
-static int
-rtld_dirname(const char *path, char *bname)
-{
- const char *endp;
-
- /* Empty or NULL string gets treated as "." */
- if (path == NULL || *path == '\0') {
- bname[0] = '.';
- bname[1] = '\0';
- return (0);
- }
-
- /* Strip trailing slashes */
- endp = path + strlen(path) - 1;
- while (endp > path && *endp == '/')
- endp--;
-
- /* Find the start of the dir */
- while (endp > path && *endp != '/')
- endp--;
-
- /* Either the dir is "/" or there are no slashes */
- if (endp == path) {
- bname[0] = *endp == '/' ? '/' : '.';
- bname[1] = '\0';
- return (0);
- } else {
- do {
- endp--;
- } while (endp > path && *endp == '/');
- }
-
- if (endp - path + 2 > PATH_MAX)
- {
- _rtld_error("Filename is too long: %s", path);
- return(-1);
- }
-
- strncpy(bname, path, endp - path + 1);
- bname[endp - path + 1] = '\0';
- return (0);
-}
-
-static void
-linkmap_add(Obj_Entry *obj)
-{
- struct link_map *l = &obj->linkmap;
- struct link_map *prev;
-
- obj->linkmap.l_name = obj->path;
- obj->linkmap.l_addr = obj->mapbase;
- obj->linkmap.l_ld = obj->dynamic;
-#ifdef __mips__
- /* GDB needs load offset on MIPS to use the symbols */
- obj->linkmap.l_offs = obj->relocbase;
-#endif
-
- if (r_debug.r_map == NULL) {
- r_debug.r_map = l;
- return;
- }
-
- /*
- * Scan to the end of the list, but not past the entry for the
- * dynamic linker, which we want to keep at the very end.
- */
- for (prev = r_debug.r_map;
- prev->l_next != NULL && prev->l_next != &obj_rtld.linkmap;
- prev = prev->l_next)
- ;
-
- /* Link in the new entry. */
- l->l_prev = prev;
- l->l_next = prev->l_next;
- if (l->l_next != NULL)
- l->l_next->l_prev = l;
- prev->l_next = l;
-}
-
-static void
-linkmap_delete(Obj_Entry *obj)
-{
- struct link_map *l = &obj->linkmap;
-
- if (l->l_prev == NULL) {
- if ((r_debug.r_map = l->l_next) != NULL)
- l->l_next->l_prev = NULL;
- return;
- }
-
- if ((l->l_prev->l_next = l->l_next) != NULL)
- l->l_next->l_prev = l->l_prev;
-}
-
-/*
- * Function for the debugger to set a breakpoint on to gain control.
- *
- * The two parameters allow the debugger to easily find and determine
- * what the runtime loader is doing and to whom it is doing it.
- *
- * When the loadhook trap is hit (r_debug_state, set at program
- * initialization), the arguments can be found on the stack:
- *
- * +8 struct link_map *m
- * +4 struct r_debug *rd
- * +0 RetAddr
- */
-void
-r_debug_state(struct r_debug* rd, struct link_map *m)
-{
-}
-
-/*
- * Get address of the pointer variable in the main program.
- */
-static const void **
-get_program_var_addr(const char *name)
-{
- const Obj_Entry *obj;
- unsigned long hash;
-
- hash = elf_hash(name);
- for (obj = obj_main; obj != NULL; obj = obj->next) {
- const Elf_Sym *def;
-
- if ((def = symlook_obj(name, hash, obj, false)) != NULL) {
- const void **addr;
-
- addr = (const void **)(obj->relocbase + def->st_value);
- return addr;
- }
- }
- return NULL;
-}
-
-/*
- * Set a pointer variable in the main program to the given value. This
- * is used to set key variables such as "environ" before any of the
- * init functions are called.
- */
-static void
-set_program_var(const char *name, const void *value)
-{
- const void **addr;
-
- if ((addr = get_program_var_addr(name)) != NULL) {
- dbg("\"%s\": *%p <-- %p", name, addr, value);
- *addr = value;
- }
-}
-
-/*
- * Given a symbol name in a referencing object, find the corresponding
- * definition of the symbol. Returns a pointer to the symbol, or NULL if
- * no definition was found. Returns a pointer to the Obj_Entry of the
- * defining object via the reference parameter DEFOBJ_OUT.
- */
-static const Elf_Sym *
-symlook_default(const char *name, unsigned long hash,
- const Obj_Entry *refobj, const Obj_Entry **defobj_out, bool in_plt)
-{
- DoneList donelist;
- const Elf_Sym *def;
- const Elf_Sym *symp;
- const Obj_Entry *obj;
- const Obj_Entry *defobj;
- const Objlist_Entry *elm;
- def = NULL;
- defobj = NULL;
- donelist_init(&donelist);
-
- /* Look first in the referencing object if linked symbolically. */
- if (refobj->symbolic && !donelist_check(&donelist, refobj)) {
- symp = symlook_obj(name, hash, refobj, in_plt);
- if (symp != NULL) {
- def = symp;
- defobj = refobj;
- }
- }
-
- /* Search all objects loaded at program start up. */
- if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) {
- symp = symlook_list(name, hash, &list_main, &obj, in_plt, &donelist);
- if (symp != NULL &&
- (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK)) {
- def = symp;
- defobj = obj;
- }
- }
-
- /* Search all DAGs whose roots are RTLD_GLOBAL objects. */
- STAILQ_FOREACH(elm, &list_global, link) {
- if (def != NULL && ELF_ST_BIND(def->st_info) != STB_WEAK)
- break;
- symp = symlook_list(name, hash, &elm->obj->dagmembers, &obj, in_plt,
- &donelist);
- if (symp != NULL &&
- (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK)) {
- def = symp;
- defobj = obj;
- }
- }
-
- /* Search all dlopened DAGs containing the referencing object. */
- STAILQ_FOREACH(elm, &refobj->dldags, link) {
- if (def != NULL && ELF_ST_BIND(def->st_info) != STB_WEAK)
- break;
- symp = symlook_list(name, hash, &elm->obj->dagmembers, &obj, in_plt,
- &donelist);
- if (symp != NULL &&
- (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK)) {
- def = symp;
- defobj = obj;
- }
- }
-
- /*
- * Search the dynamic linker itself, and possibly resolve the
- * symbol from there. This is how the application links to
- * dynamic linker services such as dlopen. Only the values listed
- * in the "exports" array can be resolved from the dynamic linker.
- */
- if (def == NULL || ELF_ST_BIND(def->st_info) == STB_WEAK) {
- symp = symlook_obj(name, hash, &obj_rtld, in_plt);
- if (symp != NULL && is_exported(symp)) {
- def = symp;
- defobj = &obj_rtld;
- }
- }
-
- if (def != NULL)
- *defobj_out = defobj;
- return def;
-}
-
-static const Elf_Sym *
-symlook_list(const char *name, unsigned long hash, Objlist *objlist,
- const Obj_Entry **defobj_out, bool in_plt, DoneList *dlp)
-{
- const Elf_Sym *symp;
- const Elf_Sym *def;
- const Obj_Entry *defobj;
- const Objlist_Entry *elm;
-
- def = NULL;
- defobj = NULL;
- STAILQ_FOREACH(elm, objlist, link) {
- if (donelist_check(dlp, elm->obj))
- continue;
- if ((symp = symlook_obj(name, hash, elm->obj, in_plt)) != NULL) {
- if (def == NULL || ELF_ST_BIND(symp->st_info) != STB_WEAK) {
- def = symp;
- defobj = elm->obj;
- if (ELF_ST_BIND(def->st_info) != STB_WEAK)
- break;
- }
- }
- }
- if (def != NULL)
- *defobj_out = defobj;
- return def;
-}
-
-/*
- * Search the symbol table of a single shared object for a symbol of
- * the given name. Returns a pointer to the symbol, or NULL if no
- * definition was found.
- *
- * The symbol's hash value is passed in for efficiency reasons; that
- * eliminates many recomputations of the hash value.
- */
-const Elf_Sym *
-symlook_obj(const char *name, unsigned long hash, const Obj_Entry *obj,
- bool in_plt)
-{
- if (obj->buckets != NULL) {
- unsigned long symnum = obj->buckets[hash % obj->nbuckets];
-
- while (symnum != STN_UNDEF) {
- const Elf_Sym *symp;
- const char *strp;
-
- if (symnum >= obj->nchains)
- return NULL; /* Bad object */
- symp = obj->symtab + symnum;
- strp = obj->strtab + symp->st_name;
-
- if (name[0] == strp[0] && strcmp(name, strp) == 0)
- return symp->st_shndx != SHN_UNDEF ||
- (!in_plt && symp->st_value != 0 &&
- ELF_ST_TYPE(symp->st_info) == STT_FUNC) ? symp : NULL;
-
- symnum = obj->chains[symnum];
- }
- }
- return NULL;
-}
-
-static void
-trace_loaded_objects(Obj_Entry *obj)
-{
- char *fmt1, *fmt2, *fmt, *main_local, *list_containers;
- int c;
-
- if ((main_local = getenv(LD_ "TRACE_LOADED_OBJECTS_PROGNAME")) == NULL)
- main_local = "";
-
- if ((fmt1 = getenv(LD_ "TRACE_LOADED_OBJECTS_FMT1")) == NULL)
- fmt1 = "\t%o => %p (%x)\n";
-
- if ((fmt2 = getenv(LD_ "TRACE_LOADED_OBJECTS_FMT2")) == NULL)
- fmt2 = "\t%o (%x)\n";
-
- list_containers = getenv(LD_ "TRACE_LOADED_OBJECTS_ALL");
-
- for (; obj; obj = obj->next) {
- Needed_Entry *needed;
- char *name, *path;
- bool is_lib;
-
- if (list_containers && obj->needed != NULL)
- printf("%s:\n", obj->path);
- for (needed = obj->needed; needed; needed = needed->next) {
- if (needed->obj != NULL) {
- if (needed->obj->traced && !list_containers)
- continue;
- needed->obj->traced = true;
- path = needed->obj->path;
- } else
- path = "not found";
-
- name = (char *)obj->strtab + needed->name;
- is_lib = strncmp(name, "lib", 3) == 0; /* XXX - bogus */
-
- fmt = is_lib ? fmt1 : fmt2;
- while ((c = *fmt++) != '\0') {
- switch (c) {
- default:
- putchar(c);
- continue;
- case '\\':
- switch (c = *fmt) {
- case '\0':
- continue;
- case 'n':
- putchar('\n');
- break;
- case 't':
- putchar('\t');
- break;
- }
- break;
- case '%':
- switch (c = *fmt) {
- case '\0':
- continue;
- case '%':
- default:
- putchar(c);
- break;
- case 'A':
- printf("%s", main_local);
- break;
- case 'a':
- printf("%s", obj_main->path);
- break;
- case 'o':
- printf("%s", name);
- break;
-#if 0
- case 'm':
- printf("%d", sodp->sod_major);
- break;
- case 'n':
- printf("%d", sodp->sod_minor);
- break;
-#endif
- case 'p':
- printf("%s", path);
- break;
- case 'x':
- printf("%p", needed->obj ? needed->obj->mapbase : 0);
- break;
- }
- break;
- }
- ++fmt;
- }
- }
- }
-}
-
-/*
- * Unload a dlopened object and its dependencies from memory and from
- * our data structures. It is assumed that the DAG rooted in the
- * object has already been unreferenced, and that the object has a
- * reference count of 0.
- */
-static void
-unload_object(Obj_Entry *root)
-{
- Obj_Entry *obj;
- Obj_Entry **linkp;
-
- assert(root->refcount == 0);
-
- /*
- * Pass over the DAG removing unreferenced objects from
- * appropriate lists.
- */
- unlink_object(root);
-
- /* Unmap all objects that are no longer referenced. */
- linkp = &obj_list->next;
- while ((obj = *linkp) != NULL) {
- if (obj->refcount == 0) {
- dbg("unloading \"%s\"", obj->path);
- munmap(obj->mapbase, obj->mapsize);
- linkmap_delete(obj);
- *linkp = obj->next;
- obj_count--;
- obj_free(obj);
- } else
- linkp = &obj->next;
- }
- obj_tail = linkp;
-}
-
-static void
-unlink_object(Obj_Entry *root)
-{
- Objlist_Entry *elm;
-
- if (root->refcount == 0) {
- /* Remove the object from the RTLD_GLOBAL list. */
- objlist_remove(&list_global, root);
-
- /* Remove the object from all objects' DAG lists. */
- STAILQ_FOREACH(elm, &root->dagmembers , link) {
- objlist_remove(&elm->obj->dldags, root);
- if (elm->obj != root)
- unlink_object(elm->obj);
- }
- }
-}
-
-static void
-ref_dag(Obj_Entry *root)
-{
- Objlist_Entry *elm;
-
- STAILQ_FOREACH(elm, &root->dagmembers , link)
- elm->obj->refcount++;
-}
-
-static void
-unref_dag(Obj_Entry *root)
-{
- Objlist_Entry *elm;
-
- STAILQ_FOREACH(elm, &root->dagmembers , link)
- elm->obj->refcount--;
-}
-
-/*
- * Common code for MD __tls_get_addr().
- */
-void *
-tls_get_addr_common(Elf_Addr** dtvp, int index, size_t offset)
-{
- Elf_Addr* dtv = *dtvp;
- int lockstate;
-
- /* Check dtv generation in case new modules have arrived */
- if (dtv[0] != tls_dtv_generation) {
- Elf_Addr* newdtv;
- int to_copy;
-
- lockstate = wlock_acquire(rtld_bind_lock);
- newdtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
- to_copy = dtv[1];
- if (to_copy > tls_max_index)
- to_copy = tls_max_index;
- memcpy(&newdtv[2], &dtv[2], to_copy * sizeof(Elf_Addr));
- newdtv[0] = tls_dtv_generation;
- newdtv[1] = tls_max_index;
- free(dtv);
- wlock_release(rtld_bind_lock, lockstate);
- *dtvp = newdtv;
- }
-
- /* Dynamically allocate module TLS if necessary */
- if (!dtv[index + 1]) {
- /* Signal safe, wlock will block out signals. */
- lockstate = wlock_acquire(rtld_bind_lock);
- if (!dtv[index + 1])
- dtv[index + 1] = (Elf_Addr)allocate_module_tls(index);
- wlock_release(rtld_bind_lock, lockstate);
- }
- return (void*) (dtv[index + 1] + offset);
-}
-
-/* XXX not sure what variants to use for arm. */
-
-#if defined(__ia64__) || defined(__alpha__) || defined(__powerpc__)
-
-/*
- * Allocate Static TLS using the Variant I method.
- */
-void *
-allocate_tls(Obj_Entry *objs, void *oldtcb, size_t tcbsize, size_t tcbalign)
-{
- Obj_Entry *obj;
- char *tcb;
- Elf_Addr **tls;
- Elf_Addr *dtv;
- Elf_Addr addr;
- int i;
-
- if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE)
- return (oldtcb);
-
- assert(tcbsize >= TLS_TCB_SIZE);
- tcb = calloc(1, tls_static_space - TLS_TCB_SIZE + tcbsize);
- tls = (Elf_Addr **)(tcb + tcbsize - TLS_TCB_SIZE);
-
- if (oldtcb != NULL) {
- memcpy(tls, oldtcb, tls_static_space);
- free(oldtcb);
-
- /* Adjust the DTV. */
- dtv = tls[0];
- for (i = 0; i < dtv[1]; i++) {
- if (dtv[i+2] >= (Elf_Addr)oldtcb &&
- dtv[i+2] < (Elf_Addr)oldtcb + tls_static_space) {
- dtv[i+2] = dtv[i+2] - (Elf_Addr)oldtcb + (Elf_Addr)tls;
- }
- }
- } else {
- dtv = calloc(tls_max_index + 2, sizeof(Elf_Addr));
- tls[0] = dtv;
- dtv[0] = tls_dtv_generation;
- dtv[1] = tls_max_index;
-
- for (obj = objs; obj; obj = obj->next) {
- if (obj->tlsoffset) {
- addr = (Elf_Addr)tls + obj->tlsoffset;
- memset((void*) (addr + obj->tlsinitsize),
- 0, obj->tlssize - obj->tlsinitsize);
- if (obj->tlsinit)
- memcpy((void*) addr, obj->tlsinit,
- obj->tlsinitsize);
- dtv[obj->tlsindex + 1] = addr;
- }
- }
- }
-
- return (tcb);
-}
-
-void
-free_tls(void *tcb, size_t tcbsize, size_t tcbalign)
-{
- Elf_Addr *dtv;
- Elf_Addr tlsstart, tlsend;
- int dtvsize, i;
-
- assert(tcbsize >= TLS_TCB_SIZE);
-
- tlsstart = (Elf_Addr)tcb + tcbsize - TLS_TCB_SIZE;
- tlsend = tlsstart + tls_static_space;
-
- dtv = *(Elf_Addr **)tlsstart;
- dtvsize = dtv[1];
- for (i = 0; i < dtvsize; i++) {
- if (dtv[i+2] && (dtv[i+2] < tlsstart || dtv[i+2] >= tlsend)) {
- free((void*)dtv[i+2]);
- }
- }
- free(dtv);
- free(tcb);
-}
-
-#endif
-
-#if defined(__i386__) || defined(__amd64__) || defined(__sparc64__) || \
- defined(__arm__)
-
-/*
- * Allocate Static TLS using the Variant II method.
- */
-void *
-allocate_tls(Obj_Entry *objs, void *oldtls, size_t tcbsize, size_t tcbalign)
-{
- Obj_Entry *obj;
- size_t size;
- char *tls;
- Elf_Addr *dtv, *olddtv;
- Elf_Addr segbase, oldsegbase, addr;
- int i;
-
- size = round(tls_static_space, tcbalign);
-
- assert(tcbsize >= 2*sizeof(Elf_Addr));
- tls = malloc(size + tcbsize);
- dtv = calloc(1, (tls_max_index + 2) * sizeof(Elf_Addr));
-
- segbase = (Elf_Addr)(tls + size);
- ((Elf_Addr*)segbase)[0] = segbase;
- ((Elf_Addr*)segbase)[1] = (Elf_Addr) dtv;
-
- dtv[0] = tls_dtv_generation;
- dtv[1] = tls_max_index;
-
- if (oldtls) {
- /*
- * Copy the static TLS block over whole.
- */
- oldsegbase = (Elf_Addr) oldtls;
- memcpy((void *)(segbase - tls_static_space),
- (const void *)(oldsegbase - tls_static_space),
- tls_static_space);
-
- /*
- * If any dynamic TLS blocks have been created tls_get_addr(),
- * move them over.
- */
- olddtv = ((Elf_Addr**)oldsegbase)[1];
- for (i = 0; i < olddtv[1]; i++) {
- if (olddtv[i+2] < oldsegbase - size || olddtv[i+2] > oldsegbase) {
- dtv[i+2] = olddtv[i+2];
- olddtv[i+2] = 0;
- }
- }
-
- /*
- * We assume that this block was the one we created with
- * allocate_initial_tls().
- */
- free_tls(oldtls, 2*sizeof(Elf_Addr), sizeof(Elf_Addr));
- } else {
- for (obj = objs; obj; obj = obj->next) {
- if (obj->tlsoffset) {
- addr = segbase - obj->tlsoffset;
- memset((void*) (addr + obj->tlsinitsize),
- 0, obj->tlssize - obj->tlsinitsize);
- if (obj->tlsinit)
- memcpy((void*) addr, obj->tlsinit, obj->tlsinitsize);
- dtv[obj->tlsindex + 1] = addr;
- }
- }
- }
-
- return (void*) segbase;
-}
-
-void
-free_tls(void *tls, size_t tcbsize, size_t tcbalign)
-{
- size_t size;
- Elf_Addr* dtv;
- int dtvsize, i;
- Elf_Addr tlsstart, tlsend;
-
- /*
- * Figure out the size of the initial TLS block so that we can
- * find stuff which ___tls_get_addr() allocated dynamically.
- */
- size = round(tls_static_space, tcbalign);
-
- dtv = ((Elf_Addr**)tls)[1];
- dtvsize = dtv[1];
- tlsend = (Elf_Addr) tls;
- tlsstart = tlsend - size;
- for (i = 0; i < dtvsize; i++) {
- if (dtv[i+2] && (dtv[i+2] < tlsstart || dtv[i+2] > tlsend)) {
- free((void*) dtv[i+2]);
- }
- }
-
- free((void*) tlsstart);
-}
-
-#endif
-
-/*
- * Allocate TLS block for module with given index.
- */
-void *
-allocate_module_tls(int index)
-{
- Obj_Entry* obj;
- char* p;
-
- for (obj = obj_list; obj; obj = obj->next) {
- if (obj->tlsindex == index)
- break;
- }
- if (!obj) {
- _rtld_error("Can't find module with TLS index %d", index);
- die();
- }
-
- p = malloc(obj->tlssize);
- memcpy(p, obj->tlsinit, obj->tlsinitsize);
- memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize);
-
- return p;
-}
-
-bool
-allocate_tls_offset(Obj_Entry *obj)
-{
- size_t off;
-
- if (obj->tls_done)
- return true;
-
- if (obj->tlssize == 0) {
- obj->tls_done = true;
- return true;
- }
-
- if (obj->tlsindex == 1)
- off = calculate_first_tls_offset(obj->tlssize, obj->tlsalign);
- else
- off = calculate_tls_offset(tls_last_offset, tls_last_size,
- obj->tlssize, obj->tlsalign);
-
- /*
- * If we have already fixed the size of the static TLS block, we
- * must stay within that size. When allocating the static TLS, we
- * leave a small amount of space spare to be used for dynamically
- * loading modules which use static TLS.
- */
- if (tls_static_space) {
- if (calculate_tls_end(off, obj->tlssize) > tls_static_space)
- return false;
- }
-
- tls_last_offset = obj->tlsoffset = off;
- tls_last_size = obj->tlssize;
- obj->tls_done = true;
-
- return true;
-}
-
-void
-free_tls_offset(Obj_Entry *obj)
-{
-#if defined(__i386__) || defined(__amd64__) || defined(__sparc64__) || \
- defined(__arm__)
- /*
- * If we were the last thing to allocate out of the static TLS
- * block, we give our space back to the 'allocator'. This is a
- * simplistic workaround to allow libGL.so.1 to be loaded and
- * unloaded multiple times. We only handle the Variant II
- * mechanism for now - this really needs a proper allocator.
- */
- if (calculate_tls_end(obj->tlsoffset, obj->tlssize)
- == calculate_tls_end(tls_last_offset, tls_last_size)) {
- tls_last_offset -= obj->tlssize;
- tls_last_size = 0;
- }
-#endif
-}
-
-void *
-_rtld_allocate_tls(void *oldtls, size_t tcbsize, size_t tcbalign)
-{
- void *ret;
- int lockstate;
-
- lockstate = wlock_acquire(rtld_bind_lock);
- ret = allocate_tls(obj_list, oldtls, tcbsize, tcbalign);
- wlock_release(rtld_bind_lock, lockstate);
- return (ret);
-}
-
-void
-_rtld_free_tls(void *tcb, size_t tcbsize, size_t tcbalign)
-{
- int lockstate;
-
- lockstate = wlock_acquire(rtld_bind_lock);
- free_tls(tcb, tcbsize, tcbalign);
- wlock_release(rtld_bind_lock, lockstate);
-}
diff --git a/src/bin/rtld-elf/rtld.h b/src/bin/rtld-elf/rtld.h
deleted file mode 100644
index d8dd379..0000000
--- a/src/bin/rtld-elf/rtld.h
+++ /dev/null
@@ -1,252 +0,0 @@
-/*-
- * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/rtld.h,v 1.35.2.1 2005/12/30 22:13:56 marcel Exp $
- */
-
-#ifndef RTLD_H /* { */
-#define RTLD_H 1
-
-#include
-#include
-#include
-
-#include
-#include
-#include
-
-#include "rtld_lock.h"
-#include "rtld_machdep.h"
-
-#ifdef COMPAT_32BIT
-#undef STANDARD_LIBRARY_PATH
-#undef _PATH_ELF_HINTS
-#define _PATH_ELF_HINTS "/var/run/ld-elf32.so.hints"
-/* For running 32 bit binaries */
-#define STANDARD_LIBRARY_PATH "/lib32:/usr/lib32"
-#define LD_ "LD_32_"
-#endif
-
-#ifndef STANDARD_LIBRARY_PATH
-#define STANDARD_LIBRARY_PATH "/lib:/usr/lib"
-#endif
-#ifndef LD_
-#define LD_ "LD_"
-#endif
-
-#define NEW(type) ((type *) xmalloc(sizeof(type)))
-#define CNEW(type) ((type *) xcalloc(sizeof(type)))
-
-/* We might as well do booleans like C++. */
-typedef unsigned char bool;
-#define false 0
-#define true 1
-
-extern size_t tls_last_offset;
-extern size_t tls_last_size;
-extern size_t tls_static_space;
-extern int tls_dtv_generation;
-extern int tls_max_index;
-
-struct stat;
-struct Struct_Obj_Entry;
-
-/* Lists of shared objects */
-typedef struct Struct_Objlist_Entry {
- STAILQ_ENTRY(Struct_Objlist_Entry) link;
- struct Struct_Obj_Entry *obj;
-} Objlist_Entry;
-
-typedef STAILQ_HEAD(Struct_Objlist, Struct_Objlist_Entry) Objlist;
-
-/* Types of init and fini functions */
-typedef void (*InitFunc)(void);
-
-/* Lists of shared object dependencies */
-typedef struct Struct_Needed_Entry {
- struct Struct_Needed_Entry *next;
- struct Struct_Obj_Entry *obj;
- unsigned long name; /* Offset of name in string table */
-} Needed_Entry;
-
-/* Lock object */
-typedef struct Struct_LockInfo {
- void *context; /* Client context for creating locks */
- void *thelock; /* The one big lock */
- /* Debugging aids. */
- volatile int rcount; /* Number of readers holding lock */
- volatile int wcount; /* Number of writers holding lock */
- /* Methods */
- void *(*lock_create)(void *context);
- void (*rlock_acquire)(void *lock);
- void (*wlock_acquire)(void *lock);
- void (*rlock_release)(void *lock);
- void (*wlock_release)(void *lock);
- void (*lock_destroy)(void *lock);
- void (*context_destroy)(void *context);
-} LockInfo;
-
-/*
- * Shared object descriptor.
- *
- * Items marked with "(%)" are dynamically allocated, and must be freed
- * when the structure is destroyed.
- *
- * CAUTION: It appears that the JDK port peeks into these structures.
- * It looks at "next" and "mapbase" at least. Don't add new members
- * near the front, until this can be straightened out.
- */
-typedef struct Struct_Obj_Entry {
- /*
- * These two items have to be set right for compatibility with the
- * original ElfKit crt1.o.
- */
- Elf_Size magic; /* Magic number (sanity check) */
- Elf_Size version; /* Version number of struct format */
-
- struct Struct_Obj_Entry *next;
- char *path; /* Pathname of underlying file (%) */
- char *origin_path; /* Directory path of origin file */
- int refcount;
- int dl_refcount; /* Number of times loaded by dlopen */
-
- /* These items are computed by map_object() or by digest_phdr(). */
- caddr_t mapbase; /* Base address of mapped region */
- size_t mapsize; /* Size of mapped region in bytes */
- size_t textsize; /* Size of text segment in bytes */
- Elf_Addr vaddrbase; /* Base address in shared object file */
- caddr_t relocbase; /* Relocation constant = mapbase - vaddrbase */
- const Elf_Dyn *dynamic; /* Dynamic section */
- caddr_t entry; /* Entry point */
- const Elf_Phdr *phdr; /* Program header if it is mapped, else NULL */
- size_t phsize; /* Size of program header in bytes */
- const char *interp; /* Pathname of the interpreter, if any */
-
- /* TLS information */
- int tlsindex; /* Index in DTV for this module */
- void *tlsinit; /* Base address of TLS init block */
- size_t tlsinitsize; /* Size of TLS init block for this module */
- size_t tlssize; /* Size of TLS block for this module */
- size_t tlsoffset; /* Offset of static TLS block for this module */
- size_t tlsalign; /* Alignment of static TLS block */
-
- /* Items from the dynamic section. */
- Elf_Addr *pltgot; /* PLT or GOT, depending on architecture */
- const Elf_Rel *rel; /* Relocation entries */
- unsigned long relsize; /* Size in bytes of relocation info */
- const Elf_Rela *rela; /* Relocation entries with addend */
- unsigned long relasize; /* Size in bytes of addend relocation info */
- const Elf_Rel *pltrel; /* PLT relocation entries */
- unsigned long pltrelsize; /* Size in bytes of PLT relocation info */
- const Elf_Rela *pltrela; /* PLT relocation entries with addend */
- unsigned long pltrelasize; /* Size in bytes of PLT addend reloc info */
- const Elf_Sym *symtab; /* Symbol table */
- const char *strtab; /* String table */
- unsigned long strsize; /* Size in bytes of string table */
-
- const Elf_Hashelt *buckets; /* Hash table buckets array */
- unsigned long nbuckets; /* Number of buckets */
- const Elf_Hashelt *chains; /* Hash table chain array */
- unsigned long nchains; /* Number of chains */
-
- const char *rpath; /* Search path specified in object */
- Needed_Entry *needed; /* Shared objects needed by this one (%) */
-
- Elf_Addr init; /* Initialization function to call */
- Elf_Addr fini; /* Termination function to call */
-
- bool mainprog; /* True if this is the main program */
- bool rtld; /* True if this is the dynamic linker */
- bool textrel; /* True if there are relocations to text seg */
- bool symbolic; /* True if generated with "-Bsymbolic" */
- bool bind_now; /* True if all relocations should be made first */
- bool traced; /* Already printed in ldd trace output */
- bool jmpslots_done; /* Already have relocated the jump slots */
- bool init_done; /* Already have added object to init list */
- bool tls_done; /* Already allocated offset for static TLS */
-
- struct link_map linkmap; /* for GDB and dlinfo() */
- Objlist dldags; /* Object belongs to these dlopened DAGs (%) */
- Objlist dagmembers; /* DAG has these members (%) */
- dev_t dev; /* Object's filesystem's device */
- ino_t ino; /* Object's inode number */
- void *priv; /* Platform-dependant */
-} Obj_Entry;
-
-#define RTLD_MAGIC 0xd550b87a
-#define RTLD_VERSION 1
-
-#define RTLD_STATIC_TLS_EXTRA 64
-
-/*
- * Symbol cache entry used during relocation to avoid multiple lookups
- * of the same symbol.
- */
-typedef struct Struct_SymCache {
- const Elf_Sym *sym; /* Symbol table entry */
- const Obj_Entry *obj; /* Shared object which defines it */
-} SymCache;
-
-extern void _rtld_error(const char *, ...) __printflike(1, 2);
-extern Obj_Entry *map_object(int, const char *, const struct stat *);
-extern void *xcalloc(size_t);
-extern void *xmalloc(size_t);
-extern char *xstrdup(const char *);
-extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
-
-extern void dump_relocations (Obj_Entry *);
-extern void dump_obj_relocations (Obj_Entry *);
-extern void dump_Elf_Rel (Obj_Entry *, const Elf_Rel *, u_long);
-extern void dump_Elf_Rela (Obj_Entry *, const Elf_Rela *, u_long);
-
-/*
- * Function declarations.
- */
-unsigned long elf_hash(const char *);
-const Elf_Sym *find_symdef(unsigned long, const Obj_Entry *,
- const Obj_Entry **, bool, SymCache *);
-void init_pltgot(Obj_Entry *);
-void lockdflt_init(void);
-void obj_free(Obj_Entry *);
-Obj_Entry *obj_new(void);
-void _rtld_bind_start(void);
-const Elf_Sym *symlook_obj(const char *, unsigned long,
- const Obj_Entry *, bool);
-void *tls_get_addr_common(Elf_Addr** dtvp, int index, size_t offset);
-void *allocate_tls(Obj_Entry *, void *, size_t, size_t);
-void free_tls(void *, size_t, size_t);
-void *allocate_module_tls(int index);
-bool allocate_tls_offset(Obj_Entry *obj);
-void free_tls_offset(Obj_Entry *obj);
-
-/*
- * MD function declarations.
- */
-int do_copy_relocations(Obj_Entry *);
-int reloc_non_plt(Obj_Entry *, Obj_Entry *);
-int reloc_plt(Obj_Entry *);
-int reloc_jmpslots(Obj_Entry *);
-void allocate_initial_tls(Obj_Entry *);
-
-#endif /* } */
diff --git a/src/bin/rtld-elf/rtld_lock.c b/src/bin/rtld-elf/rtld_lock.c
deleted file mode 100644
index 9a9fa05..0000000
--- a/src/bin/rtld-elf/rtld_lock.c
+++ /dev/null
@@ -1,317 +0,0 @@
-/*-
- * Copyright 1999, 2000 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * from: FreeBSD: src/libexec/rtld-elf/sparc64/lockdflt.c,v 1.3 2002/10/09
- * $FreeBSD: src/libexec/rtld-elf/rtld_lock.c,v 1.3 2004/11/16 20:45:51 jhb Exp $
- */
-
-/*
- * Thread locking implementation for the dynamic linker.
- *
- * We use the "simple, non-scalable reader-preference lock" from:
- *
- * J. M. Mellor-Crummey and M. L. Scott. "Scalable Reader-Writer
- * Synchronization for Shared-Memory Multiprocessors." 3rd ACM Symp. on
- * Principles and Practice of Parallel Programming, April 1991.
- *
- * In this algorithm the lock is a single word. Its low-order bit is
- * set when a writer holds the lock. The remaining high-order bits
- * contain a count of readers desiring the lock. The algorithm requires
- * atomic "compare_and_store" and "add" operations, which we implement
- * using assembly language sequences in "rtld_start.S".
- */
-
-#include
-#include
-#include
-
-#include "debug.h"
-#include "rtld.h"
-#include "rtld_machdep.h"
-
-#define WAFLAG 0x1 /* A writer holds the lock */
-#define RC_INCR 0x2 /* Adjusts count of readers desiring lock */
-
-typedef struct Struct_Lock {
- volatile int lock;
- void *base;
-} Lock;
-
-static sigset_t fullsigmask, oldsigmask;
-static int thread_flag;
-
-static void *
-def_lock_create()
-{
- void *base;
- char *p;
- uintptr_t r;
- Lock *l;
-
- /*
- * Arrange for the lock to occupy its own cache line. First, we
- * optimistically allocate just a cache line, hoping that malloc
- * will give us a well-aligned block of memory. If that doesn't
- * work, we allocate a larger block and take a well-aligned cache
- * line from it.
- */
- base = xmalloc(CACHE_LINE_SIZE);
- p = (char *)base;
- if ((uintptr_t)p % CACHE_LINE_SIZE != 0) {
- free(base);
- base = xmalloc(2 * CACHE_LINE_SIZE);
- p = (char *)base;
- if ((r = (uintptr_t)p % CACHE_LINE_SIZE) != 0)
- p += CACHE_LINE_SIZE - r;
- }
- l = (Lock *)p;
- l->base = base;
- l->lock = 0;
- return l;
-}
-
-static void
-def_lock_destroy(void *lock)
-{
- Lock *l = (Lock *)lock;
-
- free(l->base);
-}
-
-static void
-def_rlock_acquire(void *lock)
-{
- Lock *l = (Lock *)lock;
-
- atomic_add_acq_int(&l->lock, RC_INCR);
- while (l->lock & WAFLAG)
- ; /* Spin */
-}
-
-static void
-def_wlock_acquire(void *lock)
-{
- Lock *l = (Lock *)lock;
- sigset_t tmp_oldsigmask;
-
- for ( ; ; ) {
- sigprocmask(SIG_BLOCK, &fullsigmask, &tmp_oldsigmask);
- if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG))
- break;
- sigprocmask(SIG_SETMASK, &tmp_oldsigmask, NULL);
- }
- oldsigmask = tmp_oldsigmask;
-}
-
-static void
-def_lock_release(void *lock)
-{
- Lock *l = (Lock *)lock;
-
- if ((l->lock & WAFLAG) == 0)
- atomic_add_rel_int(&l->lock, -RC_INCR);
- else {
- atomic_add_rel_int(&l->lock, -WAFLAG);
- sigprocmask(SIG_SETMASK, &oldsigmask, NULL);
- }
-}
-
-static int
-def_thread_set_flag(int mask)
-{
- int old_val = thread_flag;
- thread_flag |= mask;
- return (old_val);
-}
-
-static int
-def_thread_clr_flag(int mask)
-{
- int old_val = thread_flag;
- thread_flag &= ~mask;
- return (old_val);
-}
-
-/*
- * Public interface exposed to the rest of the dynamic linker.
- */
-static struct RtldLockInfo lockinfo;
-static struct RtldLockInfo deflockinfo;
-
-static __inline int
-thread_mask_set(int mask)
-{
- return lockinfo.thread_set_flag(mask);
-}
-
-static __inline void
-thread_mask_clear(int mask)
-{
- lockinfo.thread_clr_flag(mask);
-}
-
-#define RTLD_LOCK_CNT 2
-struct rtld_lock {
- void *handle;
- int mask;
-} rtld_locks[RTLD_LOCK_CNT];
-
-rtld_lock_t rtld_bind_lock = &rtld_locks[0];
-rtld_lock_t rtld_libc_lock = &rtld_locks[1];
-
-int
-rlock_acquire(rtld_lock_t lock)
-{
- if (thread_mask_set(lock->mask)) {
- dbg("rlock_acquire: recursed");
- return (0);
- }
- lockinfo.rlock_acquire(lock->handle);
- return (1);
-}
-
-int
-wlock_acquire(rtld_lock_t lock)
-{
- if (thread_mask_set(lock->mask)) {
- dbg("wlock_acquire: recursed");
- return (0);
- }
- lockinfo.wlock_acquire(lock->handle);
- return (1);
-}
-
-void
-rlock_release(rtld_lock_t lock, int locked)
-{
- if (locked == 0)
- return;
- thread_mask_clear(lock->mask);
- lockinfo.lock_release(lock->handle);
-}
-
-void
-wlock_release(rtld_lock_t lock, int locked)
-{
- if (locked == 0)
- return;
- thread_mask_clear(lock->mask);
- lockinfo.lock_release(lock->handle);
-}
-
-void
-lockdflt_init()
-{
- int i;
-
- deflockinfo.rtli_version = RTLI_VERSION;
- deflockinfo.lock_create = def_lock_create;
- deflockinfo.lock_destroy = def_lock_destroy;
- deflockinfo.rlock_acquire = def_rlock_acquire;
- deflockinfo.wlock_acquire = def_wlock_acquire;
- deflockinfo.lock_release = def_lock_release;
- deflockinfo.thread_set_flag = def_thread_set_flag;
- deflockinfo.thread_clr_flag = def_thread_clr_flag;
- deflockinfo.at_fork = NULL;
-
- for (i = 0; i < RTLD_LOCK_CNT; i++) {
- rtld_locks[i].mask = (1 << i);
- rtld_locks[i].handle = NULL;
- }
-
- memcpy(&lockinfo, &deflockinfo, sizeof(lockinfo));
- _rtld_thread_init(NULL);
- /*
- * Construct a mask to block all signals except traps which might
- * conceivably be generated within the dynamic linker itself.
- */
- sigfillset(&fullsigmask);
- sigdelset(&fullsigmask, SIGILL);
- sigdelset(&fullsigmask, SIGTRAP);
- sigdelset(&fullsigmask, SIGABRT);
- sigdelset(&fullsigmask, SIGEMT);
- sigdelset(&fullsigmask, SIGFPE);
- sigdelset(&fullsigmask, SIGBUS);
- sigdelset(&fullsigmask, SIGSEGV);
- sigdelset(&fullsigmask, SIGSYS);
-}
-
-/*
- * Callback function to allow threads implementation to
- * register their own locking primitives if the default
- * one is not suitable.
- * The current context should be the only context
- * executing at the invocation time.
- */
-void
-_rtld_thread_init(struct RtldLockInfo *pli)
-{
- int flags, i;
- void *locks[RTLD_LOCK_CNT];
-
- /* disable all locking while this function is running */
- flags = thread_mask_set(~0);
-
- if (pli == NULL)
- pli = &deflockinfo;
-
-
- for (i = 0; i < RTLD_LOCK_CNT; i++)
- if ((locks[i] = pli->lock_create()) == NULL)
- break;
-
- if (i < RTLD_LOCK_CNT) {
- while (--i >= 0)
- pli->lock_destroy(locks[i]);
- abort();
- }
-
- for (i = 0; i < RTLD_LOCK_CNT; i++) {
- if (rtld_locks[i].handle == NULL)
- continue;
- if (flags & rtld_locks[i].mask)
- lockinfo.lock_release(rtld_locks[i].handle);
- lockinfo.lock_destroy(rtld_locks[i].handle);
- }
-
- for (i = 0; i < RTLD_LOCK_CNT; i++) {
- rtld_locks[i].handle = locks[i];
- if (flags & rtld_locks[i].mask)
- pli->wlock_acquire(rtld_locks[i].handle);
- }
-
- lockinfo.lock_create = pli->lock_create;
- lockinfo.lock_destroy = pli->lock_destroy;
- lockinfo.rlock_acquire = pli->rlock_acquire;
- lockinfo.wlock_acquire = pli->wlock_acquire;
- lockinfo.lock_release = pli->lock_release;
- lockinfo.thread_set_flag = pli->thread_set_flag;
- lockinfo.thread_clr_flag = pli->thread_clr_flag;
- lockinfo.at_fork = pli->at_fork;
-
- /* restore thread locking state, this time with new locks */
- thread_mask_clear(~0);
- thread_mask_set(flags);
- dbg("_rtld_thread_init: done");
-}
diff --git a/src/bin/rtld-elf/rtld_lock.h b/src/bin/rtld-elf/rtld_lock.h
deleted file mode 100644
index 906e472..0000000
--- a/src/bin/rtld-elf/rtld_lock.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * Copyright 2003 Alexander Kabaev.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/rtld_lock.h,v 1.2 2003/06/19 02:39:37 mdodd Exp $
- */
-
-#ifndef _RTLD_LOCK_H_
-#define _RTLD_LOCK_H_
-
-#define RTLI_VERSION 0x01
-
-struct RtldLockInfo
-{
- unsigned int rtli_version;
- void *(*lock_create)(void);
- void (*lock_destroy)(void *);
- void (*rlock_acquire)(void *);
- void (*wlock_acquire)(void *);
- void (*lock_release)(void *);
- int (*thread_set_flag)(int);
- int (*thread_clr_flag)(int);
- void (*at_fork)(void);
-};
-
-extern void _rtld_thread_init(struct RtldLockInfo *);
-
-#ifdef IN_RTLD
-
-struct rtld_lock;
-typedef struct rtld_lock *rtld_lock_t;
-
-extern rtld_lock_t rtld_bind_lock;
-extern rtld_lock_t rtld_libc_lock;
-
-int rlock_acquire(rtld_lock_t);
-int wlock_acquire(rtld_lock_t);
-void rlock_release(rtld_lock_t, int);
-void wlock_release(rtld_lock_t, int);
-
-#endif /* IN_RTLD */
-
-#endif
diff --git a/src/bin/rtld-elf/rtld_machdep.h b/src/bin/rtld-elf/rtld_machdep.h
deleted file mode 100644
index d35c99c..0000000
--- a/src/bin/rtld-elf/rtld_machdep.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/i386/rtld_machdep.h,v 1.10 2004/08/03 08:50:59 dfr Exp $
- */
-
-#ifndef RTLD_MACHDEP_H
-#define RTLD_MACHDEP_H 1
-
-#include
-#include
-
-#define CACHE_LINE_SIZE 32
-
-struct Struct_Obj_Entry;
-
-/* Return the address of the .dynamic section in the dynamic linker. */
-#define rtld_dynamic(obj) \
- ((const Elf_Dyn *)((obj)->relocbase + (Elf_Addr)&_DYNAMIC))
-
-/* Fixup the jump slot at "where" to transfer control to "target". */
-static inline Elf_Addr reloc_jmpslot(Elf_Addr *where, Elf_Addr target, const struct Struct_Obj_Entry *obj, const struct Struct_Obj_Entry *refobj, const Elf_Rel *rel) {
- //dbg("reloc_jmpslot: *%p = %p", (void *)(where), (void *)(target));
- (*(Elf_Addr *)(where) = (Elf_Addr)(target));
- return target;
- }
-
-#define make_function_pointer(def, defobj) \
- ((defobj)->relocbase + (def)->st_value)
-
-#define call_initfini_pointer(obj, target) \
- (((InitFunc)(target))())
-
-#define round(size, align) \
- (((size) + (align) - 1) & ~((align) - 1))
-#define calculate_first_tls_offset(size, align) \
- round(size, align)
-#define calculate_tls_offset(prev_offset, prev_size, size, align) \
- round((prev_offset) + (size), align)
-#define calculate_tls_end(off, size) (off)
-
-typedef struct {
- unsigned long ti_module;
- unsigned long ti_offset;
-} tls_index;
-
-extern void *___tls_get_addr(tls_index *ti) __attribute__((__regparm__(1)));
-extern void *__tls_get_addr(tls_index *ti);
-
-#endif
diff --git a/src/bin/rtld-elf/rtld_start.S b/src/bin/rtld-elf/rtld_start.S
deleted file mode 100644
index 65d900d..0000000
--- a/src/bin/rtld-elf/rtld_start.S
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * Copyright 1996-1998 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/i386/rtld_start.S,v 1.4 2005/05/19 07:32:42 dfr Exp $
- */
-
- .text
- .align 4
- .globl .rtld_start
- .type .rtld_start,@function
-.rtld_start:
- xorl %ebp,%ebp # Clear frame pointer for good form
- movl %esp,%eax # Save initial stack pointer
- movl %esp,%esi # Save initial stack pointer
- andl $0xfffffff0,%esp # Align stack pointer
- subl $16,%esp # A place to store exit procedure addr
- movl %esp,%ebx # save address of exit proc
- movl %esp,%ecx # construct address of obj_main
- addl $4,%ecx
- subl $4,%esp # Keep stack aligned
- pushl %ecx # Pass address of obj_main
- pushl %ebx # Pass address of exit proc
- pushl %eax # Pass initial stack pointer to rtld
- call _rtld@PLT # Call rtld(sp); returns entry point
- addl $16,%esp # Remove arguments from stack
- popl %edx # Get exit procedure address
- movl %esi,%esp # Ignore obj_main
-/*
- * At this point, %eax contains the entry point of the main program, and
- * %edx contains a pointer to a termination function that should be
- * registered with atexit(). (crt1.o registers it.)
- */
-.globl .rtld_goto_main
-.rtld_goto_main: # This symbol exists just to make debugging easier.
- jmp *%eax # Enter main program
-
-
-/*
- * Binder entry point. Control is transferred to here by code in the PLT.
- * On entry, there are two arguments on the stack. In ascending address
- * order, they are (1) "obj", a pointer to the calling object's Obj_Entry,
- * and (2) "reloff", the byte offset of the appropriate relocation entry
- * in the PLT relocation table.
- *
- * We are careful to preserve all registers, even the the caller-save
- * registers. That is because this code may be invoked by low-level
- * assembly-language code that is not ABI-compliant.
- */
- .align 4
- .globl _rtld_bind_start
- .type _rtld_bind_start,@function
-_rtld_bind_start:
- pushf # Save eflags
- pushl %eax # Save %eax
- pushl %edx # Save %edx
- pushl %ecx # Save %ecx
- pushl 20(%esp) # Copy reloff argument
- pushl 20(%esp) # Copy obj argument
-
- call _rtld_bind@PLT # Transfer control to the binder
- /* Now %eax contains the entry point of the function being called. */
-
- addl $8,%esp # Discard binder arguments
- movl %eax,20(%esp) # Store target over obj argument
- popl %ecx # Restore %ecx
- popl %edx # Restore %edx
- popl %eax # Restore %eax
- popf # Restore eflags
- leal 4(%esp),%esp # Discard reloff, do not change eflags
- ret # "Return" to target address
diff --git a/src/bin/rtld-elf/rtld_tls.h b/src/bin/rtld-elf/rtld_tls.h
deleted file mode 100644
index 4e17934..0000000
--- a/src/bin/rtld-elf/rtld_tls.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*-
- * Copyright (c) 2004 Doug Rabson
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/rtld_tls.h,v 1.1 2004/08/03 08:50:58 dfr Exp $
- */
-
-/*
- * Semi-public interface from thread libraries to rtld for managing
- * TLS.
- */
-
-#ifndef _RTLD_TLS_H_
-#define _RTLD_TLS_H_
-
-/*
- * Allocate a TLS block for a new thread. The memory allocated will
- * include 'tcbsize' bytes aligned to a 'tcbalign' boundary (in bytes)
- * for the thread library's private purposes. The location of the TCB
- * block is returned by this function. For architectures using
- * 'Variant I' TLS, the thread local storage follows the TCB, and for
- * 'Variant II', the thread local storage precedes it. For
- * architectures using the 'Variant II' model (e.g. i386, amd64,
- * sparc64), the TCB must begin with two pointer fields which are used
- * by rtld for its TLS implementation. For the 'Variant I' model, the
- * TCB must begin with a single pointer field for rtld's
- * implementation.
- *
- * If the value of 'oldtls' is non-NULL, the new TLS block will be
- * initialised using the values contained in 'oldtls' and 'oldtls'
- * will be freed. This is typically used when initialising a thread
- * library to migrate from using the initial bootstrap TLS block
- * created by rtld to one which contains suitable thread library
- * private data.
- *
- * The value returned from this function is suitable for installing
- * directly into the thread pointer register.
- */
-extern void *_rtld_allocate_tls(void* oldtls, size_t tcbsize, size_t tcbalign);
-
-/*
- * Free a TLS block allocated using _rtld_allocate_tls(). The tcbsize
- * and tcbalign parameters must be the same as those used to allocate
- * the block.
- */
-extern void _rtld_free_tls(void *tcb, size_t tcbsize, size_t tcbalign);
-
-#endif
diff --git a/src/bin/rtld-elf/xmalloc.c b/src/bin/rtld-elf/xmalloc.c
deleted file mode 100644
index 785e162..0000000
--- a/src/bin/rtld-elf/xmalloc.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * Copyright 1996-1998 John D. Polstra.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/libexec/rtld-elf/xmalloc.c,v 1.3 2003/06/19 05:28:26 mdodd Exp $
- */
-
-#include
-#include
-#include
-#include
-
-void *xcalloc(size_t);
-void *xmalloc(size_t);
-char *xstrdup(const char *);
-
-void *
-xcalloc(size_t size)
-{
- return memset(xmalloc(size), 0, size);
-}
-
-void *
-xmalloc(size_t size)
-{
- void *p = malloc(size);
- if (p == NULL)
- err(1, "Out of memory");
- return p;
-}
-
-char *
-xstrdup(const char *s)
-{
- char *p = strdup(s);
- if (p == NULL)
- err(1, "Out of memory");
- return p;
-}
diff --git a/src/bin/sh/Makefile b/src/bin/sh/Makefile
deleted file mode 100644
index e2e25b7..0000000
--- a/src/bin/sh/Makefile
+++ /dev/null
@@ -1,49 +0,0 @@
-# $Id$
-# Application Makefile (C) 2002-2004 The UbixOS Project
-
-# Include Global 'Source' Options
-include ../../Makefile.inc
-include ../Makefile.inc
-
-#Linker
-LD = ld
-
-#Binary File Name
-BINARY = sh
-
-#Delete Program
-REMOVE = rm -f
-
-#Objects
-OBJS = sh1.o
-
-INCLUDES = -I../../include.new
-
-LIBRARIES = ../../lib/libc/libc.so
-
-STARTUP = ../../lib/csu/*.o
-
-# Link The Binary
-$(BINARY) : $(OBJS)
- $(CC) $(CFLAGS) -o $@ $(STARTUP) $(LIBRARIES) $(OBJS)
- #strip $(BINARY)
-
-# Compile the source files
-.cc.o:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.cc.s:
- $(CXX) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.c.o:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -c -o $@ $<
-
-.c.s:
- $(CC) -Wall -O $(CFLAGS) $(INCLUDES) -S -o $@ $<
-
-.S.o:
- $(CC) -Wall $(CLFAGS) $(INCLUDES) -c -o $@ $<
-
-# Clean Up The junk
-clean:
- $(REMOVE) $(OBJS) $(BINARY)
diff --git a/src/bin/sh/sh.h b/src/bin/sh/sh.h
deleted file mode 100644
index 163cd57..0000000
--- a/src/bin/sh/sh.h
+++ /dev/null
@@ -1,385 +0,0 @@
-#include
-#include
-#include
-#include
-
-#define _NSIG 10
-
-/* Need a way to have void used for ANSI, nothing for K&R. */
-#ifndef _ANSI
-#undef _VOID
-#define _VOID
-#endif
-
-/* -------- sh.h -------- */
-/*
- * shell
- */
-
-#define LINELIM 2100
-#define NPUSH 8 /* limit to input nesting */
-
-#define NOFILE 20 /* Number of open files */
-#define NUFILE 10 /* Number of user-accessible files */
-#define FDBASE 10 /* First file usable by Shell */
-
-/*
- * values returned by wait
- */
-#define WAITSIG(s) ((s)&0177)
-#define WAITVAL(s) (((s)>>8)&0377)
-#define WAITCORE(s) (((s)&0200)!=0)
-
-/*
- * library and system defintions
- */
-#ifdef __STDC__
-typedef void xint; /* base type of jmp_buf, for not broken compilers */
-#else
-typedef char * xint; /* base type of jmp_buf, for broken compilers */
-#endif
-
-/*
- * shell components
- */
-/* #include "area.h" */
-/* #include "word.h" */
-/* #include "io.h" */
-/* #include "var.h" */
-
-#define QUOTE 0200
-
-#define NOBLOCK ((struct op *)NULL)
-#define NOWORD ((char *)NULL)
-#define NOWORDS ((char **)NULL)
-#define NOPIPE ((int *)NULL)
-
-/*
- * Description of a command or an operation on commands.
- * Might eventually use a union.
- */
-struct op {
- int type; /* operation type, see below */
- char **words; /* arguments to a command */
- struct ioword **ioact; /* IO actions (eg, < > >>) */
- struct op *left;
- struct op *right;
- char *str; /* identifier for case and for */
-};
-
-#define TCOM 1 /* command */
-#define TPAREN 2 /* (c-list) */
-#define TPIPE 3 /* a | b */
-#define TLIST 4 /* a [&;] b */
-#define TOR 5 /* || */
-#define TAND 6 /* && */
-#define TFOR 7
-#define TDO 8
-#define TCASE 9
-#define TIF 10
-#define TWHILE 11
-#define TUNTIL 12
-#define TELIF 13
-#define TPAT 14 /* pattern in case */
-#define TBRACE 15 /* {c-list} */
-#define TASYNC 16 /* c & */
-
-/*
- * actions determining the environment of a process
- */
-#define BIT(i) (1<<(i))
-#define FEXEC BIT(0) /* execute without forking */
-
-/*
- * flags to control evaluation of words
- */
-#define DOSUB 1 /* interpret $, `, and quotes */
-#define DOBLANK 2 /* perform blank interpretation */
-#define DOGLOB 4 /* interpret [?* */
-#define DOKEY 8 /* move words with `=' to 2nd arg. list */
-#define DOTRIM 16 /* trim resulting string */
-
-#define DOALL (DOSUB|DOBLANK|DOGLOB|DOKEY|DOTRIM)
-
-Extern char **dolv;
-Extern int dolc;
-Extern int exstat;
-Extern char gflg;
-Extern int talking; /* interactive (talking-type wireless) */
-Extern int execflg;
-Extern int multiline; /* \n changed to ; */
-Extern struct op *outtree; /* result from parser */
-
-Extern xint *failpt;
-Extern xint *errpt;
-
-struct brkcon {
- jmp_buf brkpt;
- struct brkcon *nextlev;
-} ;
-Extern struct brkcon *brklist;
-Extern int isbreak;
-
-/*
- * redirection
- */
-struct ioword {
- short io_unit; /* unit affected */
- short io_flag; /* action (below) */
- char *io_name; /* file name */
-};
-#define IOREAD 1 /* < */
-#define IOHERE 2 /* << (here file) */
-#define IOWRITE 4 /* > */
-#define IOCAT 8 /* >> */
-#define IOXHERE 16 /* ${}, ` in << */
-#define IODUP 32 /* >&digit */
-#define IOCLOSE 64 /* >&- */
-
-#define IODEFAULT (-1) /* token for default IO unit */
-
-Extern struct wdblock *wdlist;
-Extern struct wdblock *iolist;
-
-/*
- * parsing & execution environment
- */
-extern struct env {
- char *linep;
- struct io *iobase;
- struct io *iop;
- xint *errpt;
- int iofd;
- struct env *oenv;
-} e;
-
-/*
- * flags:
- * -e: quit on error
- * -k: look for name=value everywhere on command line
- * -n: no execution
- * -t: exit after reading and executing one command
- * -v: echo as read
- * -x: trace
- * -u: unset variables net diagnostic
- */
-extern char *flag;
-
-extern char *null; /* null value for variable */
-extern int intr; /* interrupt pending */
-
-Extern char *trap[_NSIG+1];
-Extern char ourtrap[_NSIG+1];
-Extern int trapset; /* trap pending */
-
-extern int heedint; /* heed interrupt signals */
-
-Extern int yynerrs; /* yacc */
-
-Extern char line[LINELIM];
-extern char *elinep;
-
-/*
- * other functions
- */
-#ifdef __STDC__
-int (*inbuilt(char *s ))(void);
-#else
-int (*inbuilt())();
-#endif
-_PROTOTYPE(char *rexecve , (char *c , char **v , char **envp ));
-_PROTOTYPE(char *space , (int n ));
-_PROTOTYPE(char *strsave , (char *s , int a ));
-_PROTOTYPE(char *evalstr , (char *cp , int f ));
-_PROTOTYPE(char *putn , (int n ));
-_PROTOTYPE(char *itoa , (unsigned u , int n ));
-_PROTOTYPE(char *unquote , (char *as ));
-_PROTOTYPE(struct var *lookup , (char *n ));
-_PROTOTYPE(int rlookup , (char *n ));
-_PROTOTYPE(struct wdblock *glob , (char *cp , struct wdblock *wb ));
-_PROTOTYPE(int subgetc , (int ec , int quoted ));
-_PROTOTYPE(char **makenv , (void));
-_PROTOTYPE(char **eval , (char **ap , int f ));
-_PROTOTYPE(int setstatus , (int s ));
-_PROTOTYPE(int waitfor , (int lastpid , int canintr ));
-
-_PROTOTYPE(void onintr , (int s )); /* SIGINT handler */
-
-_PROTOTYPE(int newenv , (int f ));
-_PROTOTYPE(void quitenv , (void));
-_PROTOTYPE(void err , (char *s ));
-_PROTOTYPE(int anys , (char *s1 , char *s2 ));
-_PROTOTYPE(int any , (int c , char *s ));
-_PROTOTYPE(void next , (int f ));
-_PROTOTYPE(void setdash , (void));
-_PROTOTYPE(void onecommand , (void));
-_PROTOTYPE(void runtrap , (int i ));
-_PROTOTYPE(void xfree , (char *s ));
-_PROTOTYPE(int letter , (int c ));
-_PROTOTYPE(int digit , (int c ));
-_PROTOTYPE(int letnum , (int c ));
-_PROTOTYPE(int gmatch , (char *s , char *p ));
-
-/*
- * error handling
- */
-_PROTOTYPE(void leave , (void)); /* abort shell (or fail in subshell) */
-_PROTOTYPE(void fail , (void)); /* fail but return to process next command */
-_PROTOTYPE(void warn , (char *s ));
-_PROTOTYPE(void sig , (int i )); /* default signal handler */
-
-/* -------- var.h -------- */
-
-struct var {
- char *value;
- char *name;
- struct var *next;
- char status;
-};
-#define COPYV 1 /* flag to setval, suggesting copy */
-#define RONLY 01 /* variable is read-only */
-#define EXPORT 02 /* variable is to be exported */
-#define GETCELL 04 /* name & value space was got with getcell */
-
-Extern struct var *vlist; /* dictionary */
-
-Extern struct var *homedir; /* home directory */
-Extern struct var *prompt; /* main prompt */
-Extern struct var *cprompt; /* continuation prompt */
-Extern struct var *path; /* search path for commands */
-Extern struct var *shell; /* shell to interpret command files */
-Extern struct var *ifs; /* field separators */
-
-_PROTOTYPE(int yyparse , (void));
-_PROTOTYPE(struct var *lookup , (char *n ));
-_PROTOTYPE(void setval , (struct var *vp , char *val ));
-_PROTOTYPE(void nameval , (struct var *vp , char *val , char *name ));
-_PROTOTYPE(void export , (struct var *vp ));
-_PROTOTYPE(void ronly , (struct var *vp ));
-_PROTOTYPE(int isassign , (char *s ));
-_PROTOTYPE(int checkname , (char *cp ));
-_PROTOTYPE(int assign , (char *s , int cf ));
-_PROTOTYPE(void putvlist , (int f , int out ));
-_PROTOTYPE(int eqname , (char *n1 , char *n2 ));
-
-_PROTOTYPE(int execute , (struct op *t , int *pin , int *pout , int act ));
-
-/* -------- io.h -------- */
-/* io buffer */
-struct iobuf {
- unsigned id; /* buffer id */
- char buf[512]; /* buffer */
- char *bufp; /* pointer into buffer */
- char *ebufp; /* pointer to end of buffer */
-};
-
-/* possible arguments to an IO function */
-struct ioarg {
- char *aword;
- char **awordlist;
- int afile; /* file descriptor */
- unsigned afid; /* buffer id */
- long afpos; /* file position */
- struct iobuf *afbuf; /* buffer for this file */
-};
-Extern struct ioarg ioargstack[NPUSH];
-#define AFID_NOBUF (~0)
-#define AFID_ID 0
-
-/* an input generator's state */
-struct io {
- int (*iofn)(_VOID);
- struct ioarg *argp;
- int peekc;
- char prev; /* previous character read by readc() */
- char nlcount; /* for `'s */
- char xchar; /* for `'s */
- char task; /* reason for pushed IO */
-};
-Extern struct io iostack[NPUSH];
-#define XOTHER 0 /* none of the below */
-#define XDOLL 1 /* expanding ${} */
-#define XGRAVE 2 /* expanding `'s */
-#define XIO 3 /* file IO */
-
-/* in substitution */
-#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
-
-/*
- * input generators for IO structure
- */
-_PROTOTYPE(int nlchar , (struct ioarg *ap ));
-_PROTOTYPE(int strchar , (struct ioarg *ap ));
-_PROTOTYPE(int qstrchar , (struct ioarg *ap ));
-_PROTOTYPE(int filechar , (struct ioarg *ap ));
-_PROTOTYPE(int herechar , (struct ioarg *ap ));
-_PROTOTYPE(int linechar , (struct ioarg *ap ));
-_PROTOTYPE(int gravechar , (struct ioarg *ap , struct io *iop ));
-_PROTOTYPE(int qgravechar , (struct ioarg *ap , struct io *iop ));
-_PROTOTYPE(int dolchar , (struct ioarg *ap ));
-_PROTOTYPE(int wdchar , (struct ioarg *ap ));
-_PROTOTYPE(void scraphere , (void));
-_PROTOTYPE(void freehere , (int area ));
-_PROTOTYPE(void gethere , (void));
-_PROTOTYPE(void markhere , (char *s , struct ioword *iop ));
-_PROTOTYPE(int herein , (char *hname , int xdoll ));
-_PROTOTYPE(int run , (struct ioarg *argp , int (*f)(_VOID)));
-
-/*
- * IO functions
- */
-_PROTOTYPE(int eofc , (void));
-_PROTOTYPE(int getc , (int ec ));
-_PROTOTYPE(int readc , (void));
-_PROTOTYPE(void unget , (int c ));
-_PROTOTYPE(void ioecho , (int c ));
-_PROTOTYPE(void prs , (char *s ));
-_PROTOTYPE(void putc , (int c ));
-_PROTOTYPE(void prn , (unsigned u ));
-_PROTOTYPE(void closef , (int i ));
-_PROTOTYPE(void closeall , (void));
-
-/*
- * IO control
- */
-_PROTOTYPE(void pushio , (struct ioarg *argp , int (*fn)(_VOID)));
-_PROTOTYPE(int remap , (int fd ));
-_PROTOTYPE(int openpipe , (int *pv ));
-_PROTOTYPE(void closepipe , (int *pv ));
-_PROTOTYPE(struct io *setbase , (struct io *ip ));
-
-extern struct ioarg temparg; /* temporary for PUSHIO */
-#define PUSHIO(what,arg,gen) ((temparg.what = (arg)),pushio(&temparg,(gen)))
-#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
-
-/* -------- word.h -------- */
-#ifndef WORD_H
-#define WORD_H 1
-struct wdblock {
- short w_bsize;
- short w_nword;
- /* bounds are arbitrary */
- char *w_words[1];
-};
-
-_PROTOTYPE(struct wdblock *addword , (char *wd , struct wdblock *wb ));
-_PROTOTYPE(struct wdblock *newword , (int nw ));
-_PROTOTYPE(char **getwords , (struct wdblock *wb ));
-#endif
-
-/* -------- area.h -------- */
-
-/*
- * storage allocation
- */
-_PROTOTYPE(char *getcell , (unsigned nbytes ));
-_PROTOTYPE(void garbage , (void));
-_PROTOTYPE(void setarea , (char *cp , int a ));
-_PROTOTYPE(int getarea , (char *cp ));
-_PROTOTYPE(void freearea , (int a ));
-_PROTOTYPE(void freecell , (char *cp ));
-
-Extern int areanum; /* current allocation area */
-
-#define NEW(type) (type *)getcell(sizeof(type))
-#define DELETE(obj) freecell((char *)obj)
diff --git a/src/bin/sh/sh1.c b/src/bin/sh/sh1.c
deleted file mode 100644
index cf45644..0000000
--- a/src/bin/sh/sh1.c
+++ /dev/null
@@ -1,952 +0,0 @@
-#define Extern extern
-#include
-#include
-#include
-#include
-#include "sh.h"
-/* -------- sh.c -------- */
-/*
- * shell
- */
-
-/* #include "sh.h" */
-
-int intr;
-int inparse;
-char flags['z'-'a'+1];
-char *flag = flags-'a';
-char *elinep = line+sizeof(line)-5;
-char *null = "";
-int heedint =1;
-struct env e ={line, iostack, iostack-1,
- (xint *)NULL, FDBASE, (struct env *)NULL};
-
-extern char **environ; /* environment pointer */
-
-/*
- * default shell, search rules
- */
-char shellname[] = "/bin/sh";
-char search[] = ":/bin:/usr/bin";
-
-_PROTOTYPE(void (*qflag), (int)) = SIG_IGN;
-
-_PROTOTYPE(int main, (int argc, char **argv ));
-_PROTOTYPE(int newfile, (char *s ));
-_PROTOTYPE(static char *findeq, (char *cp ));
-_PROTOTYPE(static char *cclass, (char *p, int sub ));
-_PROTOTYPE(void initarea, (void));
-
-int main(argc, argv)
-int argc;
-register char **argv;
-{
- register int f;
- register char *s;
- int cflag;
- char *name, **ap;
- int (*iof)();
-
- initarea();
- if ((ap = environ) != NULL) {
- while (*ap)
- assign(*ap++, !COPYV);
- for (ap = environ; *ap;)
- export(lookup(*ap++));
- }
- closeall();
- areanum = 1;
-
- shell = lookup("SHELL");
- if (shell->value == null)
- setval(shell, shellname);
- export(shell);
-
- homedir = lookup("HOME");
- if (homedir->value == null)
- setval(homedir, "/");
- export(homedir);
-
- setval(lookup("$"), itoa(getpid(), 5));
-
- path = lookup("PATH");
- if (path->value == null)
- setval(path, search);
- export(path);
-
- ifs = lookup("IFS");
- if (ifs->value == null)
- setval(ifs, " \t\n");
-
- prompt = lookup("PS1");
- if (prompt->value == null)
-#ifndef UNIXSHELL
- setval(prompt, "$ ");
-#else
- setval(prompt, "% ");
-#endif
-
- if (geteuid() == 0) {
- setval(prompt, "# ");
- prompt->status &= ~EXPORT;
- }
- cprompt = lookup("PS2");
- if (cprompt->value == null)
- setval(cprompt, "> ");
-
- iof = filechar;
- cflag = 0;
- name = *argv++;
- if (--argc >= 1) {
- if(argv[0][0] == '-' && argv[0][1] != '\0') {
- for (s = argv[0]+1; *s; s++)
- switch (*s) {
- case 'c':
- prompt->status &= ~EXPORT;
- cprompt->status &= ~EXPORT;
- setval(prompt, "");
- setval(cprompt, "");
- cflag = 1;
- if (--argc > 0)
- PUSHIO(aword, *++argv, iof = nlchar);
- break;
-
- case 'q':
- qflag = SIG_DFL;
- break;
-
- case 's':
- /* standard input */
- break;
-
- case 't':
- prompt->status &= ~EXPORT;
- setval(prompt, "");
- iof = linechar;
- break;
-
- case 'i':
- talking++;
- default:
- if (*s>='a' && *s<='z')
- flag[*s]++;
- }
- } else {
- argv--;
- argc++;
- }
- if (iof == filechar && --argc > 0) {
- setval(prompt, "");
- setval(cprompt, "");
- prompt->status &= ~EXPORT;
- cprompt->status &= ~EXPORT;
- if (newfile(name = *++argv))
- exit(1);
- }
- }
- setdash();
- if (e.iop < iostack) {
- PUSHIO(afile, 0, iof);
- if (isatty(0) && isatty(1) && !cflag)
- talking++;
- }
- signal(SIGQUIT, qflag);
- if (name && name[0] == '-') {
- talking++;
- if ((f = open(".profile", 0)) >= 0)
- next(remap(f));
- if ((f = open("/etc/profile", 0)) >= 0)
- next(remap(f));
- }
- if (talking)
- signal(SIGTERM, sig);
- if (signal(SIGINT, SIG_IGN) != SIG_IGN)
- signal(SIGINT, onintr);
- dolv = argv;
- dolc = argc;
- dolv[0] = name;
- if (dolc > 1)
- for (ap = ++argv; --argc > 0;)
- if (assign(*ap = *argv++, !COPYV))
- dolc--; /* keyword */
- else
- ap++;
- setval(lookup("#"), putn((--dolc < 0) ? (dolc = 0) : dolc));
-
- for (;;) {
- if (talking && e.iop <= iostack)
- prs(prompt->value);
- onecommand();
- }
-}
-
-void
-setdash()
-{
- register char *cp, c;
- char m['z'-'a'+1];
-
- cp = m;
- for (c='a'; c<='z'; c++)
- if (flag[c])
- *cp++ = c;
- *cp = 0;
- setval(lookup("-"), m);
-}
-
-int
-newfile(s)
-register char *s;
-{
- register f;
-
- if (strcmp(s, "-") != 0) {
- f = open(s, 0);
- if (f < 0) {
- prs(s);
- err(": cannot open");
- return(1);
- }
- } else
- f = 0;
- next(remap(f));
- return(0);
-}
-
-void
-onecommand()
-{
- register i;
- jmp_buf m1;
-
- while (e.oenv)
- quitenv();
- areanum = 1;
- freehere(areanum);
- freearea(areanum);
- garbage();
- wdlist = 0;
- iolist = 0;
- e.errpt = 0;
- e.linep = line;
- yynerrs = 0;
- multiline = 0;
- inparse = 1;
- intr = 0;
- execflg = 0;
- setjmp(failpt = m1); /* Bruce Evans' fix */
- if (setjmp(failpt = m1) || yyparse() || intr) {
- while (e.oenv)
- quitenv();
- scraphere();
- if (!talking && intr)
- leave();
- inparse = 0;
- intr = 0;
- return;
- }
- inparse = 0;
- brklist = 0;
- intr = 0;
- execflg = 0;
- if (!flag['n'])
- execute(outtree, NOPIPE, NOPIPE, 0);
- if (!talking && intr) {
- execflg = 0;
- leave();
- }
- if ((i = trapset) != 0) {
- trapset = 0;
- runtrap(i);
- }
-}
-
-void
-fail()
-{
- longjmp(failpt, 1);
- /* NOTREACHED */
-}
-
-void
-leave()
-{
- if (execflg)
- fail();
- scraphere();
- freehere(1);
- runtrap(0);
- exit(exstat);
- /* NOTREACHED */
-}
-
-void
-warn(s)
-register char *s;
-{
- if(*s) {
- prs(s);
- exstat = -1;
- }
- prs("\n");
- if (flag['e'])
- leave();
-}
-
-void
-err(s)
-char *s;
-{
- warn(s);
- if (flag['n'])
- return;
- if (!talking)
- leave();
- if (e.errpt)
- longjmp(e.errpt, 1);
- closeall();
- e.iop = e.iobase = iostack;
-}
-
-int
-newenv(f)
-int f;
-{
- register struct env *ep;
-
- if (f) {
- quitenv();
- return(1);
- }
- ep = (struct env *) space(sizeof(*ep));
- if (ep == NULL) {
- while (e.oenv)
- quitenv();
- fail();
- }
- *ep = e;
- e.oenv = ep;
- e.errpt = errpt;
- return(0);
-}
-
-void
-quitenv()
-{
- register struct env *ep;
- register fd;
-
- if ((ep = e.oenv) != NULL) {
- fd = e.iofd;
- e = *ep;
- /* should close `'d files */
- DELETE(ep);
- while (--fd >= e.iofd)
- close(fd);
- }
-}
-
-/*
- * Is any character from s1 in s2?
- */
-int
-anys(s1, s2)
-register char *s1, *s2;
-{
- while (*s1)
- if (any(*s1++, s2))
- return(1);
- return(0);
-}
-
-/*
- * Is character c in s?
- */
-int
-any(c, s)
-register int c;
-register char *s;
-{
- while (*s)
- if (*s++ == c)
- return(1);
- return(0);
-}
-
-char *
-putn(n)
-register int n;
-{
- return(itoa(n, -1));
-}
-
-char *
-itoa(u, n)
-register unsigned u;
-int n;
-{
- register char *cp;
- static char s[20];
- int m;
-
- m = 0;
- if (n < 0 && (int) u < 0) {
- m++;
- u = -u;
- }
- cp = s+sizeof(s);
- *--cp = 0;
- do {
- *--cp = u%10 + '0';
- u /= 10;
- } while (--n > 0 || u);
- if (m)
- *--cp = '-';
- return(cp);
-}
-
-void
-next(f)
-int f;
-{
- PUSHIO(afile, f, filechar);
-}
-
-void
-onintr(s)
-int s; /* ANSI C requires a parameter */
-{
- signal(SIGINT, onintr);
- intr = 1;
- if (talking) {
- if (inparse) {
- prs("\n");
- fail();
- }
- }
- else if (heedint) {
- execflg = 0;
- leave();
- }
-}
-
-int
-letter(c)
-register c;
-{
- return((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_');
-}
-
-int
-digit(c)
-register c;
-{
- return(c >= '0' && c <= '9');
-}
-
-int
-letnum(c)
-register c;
-{
- return(letter(c) || digit(c));
-}
-
-char *
-space(n)
-int n;
-{
- register char *cp;
-
- if ((cp = getcell(n)) == 0)
- err("out of string space");
- return(cp);
-}
-
-char *
-strsave(s, a)
-register char *s;
-int a;
-{
- register char *cp, *xp;
-
- if ((cp = space(strlen(s)+1)) != NULL) {
- setarea((char *)cp, a);
- for (xp = cp; (*xp++ = *s++) != '\0';)
- ;
- return(cp);
- }
- return("");
-}
-
-void
-xfree(s)
-register char *s;
-{
- DELETE(s);
-}
-
-/*
- * trap handling
- */
-void
-sig(i)
-register int i;
-{
- trapset = i;
- signal(i, sig);
-}
-
-void runtrap(i)
-int i;
-{
- char *trapstr;
-
- if ((trapstr = trap[i]) == NULL)
- return;
- if (i == 0)
- trap[i] = 0;
- RUN(aword, trapstr, nlchar);
-}
-
-/* -------- var.c -------- */
-/* #include "sh.h" */
-
-/*
- * Find the given name in the dictionary
- * and return its value. If the name was
- * not previously there, enter it now and
- * return a null value.
- */
-struct var *
-lookup(n)
-register char *n;
-{
- register struct var *vp;
- register char *cp;
- register int c;
- static struct var dummy;
-
- if (digit(*n)) {
- dummy.name = n;
- for (c = 0; digit(*n) && c < 1000; n++)
- c = c*10 + *n-'0';
- dummy.status = RONLY;
- dummy.value = c <= dolc? dolv[c]: null;
- return(&dummy);
- }
- for (vp = vlist; vp; vp = vp->next)
- if (eqname(vp->name, n))
- return(vp);
- cp = findeq(n);
- vp = (struct var *)space(sizeof(*vp));
- if (vp == 0 || (vp->name = space((int)(cp-n)+2)) == 0) {
- dummy.name = dummy.value = "";
- return(&dummy);
- }
- for (cp = vp->name; (*cp = *n++) && *cp != '='; cp++)
- ;
- if (*cp == 0)
- *cp = '=';
- *++cp = 0;
- setarea((char *)vp, 0);
- setarea((char *)vp->name, 0);
- vp->value = null;
- vp->next = vlist;
- vp->status = GETCELL;
- vlist = vp;
- return(vp);
-}
-
-/*
- * give variable at `vp' the value `val'.
- */
-void
-setval(vp, val)
-struct var *vp;
-char *val;
-{
- nameval(vp, val, (char *)NULL);
-}
-
-/*
- * if name is not NULL, it must be
- * a prefix of the space `val',
- * and end with `='.
- * this is all so that exporting
- * values is reasonably painless.
- */
-void
-nameval(vp, val, name)
-register struct var *vp;
-char *val, *name;
-{
- register char *cp, *xp;
- char *nv;
- int fl;
-
- if (vp->status & RONLY) {
- for (xp = vp->name; *xp && *xp != '=';)
- putc(*xp++);
- err(" is read-only");
- return;
- }
- fl = 0;
- if (name == NULL) {
- xp = space(strlen(vp->name)+strlen(val)+2);
- if (xp == 0)
- return;
- /* make string: name=value */
- setarea((char *)xp, 0);
- name = xp;
- for (cp = vp->name; (*xp = *cp++) && *xp!='='; xp++)
- ;
- if (*xp++ == 0)
- xp[-1] = '=';
- nv = xp;
- for (cp = val; (*xp++ = *cp++) != '\0';)
- ;
- val = nv;
- fl = GETCELL;
- }
- if (vp->status & GETCELL)
- xfree(vp->name); /* form new string `name=value' */
- vp->name = name;
- vp->value = val;
- vp->status |= fl;
-}
-
-void
-export(vp)
-struct var *vp;
-{
- vp->status |= EXPORT;
-}
-
-void
-ronly(vp)
-struct var *vp;
-{
- if (letter(vp->name[0])) /* not an internal symbol ($# etc) */
- vp->status |= RONLY;
-}
-
-int
-isassign(s)
-register char *s;
-{
- if (!letter((int)*s))
- return(0);
- for (; *s != '='; s++)
- if (*s == 0 || !letnum(*s))
- return(0);
- return(1);
-}
-
-int
-assign(s, cf)
-register char *s;
-int cf;
-{
- register char *cp;
- struct var *vp;
-
- if (!letter(*s))
- return(0);
- for (cp = s; *cp != '='; cp++)
- if (*cp == 0 || !letnum(*cp))
- return(0);
- vp = lookup(s);
- nameval(vp, ++cp, cf == COPYV? (char *)NULL: s);
- if (cf != COPYV)
- vp->status &= ~GETCELL;
- return(1);
-}
-
-int
-checkname(cp)
-register char *cp;
-{
- if (!letter(*cp++))
- return(0);
- while (*cp)
- if (!letnum(*cp++))
- return(0);
- return(1);
-}
-
-void
-putvlist(f, out)
-register int f, out;
-{
- register struct var *vp;
-
- for (vp = vlist; vp; vp = vp->next)
- if (vp->status & f && letter(*vp->name)) {
- if (vp->status & EXPORT)
- write(out, "export ", 7);
- if (vp->status & RONLY)
- write(out, "readonly ", 9);
- write(out, vp->name, (int)(findeq(vp->name) - vp->name));
- write(out, "\n", 1);
- }
-}
-
-int
-eqname(n1, n2)
-register char *n1, *n2;
-{
- for (; *n1 != '=' && *n1 != 0; n1++)
- if (*n2++ != *n1)
- return(0);
- return(*n2 == 0 || *n2 == '=');
-}
-
-static char *
-findeq(cp)
-register char *cp;
-{
- while (*cp != '\0' && *cp != '=')
- cp++;
- return(cp);
-}
-
-/* -------- gmatch.c -------- */
-/*
- * int gmatch(string, pattern)
- * char *string, *pattern;
- *
- * Match a pattern as in sh(1).
- */
-
-#define CMASK 0377
-#define QUOTE 0200
-#define QMASK (CMASK&~QUOTE)
-#define NOT '!' /* might use ^ */
-
-int
-gmatch(s, p)
-register char *s, *p;
-{
- register int sc, pc;
-
- if (s == NULL || p == NULL)
- return(0);
- while ((pc = *p++ & CMASK) != '\0') {
- sc = *s++ & QMASK;
- switch (pc) {
- case '[':
- if ((p = cclass(p, sc)) == NULL)
- return(0);
- break;
-
- case '?':
- if (sc == 0)
- return(0);
- break;
-
- case '*':
- s--;
- do {
- if (*p == '\0' || gmatch(s, p))
- return(1);
- } while (*s++ != '\0');
- return(0);
-
- default:
- if (sc != (pc&~QUOTE))
- return(0);
- }
- }
- return(*s == 0);
-}
-
-static char *
-cclass(p, sub)
-register char *p;
-register int sub;
-{
- register int c, d, not, found;
-
- if ((not = *p == NOT) != 0)
- p++;
- found = not;
- do {
- if (*p == '\0')
- return((char *)NULL);
- c = *p & CMASK;
- if (p[1] == '-' && p[2] != ']') {
- d = p[2] & CMASK;
- p++;
- } else
- d = c;
- if (c == sub || (c <= sub && sub <= d))
- found = !not;
- } while (*++p != ']');
- return(found? p+1: (char *)NULL);
-}
-
-/* -------- area.c -------- */
-#define REGSIZE sizeof(struct region)
-#define GROWBY 256
-#undef SHRINKBY 64
-#define FREE 32767
-#define BUSY 0
-#define ALIGN (sizeof(int)-1)
-
-/* #include "area.h" */
-
-struct region {
- struct region *next;
- int area;
-};
-
-/*
- * All memory between (char *)areabot and (char *)(areatop+1) is
- * exclusively administered by the area management routines.
- * It is assumed that sbrk() and brk() manipulate the high end.
- */
-static struct region *areabot; /* bottom of area */
-static struct region *areatop; /* top of area */
-static struct region *areanxt; /* starting point of scan */
-
-void
-initarea()
-{
- while ((int)sbrk(0) & ALIGN)
- sbrk(1);
- areabot = (struct region *)sbrk(REGSIZE);
- areabot->next = areabot;
- areabot->area = BUSY;
- areatop = areabot;
- areanxt = areabot;
-}
-
-char *
-getcell(nbytes)
-unsigned nbytes;
-{
- register int nregio;
- register struct region *p, *q;
- register i;
-
- if (nbytes == 0)
- abort(); /* silly and defeats the algorithm */
- /*
- * round upwards and add administration area
- */
- nregio = (nbytes+(REGSIZE-1))/REGSIZE + 1;
- for (p = areanxt;;) {
- if (p->area > areanum) {
- /*
- * merge free cells
- */
- while ((q = p->next)->area > areanum && q != areanxt)
- p->next = q->next;
- /*
- * exit loop if cell big enough
- */
- if (q >= p + nregio)
- goto found;
- }
- p = p->next;
- if (p == areanxt)
- break;
- }
- i = nregio >= GROWBY ? nregio : GROWBY;
- p = (struct region *)sbrk(i * REGSIZE);
- if (p == (struct region *)-1)
- return((char *)NULL);
- p--;
- if (p != areatop)
- abort(); /* allocated areas are contiguous */
- q = p + i;
- p->next = q;
- p->area = FREE;
- q->next = areabot;
- q->area = BUSY;
- areatop = q;
-found:
- /*
- * we found a FREE area big enough, pointed to by 'p', and up to 'q'
- */
- areanxt = p + nregio;
- if (areanxt < q) {
- /*
- * split into requested area and rest
- */
- if (areanxt+1 > q)
- abort(); /* insufficient space left for admin */
- areanxt->next = q;
- areanxt->area = FREE;
- p->next = areanxt;
- }
- p->area = areanum;
- return((char *)(p+1));
-}
-
-void
-freecell(cp)
-char *cp;
-{
- register struct region *p;
-
- if ((p = (struct region *)cp) != NULL) {
- p--;
- if (p < areanxt)
- areanxt = p;
- p->area = FREE;
- }
-}
-
-void
-freearea(a)
-register int a;
-{
- register struct region *p, *top;
-
- top = areatop;
- for (p = areabot; p != top; p = p->next)
- if (p->area >= a)
- p->area = FREE;
-}
-
-void
-setarea(cp,a)
-char *cp;
-int a;
-{
- register struct region *p;
-
- if ((p = (struct region *)cp) != NULL)
- (p-1)->area = a;
-}
-
-int
-getarea(cp)
-char *cp;
-{
- return ((struct region*)cp-1)->area;
-}
-
-void
-garbage()
-{
- register struct region *p, *q, *top;
-
- top = areatop;
- for (p = areabot; p != top; p = p->next) {
- if (p->area > areanum) {
- while ((q = p->next)->area > areanum)
- p->next = q->next;
- areanxt = p;
- }
- }
-#ifdef SHRINKBY
- if (areatop >= q + SHRINKBY && q->area > areanum) {
- brk((char *)(q+1));
- q->next = areabot;
- q->area = BUSY;
- areatop = q;
- }
-#endif
-}
diff --git a/src/bin/sh/sh2.c b/src/bin/sh/sh2.c
deleted file mode 100644
index 2a9f80f..0000000
--- a/src/bin/sh/sh2.c
+++ /dev/null
@@ -1,800 +0,0 @@
-#define Extern extern
-#include
-#include
-#include
-#include
-#include "sh.h"
-
-/* -------- csyn.c -------- */
-/*
- * shell: syntax (C version)
- */
-
-typedef union {
- char *cp;
- char **wp;
- int i;
- struct op *o;
-} YYSTYPE;
-#define WORD 256
-#define LOGAND 257
-#define LOGOR 258
-#define BREAK 259
-#define IF 260
-#define THEN 261
-#define ELSE 262
-#define ELIF 263
-#define FI 264
-#define CASE 265
-#define ESAC 266
-#define FOR 267
-#define WHILE 268
-#define UNTIL 269
-#define DO 270
-#define DONE 271
-#define IN 272
-#define YYERRCODE 300
-
-/* flags to yylex */
-#define CONTIN 01 /* skip new lines to complete command */
-
-/* #include "sh.h" */
-#define SYNTAXERR zzerr()
-static int startl;
-static int peeksym;
-static int nlseen;
-static int iounit = IODEFAULT;
-
-static YYSTYPE yylval;
-
-_PROTOTYPE(static struct op *pipeline, (int cf ));
-_PROTOTYPE(static struct op *andor, (void));
-_PROTOTYPE(static struct op *c_list, (void));
-_PROTOTYPE(static int synio, (int cf ));
-_PROTOTYPE(static void musthave, (int c, int cf ));
-_PROTOTYPE(static struct op *simple, (void));
-_PROTOTYPE(static struct op *nested, (int type, int mark ));
-_PROTOTYPE(static struct op *command, (int cf ));
-_PROTOTYPE(static struct op *dogroup, (int onlydone ));
-_PROTOTYPE(static struct op *thenpart, (void));
-_PROTOTYPE(static struct op *elsepart, (void));
-_PROTOTYPE(static struct op *caselist, (void));
-_PROTOTYPE(static struct op *casepart, (void));
-_PROTOTYPE(static char **pattern, (void));
-_PROTOTYPE(static char **wordlist, (void));
-_PROTOTYPE(static struct op *list, (struct op *t1, struct op *t2 ));
-_PROTOTYPE(static struct op *block, (int type, struct op *t1, struct op *t2, char **wp ));
-_PROTOTYPE(static struct op *newtp, (void));
-_PROTOTYPE(static struct op *namelist, (struct op *t ));
-_PROTOTYPE(static char **copyw, (void));
-_PROTOTYPE(static void word, (char *cp ));
-_PROTOTYPE(static struct ioword **copyio, (void));
-_PROTOTYPE(static struct ioword *io, (int u, int f, char *cp ));
-_PROTOTYPE(static void zzerr, (void));
-_PROTOTYPE(void yyerror, (char *s ));
-_PROTOTYPE(static int yylex, (int cf ));
-_PROTOTYPE(int collect, (int c, int c1 ));
-_PROTOTYPE(int dual, (int c ));
-_PROTOTYPE(static void diag, (int ec ));
-_PROTOTYPE(static char *tree, (unsigned size ));
-_PROTOTYPE(void printf, (char *s ));
-
-int
-yyparse()
-{
- startl = 1;
- peeksym = 0;
- yynerrs = 0;
- outtree = c_list();
- musthave('\n', 0);
- return(yynerrs!=0);
-}
-
-static struct op *
-pipeline(cf)
-int cf;
-{
- register struct op *t, *p;
- register int c;
-
- t = command(cf);
- if (t != NULL) {
- while ((c = yylex(0)) == '|') {
- if ((p = command(CONTIN)) == NULL)
- SYNTAXERR;
- if (t->type != TPAREN && t->type != TCOM) {
- /* shell statement */
- t = block(TPAREN, t, NOBLOCK, NOWORDS);
- }
- t = block(TPIPE, t, p, NOWORDS);
- }
- peeksym = c;
- }
- return(t);
-}
-
-static struct op *
-andor()
-{
- register struct op *t, *p;
- register int c;
-
- t = pipeline(0);
- if (t != NULL) {
- while ((c = yylex(0)) == LOGAND || c == LOGOR) {
- if ((p = pipeline(CONTIN)) == NULL)
- SYNTAXERR;
- t = block(c == LOGAND? TAND: TOR, t, p, NOWORDS);
- }
- peeksym = c;
- }
- return(t);
-}
-
-static struct op *
-c_list()
-{
- register struct op *t, *p;
- register int c;
-
- t = andor();
- if (t != NULL) {
- if((peeksym = yylex(0)) == '&')
- t = block(TASYNC, t, NOBLOCK, NOWORDS);
- while ((c = yylex(0)) == ';' || c == '&' || (multiline && c == '\n')) {
- if ((p = andor()) == NULL)
- return(t);
- if((peeksym = yylex(0)) == '&')
- p = block(TASYNC, p, NOBLOCK, NOWORDS);
- t = list(t, p);
- }
- peeksym = c;
- }
- return(t);
-}
-
-
-static int
-synio(cf)
-int cf;
-{
- register struct ioword *iop;
- register int i;
- register int c;
-
- if ((c = yylex(cf)) != '<' && c != '>') {
- peeksym = c;
- return(0);
- }
- i = yylval.i;
- musthave(WORD, 0);
- iop = io(iounit, i, yylval.cp);
- iounit = IODEFAULT;
- if (i & IOHERE)
- markhere(yylval.cp, iop);
- return(1);
-}
-
-static void
-musthave(c, cf)
-int c, cf;
-{
- if ((peeksym = yylex(cf)) != c)
- SYNTAXERR;
- peeksym = 0;
-}
-
-static struct op *
-simple()
-{
- register struct op *t;
-
- t = NULL;
- for (;;) {
- switch (peeksym = yylex(0)) {
- case '<':
- case '>':
- (void) synio(0);
- break;
-
- case WORD:
- if (t == NULL) {
- t = newtp();
- t->type = TCOM;
- }
- peeksym = 0;
- word(yylval.cp);
- break;
-
- default:
- return(t);
- }
- }
-}
-
-static struct op *
-nested(type, mark)
-int type, mark;
-{
- register struct op *t;
-
- multiline++;
- t = c_list();
- musthave(mark, 0);
- multiline--;
- return(block(type, t, NOBLOCK, NOWORDS));
-}
-
-static struct op *
-command(cf)
-int cf;
-{
- register struct op *t;
- struct wdblock *iosave;
- register int c;
-
- iosave = iolist;
- iolist = NULL;
- if (multiline)
- cf |= CONTIN;
- while (synio(cf))
- cf = 0;
- switch (c = yylex(cf)) {
- default:
- peeksym = c;
- if ((t = simple()) == NULL) {
- if (iolist == NULL)
- return((struct op *)NULL);
- t = newtp();
- t->type = TCOM;
- }
- break;
-
- case '(':
- t = nested(TPAREN, ')');
- break;
-
- case '{':
- t = nested(TBRACE, '}');
- break;
-
- case FOR:
- t = newtp();
- t->type = TFOR;
- musthave(WORD, 0);
- startl = 1;
- t->str = yylval.cp;
- multiline++;
- t->words = wordlist();
- if ((c = yylex(0)) != '\n' && c != ';')
- peeksym = c;
- t->left = dogroup(0);
- multiline--;
- break;
-
- case WHILE:
- case UNTIL:
- multiline++;
- t = newtp();
- t->type = c == WHILE? TWHILE: TUNTIL;
- t->left = c_list();
- t->right = dogroup(1);
- t->words = NULL;
- multiline--;
- break;
-
- case CASE:
- t = newtp();
- t->type = TCASE;
- musthave(WORD, 0);
- t->str = yylval.cp;
- startl++;
- multiline++;
- musthave(IN, CONTIN);
- startl++;
- t->left = caselist();
- musthave(ESAC, 0);
- multiline--;
- break;
-
- case IF:
- multiline++;
- t = newtp();
- t->type = TIF;
- t->left = c_list();
- t->right = thenpart();
- musthave(FI, 0);
- multiline--;
- break;
- }
- while (synio(0))
- ;
- t = namelist(t);
- iolist = iosave;
- return(t);
-}
-
-static struct op *
-dogroup(onlydone)
-int onlydone;
-{
- register int c;
- register struct op *list;
-
- c = yylex(CONTIN);
- if (c == DONE && onlydone)
- return((struct op *)NULL);
- if (c != DO)
- SYNTAXERR;
- list = c_list();
- musthave(DONE, 0);
- return(list);
-}
-
-static struct op *
-thenpart()
-{
- register int c;
- register struct op *t;
-
- if ((c = yylex(0)) != THEN) {
- peeksym = c;
- return((struct op *)NULL);
- }
- t = newtp();
- t->type = 0;
- t->left = c_list();
- if (t->left == NULL)
- SYNTAXERR;
- t->right = elsepart();
- return(t);
-}
-
-static struct op *
-elsepart()
-{
- register int c;
- register struct op *t;
-
- switch (c = yylex(0)) {
- case ELSE:
- if ((t = c_list()) == NULL)
- SYNTAXERR;
- return(t);
-
- case ELIF:
- t = newtp();
- t->type = TELIF;
- t->left = c_list();
- t->right = thenpart();
- return(t);
-
- default:
- peeksym = c;
- return((struct op *)NULL);
- }
-}
-
-static struct op *
-caselist()
-{
- register struct op *t;
-
- t = NULL;
- while ((peeksym = yylex(CONTIN)) != ESAC)
- t = list(t, casepart());
- return(t);
-}
-
-static struct op *
-casepart()
-{
- register struct op *t;
-
- t = newtp();
- t->type = TPAT;
- t->words = pattern();
- musthave(')', 0);
- t->left = c_list();
- if ((peeksym = yylex(CONTIN)) != ESAC)
- musthave(BREAK, CONTIN);
- return(t);
-}
-
-static char **
-pattern()
-{
- register int c, cf;
-
- cf = CONTIN;
- do {
- musthave(WORD, cf);
- word(yylval.cp);
- cf = 0;
- } while ((c = yylex(0)) == '|');
- peeksym = c;
- word(NOWORD);
- return(copyw());
-}
-
-static char **
-wordlist()
-{
- register int c;
-
- if ((c = yylex(0)) != IN) {
- peeksym = c;
- return((char **)NULL);
- }
- startl = 0;
- while ((c = yylex(0)) == WORD)
- word(yylval.cp);
- word(NOWORD);
- peeksym = c;
- return(copyw());
-}
-
-/*
- * supporting functions
- */
-static struct op *
-list(t1, t2)
-register struct op *t1, *t2;
-{
- if (t1 == NULL)
- return(t2);
- if (t2 == NULL)
- return(t1);
- return(block(TLIST, t1, t2, NOWORDS));
-}
-
-static struct op *
-block(type, t1, t2, wp)
-int type;
-struct op *t1, *t2;
-char **wp;
-{
- register struct op *t;
-
- t = newtp();
- t->type = type;
- t->left = t1;
- t->right = t2;
- t->words = wp;
- return(t);
-}
-
-struct res {
- char *r_name;
- int r_val;
-} restab[] = {
- "for", FOR,
- "case", CASE,
- "esac", ESAC,
- "while", WHILE,
- "do", DO,
- "done", DONE,
- "if", IF,
- "in", IN,
- "then", THEN,
- "else", ELSE,
- "elif", ELIF,
- "until", UNTIL,
- "fi", FI,
-
- ";;", BREAK,
- "||", LOGOR,
- "&&", LOGAND,
- "{", '{',
- "}", '}',
-
- 0,
-};
-
-int
-rlookup(n)
-register char *n;
-{
- register struct res *rp;
-
- for (rp = restab; rp->r_name; rp++)
- if (strcmp(rp->r_name, n) == 0)
- return(rp->r_val);
- return(0);
-}
-
-static struct op *
-newtp()
-{
- register struct op *t;
-
- t = (struct op *)tree(sizeof(*t));
- t->type = 0;
- t->words = NULL;
- t->ioact = NULL;
- t->left = NULL;
- t->right = NULL;
- t->str = NULL;
- return(t);
-}
-
-static struct op *
-namelist(t)
-register struct op *t;
-{
- if (iolist) {
- iolist = addword((char *)NULL, iolist);
- t->ioact = copyio();
- } else
- t->ioact = NULL;
- if (t->type != TCOM) {
- if (t->type != TPAREN && t->ioact != NULL) {
- t = block(TPAREN, t, NOBLOCK, NOWORDS);
- t->ioact = t->left->ioact;
- t->left->ioact = NULL;
- }
- return(t);
- }
- word(NOWORD);
- t->words = copyw();
- return(t);
-}
-
-static char **
-copyw()
-{
- register char **wd;
-
- wd = getwords(wdlist);
- wdlist = 0;
- return(wd);
-}
-
-static void
-word(cp)
-char *cp;
-{
- wdlist = addword(cp, wdlist);
-}
-
-static struct ioword **
-copyio()
-{
- register struct ioword **iop;
-
- iop = (struct ioword **) getwords(iolist);
- iolist = 0;
- return(iop);
-}
-
-static struct ioword *
-io(u, f, cp)
-int u;
-int f;
-char *cp;
-{
- register struct ioword *iop;
-
- iop = (struct ioword *) tree(sizeof(*iop));
- iop->io_unit = u;
- iop->io_flag = f;
- iop->io_name = cp;
- iolist = addword((char *)iop, iolist);
- return(iop);
-}
-
-static void
-zzerr()
-{
- yyerror("syntax error");
-}
-
-void
-yyerror(s)
-char *s;
-{
- yynerrs++;
- if (talking && e.iop <= iostack) {
- multiline = 0;
- while (eofc() == 0 && yylex(0) != '\n')
- ;
- }
- err(s);
- fail();
-}
-
-static int
-yylex(cf)
-int cf;
-{
- register int c, c1;
- int atstart;
-
- if ((c = peeksym) > 0) {
- peeksym = 0;
- if (c == '\n')
- startl = 1;
- return(c);
- }
- nlseen = 0;
- e.linep = line;
- atstart = startl;
- startl = 0;
- yylval.i = 0;
-
-loop:
- while ((c = getc(0)) == ' ' || c == '\t')
- ;
- switch (c) {
- default:
- if (any(c, "0123456789")) {
- unget(c1 = getc(0));
- if (c1 == '<' || c1 == '>') {
- iounit = c - '0';
- goto loop;
- }
- *e.linep++ = c;
- c = c1;
- }
- break;
-
- case '#':
- while ((c = getc(0)) != 0 && c != '\n')
- ;
- unget(c);
- goto loop;
-
- case 0:
- return(c);
-
- case '$':
- *e.linep++ = c;
- if ((c = getc(0)) == '{') {
- if ((c = collect(c, '}')) != '\0')
- return(c);
- goto pack;
- }
- break;
-
- case '`':
- case '\'':
- case '"':
- if ((c = collect(c, c)) != '\0')
- return(c);
- goto pack;
-
- case '|':
- case '&':
- case ';':
- if ((c1 = dual(c)) != '\0') {
- startl = 1;
- return(c1);
- }
- startl = 1;
- return(c);
- case '^':
- startl = 1;
- return('|');
- case '>':
- case '<':
- diag(c);
- return(c);
-
- case '\n':
- nlseen++;
- gethere();
- startl = 1;
- if (multiline || cf & CONTIN) {
- if (talking && e.iop <= iostack)
- prs(cprompt->value);
- if (cf & CONTIN)
- goto loop;
- }
- return(c);
-
- case '(':
- case ')':
- startl = 1;
- return(c);
- }
-
- unget(c);
-
-pack:
- while ((c = getc(0)) != 0 && !any(c, "`$ '\"\t;&<>()|^\n"))
- if (e.linep >= elinep)
- err("word too long");
- else
- *e.linep++ = c;
- unget(c);
- if(any(c, "\"'`$"))
- goto loop;
- *e.linep++ = '\0';
- if (atstart && (c = rlookup(line))!=0) {
- startl = 1;
- return(c);
- }
- yylval.cp = strsave(line, areanum);
- return(WORD);
-}
-
-int
-collect(c, c1)
-register c, c1;
-{
- char s[2];
-
- *e.linep++ = c;
- while ((c = getc(c1)) != c1) {
- if (c == 0) {
- unget(c);
- s[0] = c1;
- s[1] = 0;
- prs("no closing "); yyerror(s);
- return(YYERRCODE);
- }
- if (talking && c == '\n' && e.iop <= iostack)
- prs(cprompt->value);
- *e.linep++ = c;
- }
- *e.linep++ = c;
- return(0);
-}
-
-int
-dual(c)
-register c;
-{
- char s[3];
- register char *cp = s;
-
- *cp++ = c;
- *cp++ = getc(0);
- *cp = 0;
- if ((c = rlookup(s)) == 0)
- unget(*--cp);
- return(c);
-}
-
-static void
-diag(ec)
-register int ec;
-{
- register int c;
-
- c = getc(0);
- if (c == '>' || c == '<') {
- if (c != ec)
- zzerr();
- yylval.i = ec == '>'? IOWRITE|IOCAT: IOHERE;
- c = getc(0);
- } else
- yylval.i = ec == '>'? IOWRITE: IOREAD;
- if (c != '&' || yylval.i == IOHERE)
- unget(c);
- else
- yylval.i |= IODUP;
-}
-
-static char *
-tree(size)
-unsigned size;
-{
- register char *t;
-
- if ((t = getcell(size)) == NULL) {
- prs("command line too complicated\n");
- fail();
- /* NOTREACHED */
- }
- return(t);
-}
-
-/* VARARGS1 */
-/* ARGSUSED */
-void
-printf(s) /* yyparse calls it */
-char *s;
-{
-}
-
diff --git a/src/bin/sh/sh3.c b/src/bin/sh/sh3.c
deleted file mode 100644
index b67c426..0000000
--- a/src/bin/sh/sh3.c
+++ /dev/null
@@ -1,1142 +0,0 @@
-#define Extern extern
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#undef NULL
-#include "sh.h"
-
-/* -------- exec.c -------- */
-/* #include "sh.h" */
-
-/*
- * execute tree
- */
-
-static char *signame[] = {
- "Signal 0",
- "Hangup",
- (char *)NULL, /* interrupt */
- "Quit",
- "Illegal instruction",
- "Trace/BPT trap",
- "Abort",
- "EMT trap",
- "Floating exception",
- "Killed",
- "Bus error",
- "Memory fault",
- "Bad system call",
- (char *)NULL, /* broken pipe */
- "Alarm clock",
- "Terminated",
-};
-#define NSIGNAL (sizeof(signame)/sizeof(signame[0]))
-
-
-_PROTOTYPE(static int forkexec, (struct op *t, int *pin, int *pout, int act, char **wp, int *pforked ));
-_PROTOTYPE(static int parent, (void));
-_PROTOTYPE(int iosetup, (struct ioword *iop, int pipein, int pipeout ));
-_PROTOTYPE(static void echo, (char **wp ));
-_PROTOTYPE(static struct op **find1case, (struct op *t, char *w ));
-_PROTOTYPE(static struct op *findcase, (struct op *t, char *w ));
-_PROTOTYPE(static void brkset, (struct brkcon *bc ));
-_PROTOTYPE(int dolabel, (void));
-_PROTOTYPE(int dochdir, (struct op *t ));
-_PROTOTYPE(int doshift, (struct op *t ));
-_PROTOTYPE(int dologin, (struct op *t ));
-_PROTOTYPE(int doumask, (struct op *t ));
-_PROTOTYPE(int doexec, (struct op *t ));
-_PROTOTYPE(int dodot, (struct op *t ));
-_PROTOTYPE(int dowait, (struct op *t ));
-_PROTOTYPE(int doread, (struct op *t ));
-_PROTOTYPE(int doeval, (struct op *t ));
-_PROTOTYPE(int dotrap, (struct op *t ));
-_PROTOTYPE(int getsig, (char *s ));
-_PROTOTYPE(void setsig, (int n, void (*f)()));
-_PROTOTYPE(int getn, (char *as ));
-_PROTOTYPE(int dobreak, (struct op *t ));
-_PROTOTYPE(int docontinue, (struct op *t ));
-_PROTOTYPE(static int brkcontin, (char *cp, int val ));
-_PROTOTYPE(int doexit, (struct op *t ));
-_PROTOTYPE(int doexport, (struct op *t ));
-_PROTOTYPE(int doreadonly, (struct op *t ));
-_PROTOTYPE(static void rdexp, (char **wp, void (*f)(), int key));
-_PROTOTYPE(static void badid, (char *s ));
-_PROTOTYPE(int doset, (struct op *t ));
-_PROTOTYPE(void varput, (char *s, int out ));
-_PROTOTYPE(int dotimes, (void));
-
-int
-execute(t, pin, pout, act)
-register struct op *t;
-int *pin, *pout;
-int act;
-{
- register struct op *t1;
- int i, pv[2], rv, child, a;
- char *cp, **wp, **wp2;
- struct var *vp;
- struct brkcon bc;
-
- if (t == NULL)
- return(0);
- rv = 0;
- a = areanum++;
- wp = (wp2 = t->words) != NULL
- ? eval(wp2, t->type == TCOM ? DOALL : DOALL & ~DOKEY)
- : NULL;
-
- switch(t->type) {
- case TPAREN:
- case TCOM:
- rv = forkexec(t, pin, pout, act, wp, &child);
- if (child) {
- exstat = rv;
- leave();
- }
- break;
-
- case TPIPE:
- if ((rv = openpipe(pv)) < 0)
- break;
- pv[0] = remap(pv[0]);
- pv[1] = remap(pv[1]);
- (void) execute(t->left, pin, pv, 0);
- rv = execute(t->right, pv, pout, 0);
- break;
-
- case TLIST:
- (void) execute(t->left, pin, pout, 0);
- rv = execute(t->right, pin, pout, 0);
- break;
-
- case TASYNC:
- i = parent();
- if (i != 0) {
- if (i != -1) {
- setval(lookup("!"), putn(i));
- if (pin != NULL)
- closepipe(pin);
- if (talking) {
- prs(putn(i));
- prs("\n");
- }
- } else
- rv = -1;
- setstatus(rv);
- } else {
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- if (talking)
- signal(SIGTERM, SIG_DFL);
- talking = 0;
- if (pin == NULL) {
- close(0);
- open("/dev/null", 0);
- }
- exit(execute(t->left, pin, pout, FEXEC));
- }
- break;
-
- case TOR:
- case TAND:
- rv = execute(t->left, pin, pout, 0);
- if ((t1 = t->right)!=NULL && (rv == 0) == (t->type == TAND))
- rv = execute(t1, pin, pout, 0);
- break;
-
- case TFOR:
- if (wp == NULL) {
- wp = dolv+1;
- if ((i = dolc) < 0)
- i = 0;
- } else {
- i = -1;
- while (*wp++ != NULL)
- ;
- }
- vp = lookup(t->str);
- while (setjmp(bc.brkpt))
- if (isbreak)
- goto broken;
- brkset(&bc);
- for (t1 = t->left; i-- && *wp != NULL;) {
- setval(vp, *wp++);
- rv = execute(t1, pin, pout, 0);
- }
- brklist = brklist->nextlev;
- break;
-
- case TWHILE:
- case TUNTIL:
- while (setjmp(bc.brkpt))
- if (isbreak)
- goto broken;
- brkset(&bc);
- t1 = t->left;
- while ((execute(t1, pin, pout, 0) == 0) == (t->type == TWHILE))
- rv = execute(t->right, pin, pout, 0);
- brklist = brklist->nextlev;
- break;
-
- case TIF:
- case TELIF:
- if (t->right != NULL) {
- rv = !execute(t->left, pin, pout, 0) ?
- execute(t->right->left, pin, pout, 0):
- execute(t->right->right, pin, pout, 0);
- }
- break;
-
- case TCASE:
- if ((cp = evalstr(t->str, DOSUB|DOTRIM)) == 0)
- cp = "";
- if ((t1 = findcase(t->left, cp)) != NULL)
- rv = execute(t1, pin, pout, 0);
- break;
-
- case TBRACE:
-/*
- if (iopp = t->ioact)
- while (*iopp)
- if (iosetup(*iopp++, pin!=NULL, pout!=NULL)) {
- rv = -1;
- break;
- }
-*/
- if (rv >= 0 && (t1 = t->left))
- rv = execute(t1, pin, pout, 0);
- break;
- }
-
-broken:
- t->words = wp2;
- isbreak = 0;
- freehere(areanum);
- freearea(areanum);
- areanum = a;
- if (talking && intr) {
- closeall();
- fail();
- }
- if ((i = trapset) != 0) {
- trapset = 0;
- runtrap(i);
- }
- return(rv);
-}
-
-static int
-forkexec(t, pin, pout, act, wp, pforked)
-register struct op *t;
-int *pin, *pout;
-int act;
-char **wp;
-int *pforked;
-{
- int i, rv, (*shcom)();
- register int f;
- char *cp;
- struct ioword **iopp;
- int resetsig;
- char **owp;
-
- owp = wp;
- resetsig = 0;
- *pforked = 0;
- shcom = NULL;
- rv = -1; /* system-detected error */
- if (t->type == TCOM) {
- while ((cp = *wp++) != NULL)
- ;
- cp = *wp;
-
- /* strip all initial assignments */
- /* not correct wrt PATH=yyy command etc */
- if (flag['x'])
- echo (cp ? wp: owp);
- if (cp == NULL && t->ioact == NULL) {
- while ((cp = *owp++) != NULL && assign(cp, COPYV))
- ;
- return(setstatus(0));
- }
- else if (cp != NULL)
- shcom = inbuilt(cp);
- }
- t->words = wp;
- f = act;
- if (shcom == NULL && (f & FEXEC) == 0) {
- i = parent();
- if (i != 0) {
- if (i == -1)
- return(rv);
- if (pin != NULL)
- closepipe(pin);
- return(pout==NULL? setstatus(waitfor(i,0)): 0);
- }
- if (talking) {
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- resetsig = 1;
- }
- talking = 0;
- intr = 0;
- (*pforked)++;
- brklist = 0;
- execflg = 0;
- }
- if (owp != NULL)
- while ((cp = *owp++) != NULL && assign(cp, COPYV))
- if (shcom == NULL)
- export(lookup(cp));
-#ifdef COMPIPE
- if ((pin != NULL || pout != NULL) && shcom != NULL && shcom != doexec) {
- err("piping to/from shell builtins not yet done");
- return(-1);
- }
-#endif
- if (pin != NULL) {
- dup2(pin[0], 0);
- closepipe(pin);
- }
- if (pout != NULL) {
- dup2(pout[1], 1);
- closepipe(pout);
- }
- if ((iopp = t->ioact) != NULL) {
- if (shcom != NULL && shcom != doexec) {
- prs(cp);
- err(": cannot redirect shell command");
- return(-1);
- }
- while (*iopp)
- if (iosetup(*iopp++, pin!=NULL, pout!=NULL))
- return(rv);
- }
- if (shcom)
- return(setstatus((*shcom)(t)));
- /* should use FIOCEXCL */
- for (i=FDBASE; itype == TPAREN)
- exit(execute(t->left, NOPIPE, NOPIPE, FEXEC));
- if (wp[0] == NULL)
- exit(0);
- cp = rexecve(wp[0], wp, makenv());
- prs(wp[0]); prs(": "); warn(cp);
- if (!execflg)
- trap[0] = NULL;
- leave();
- /* NOTREACHED */
-}
-
-/*
- * common actions when creating a new child
- */
-static int
-parent()
-{
- register int i;
-
- i = fork();
- if (i != 0) {
- if (i == -1)
- warn("try again");
- }
- return(i);
-}
-
-/*
- * 0< 1> are ignored as required
- * within pipelines.
- */
-int
-iosetup(iop, pipein, pipeout)
-register struct ioword *iop;
-int pipein, pipeout;
-{
- register u;
- char *cp, *msg;
-
- if (iop->io_unit == IODEFAULT) /* take default */
- iop->io_unit = iop->io_flag&(IOREAD|IOHERE)? 0: 1;
- if (pipein && iop->io_unit == 0)
- return(0);
- if (pipeout && iop->io_unit == 1)
- return(0);
- msg = iop->io_flag&(IOREAD|IOHERE)? "open": "create";
- if ((iop->io_flag & IOHERE) == 0) {
- cp = iop->io_name;
- if ((cp = evalstr(cp, DOSUB|DOTRIM)) == NULL)
- return(1);
- }
- if (iop->io_flag & IODUP) {
- if (cp[1] || (!digit(*cp) && *cp != '-')) {
- prs(cp);
- err(": illegal >& argument");
- return(1);
- }
- if (*cp == '-')
- iop->io_flag = IOCLOSE;
- iop->io_flag &= ~(IOREAD|IOWRITE);
- }
- switch (iop->io_flag) {
- case IOREAD:
- u = open(cp, 0);
- break;
-
- case IOHERE:
- case IOHERE|IOXHERE:
- u = herein(iop->io_name, iop->io_flag&IOXHERE);
- cp = "here file";
- break;
-
- case IOWRITE|IOCAT:
- if ((u = open(cp, 1)) >= 0) {
- lseek(u, (long)0, 2);
- break;
- }
- case IOWRITE:
- u = creat(cp, 0666);
- break;
-
- case IODUP:
- u = dup2(*cp-'0', iop->io_unit);
- break;
-
- case IOCLOSE:
- close(iop->io_unit);
- return(0);
- }
- if (u < 0) {
- prs(cp);
- prs(": cannot ");
- warn(msg);
- return(1);
- } else {
- if (u != iop->io_unit) {
- dup2(u, iop->io_unit);
- close(u);
- }
- }
- return(0);
-}
-
-static void
-echo(wp)
-register char **wp;
-{
- register i;
-
- prs("+");
- for (i=0; wp[i]; i++) {
- if (i)
- prs(" ");
- prs(wp[i]);
- }
- prs("\n");
-}
-
-static struct op **
-find1case(t, w)
-struct op *t;
-char *w;
-{
- register struct op *t1;
- struct op **tp;
- register char **wp, *cp;
-
- if (t == NULL)
- return((struct op **)NULL);
- if (t->type == TLIST) {
- if ((tp = find1case(t->left, w)) != NULL)
- return(tp);
- t1 = t->right; /* TPAT */
- } else
- t1 = t;
- for (wp = t1->words; *wp;)
- if ((cp = evalstr(*wp++, DOSUB)) && gmatch(w, cp))
- return(&t1->left);
- return((struct op **)NULL);
-}
-
-static struct op *
-findcase(t, w)
-struct op *t;
-char *w;
-{
- register struct op **tp;
-
- return((tp = find1case(t, w)) != NULL? *tp: (struct op *)NULL);
-}
-
-/*
- * Enter a new loop level (marked for break/continue).
- */
-static void
-brkset(bc)
-struct brkcon *bc;
-{
- bc->nextlev = brklist;
- brklist = bc;
-}
-
-/*
- * Wait for the last process created.
- * Print a message for each process found
- * that was killed by a signal.
- * Ignore interrupt signals while waiting
- * unless `canintr' is true.
- */
-int
-waitfor(lastpid, canintr)
-register int lastpid;
-int canintr;
-{
- register int pid, rv;
- int s;
- int oheedint = heedint;
-
- heedint = 0;
- rv = 0;
- do {
- pid = wait(&s);
- if (pid == -1) {
- if (errno != EINTR || canintr)
- break;
- } else {
- if ((rv = WAITSIG(s)) != 0) {
- if (rv < NSIGNAL) {
- if (signame[rv] != NULL) {
- if (pid != lastpid) {
- prn(pid);
- prs(": ");
- }
- prs(signame[rv]);
- }
- } else {
- if (pid != lastpid) {
- prn(pid);
- prs(": ");
- }
- prs("Signal "); prn(rv); prs(" ");
- }
- if (WAITCORE(s))
- prs(" - core dumped");
- if (rv >= NSIGNAL || signame[rv])
- prs("\n");
- rv = -1;
- } else
- rv = WAITVAL(s);
- }
- } while (pid != lastpid);
- heedint = oheedint;
- if (intr)
- if (talking) {
- if (canintr)
- intr = 0;
- } else {
- if (exstat == 0) exstat = rv;
- onintr(0);
- }
- return(rv);
-}
-
-int
-setstatus(s)
-register int s;
-{
- exstat = s;
- setval(lookup("?"), putn(s));
- return(s);
-}
-
-/*
- * PATH-searching interface to execve.
- * If getenv("PATH") were kept up-to-date,
- * execvp might be used.
- */
-char *
-rexecve(c, v, envp)
-char *c, **v, **envp;
-{
- register int i;
- register char *sp, *tp;
- int eacces = 0, asis = 0;
-
- sp = any('/', c)? "": path->value;
- asis = *sp == '\0';
- while (asis || *sp != '\0') {
- asis = 0;
- tp = e.linep;
- for (; *sp != '\0'; tp++)
- if ((*tp = *sp++) == ':') {
- asis = *sp == '\0';
- break;
- }
- if (tp != e.linep)
- *tp++ = '/';
- for (i = 0; (*tp++ = c[i++]) != '\0';)
- ;
- execve(e.linep, v, envp);
- switch (errno) {
- case ENOEXEC:
- *v = e.linep;
- tp = *--v;
- *v = e.linep;
- execve("/bin/sh", v, envp);
- *v = tp;
- return("no Shell");
-
- case ENOMEM:
- return("program too big");
-
- case E2BIG:
- return("argument list too long");
-
- case EACCES:
- eacces++;
- break;
- }
- }
- return(errno==ENOENT ? "not found" : "cannot execute");
-}
-
-/*
- * Run the command produced by generator `f'
- * applied to stream `arg'.
- */
-int
-run(argp, f)
-struct ioarg *argp;
-int (*f)();
-{
- struct op *otree;
- struct wdblock *swdlist;
- struct wdblock *siolist;
- jmp_buf ev, rt;
- xint *ofail;
- int rv;
-
- areanum++;
- swdlist = wdlist;
- siolist = iolist;
- otree = outtree;
- ofail = failpt;
- rv = -1;
- if (newenv(setjmp(errpt = ev)) == 0) {
- wdlist = 0;
- iolist = 0;
- pushio(argp, f);
- e.iobase = e.iop;
- yynerrs = 0;
- if (setjmp(failpt = rt) == 0 && yyparse() == 0)
- rv = execute(outtree, NOPIPE, NOPIPE, 0);
- quitenv();
- }
- wdlist = swdlist;
- iolist = siolist;
- failpt = ofail;
- outtree = otree;
- freearea(areanum--);
- return(rv);
-}
-
-/* -------- do.c -------- */
-/* #include "sh.h" */
-
-/*
- * built-in commands: doX
- */
-
-int
-dolabel()
-{
- return(0);
-}
-
-int
-dochdir(t)
-register struct op *t;
-{
- register char *cp, *er;
-
- if ((cp = t->words[1]) == NULL && (cp = homedir->value) == NULL)
- er = ": no home directory";
- else if(chdir(cp) < 0)
- er = ": bad directory";
- else
- return(0);
- prs(cp != NULL? cp: "cd");
- err(er);
- return(1);
-}
-
-int
-doshift(t)
-register struct op *t;
-{
- register n;
-
- n = t->words[1]? getn(t->words[1]): 1;
- if(dolc < n) {
- err("nothing to shift");
- return(1);
- }
- dolv[n] = dolv[0];
- dolv += n;
- dolc -= n;
- setval(lookup("#"), putn(dolc));
- return(0);
-}
-
-/*
- * execute login and newgrp directly
- */
-int
-dologin(t)
-struct op *t;
-{
- register char *cp;
-
- if (talking) {
- signal(SIGINT, SIG_DFL);
- signal(SIGQUIT, SIG_DFL);
- }
- cp = rexecve(t->words[0], t->words, makenv());
- prs(t->words[0]); prs(": "); err(cp);
- return(1);
-}
-
-int
-doumask(t)
-register struct op *t;
-{
- register int i, n;
- register char *cp;
-
- if ((cp = t->words[1]) == NULL) {
- i = umask(0);
- umask(i);
- for (n=3*4; (n-=3) >= 0;)
- putc('0'+((i>>n)&07));
- putc('\n');
- } else {
- for (n=0; *cp>='0' && *cp<='9'; cp++)
- n = n*8 + (*cp-'0');
- umask(n);
- }
- return(0);
-}
-
-int
-doexec(t)
-register struct op *t;
-{
- register i;
- jmp_buf ex;
- xint *ofail;
-
- t->ioact = NULL;
- for(i = 0; (t->words[i]=t->words[i+1]) != NULL; i++)
- ;
- if (i == 0)
- return(1);
- execflg = 1;
- ofail = failpt;
- if (setjmp(failpt = ex) == 0)
- execute(t, NOPIPE, NOPIPE, FEXEC);
- failpt = ofail;
- execflg = 0;
- return(1);
-}
-
-int
-dodot(t)
-struct op *t;
-{
- register i;
- register char *sp, *tp;
- char *cp;
-
- if ((cp = t->words[1]) == NULL)
- return(0);
- sp = any('/', cp)? ":": path->value;
- while (*sp) {
- tp = e.linep;
- while (*sp && (*tp = *sp++) != ':')
- tp++;
- if (tp != e.linep)
- *tp++ = '/';
- for (i = 0; (*tp++ = cp[i++]) != '\0';)
- ;
- if ((i = open(e.linep, 0)) >= 0) {
- exstat = 0;
- next(remap(i));
- return(exstat);
- }
- }
- prs(cp);
- err(": not found");
- return(-1);
-}
-
-int
-dowait(t)
-struct op *t;
-{
- register i;
- register char *cp;
-
- if ((cp = t->words[1]) != NULL) {
- i = getn(cp);
- if (i == 0)
- return(0);
- } else
- i = -1;
- setstatus(waitfor(i, 1));
- return(0);
-}
-
-int
-doread(t)
-struct op *t;
-{
- register char *cp, **wp;
- register nb;
- register int nl = 0;
-
- if (t->words[1] == NULL) {
- err("Usage: read name ...");
- return(1);
- }
- for (wp = t->words+1; *wp; wp++) {
- for (cp = e.linep; !nl && cp < elinep-1; cp++)
- if ((nb = read(0, cp, sizeof(*cp))) != sizeof(*cp) ||
- (nl = (*cp == '\n')) ||
- (wp[1] && any(*cp, ifs->value)))
- break;
- *cp = 0;
- if (nb <= 0)
- break;
- setval(lookup(*wp), e.linep);
- }
- return(nb <= 0);
-}
-
-int
-doeval(t)
-register struct op *t;
-{
- return(RUN(awordlist, t->words+1, wdchar));
-}
-
-int
-dotrap(t)
-register struct op *t;
-{
- register int n, i;
- register int resetsig;
-
- if (t->words[1] == NULL) {
- for (i=0; i<=_NSIG; i++)
- if (trap[i]) {
- prn(i);
- prs(": ");
- prs(trap[i]);
- prs("\n");
- }
- return(0);
- }
- resetsig = digit(*t->words[1]);
- for (i = resetsig ? 1 : 2; t->words[i] != NULL; ++i) {
- n = getsig(t->words[i]);
- xfree(trap[n]);
- trap[n] = 0;
- if (!resetsig) {
- if (*t->words[1] != '\0') {
- trap[n] = strsave(t->words[1], 0);
- setsig(n, sig);
- } else
- setsig(n, SIG_IGN);
- } else {
- if (talking)
- if (n == SIGINT)
- setsig(n, onintr);
- else
- setsig(n, n == SIGQUIT ? SIG_IGN
- : SIG_DFL);
- else
- setsig(n, SIG_DFL);
- }
- }
- return(0);
-}
-
-int
-getsig(s)
-char *s;
-{
- register int n;
-
- if ((n = getn(s)) < 0 || n > _NSIG) {
- err("trap: bad signal number");
- n = 0;
- }
- return(n);
-}
-
-void
-setsig(n, f)
-register n;
-_PROTOTYPE(void (*f), (int));
-{
- if (n == 0)
- return;
- if (signal(n, SIG_IGN) != SIG_IGN || ourtrap[n]) {
- ourtrap[n] = 1;
- signal(n, f);
- }
-}
-
-int
-getn(as)
-char *as;
-{
- register char *s;
- register n, m;
-
- s = as;
- m = 1;
- if (*s == '-') {
- m = -1;
- s++;
- }
- for (n = 0; digit(*s); s++)
- n = (n*10) + (*s-'0');
- if (*s) {
- prs(as);
- err(": bad number");
- }
- return(n*m);
-}
-
-int
-dobreak(t)
-struct op *t;
-{
- return(brkcontin(t->words[1], 1));
-}
-
-int
-docontinue(t)
-struct op *t;
-{
- return(brkcontin(t->words[1], 0));
-}
-
-static int
-brkcontin(cp, val)
-register char *cp;
-int val;
-{
- register struct brkcon *bc;
- register nl;
-
- nl = cp == NULL? 1: getn(cp);
- if (nl <= 0)
- nl = 999;
- do {
- if ((bc = brklist) == NULL)
- break;
- brklist = bc->nextlev;
- } while (--nl);
- if (nl) {
- err("bad break/continue level");
- return(1);
- }
- isbreak = val;
- longjmp(bc->brkpt, 1);
- /* NOTREACHED */
-}
-
-int
-doexit(t)
-struct op *t;
-{
- register char *cp;
-
- execflg = 0;
- if ((cp = t->words[1]) != NULL)
- setstatus(getn(cp));
- leave();
- /* NOTREACHED */
-}
-
-int
-doexport(t)
-struct op *t;
-{
- rdexp(t->words+1, export, EXPORT);
- return(0);
-}
-
-int
-doreadonly(t)
-struct op *t;
-{
- rdexp(t->words+1, ronly, RONLY);
- return(0);
-}
-
-static void
-rdexp(wp, f, key)
-register char **wp;
-void (*f)();
-int key;
-{
- if (*wp != NULL) {
- for (; *wp != NULL; wp++)
- if (checkname(*wp))
- (*f)(lookup(*wp));
- else
- badid(*wp);
- } else
- putvlist(key, 1);
-}
-
-static void
-badid(s)
-register char *s;
-{
- prs(s);
- err(": bad identifier");
-}
-
-int
-doset(t)
-register struct op *t;
-{
- register struct var *vp;
- register char *cp;
- register n;
-
- if ((cp = t->words[1]) == NULL) {
- for (vp = vlist; vp; vp = vp->next)
- varput(vp->name, 1);
- return(0);
- }
- if (*cp == '-') {
- /* bad: t->words++; */
- for(n = 0; (t->words[n]=t->words[n+1]) != NULL; n++)
- ;
- if (*++cp == 0)
- flag['x'] = flag['v'] = 0;
- else
- for (; *cp; cp++)
- switch (*cp) {
- case 'e':
- if (!talking)
- flag['e']++;
- break;
-
- default:
- if (*cp>='a' && *cp<='z')
- flag[*cp]++;
- break;
- }
- setdash();
- }
- if (t->words[1]) {
- t->words[0] = dolv[0];
- for (n=1; t->words[n]; n++)
- setarea((char *)t->words[n], 0);
- dolc = n-1;
- dolv = t->words;
- setval(lookup("#"), putn(dolc));
- setarea((char *)(dolv-1), 0);
- }
- return(0);
-}
-
-void
-varput(s, out)
-register char *s;
-int out;
-{
- if (letnum(*s)) {
- write(out, s, strlen(s));
- write(out, "\n", 1);
- }
-}
-
-
-#define SECS 60L
-#define MINS 3600L
-
-int
-dotimes()
-{
- struct tms tbuf;
-
- times(&tbuf);
-
- prn((int)(tbuf.tms_cutime / MINS));
- prs("m");
- prn((int)((tbuf.tms_cutime % MINS) / SECS));
- prs("s ");
- prn((int)(tbuf.tms_cstime / MINS));
- prs("m");
- prn((int)((tbuf.tms_cstime % MINS) / SECS));
- prs("s\n");
- return(0);
-}
-
-struct builtin {
- char *command;
- int (*fn)();
-};
-static struct builtin builtin[] = {
- ":", dolabel,
- "cd", dochdir,
- "shift", doshift,
- "exec", doexec,
- "wait", dowait,
- "read", doread,
- "eval", doeval,
- "trap", dotrap,
- "break", dobreak,
- "continue", docontinue,
- "exit", doexit,
- "export", doexport,
- "readonly", doreadonly,
- "set", doset,
- ".", dodot,
- "umask", doumask,
- "login", dologin,
- "newgrp", dologin,
- "times", dotimes,
- 0,
-};
-
-int (*inbuilt(s))()
-register char *s;
-{
- register struct builtin *bp;
-
- for (bp = builtin; bp->command != NULL; bp++)
- if (strcmp(bp->command, s) == 0)
- return(bp->fn);
- return((int(*)())NULL);
-}
-
diff --git a/src/bin/sh/sh4.c b/src/bin/sh/sh4.c
deleted file mode 100644
index 7308b41..0000000
--- a/src/bin/sh/sh4.c
+++ /dev/null
@@ -1,765 +0,0 @@
-#define Extern extern
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include "sh.h"
-
-/* -------- eval.c -------- */
-/* #include "sh.h" */
-/* #include "word.h" */
-
-/*
- * ${}
- * `command`
- * blank interpretation
- * quoting
- * glob
- */
-
-_PROTOTYPE(static int expand, (char *cp, struct wdblock **wbp, int f ));
-_PROTOTYPE(static char *blank, (int f ));
-_PROTOTYPE(static int dollar, (int quoted ));
-_PROTOTYPE(static int grave, (int quoted ));
-_PROTOTYPE(void globname, (char *we, char *pp ));
-_PROTOTYPE(static char *generate, (char *start1, char *end1, char *middle, char *end ));
-_PROTOTYPE(static int anyspcl, (struct wdblock *wb ));
-_PROTOTYPE(static int xstrcmp, (char *p1, char *p2 ));
-_PROTOTYPE(void glob0, (char *a0, unsigned int a1, int a2, int (*a3)(char *, char *)));
-_PROTOTYPE(void glob1, (char *base, char *lim ));
-_PROTOTYPE(void glob2, (char *i, char *j ));
-_PROTOTYPE(void glob3, (char *i, char *j, char *k ));
-_PROTOTYPE(char *memcopy, (char *ato, char *from, int nb ));
-
-char **
-eval(ap, f)
-register char **ap;
-int f;
-{
- struct wdblock *wb;
- char **wp;
- char **wf;
- jmp_buf ev;
-
- wp = NULL;
- wb = NULL;
- wf = NULL;
- if (newenv(setjmp(errpt = ev)) == 0) {
- while (*ap && isassign(*ap))
- expand(*ap++, &wb, f & ~DOGLOB);
- if (flag['k']) {
- for (wf = ap; *wf; wf++) {
- if (isassign(*wf))
- expand(*wf, &wb, f & ~DOGLOB);
- }
- }
- for (wb = addword((char *)0, wb); *ap; ap++) {
- if (!flag['k'] || !isassign(*ap))
- expand(*ap, &wb, f & ~DOKEY);
- }
- wb = addword((char *)0, wb);
- wp = getwords(wb);
- quitenv();
- } else
- gflg = 1;
- return(gflg? (char **)NULL: wp);
-}
-
-/*
- * Make the exported environment from the exported
- * names in the dictionary. Keyword assignments
- * will already have been done.
- */
-char **
-makenv()
-
-{
- register struct wdblock *wb;
- register struct var *vp;
-
- wb = NULL;
- for (vp = vlist; vp; vp = vp->next)
- if (vp->status & EXPORT)
- wb = addword(vp->name, wb);
- wb = addword((char *)0, wb);
- return(getwords(wb));
-}
-
-char *
-evalstr(cp, f)
-register char *cp;
-int f;
-{
- struct wdblock *wb;
-
- wb = NULL;
- if (expand(cp, &wb, f)) {
- if (wb == NULL || wb->w_nword == 0 || (cp = wb->w_words[0]) == NULL)
- cp = "";
- DELETE(wb);
- } else
- cp = NULL;
- return(cp);
-}
-
-static int
-expand(cp, wbp, f)
-register char *cp;
-register struct wdblock **wbp;
-int f;
-{
- jmp_buf ev;
-
- gflg = 0;
- if (cp == NULL)
- return(0);
- if (!anys("$`'\"", cp) &&
- !anys(ifs->value, cp) &&
- ((f&DOGLOB)==0 || !anys("[*?", cp))) {
- cp = strsave(cp, areanum);
- if (f & DOTRIM)
- unquote(cp);
- *wbp = addword(cp, *wbp);
- return(1);
- }
- if (newenv(setjmp(errpt = ev)) == 0) {
- PUSHIO(aword, cp, strchar);
- e.iobase = e.iop;
- while ((cp = blank(f)) && gflg == 0) {
- e.linep = cp;
- cp = strsave(cp, areanum);
- if ((f&DOGLOB) == 0) {
- if (f & DOTRIM)
- unquote(cp);
- *wbp = addword(cp, *wbp);
- } else
- *wbp = glob(cp, *wbp);
- }
- quitenv();
- } else
- gflg = 1;
- return(gflg == 0);
-}
-
-/*
- * Blank interpretation and quoting
- */
-static char *
-blank(f)
-int f;
-{
- register c, c1;
- register char *sp;
- int scanequals, foundequals;
-
- sp = e.linep;
- scanequals = f & DOKEY;
- foundequals = 0;
-
-loop:
- switch (c = subgetc('"', foundequals)) {
- case 0:
- if (sp == e.linep)
- return(0);
- *e.linep++ = 0;
- return(sp);
-
- default:
- if (f & DOBLANK && any(c, ifs->value))
- goto loop;
- break;
-
- case '"':
- case '\'':
- scanequals = 0;
- if (INSUB())
- break;
- for (c1 = c; (c = subgetc(c1, 1)) != c1;) {
- if (c == 0)
- break;
- if (c == '\'' || !any(c, "$`\""))
- c |= QUOTE;
- *e.linep++ = c;
- }
- c = 0;
- }
- unget(c);
- if (!letter(c))
- scanequals = 0;
- for (;;) {
- c = subgetc('"', foundequals);
- if (c == 0 ||
- f & (DOBLANK && any(c, ifs->value)) ||
- (!INSUB() && any(c, "\"'"))) {
- scanequals = 0;
- unget(c);
- if (any(c, "\"'"))
- goto loop;
- break;
- }
- if (scanequals)
- if (c == '=') {
- foundequals = 1;
- scanequals = 0;
- }
- else if (!letnum(c))
- scanequals = 0;
- *e.linep++ = c;
- }
- *e.linep++ = 0;
- return(sp);
-}
-
-/*
- * Get characters, substituting for ` and $
- */
-int
-subgetc(ec, quoted)
-register char ec;
-int quoted;
-{
- register char c;
-
-again:
- c = getc(ec);
- if (!INSUB() && ec != '\'') {
- if (c == '`') {
- if (grave(quoted) == 0)
- return(0);
- e.iop->task = XGRAVE;
- goto again;
- }
- if (c == '$' && (c = dollar(quoted)) == 0) {
- e.iop->task = XDOLL;
- goto again;
- }
- }
- return(c);
-}
-
-/*
- * Prepare to generate the string returned by ${} substitution.
- */
-static int
-dollar(quoted)
-int quoted;
-{
- int otask;
- struct io *oiop;
- char *dolp;
- register char *s, c, *cp;
- struct var *vp;
-
- c = readc();
- s = e.linep;
- if (c != '{') {
- *e.linep++ = c;
- if (letter(c)) {
- while ((c = readc())!=0 && letnum(c))
- if (e.linep < elinep)
- *e.linep++ = c;
- unget(c);
- }
- c = 0;
- } else {
- oiop = e.iop;
- otask = e.iop->task;
- e.iop->task = XOTHER;
- while ((c = subgetc('"', 0))!=0 && c!='}' && c!='\n')
- if (e.linep < elinep)
- *e.linep++ = c;
- if (oiop == e.iop)
- e.iop->task = otask;
- if (c != '}') {
- err("unclosed ${");
- gflg++;
- return(c);
- }
- }
- if (e.linep >= elinep) {
- err("string in ${} too long");
- gflg++;
- e.linep -= 10;
- }
- *e.linep = 0;
- if (*s)
- for (cp = s+1; *cp; cp++)
- if (any(*cp, "=-+?")) {
- c = *cp;
- *cp++ = 0;
- break;
- }
- if (s[1] == 0 && (*s == '*' || *s == '@')) {
- if (dolc > 1) {
- /* currently this does not distinguish $* and $@ */
- /* should check dollar */
- e.linep = s;
- PUSHIO(awordlist, dolv+1, dolchar);
- return(0);
- } else { /* trap the nasty ${=} */
- s[0] = '1';
- s[1] = 0;
- }
- }
- vp = lookup(s);
- if ((dolp = vp->value) == null) {
- switch (c) {
- case '=':
- if (digit(*s)) {
- err("cannot use ${...=...} with $n");
- gflg++;
- break;
- }
- setval(vp, cp);
- dolp = vp->value;
- break;
-
- case '-':
- dolp = strsave(cp, areanum);
- break;
-
- case '?':
- if (*cp == 0) {
- prs("missing value for ");
- err(s);
- } else
- err(cp);
- gflg++;
- break;
- }
- } else if (c == '+')
- dolp = strsave(cp, areanum);
- if (flag['u'] && dolp == null) {
- prs("unset variable: ");
- err(s);
- gflg++;
- }
- e.linep = s;
- PUSHIO(aword, dolp, quoted ? qstrchar : strchar);
- return(0);
-}
-
-/*
- * Run the command in `...` and read its output.
- */
-static int
-grave(quoted)
-int quoted;
-{
- register char *cp;
- register int i;
- int pf[2];
-
- for (cp = e.iop->argp->aword; *cp != '`'; cp++)
- if (*cp == 0) {
- err("no closing `");
- return(0);
- }
- if (openpipe(pf) < 0)
- return(0);
- if ((i = fork()) == -1) {
- closepipe(pf);
- err("try again");
- return(0);
- }
- if (i != 0) {
- e.iop->argp->aword = ++cp;
- close(pf[1]);
- PUSHIO(afile, remap(pf[0]), quoted? qgravechar: gravechar);
- return(1);
- }
- *cp = 0;
- /* allow trapped signals */
- for (i=0; i<=_NSIG; i++)
- if (ourtrap[i] && signal(i, SIG_IGN) != SIG_IGN)
- signal(i, SIG_DFL);
- dup2(pf[1], 1);
- closepipe(pf);
- flag['e'] = 0;
- flag['v'] = 0;
- flag['n'] = 0;
- cp = strsave(e.iop->argp->aword, 0);
- areanum = 1;
- freehere(areanum);
- freearea(areanum); /* free old space */
- e.oenv = NULL;
- e.iop = (e.iobase = iostack) - 1;
- unquote(cp);
- talking = 0;
- PUSHIO(aword, cp, nlchar);
- onecommand();
- exit(1);
-}
-
-char *
-unquote(as)
-register char *as;
-{
- register char *s;
-
- if ((s = as) != NULL)
- while (*s)
- *s++ &= ~QUOTE;
- return(as);
-}
-
-/* -------- glob.c -------- */
-/* #include "sh.h" */
-
-/*
- * glob
- */
-
-#define scopy(x) strsave((x), areanum)
-#define BLKSIZ 512
-#define NDENT ((BLKSIZ+sizeof(struct direct)-1)/sizeof(struct direct))
-
-static struct wdblock *cl, *nl;
-static char spcl[] = "[?*";
-
-struct wdblock *
-glob(cp, wb)
-char *cp;
-struct wdblock *wb;
-{
- register i;
- register char *pp;
-
- if (cp == 0)
- return(wb);
- i = 0;
- for (pp = cp; *pp; pp++)
- if (any(*pp, spcl))
- i++;
- else if (!any(*pp & ~QUOTE, spcl))
- *pp &= ~QUOTE;
- if (i != 0) {
- for (cl = addword(scopy(cp), (struct wdblock *)0); anyspcl(cl); cl = nl) {
- nl = newword(cl->w_nword*2);
- for(i=0; iw_nword; i++) { /* for each argument */
- for (pp = cl->w_words[i]; *pp; pp++)
- if (any(*pp, spcl)) {
- globname(cl->w_words[i], pp);
- break;
- }
- if (*pp == '\0')
- nl = addword(scopy(cl->w_words[i]), nl);
- }
- for(i=0; iw_nword; i++)
- DELETE(cl->w_words[i]);
- DELETE(cl);
- }
- for(i=0; iw_nword; i++)
- unquote(cl->w_words[i]);
- glob0((char *)cl->w_words, cl->w_nword, sizeof(char *), xstrcmp);
- if (cl->w_nword) {
- for (i=0; iw_nword; i++)
- wb = addword(cl->w_words[i], wb);
- DELETE(cl);
- return(wb);
- }
- }
- wb = addword(unquote(cp), wb);
- return(wb);
-}
-
-void
-globname(we, pp)
-char *we;
-register char *pp;
-{
- register char *np, *cp;
- char *name, *gp, *dp;
- int dn, j, n, k;
- struct direct ent[NDENT];
- char dname[NAME_MAX+1];
- struct stat dbuf;
-
- for (np = we; np != pp; pp--)
- if (pp[-1] == '/')
- break;
- for (dp = cp = space((int)(pp-np)+3); np < pp;)
- *cp++ = *np++;
- *cp++ = '.';
- *cp = '\0';
- for (gp = cp = space(strlen(pp)+1); *np && *np != '/';)
- *cp++ = *np++;
- *cp = '\0';
- dn = open(dp, 0);
- if (dn < 0) {
- DELETE(dp);
- DELETE(gp);
- return;
- }
- dname[NAME_MAX] = '\0';
- while ((n = read(dn, (char *)ent, sizeof(ent))) >= sizeof(*ent)) {
- n /= sizeof(*ent);
- for (j=0; jw_words;
- for (i=0; iw_nword; i++)
- if (anys(spcl, *wd++))
- return(1);
- return(0);
-}
-
-static int
-xstrcmp(p1, p2)
-char *p1, *p2;
-{
- return(strcmp(*(char **)p1, *(char **)p2));
-}
-
-/* -------- word.c -------- */
-/* #include "sh.h" */
-/* #include "word.h" */
-
-#define NSTART 16 /* default number of words to allow for initially */
-
-struct wdblock *
-newword(nw)
-register int nw;
-{
- register struct wdblock *wb;
-
- wb = (struct wdblock *) space(sizeof(*wb) + nw*sizeof(char *));
- wb->w_bsize = nw;
- wb->w_nword = 0;
- return(wb);
-}
-
-struct wdblock *
-addword(wd, wb)
-char *wd;
-register struct wdblock *wb;
-{
- register struct wdblock *wb2;
- register nw;
-
- if (wb == NULL)
- wb = newword(NSTART);
- if ((nw = wb->w_nword) >= wb->w_bsize) {
- wb2 = newword(nw * 2);
- memcopy((char *)wb2->w_words, (char *)wb->w_words, nw*sizeof(char *));
- wb2->w_nword = nw;
- DELETE(wb);
- wb = wb2;
- }
- wb->w_words[wb->w_nword++] = wd;
- return(wb);
-}
-
-char **
-getwords(wb)
-register struct wdblock *wb;
-{
- register char **wd;
- register nb;
-
- if (wb == NULL)
- return((char **)NULL);
- if (wb->w_nword == 0) {
- DELETE(wb);
- return((char **)NULL);
- }
- wd = (char **) space(nb = sizeof(*wd) * wb->w_nword);
- memcopy((char *)wd, (char *)wb->w_words, nb);
- DELETE(wb); /* perhaps should done by caller */
- return(wd);
-}
-
-_PROTOTYPE(int (*func), (char *, char *));
-int globv;
-
-void
-glob0(a0, a1, a2, a3)
-char *a0;
-unsigned a1;
-int a2;
-_PROTOTYPE(int (*a3), (char *, char *));
-{
- func = a3;
- globv = a2;
- glob1(a0, a0 + a1 * a2);
-}
-
-void
-glob1(base, lim)
-char *base, *lim;
-{
- register char *i, *j;
- int v2;
- char *lptr, *hptr;
- int c;
- unsigned n;
-
-
- v2 = globv;
-
-top:
- if ((n=(int)(lim-base)) <= v2)
- return;
- n = v2 * (n / (2*v2));
- hptr = lptr = base+n;
- i = base;
- j = lim-v2;
- for(;;) {
- if (i < lptr) {
- if ((c = (*func)(i, lptr)) == 0) {
- glob2(i, lptr -= v2);
- continue;
- }
- if (c < 0) {
- i += v2;
- continue;
- }
- }
-
-begin:
- if (j > hptr) {
- if ((c = (*func)(hptr, j)) == 0) {
- glob2(hptr += v2, j);
- goto begin;
- }
- if (c > 0) {
- if (i == lptr) {
- glob3(i, hptr += v2, j);
- i = lptr += v2;
- goto begin;
- }
- glob2(i, j);
- j -= v2;
- i += v2;
- continue;
- }
- j -= v2;
- goto begin;
- }
-
-
- if (i == lptr) {
- if (lptr-base >= lim-hptr) {
- glob1(hptr+v2, lim);
- lim = lptr;
- } else {
- glob1(base, lptr);
- base = hptr+v2;
- }
- goto top;
- }
-
-
- glob3(j, lptr -= v2, i);
- j = hptr -= v2;
- }
-}
-
-void
-glob2(i, j)
-char *i, *j;
-{
- register char *index1, *index2, c;
- int m;
-
- m = globv;
- index1 = i;
- index2 = j;
- do {
- c = *index1;
- *index1++ = *index2;
- *index2++ = c;
- } while(--m);
-}
-
-void
-glob3(i, j, k)
-char *i, *j, *k;
-{
- register char *index1, *index2, *index3;
- int c;
- int m;
-
- m = globv;
- index1 = i;
- index2 = j;
- index3 = k;
- do {
- c = *index1;
- *index1++ = *index3;
- *index3++ = *index2;
- *index2++ = c;
- } while(--m);
-}
-
-char *
-memcopy(ato, from, nb)
-register char *ato, *from;
-register int nb;
-{
- register char *to;
-
- to = ato;
- while (--nb >= 0)
- *to++ = *from++;
- return(ato);
-}
diff --git a/src/bin/sh/sh5.c b/src/bin/sh/sh5.c
deleted file mode 100644
index 9786a6a..0000000
--- a/src/bin/sh/sh5.c
+++ /dev/null
@@ -1,674 +0,0 @@
-#define Extern extern
-#include
-#include
-#include
-#include
-#include "sh.h"
-
-/* -------- io.c -------- */
-/* #include "sh.h" */
-
-/*
- * shell IO
- */
-
-static struct iobuf sharedbuf = {AFID_NOBUF};
-static struct iobuf mainbuf = {AFID_NOBUF};
-static unsigned bufid = AFID_ID; /* buffer id counter */
-
-struct ioarg temparg = {0, 0, 0, AFID_NOBUF, 0};
-
-_PROTOTYPE(static void readhere, (char **name, char *s, int ec ));
-_PROTOTYPE(void pushio, (struct ioarg *argp, int (*fn)()));
-_PROTOTYPE(static int xxchar, (struct ioarg *ap ));
-_PROTOTYPE(void tempname, (char *tname ));
-
-int
-getc(ec)
-register int ec;
-{
- register int c;
-
- if(e.linep > elinep) {
- while((c=readc()) != '\n' && c)
- ;
- err("input line too long");
- gflg++;
- return(c);
- }
- c = readc();
- if (ec != '\'' && e.iop->task != XGRAVE) {
- if(c == '\\') {
- c = readc();
- if (c == '\n' && ec != '\"')
- return(getc(ec));
- c |= QUOTE;
- }
- }
- return(c);
-}
-
-void
-unget(c)
-int c;
-{
- if (e.iop >= e.iobase)
- e.iop->peekc = c;
-}
-
-int
-eofc()
-
-{
- return e.iop < e.iobase || (e.iop->peekc == 0 && e.iop->prev == 0);
-}
-
-int
-readc()
-{
- register c;
-
- for (; e.iop >= e.iobase; e.iop--)
- if ((c = e.iop->peekc) != '\0') {
- e.iop->peekc = 0;
- return(c);
- }
- else {
- if (e.iop->prev != 0) {
- if ((c = (*e.iop->iofn)(e.iop->argp, e.iop)) != '\0') {
- if (c == -1) {
- e.iop++;
- continue;
- }
- if (e.iop == iostack)
- ioecho(c);
- return(e.iop->prev = c);
- }
- else if (e.iop->task == XIO && e.iop->prev != '\n') {
- e.iop->prev = 0;
- if (e.iop == iostack)
- ioecho('\n');
- return '\n';
- }
- }
- if (e.iop->task == XIO) {
- if (multiline)
- return e.iop->prev = 0;
- if (talking && e.iop == iostack+1)
- prs(prompt->value);
- }
- }
- if (e.iop >= iostack)
- return(0);
- leave();
- /* NOTREACHED */
-}
-
-void
-ioecho(c)
-char c;
-{
- if (flag['v'])
- write(2, &c, sizeof c);
-}
-
-void
-pushio(argp, fn)
-struct ioarg *argp;
-int (*fn)();
-{
- if (++e.iop >= &iostack[NPUSH]) {
- e.iop--;
- err("Shell input nested too deeply");
- gflg++;
- return;
- }
- e.iop->iofn = fn;
-
- if (argp->afid != AFID_NOBUF)
- e.iop->argp = argp;
- else {
- e.iop->argp = ioargstack + (e.iop - iostack);
- *e.iop->argp = *argp;
- e.iop->argp->afbuf = e.iop == &iostack[0] ? &mainbuf : &sharedbuf;
- if (isatty(e.iop->argp->afile) == 0 &&
- (e.iop == &iostack[0] ||
- lseek(e.iop->argp->afile, 0L, 1) != -1)) {
- if (++bufid == AFID_NOBUF)
- bufid = AFID_ID;
- e.iop->argp->afid = bufid;
- }
- }
-
- e.iop->prev = ~'\n';
- e.iop->peekc = 0;
- e.iop->xchar = 0;
- e.iop->nlcount = 0;
- if (fn == filechar || fn == linechar)
- e.iop->task = XIO;
- else if (fn == gravechar || fn == qgravechar)
- e.iop->task = XGRAVE;
- else
- e.iop->task = XOTHER;
-}
-
-struct io *
-setbase(ip)
-struct io *ip;
-{
- register struct io *xp;
-
- xp = e.iobase;
- e.iobase = ip;
- return(xp);
-}
-
-/*
- * Input generating functions
- */
-
-/*
- * Produce the characters of a string, then a newline, then EOF.
- */
-int
-nlchar(ap)
-register struct ioarg *ap;
-{
- register int c;
-
- if (ap->aword == NULL)
- return(0);
- if ((c = *ap->aword++) == 0) {
- ap->aword = NULL;
- return('\n');
- }
- return(c);
-}
-
-/*
- * Given a list of words, produce the characters
- * in them, with a space after each word.
- */
-int
-wdchar(ap)
-register struct ioarg *ap;
-{
- register char c;
- register char **wl;
-
- if ((wl = ap->awordlist) == NULL)
- return(0);
- if (*wl != NULL) {
- if ((c = *(*wl)++) != 0)
- return(c & 0177);
- ap->awordlist++;
- return(' ');
- }
- ap->awordlist = NULL;
- return('\n');
-}
-
-/*
- * Return the characters of a list of words,
- * producing a space between them.
- */
-int
-dolchar(ap)
-register struct ioarg *ap;
-{
- register char *wp;
-
- if ((wp = *ap->awordlist++) != NULL) {
- PUSHIO(aword, wp, *ap->awordlist == NULL? strchar: xxchar);
- return(-1);
- }
- return(0);
-}
-
-static int
-xxchar(ap)
-register struct ioarg *ap;
-{
- register int c;
-
- if (ap->aword == NULL)
- return(0);
- if ((c = *ap->aword++) == '\0') {
- ap->aword = NULL;
- return(' ');
- }
- return(c);
-}
-
-/*
- * Produce the characters from a single word (string).
- */
-int
-strchar(ap)
-register struct ioarg *ap;
-{
- register int c;
-
- if (ap->aword == NULL || (c = *ap->aword++) == 0)
- return(0);
- return(c);
-}
-
-/*
- * Produce quoted characters from a single word (string).
- */
-int
-qstrchar(ap)
-register struct ioarg *ap;
-{
- register int c;
-
- if (ap->aword == NULL || (c = *ap->aword++) == 0)
- return(0);
- return(c|QUOTE);
-}
-
-/*
- * Return the characters from a file.
- */
-int
-filechar(ap)
-register struct ioarg *ap;
-{
- register int i;
- char c;
- struct iobuf *bp = ap->afbuf;
-
- if (ap->afid != AFID_NOBUF) {
- if ((i = ap->afid != bp->id) || bp->bufp == bp->ebufp) {
- if (i)
- lseek(ap->afile, ap->afpos, 0);
- do {
- i = read(ap->afile, bp->buf, sizeof(bp->buf));
- } while (i < 0 && errno == EINTR);
- if (i <= 0) {
- closef(ap->afile);
- return 0;
- }
- bp->id = ap->afid;
- bp->ebufp = (bp->bufp = bp->buf) + i;
- }
- ap->afpos++;
- return *bp->bufp++ & 0177;
- }
-
- do {
- i = read(ap->afile, &c, sizeof(c));
- } while (i < 0 && errno == EINTR);
- return(i == sizeof(c)? c&0177: (closef(ap->afile), 0));
-}
-
-/*
- * Return the characters from a here temp file.
- */
-int
-herechar(ap)
-register struct ioarg *ap;
-{
- char c;
-
-
- if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
- close(ap->afile);
- c = 0;
- }
- return (c);
-
-}
-
-/*
- * Return the characters produced by a process (`...`).
- * Quote them if required, and remove any trailing newline characters.
- */
-int
-gravechar(ap, iop)
-struct ioarg *ap;
-struct io *iop;
-{
- register int c;
-
- if ((c = qgravechar(ap, iop)&~QUOTE) == '\n')
- c = ' ';
- return(c);
-}
-
-int
-qgravechar(ap, iop)
-register struct ioarg *ap;
-struct io *iop;
-{
- register int c;
-
- if (iop->xchar) {
- if (iop->nlcount) {
- iop->nlcount--;
- return('\n'|QUOTE);
- }
- c = iop->xchar;
- iop->xchar = 0;
- } else if ((c = filechar(ap)) == '\n') {
- iop->nlcount = 1;
- while ((c = filechar(ap)) == '\n')
- iop->nlcount++;
- iop->xchar = c;
- if (c == 0)
- return(c);
- iop->nlcount--;
- c = '\n';
- }
- return(c!=0? c|QUOTE: 0);
-}
-
-/*
- * Return a single command (usually the first line) from a file.
- */
-int
-linechar(ap)
-register struct ioarg *ap;
-{
- register int c;
-
- if ((c = filechar(ap)) == '\n') {
- if (!multiline) {
- closef(ap->afile);
- ap->afile = -1; /* illegal value */
- }
- }
- return(c);
-}
-
-void
-prs(s)
-register char *s;
-{
- if (*s)
- write(2, s, strlen(s));
-}
-
-void
-putc(c)
-char c;
-{
- write(2, &c, sizeof c);
-}
-
-void
-prn(u)
-unsigned u;
-{
- prs(itoa(u, 0));
-}
-
-void
-closef(i)
-register int i;
-{
- if (i > 2)
- close(i);
-}
-
-void
-closeall()
-{
- register u;
-
- for (u=NUFILE; u= 0 && fd < e.iofd);
- for (i=0; ih_tag = evalstr(s, DOSUB);
- if (h->h_tag == 0)
- return;
- h->h_iop = iop;
- iop->io_name = 0;
- h->h_next = NULL;
- if (inhere == 0)
- inhere = h;
- else
- for (lh = inhere; lh!=NULL; lh = lh->h_next)
- if (lh->h_next == 0) {
- lh->h_next = h;
- break;
- }
- iop->io_flag |= IOHERE|IOXHERE;
- for (s = h->h_tag; *s; s++)
- if (*s & QUOTE) {
- iop->io_flag &= ~ IOXHERE;
- *s &= ~ QUOTE;
- }
- h->h_dosub = iop->io_flag & IOXHERE;
-}
-
-void
-gethere()
-{
- register struct here *h, *hp;
-
- /* Scan here files first leaving inhere list in place */
- for (hp = h = inhere; h != NULL; hp = h, h = h->h_next)
- readhere(&h->h_iop->io_name, h->h_tag, h->h_dosub? 0: '\'');
-
- /* Make inhere list active - keep list intact for scraphere */
- if (hp != NULL) {
- hp->h_next = acthere;
- acthere = inhere;
- inhere = NULL;
- }
-}
-
-static void
-readhere(name, s, ec)
-char **name;
-register char *s;
-int ec;
-{
- int tf;
- char tname[30];
- register c;
- jmp_buf ev;
- char line [LINELIM+1];
- char *next;
-
- tempname(tname);
- *name = strsave(tname, areanum);
- tf = creat(tname, 0600);
- if (tf < 0)
- return;
- if (newenv(setjmp(errpt = ev)) != 0)
- unlink(tname);
- else {
- pushio(e.iop->argp, e.iop->iofn);
- e.iobase = e.iop;
- for (;;) {
- if (talking && e.iop <= iostack)
- prs(cprompt->value);
- next = line;
- while ((c = getc(ec)) != '\n' && c) {
- if (ec == '\'')
- c &= ~ QUOTE;
- if (next >= &line[LINELIM]) {
- c = 0;
- break;
- }
- *next++ = c;
- }
- *next = 0;
- if (strcmp(s, line) == 0 || c == 0)
- break;
- *next++ = '\n';
- write (tf, line, (int)(next-line));
- }
- if (c == 0) {
- prs("here document `"); prs(s); err("' unclosed");
- }
- quitenv();
- }
- close(tf);
-}
-
-/*
- * open here temp file.
- * if unquoted here, expand here temp file into second temp file.
- */
-int
-herein(hname, xdoll)
-char *hname;
-int xdoll;
-{
- register hf, tf;
-
- if (hname == 0)
- return(-1);
- hf = open(hname, 0);
- if (hf < 0)
- return (-1);
- if (xdoll) {
- char c;
- char tname[30];
- jmp_buf ev;
-
- tempname(tname);
- if ((tf = creat(tname, 0600)) < 0)
- return (-1);
- if (newenv(setjmp(errpt = ev)) == 0) {
- PUSHIO(afile, hf, herechar);
- setbase(e.iop);
- while ((c = subgetc(0, 0)) != 0) {
- c &= ~ QUOTE;
- write(tf, &c, sizeof c);
- }
- quitenv();
- } else
- unlink(tname);
- close(tf);
- tf = open(tname, 0);
- unlink(tname);
- return (tf);
- } else
- return (hf);
-}
-
-void
-scraphere()
-{
- register struct here *h;
-
- for (h = inhere; h != NULL; h = h->h_next) {
- if (h->h_iop && h->h_iop->io_name)
- unlink(h->h_iop->io_name);
- }
- inhere = NULL;
-}
-
-/* unlink here temp files before a freearea(area) */
-void
-freehere(area)
-int area;
-{
- register struct here *h, *hl;
-
- hl = NULL;
- for (h = acthere; h != NULL; h = h->h_next)
- if (getarea((char *) h) >= area) {
- if (h->h_iop->io_name != NULL)
- unlink(h->h_iop->io_name);
- if (hl == NULL)
- acthere = h->h_next;
- else
- hl->h_next = h->h_next;
- } else
- hl = h;
-}
-
-void
-tempname(tname)
-char *tname;
-{
- static int inc;
- register char *cp, *lp;
-
- for (cp = tname, lp = "/tmp/shtm"; (*cp = *lp++) != '\0'; cp++)
- ;
- lp = putn(getpid()*1000 + inc++);
- for (; (*cp = *lp++) != '\0'; cp++)
- ;
-}
diff --git a/src/bin/sh/sh6.c b/src/bin/sh/sh6.c
deleted file mode 100644
index 802be74..0000000
--- a/src/bin/sh/sh6.c
+++ /dev/null
@@ -1,8 +0,0 @@
-#define Extern
-
-#include
-#include
-#include
-#include
-#include "sh.h"
-
diff --git a/src/bin/shell/Makefile b/src/bin/shell/Makefile
index c7631d1..4efdfa8 100644
--- a/src/bin/shell/Makefile
+++ b/src/bin/shell/Makefile
@@ -17,7 +17,7 @@
#Objects
OBJS = main.o error.o commands.o exec.o input.o
-LIBRARIES = ../../lib/libc_old/libc_old.so ../../lib/ubix_api/ubix_api.so
+LIBRARIES = ../../lib/libc_old/libc_old.so
# Link The Binary
$(BINARY) : $(OBJS)
diff --git a/src/bin/shell/commands.c b/src/bin/shell/commands.c
index cf987d0..ce88c66 100644
--- a/src/bin/shell/commands.c
+++ b/src/bin/shell/commands.c
@@ -1,5 +1,5 @@
/*****************************************************************************************
- Copyright (c) 2002-2004,2008 The UbixOS Project
+ Copyright (c) 2002-2004 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
@@ -40,15 +40,15 @@
int commands(inputBuffer *data) {
int cPid = 0x0,i = 0x0,x = 0x0;
- char **argv = data->argv;
mpi_message_t cmdMsg;
if (data == NULL) return 1;
if (data->args->arg == NULL) return 1;
+ if (*data->args->arg == '\0') return 1;
if (0 == memcmp(data->args->arg, "uname", 5)) {
- printf("UbixOS v1.00 " __DATE__" " __TIME__ " \n");
+ printf("UbixOS v0.87 " __DATE__" " __TIME__ " \n");
return(1);
}
else if (0 == memcmp(data->args->arg, "exit", 4)) {
@@ -73,7 +73,7 @@
}
cPid = fork();
if (cPid == 0x0) {
- exec("ls", 0x0,0x0);
+ exec("ls", 0x0, 0x0);
exit(0x1);
} else {
printf("Childs Pid: [%i]\n",cPid);
@@ -111,7 +111,7 @@
}
else if (memcmp(data->args->arg,"echo",4) == 0) {
for (i=1;iargc;i++) {
- printf("%s ",argv[i]);
+ printf("%s ",data->argv[i]);
}
printf("\n");
}
@@ -120,43 +120,35 @@
printf("Base Command Line Interface\n");
}
else if (memcmp(data->args->arg,"cd",2) == 0) {
- if (argv[2]) {
- chdir(argv[2]);
+ if (data->argv[1]) {
+ chdir(data->argv[1]);
getcwd(cwd,1024);
}
}
else if (memcmp(data->args->arg,"unlink",6) == 0) {
- if (argv[1]) {
- unlink(argv[1]);
+ if (data->argv[1]) {
+ unlink(data->argv[1]);
}
}
else if (memcmp(data->args->arg,"msg",3) == 0x0) {
printf("Posting Message\n");
- cmdMsg.header = atoi(argv[2]);
- sprintf(cmdMsg.data,argv[3]);
- mpi_postMessage(argv[1],0x1,&cmdMsg);
+ cmdMsg.header = atoi(data->argv[2]);
+ sprintf(cmdMsg.data,data->argv[3]);
+ mpi_postMessage(data->argv[1],0x1,&cmdMsg);
}
else if (memcmp(data->args->arg,"mkdir",5) == 0x0) {
- if (argv[1]) {
- mkdir(argv[1],0xEAA);
+ if (data->argv[1]) {
+ mkdir(data->argv[1],0xEAA);
}
}
else if (memcmp(data->args->arg,"id",2) == 0x0) {
printf("UID: %i, GID: %i\n",getuid(),getgid());
}
- else if (!strcmp(argv[1],"reboot")) {
+ else if (!strcmp(data->argv[0],"reboot")) {
cmdMsg.header = 1000;
cmdMsg.data[0] = '\0';
mpi_postMessage("system",0x1,&cmdMsg);
}
- else if (!strcmp(argv[1],"newexec")) {
- printf("Switching To New EXEC\n");
- boo = 0x1;
- }
- else if (!strcmp(argv[1],"oldexec")) {
- printf("Switching To Old EXEC\n");
- boo = 0x0;
- }
else {
return(0);
}
diff --git a/src/bin/shell/exec.c b/src/bin/shell/exec.c
index 0bfa058..1a34679 100644
--- a/src/bin/shell/exec.c
+++ b/src/bin/shell/exec.c
@@ -28,32 +28,18 @@
#include
#include "shell.h"
-int boo = 0x0;
-
void execProgram(inputBuffer *data) {
- char file[1024];
- char **argv = data->argv;
int cPid = 0x0;
-
- printf("Executing App: %s\n",argv[1]);
-
cPid = fork();
-
if (!cPid) {
- sprintf(file,"%s%s",cwd,argv[1]);
- printf("Forked And Ready To Roll: %s\n",file);
- if (boo == 0)
- exec(file,data->argv,data->envp);
- else
- execn(file,&data->argv);
-
- printf("%s: Command Not Found.\n",argv[1]);
+ exec(data->argv[0],data->argc,data->argv);
+ printf("%s: Command Not Found.\n",data->argv[0]);
exit(-1);
}
else {
- //if (data->bg == 0x0) {
+ if (data->bg == 0x0) {
while (pidStatus(cPid) > 0)
sched_yield();
- //}
- }
+ }
+ }
}
diff --git a/src/bin/shell/input.c b/src/bin/shell/input.c
index 917289d..7b57d7f 100644
--- a/src/bin/shell/input.c
+++ b/src/bin/shell/input.c
@@ -1,5 +1,5 @@
/**************************************************************************************
- Copyright (c) 2002,2008 The UbixOS Project
+ Copyright (c) 2002 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -27,60 +27,44 @@
#include "shell.h"
void parseInput(inputBuffer *buffer,char *data) {
- int i = 0x0;
- char *tmpDat = data;
- char *arg = 0x0;
- char **argv = 0x0;
- struct argsStruct *tmpArgs = 0x0;
-
+ int i = 0x0;
+ char *arg = 0x0;
+ struct argsStruct *tmpArgs = 0x0;
+
while (data[0] == ' ') {
data++;
}
- if (*data == '\0')
- return;
+ if (*data == '\0') return;
buffer->args = (struct argsStruct *)malloc(sizeof(struct argsStruct));
-
tmpArgs = buffer->args;
- while(tmpDat != 0x0) {
- arg = strtok(tmpDat," ");
- tmpDat = strtok(NULL,"\n");
-
- //printf("sh[%s:%s]",arg,data);
+ while(data != 0x0) {
+ arg = strtok(data," ");
+ data = strtok(NULL,"\n");
if (arg[0] == '&') {
buffer->bg = 0x1;
}
else {
buffer->argc++;
tmpArgs->arg = arg;
- if (tmpDat != 0x0) {
+ if (data != 0x0) {
tmpArgs->next = (struct argsStruct *)malloc(sizeof(struct argsStruct));
}
tmpArgs = tmpArgs->next;
}
}
- /* Alloc memory for argv[] */
- buffer->argv = (char *)malloc(sizeof(char *) * (buffer->argc + 2));
- buffer->envp = (char *)malloc(sizeof(char *));
-
- buffer->envp[0] = 0x0;
-
+ buffer->argv = (char **)malloc(4*buffer->argc);
tmpArgs = buffer->args;
- argv = buffer->argv;
-
- for (i=0x1;i <= buffer->argc;i++) {
- argv[i] = tmpArgs->arg;
+ for (i=0;iargc;i++) {
+ buffer->argv[i] = tmpArgs->arg;
tmpArgs = tmpArgs->next;
}
- argv[0] = (char *)buffer->argc;
}
void freeArgs(inputBuffer *ptr) {
free(ptr->args);
- free(ptr->argv);
- free(ptr->envp);
//free(tmpArgs->argv);
}
diff --git a/src/bin/shell/main.c b/src/bin/shell/main.c
index aa92cbb..c9e10fc 100644
--- a/src/bin/shell/main.c
+++ b/src/bin/shell/main.c
@@ -1,5 +1,5 @@
/**************************************************************************************
- Copyright (c) 2002,2008 The UbixOS Project
+ Copyright (c) 2002 The UbixOS Project
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -26,15 +26,14 @@
#include
#include