Commits

Wez Furlong committed 0f8944d

Get all these files into a mercurial repo.

  • Participants

Comments (0)

Files changed (62)

+linux
+Makefile.objects
+*.zip
+readme.txt
+# $Id: Makefile,v 1.3 2004/01/22 12:37:08 Wez Exp $
+
+PHP=c:/tbr/dev/php5/Release_TS/php.exe
+DDK=C:\WINDDK\3790
+VERSION=0.2
+
+INTERP=pengwin
+KERNEL=pengwin-kernel
+DRIVER=pengwin-int
+
+#LOW=low
+BD_OUT=/Foout\ /Fdout\ /Fpout\ /FRout\ 
+
+default: all
+
+DEBUG_CFLAGS=/DDEBUG /Od /Zi
+DEBUG_LDFLAGS=/DEBUG
+
+INTERP_CFLAGS=/nologo /DLOW_IMPORTS /Iinclude
+INTERP_LDFLAGS=/VERSION:$(VERSION)
+INTERP_LIBS=out\$(KERNEL).lib
+KERNEL_LIBS=kernel32.lib user32.lib ws2_32.lib psapi.lib advapi32.lib
+KERNEL_CFLAGS=/nologo /Iinclude $(DEBUG_CFLAGS) /DKERNEL_DLL=\"$(KERNEL).dll\" /DDRIVER_SYS=\"$(DRIVER).sys\"
+KERNEL_LDFLAGS=/VERSION:$(VERSION) $(DEBUG_LDFLAGS)
+SYS_CFLAGS=/nologo /I$(DDK)\inc\ddk\w2k /I$(DDK)\inc\w2k /D_M_IX86 /D_X86_ /Iinclude /Gz $(DEBUG_CFLAGS)
+SYS_LDFLAGS=/VERSION:$(VERSION)  $(DEBUG_LDFLAGS)
+SYS_LIBS=/libpath:$(DDK)\lib\w2k\i386 ntoskrnl.lib
+
+!if !EXIST(Makefile.objects)
+!message Generating objects file
+!if [$(PHP) -n mkobjects.php]
+!error failed to generate objects rules
+!endif
+!endif
+
+!include Makefile.objects
+
+all: KERNEL_dirs INTERP_dirs SYS_dirs bin\$(KERNEL).dll bin\$(INTERP).exe bin\$(DRIVER).sys
+
+release: all
+	$(PHP) -n mkrelease.php "$(VERSION)"
+
+objects:
+	$(PHP) -n mkobjects.php
+
+clean:
+	del /s /q $(INTERP_OBJS)
+	del /s /q $(KERNEL_OBJS)
+	del /s /q $(SYS_OBJS)
+
+bin\$(INTERP).exe: out\$(INTERP).exe out\$(KERNEL).dll
+	copy /y out\$(INTERP).exe bin\$(INTERP).exe
+
+bin\$(KERNEL).dll: out\$(KERNEL).dll
+	copy /y out\$(KERNEL).dll bin\$(KERNEL).dll
+
+bin\$(DRIVER).sys: out\$(DRIVER).sys
+	copy /y out\$(DRIVER).sys bin\$(DRIVER).sys
+
+out\$(INTERP).exe: $(INTERP_OBJS) $(INTERP_RC)
+	link /nologo /out:out\$(INTERP).exe /entry:startup /subsystem:console $(INTERP_LDFLAGS) $(INTERP_OBJS) $(INTERP_LIBS) $(INTERP_RC)
+
+out\$(KERNEL).dll: $(KERNEL_OBJS) $(KERNEL_RC)
+	link /nologo /out:out\$(KERNEL).dll /dll /entry:DllMain $(KERNEL_LDFLAGS) $(KERNEL_OBJS) $(KERNEL_LIBS) $(KERNEL_RC)
+
+out\$(DRIVER).sys: $(SYS_OBJS) $(SYS_RC)
+	link /nologo /out:out\$(DRIVER).sys /driver /subsystem:NATIVE /entry:DriverEntry $(SYS_LDFLAGS) $(SYS_OBJS) $(SYS_LIBS) $(SYS_RC)
+

File Makefile.objects

+out\kernel\boot.obj: kernel\boot.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\boot.c
+out\kernel\dllboot.obj: kernel\dllboot.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\dllboot.c
+out\kernel\driver_install.obj: kernel\driver_install.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\driver_install.c
+out\kernel\errno.obj: kernel\errno.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\errno.c
+out\kernel\exec.obj: kernel\exec.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\exec.c
+out\kernel\fs\common.obj: kernel\fs\common.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\fs\ /Fdout\kernel\fs\ /Fpout\kernel\fs\ /FRout\kernel\fs\ kernel\fs\common.c
+out\kernel\fs\descriptors.obj: kernel\fs\descriptors.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\fs\ /Fdout\kernel\fs\ /Fpout\kernel\fs\ /FRout\kernel\fs\ kernel\fs\descriptors.c
+out\kernel\fs\dir.obj: kernel\fs\dir.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\fs\ /Fdout\kernel\fs\ /Fpout\kernel\fs\ /FRout\kernel\fs\ kernel\fs\dir.c
+out\kernel\fs\handles.obj: kernel\fs\handles.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\fs\ /Fdout\kernel\fs\ /Fpout\kernel\fs\ /FRout\kernel\fs\ kernel\fs\handles.c
+out\kernel\info.obj: kernel\info.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\info.c
+out\kernel\initfuncs.obj: kernel\initfuncs.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\initfuncs.c
+out\kernel\kmem.obj: kernel\kmem.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\kmem.c
+out\kernel\kprint.obj: kernel\kprint.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\kprint.c
+out\kernel\mgr_thread.obj: kernel\mgr_thread.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\mgr_thread.c
+out\kernel\mmap.obj: kernel\mmap.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\mmap.c
+out\kernel\net\init.obj: kernel\net\init.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\net\ /Fdout\kernel\net\ /Fpout\kernel\net\ /FRout\kernel\net\ kernel\net\init.c
+out\kernel\proc.obj: kernel\proc.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\proc.c
+out\kernel\signal.obj: kernel\signal.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\signal.c
+out\kernel\syscalltable.obj: kernel\syscalltable.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\syscalltable.c
+out\kernel\systrap.obj: kernel\systrap.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\systrap.c
+out\kernel\time.obj: kernel\time.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\time.c
+out\kernel\trap.obj: kernel\trap.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\trap.c
+out\kernel\win_error.obj: kernel\win_error.c
+	cl /c $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) /Foout\kernel\ /Fdout\kernel\ /Fpout\kernel\ /FRout\kernel\ kernel\win_error.c
+
+KERNEL_OBJS=out\kernel\boot.obj out\kernel\dllboot.obj out\kernel\driver_install.obj out\kernel\errno.obj out\kernel\exec.obj out\kernel\fs\common.obj out\kernel\fs\descriptors.obj out\kernel\fs\dir.obj out\kernel\fs\handles.obj out\kernel\info.obj out\kernel\initfuncs.obj out\kernel\kmem.obj out\kernel\kprint.obj out\kernel\mgr_thread.obj out\kernel\mmap.obj out\kernel\net\init.obj out\kernel\proc.obj out\kernel\signal.obj out\kernel\syscalltable.obj out\kernel\systrap.obj out\kernel\time.obj out\kernel\trap.obj out\kernel\win_error.obj
+
+KERNEL_dirs:
+	@if not exist out\kernel mkdir out\kernel
+	@if not exist out\kernel\fs mkdir out\kernel\fs
+	@if not exist out\kernel\net mkdir out\kernel\net
+out\interp\boot.obj: interp\boot.c
+	cl /c $(INTERP_CFLAGS) $(INTERP_LDFLAGS) /Foout\interp\ /Fdout\interp\ /Fpout\interp\ /FRout\interp\ interp\boot.c
+
+INTERP_OBJS=out\interp\boot.obj
+
+INTERP_dirs:
+	@if not exist out\interp mkdir out\interp
+out\sys\test.obj: sys\test.c
+	cl /c $(SYS_CFLAGS) $(SYS_LDFLAGS) /Foout\sys\ /Fdout\sys\ /Fpout\sys\ /FRout\sys\ sys\test.c
+out\sys\trapsys.obj: sys\trapsys.c
+	cl /c $(SYS_CFLAGS) $(SYS_LDFLAGS) /Foout\sys\ /Fdout\sys\ /Fpout\sys\ /FRout\sys\ sys\trapsys.c
+
+SYS_OBJS=out\sys\test.obj out\sys\trapsys.obj
+
+SYS_dirs:
+	@if not exist out\sys mkdir out\sys

File bin/.cvsignore

+*.exe
+*.dll
+*.sys

File bin/devcon.exe

Binary file added.

File bin/pengwin-int.sys

Binary file added.

File bin/pengwin-kernel.dll

Binary file added.

File bin/pengwin.exe

Binary file added.

File include/low/buildutil.h

+/* stuff to reduce build maintenance */
+/* $Id: buildutil.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+typedef int (*low_system_init_func)(void);
+typedef void (*low_system_fini_func)(void);
+
+#define LOW_INITFUNC(name)		int init_system_##name(void)
+#define LOW_FINIFUNC(name)		void fini_system_##name(void)
+
+#define LOW_PROCINITFUNC(name)		int init_proc_##name(void)
+#define LOW_PROCFINIFUNC(name)		void fini_proc_##name(void)
+

File include/low/dirent.h

+/* $Id: dirent.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#if 0
+struct dirent {
+	long		d_ino;
+	__kernel_off_t	d_off;
+	unsigned short	d_reclen;
+	char		d_name[256]; /* We must not include limits.h! */
+};
+#endif
+
+struct dirent64 {
+	UINT64		d_ino;
+	INT64		d_off;
+	unsigned short	d_reclen;
+	unsigned char	d_type;
+	char		d_name[256];
+};
+
+struct linux_dirent64 {
+	UINT64		d_ino;
+	INT64		d_off;
+	unsigned short	d_reclen;
+	unsigned char	d_type;
+	char		d_name[0];
+};
+
+
+

File include/low/elf.h

+/* ELF structures and types,
+ * derived from the ELF specification
+ * $Id: elf.h,v 1.1 2004/01/20 13:21:14 Wez Exp $
+ */
+
+typedef DWORD	Elf32_Addr;
+typedef DWORD	Elf32_Off;
+typedef WORD	Elf32_Half;
+typedef DWORD	Elf32_Word;
+typedef LONG	Elf32_Sword;
+
+typedef UINT64	Elf64_Addr;
+typedef UINT64	Elf64_Off;
+typedef WORD	Elf64_Half;
+typedef DWORD	Elf64_Word;
+typedef LONG	Elf64_Sword;
+typedef UINT64	Elf64_Xword;
+typedef INT64	Elf64_Sxword;
+
+#define EI_NIDENT 16
+
+#define	ET_NONE		0 /* No file type  */
+#define	ET_REL		1 /* Relocatable file */
+#define	ET_EXEC		2 /* Executable file */
+#define	ET_DYN		3 /* Shared object file */ 
+#define	ET_CORE		4 /* Core file */
+#define	ET_LOOS		0xfe00 /* Operating system-specific */
+#define	ET_HIOS		0xfeff /* Operating system-specific */ 
+#define	ET_LOPROC	0xff00 /* Processor-specific */
+#define	ET_HIPROC	0xffff /* Processor-specific */ 
+
+#define	EM_NONE 0 // No machine 
+#define	EM_M32 1 // AT&T WE 32100 
+#define	EM_SPARC 2 // SPARC 
+#define	EM_386 3 // Intel 80386 
+#define	EM_68K 4 // Motorola 68000 
+#define	EM_88K 5 // Motorola 88000 
+#define	EM_486 6 // Reserved for future use (was EM_486) 
+#define	EM_860 7 // Intel 80860 
+#define	EM_MIPS 8 // MIPS I Architecture 
+#define	EM_S370 9 // IBM System/370 Processor 
+#define	EM_MIPS_RS3_LE 10 // MIPS RS3000 Little-endian 
+#define	EM_PARISC 15 // Hewlett-Packard PA-RISC 
+#define	EM_VPP500 17 // Fujitsu VPP500 
+#define	EM_SPARC32PLUS 18 // Enhanced instruction set SPARC 
+#define	EM_960 19 // Intel 80960 
+#define	EM_PPC 20 // PowerPC 
+#define	EM_PPC64 21 // 64-bit PowerPC 
+#define	EM_S390 22 // IBM System/390 Processor 
+#define	EM_V800 36 // NEC V800 
+#define	EM_FR20 37 // Fujitsu FR20 
+#define	EM_RH32 38 // TRW RH-32 
+#define	EM_RCE 39 // Motorola RCE 
+#define	EM_ARM 40 // Advanced RISC Machines ARM 
+#define	EM_ALPHA 41 // Digital Alpha 
+#define	EM_SH 42 // Hitachi SH 
+#define	EM_SPARCV9 43 // SPARC Version 9 
+#define	EM_TRICORE 44 // Siemens TriCore embedded processor 
+#define	EM_ARC 45 // Argonaut RISC Core, Argonaut Technologies Inc. 
+#define	EM_H8_300 46 // Hitachi H8/300 
+#define	EM_H8_300H 47 // Hitachi H8/300H 
+#define	EM_H8S 48 // Hitachi H8S 
+#define	EM_H8_500 49 // Hitachi H8/500 
+#define	EM_IA_64 50 // Intel IA-64 processor architecture 
+#define	EM_MIPS_X 51 // Stanford MIPS-X 
+#define	EM_COLDFIRE 52 // Motorola ColdFire 
+#define	EM_68HC12 53 // Motorola M68HC12 
+#define	EM_MMA 54 // Fujitsu MMA Multimedia Accelerator 
+#define	EM_PCP 55 // Siemens PCP 
+#define	EM_NCPU 56 // Sony nCPU embedded RISC processor 
+#define	EM_NDR1 57 // Denso NDR1 microprocessor 
+#define	EM_STARCORE 58 // Motorola Star*Core processor 
+#define	EM_ME16 59 // Toyota ME16 processor 
+#define	EM_ST100 60 // STMicroelectronics ST100 processor 
+#define	EM_TINYJ 61 // Advanced Logic Corp. TinyJ embedded processor family 
+#define	EM_X86_64 62 // AMD x86-64 architecture 
+#define	EM_PDSP 63 // Sony DSP Processor 
+#define	EM_PDP10 64 // Digital Equipment Corp. PDP-10 
+#define	EM_PDP11 65 // Digital Equipment Corp. PDP-11 
+#define	EM_FX66 66 // Siemens FX66 microcontroller 
+#define	EM_ST9PLUS 67 // STMicroelectronics ST9+ 8/16 bit microcontroller 
+#define	EM_ST7 68 // STMicroelectronics ST7 8-bit microcontroller 
+#define	EM_68HC16 69 // Motorola MC68HC16 Microcontroller 
+#define	EM_68HC11 70 // Motorola MC68HC11 Microcontroller 
+#define	EM_68HC08 71 // Motorola MC68HC08 Microcontroller 
+#define	EM_68HC05 72 // Motorola MC68HC05 Microcontroller 
+#define	EM_SVX 73 // Silicon Graphics SVx 
+#define	EM_ST19 74 // STMicroelectronics ST19 8-bit microcontroller 
+#define	EM_VAX 75 // Digital VAX 
+#define	EM_CRIS 76 // Axis Communications 32-bit embedded processor 
+#define	EM_JAVELIN 77 // Infineon Technologies 32-bit embedded processor 
+#define	EM_FIREPATH 78 // Element 14 64-bit DSP Processor 
+#define	EM_ZSP 79 // LSI Logic 16-bit DSP Processor 
+#define	EM_MMIX 80 // Donald Knuth's educational 64-bit processor 
+#define	EM_HUANY 81 // Harvard University machine-independent object files 
+#define	EM_PRISM 82 // SiTera Prism 
+#define	EM_AVR 83 // Atmel AVR 8-bit microcontroller 
+#define	EM_FR30 84 // Fujitsu FR30 
+#define	EM_D10V 85 // Mitsubishi D10V 
+#define	EM_D30V 86 // Mitsubishi D30V 
+#define	EM_V850 87 // NEC v850 
+#define	EM_M32R 88 // Mitsubishi M32R 
+#define	EM_MN10300 89 // Matsushita MN10300 
+#define	EM_MN10200 90 // Matsushita MN10200 
+#define	EM_PJ 91 // picoJava 
+#define	EM_OPENRISC 92 // OpenRISC 32-bit embedded processor 
+#define	EM_ARC_A5 93 // ARC Cores Tangent-A5 
+#define	EM_XTENSA 94 // Tensilica Xtensa Architecture 
+#define	EM_VIDEOCORE 95 // Alphamosaic VideoCore processor 
+#define	EM_TMM_GPP 96 // Thompson Multimedia General Purpose Processor 
+#define	EM_NS32K 97 // National Semiconductor 32000 series 
+#define	EM_TPC 98 // Tenor Network TPC processor 
+#define	EM_SNP1K 99 // Trebia SNP 1000 processor 
+#define	EM_ST200 100 // STMicroelectronics (www.st.com) ST200 microcontroller 
+#define	EM_IP2K 101 // Ubicom IP2xxx microcontroller family 
+#define	EM_MAX 102 // MAX Processor 
+#define	EM_CR 103 // National Semiconductor CompactRISC microprocessor 
+#define	EM_F2MC16 104 // Fujitsu F2MC16 
+#define	EM_MSP430 105 // Texas Instruments embedded microcontroller msp430 
+#define	EM_BLACKFIN 106 // Analog Devices Blackfin (DSP) processor 
+#define	EM_SE_C33 107 // S1C33 Family of Seiko Epson processors 
+#define	EM_SEP 108 // Sharp embedded microprocessor 
+#define	EM_ARCA 109 // Arca RISC Microprocessor 
+#define	EM_UNICORE 110 // Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University 
+
+#define EV_NONE 0 // Invalid version 
+#define EV_CURRENT 1 // Current version 
+
+#define EI_MAG0 0 // File identification 
+#define EI_MAG1 1 // File identification 
+#define EI_MAG2 2 // File identification 
+#define EI_MAG3 3 // File identification 
+#define EI_CLASS 4 // File class 
+#define EI_DATA 5 // Data encoding 
+#define EI_VERSION 6 // File version 
+#define EI_OSABI 7 // Operating system/ABI identification 
+#define EI_ABIVERSION 8 // ABI version 
+#define EI_PAD 9 // Start of padding bytes 
+#define EI_NIDENT 16 // Size of e_ident[] 
+
+#define ELFMAG0 0x7f // e_ident[EI_MAG0] 
+#define ELFMAG1 'E' // e_ident[EI_MAG1] 
+#define ELFMAG2 'L' // e_ident[EI_MAG2] 
+#define ELFMAG3 'F' // e_ident[EI_MAG3] 
+
+#define ELFCLASSNONE 0 // Invalid class 
+#define ELFCLASS32 1 // 32-bit objects 
+#define ELFCLASS64 2 // 64-bit objects 
+
+#define ELFDATANONE 0 // Invalid data encoding 
+#define ELFDATA2LSB 1 // See below 
+#define ELFDATA2MSB 2 // See below 
+
+#define ELFOSABI_NONE 0 // No extensions or unspecified 
+#define ELFOSABI_HPUX 1 // Hewlett-Packard HP-UX 
+#define ELFOSABI_NETBSD 2 // NetBSD 
+#define ELFOSABI_LINUX 3 // Linux 
+#define ELFOSABI_SOLARIS 6 // Sun Solaris 
+#define ELFOSABI_AIX 7 // AIX 
+#define ELFOSABI_IRIX 8 // IRIX 
+#define ELFOSABI_FREEBSD 9 // FreeBSD 
+#define ELFOSABI_TRU64 10 // Compaq TRU64 UNIX 
+#define ELFOSABI_MODESTO 11 // Novell Modesto 
+#define ELFOSABI_OPENBSD 12 // Open BSD 
+#define ELFOSABI_OPENVMS 13 // Open VMS 
+#define ELFOSABI_NSK 14 // Hewlett-Packard Non-Stop Kernel 
+#define ELFOSABI_AROS 15 // Amiga Research OS 
+
+typedef struct {
+        unsigned char   e_ident[EI_NIDENT];
+        Elf32_Half      e_type;
+        Elf32_Half      e_machine;
+        Elf32_Word      e_version;
+        Elf32_Addr      e_entry;
+        Elf32_Off       e_phoff;
+        Elf32_Off       e_shoff;
+        Elf32_Word      e_flags;
+        Elf32_Half      e_ehsize;
+        Elf32_Half      e_phentsize;
+        Elf32_Half      e_phnum;
+        Elf32_Half      e_shentsize;
+        Elf32_Half      e_shnum;
+        Elf32_Half      e_shstrndx;
+} Elf32_Ehdr;
+
+typedef struct {
+        unsigned char   e_ident[EI_NIDENT];
+        Elf64_Half      e_type;
+        Elf64_Half      e_machine;
+        Elf64_Word      e_version;
+        Elf64_Addr      e_entry;
+        Elf64_Off       e_phoff;
+        Elf64_Off       e_shoff;
+        Elf64_Word      e_flags;
+        Elf64_Half      e_ehsize;
+        Elf64_Half      e_phentsize;
+        Elf64_Half      e_phnum;
+        Elf64_Half      e_shentsize;
+        Elf64_Half      e_shnum;
+        Elf64_Half      e_shstrndx;
+} Elf64_Ehdr;
+
+#define SHN_UNDEF 0 
+#define SHN_LORESERVE 0xff00 
+#define SHN_LOPROC 0xff00 
+#define SHN_HIPROC 0xff1f 
+#define SHN_LOOS 0xff20 
+#define SHN_HIOS 0xff3f 
+#define SHN_ABS 0xfff1 
+#define SHN_COMMON 0xfff2 
+#define SHN_XINDEX 0xffff 
+#define SHN_HIRESERVE 0xffff 
+
+typedef struct {
+	Elf32_Word	sh_name;
+	Elf32_Word	sh_type;
+	Elf32_Word	sh_flags;
+	Elf32_Addr	sh_addr;
+	Elf32_Off	sh_offset;
+	Elf32_Word	sh_size;
+	Elf32_Word	sh_link;
+	Elf32_Word	sh_info;
+	Elf32_Word	sh_addralign;
+	Elf32_Word	sh_entsize;
+} Elf32_Shdr;
+
+typedef struct {
+	Elf64_Word	sh_name;
+	Elf64_Word	sh_type;
+	Elf64_Xword	sh_flags;
+	Elf64_Addr	sh_addr;
+	Elf64_Off	sh_offset;
+	Elf64_Xword	sh_size;
+	Elf64_Word	sh_link;
+	Elf64_Word	sh_info;
+	Elf64_Xword	sh_addralign;
+	Elf64_Xword	sh_entsize;
+} Elf64_Shdr;
+
+#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_INIT_ARRAY 14 
+#define SHT_FINI_ARRAY 15 
+#define SHT_PREINIT_ARRAY 16 
+#define SHT_GROUP 17 
+#define SHT_SYMTAB_SHNDX 18 
+#define SHT_LOOS 0x60000000 
+#define SHT_HIOS 0x6fffffff 
+#define SHT_LOPROC 0x70000000 
+#define SHT_HIPROC 0x7fffffff 
+#define SHT_LOUSER 0x80000000 
+#define SHT_HIUSER 0xffffffff 
+
+#define SHF_WRITE 0x1 
+#define SHF_ALLOC 0x2 
+#define SHF_EXECINSTR 0x4 
+#define SHF_MERGE 0x10 
+#define SHF_STRINGS 0x20 
+#define SHF_INFO_LINK 0x40 
+#define SHF_LINK_ORDER 0x80 
+#define SHF_OS_NONCONFORMING 0x100 
+#define SHF_GROUP 0x200 
+#define SHF_TLS 0x400 
+#define SHF_MASKOS 0x0ff00000 
+#define SHF_MASKPROC 0xf0000000 
+
+#define GRP_COMDAT 0x1 
+#define GRP_MASKOS 0x0ff00000 
+#define GRP_MASKPROC 0xf0000000 
+
+typedef struct {
+	Elf32_Word	st_name;
+	Elf32_Addr	st_value;
+	Elf32_Word	st_size;
+	unsigned char	st_info;
+	unsigned char	st_other;
+	Elf32_Half	st_shndx;
+} Elf32_Sym;
+
+typedef struct {
+	Elf64_Word	st_name;
+	unsigned char	st_info;
+	unsigned char	st_other;
+	Elf64_Half	st_shndx;
+	Elf64_Addr	st_value;
+	Elf64_Xword	st_size;
+} Elf64_Sym;
+
+#define ELF32_ST_BIND(i)   ((i)>>4)
+#define ELF32_ST_TYPE(i)   ((i)&0xf)
+#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
+
+#define ELF64_ST_BIND(i)   ((i)>>4)
+#define ELF64_ST_TYPE(i)   ((i)&0xf)
+#define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
+#define ELF32_ST_VISIBILITY(o) ((o)&0x3)
+#define ELF64_ST_VISIBILITY(o) ((o)&0x3)
+
+#define STB_LOCAL 0 
+#define STB_GLOBAL 1 
+#define STB_WEAK 2 
+#define STB_LOOS 10 
+#define STB_HIOS 12 
+#define STB_LOPROC 13 
+#define STB_HIPROC 15 
+
+#define STT_NOTYPE 0 
+#define STT_OBJECT 1 
+#define STT_FUNC 2 
+#define STT_SECTION 3 
+#define STT_FILE 4 
+#define STT_COMMON 5 
+#define STT_TLS 6 
+#define STT_LOOS 10 
+#define STT_HIOS 12 
+#define STT_LOPROC 13 
+#define STT_HIPROC 15 
+
+#define STV_DEFAULT 0 
+#define STV_INTERNAL 1 
+#define STV_HIDDEN 2 
+#define STV_PROTECTED 3 
+
+typedef struct {
+	Elf32_Addr	r_offset;
+	Elf32_Word	r_info;
+} Elf32_Rel;
+
+typedef struct {
+	Elf32_Addr	r_offset;
+	Elf32_Word	r_info;
+	Elf32_Sword	r_addend;
+} Elf32_Rela;
+
+typedef struct {
+	Elf64_Addr	r_offset;
+	Elf64_Xword	r_info;
+} Elf64_Rel;
+
+typedef struct {
+	Elf64_Addr	r_offset;
+	Elf64_Xword	r_info;
+	Elf64_Sxword	r_addend;
+} Elf64_Rela;
+
+#define ELF32_R_SYM(i)	((i)>>8)
+#define ELF32_R_TYPE(i)   ((unsigned char)(i))
+#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
+
+#define ELF64_R_SYM(i)    ((i)>>32)
+#define ELF64_R_TYPE(i)   ((i)&0xffffffffL)
+#define ELF64_R_INFO(s,t) (((s)<<32)+((t)&0xffffffffL))
+
+typedef struct {
+	Elf32_Word	p_type;
+	Elf32_Off	p_offset;
+	Elf32_Addr	p_vaddr;
+	Elf32_Addr	p_paddr;
+	Elf32_Word	p_filesz;
+	Elf32_Word	p_memsz;
+	Elf32_Word	p_flags;
+	Elf32_Word	p_align;
+} Elf32_Phdr;
+
+typedef struct {
+	Elf64_Word	p_type;
+	Elf64_Word	p_flags;
+	Elf64_Off	p_offset;
+	Elf64_Addr	p_vaddr;
+	Elf64_Addr	p_paddr;
+	Elf64_Xword	p_filesz;
+	Elf64_Xword	p_memsz;
+	Elf64_Xword	p_align;
+} Elf64_Phdr;
+
+#define PT_NULL 0 
+#define PT_LOAD 1 
+#define PT_DYNAMIC 2 
+#define PT_INTERP 3 
+#define PT_NOTE 4 
+#define PT_SHLIB 5 
+#define PT_PHDR 6 
+#define PT_TLS 7 
+#define PT_LOOS 0x60000000 
+#define PT_HIOS 0x6fffffff 
+#define PT_LOPROC 0x70000000 
+#define PT_HIPROC 0x7fffffff 
+
+#define PF_X 0x1 // Execute 
+#define PF_W 0x2 // Write 
+#define PF_R 0x4 // Read 
+#define PF_MASKOS 0x0ff00000 // Unspecified 
+#define PF_MASKPROC 0xf0000000 // Unspecified 
+
+typedef struct {
+	Elf32_Sword	d_tag;
+   	union {
+   		Elf32_Word	d_val;
+   		Elf32_Addr	d_ptr;
+	} d_un;
+} Elf32_Dyn;
+
+//extern Elf32_Dyn	_DYNAMIC[];
+
+typedef struct {
+	Elf64_Sxword	d_tag;
+   	union {
+   		Elf64_Xword	d_val;
+   		Elf64_Addr	d_ptr;
+	} d_un;
+} Elf64_Dyn;
+
+//extern Elf64_Dyn	_DYNAMIC[];
+
+// Name Value d_un Executable Shared Object 
+#define DT_NULL 0 // ignored mandatory mandatory 
+#define DT_NEEDED 1 // d_val optional optional 
+#define DT_PLTRELSZ 2 // d_val optional optional 
+#define DT_PLTGOT 3 // d_ptr optional optional 
+#define DT_HASH 4 // d_ptr mandatory mandatory 
+#define DT_STRTAB 5 // d_ptr mandatory mandatory 
+#define DT_SYMTAB 6 // d_ptr mandatory mandatory 
+#define DT_RELA 7 // d_ptr mandatory optional 
+#define DT_RELASZ 8 // d_val mandatory optional 
+#define DT_RELAENT 9 // d_val mandatory optional 
+#define DT_STRSZ 10 // d_val mandatory mandatory 
+#define DT_SYMENT 11 // d_val mandatory mandatory 
+#define DT_INIT 12 // d_ptr optional optional 
+#define DT_FINI 13 // d_ptr optional optional 
+#define DT_SONAME 14 // d_val ignored optional 
+#define DT_RPATH 15 // d_val optional ignored 
+#define DT_SYMBOLIC 16 // ignored ignored optional 
+#define DT_REL 17 // d_ptr mandatory optional 
+#define DT_RELSZ 18 // d_val mandatory optional 
+#define DT_RELENT 19 // d_val mandatory optional 
+#define DT_PLTREL 20 // d_val optional optional 
+#define DT_DEBUG 21 // d_ptr optional ignored 
+#define DT_TEXTREL 22 // ignored optional optional 
+#define DT_JMPREL 23 // d_ptr optional optional 
+#define DT_BIND_NOW 24 // ignored optional optional 
+#define DT_INIT_ARRAY 25 // d_ptr optional optional 
+#define DT_FINI_ARRAY 26 // d_ptr optional optional 
+#define DT_INIT_ARRAYSZ 27 // d_val optional optional 
+#define DT_FINI_ARRAYSZ 28 // d_val optional optional 
+#define DT_RUNPATH 29 // d_val optional optional 
+#define DT_FLAGS 30 // d_val optional optional 
+#define DT_ENCODING 32 // unspecified unspecified unspecified 
+#define DT_PREINIT_ARRAY 32 // d_ptr optional ignored 
+#define DT_PREINIT_ARRAYSZ 33 // d_val optional ignored 
+#define DT_LOOS 0x6000000D // unspecified unspecified unspecified 
+#define DT_HIOS 0x6ffff000 // unspecified unspecified unspecified 
+#define DT_LOPROC 0x70000000 // unspecified unspecified unspecified 
+#define DT_HIPROC 0x7fffffff // unspecified unspecified unspecified 
+
+#define DF_ORIGIN 0x1 
+#define DF_SYMBOLIC 0x2 
+#define DF_TEXTREL 0x4 
+#define DF_BIND_NOW 0x8 
+#define DF_STATIC_TLS 0x10 
+

File include/low/errno.h

+/* $Id: errno.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#define	EPERM		 1	/* Operation not permitted */
+#define	ENOENT		 2	/* No such file or directory */
+#define	ESRCH		 3	/* No such process */
+#define	EINTR		 4	/* Interrupted system call */
+#define	EIO		 5	/* I/O error */
+#define	ENXIO		 6	/* No such device or address */
+#define	E2BIG		 7	/* Argument list too long */
+#define	ENOEXEC		 8	/* Exec format error */
+#define	EBADF		 9	/* Bad file number */
+#define	ECHILD		10	/* No child processes */
+#define	EAGAIN		11	/* Try again */
+#define	ENOMEM		12	/* Out of memory */
+#define	EACCES		13	/* Permission denied */
+#define	EFAULT		14	/* Bad address */
+#define	ENOTBLK		15	/* Block device required */
+#define	EBUSY		16	/* Device or resource busy */
+#define	EEXIST		17	/* File exists */
+#define	EXDEV		18	/* Cross-device link */
+#define	ENODEV		19	/* No such device */
+#define	ENOTDIR		20	/* Not a directory */
+#define	EISDIR		21	/* Is a directory */
+#define	EINVAL		22	/* Invalid argument */
+#define	ENFILE		23	/* File table overflow */
+#define	EMFILE		24	/* Too many open files */
+#define	ENOTTY		25	/* Not a typewriter */
+#define	ETXTBSY		26	/* Text file busy */
+#define	EFBIG		27	/* File too large */
+#define	ENOSPC		28	/* No space left on device */
+#define	ESPIPE		29	/* Illegal seek */
+#define	EROFS		30	/* Read-only file system */
+#define	EMLINK		31	/* Too many links */
+#define	EPIPE		32	/* Broken pipe */
+#define	EDOM		33	/* Math argument out of domain of func */
+#define	ERANGE		34	/* Math result not representable */
+
+#define	EDEADLK		35	/* Resource deadlock would occur */
+#define	ENAMETOOLONG	36	/* File name too long */
+#define	ENOLCK		37	/* No record locks available */
+#define	ENOSYS		38	/* Function not implemented */
+#define	ENOTEMPTY	39	/* Directory not empty */
+#define	ELOOP		40	/* Too many symbolic links encountered */
+#define	EWOULDBLOCK	EAGAIN	/* Operation would block */
+#define	ENOMSG		42	/* No message of desired type */
+#define	EIDRM		43	/* Identifier removed */
+#define	ECHRNG		44	/* Channel number out of range */
+#define	EL2NSYNC	45	/* Level 2 not synchronized */
+#define	EL3HLT		46	/* Level 3 halted */
+#define	EL3RST		47	/* Level 3 reset */
+#define	ELNRNG		48	/* Link number out of range */
+#define	EUNATCH		49	/* Protocol driver not attached */
+#define	ENOCSI		50	/* No CSI structure available */
+#define	EL2HLT		51	/* Level 2 halted */
+#define	EBADE		52	/* Invalid exchange */
+#define	EBADR		53	/* Invalid request descriptor */
+#define	EXFULL		54	/* Exchange full */
+#define	ENOANO		55	/* No anode */
+#define	EBADRQC		56	/* Invalid request code */
+#define	EBADSLT		57	/* Invalid slot */
+
+#define	EDEADLOCK	EDEADLK
+
+#define	EBFONT		59	/* Bad font file format */
+#define	ENOSTR		60	/* Device not a stream */
+#define	ENODATA		61	/* No data available */
+#define	ETIME		62	/* Timer expired */
+#define	ENOSR		63	/* Out of streams resources */
+#define	ENONET		64	/* Machine is not on the network */
+#define	ENOPKG		65	/* Package not installed */
+#define	EREMOTE		66	/* Object is remote */
+#define	ENOLINK		67	/* Link has been severed */
+#define	EADV		68	/* Advertise error */
+#define	ESRMNT		69	/* Srmount error */
+#define	ECOMM		70	/* Communication error on send */
+#define	EPROTO		71	/* Protocol error */
+#define	EMULTIHOP	72	/* Multihop attempted */
+#define	EDOTDOT		73	/* RFS specific error */
+#define	EBADMSG		74	/* Not a data message */
+#define	EOVERFLOW	75	/* Value too large for defined data type */
+#define	ENOTUNIQ	76	/* Name not unique on network */
+#define	EBADFD		77	/* File descriptor in bad state */
+#define	EREMCHG		78	/* Remote address changed */
+#define	ELIBACC		79	/* Can not access a needed shared library */
+#define	ELIBBAD		80	/* Accessing a corrupted shared library */
+#define	ELIBSCN		81	/* .lib section in a.out corrupted */
+#define	ELIBMAX		82	/* Attempting to link in too many shared libraries */
+#define	ELIBEXEC	83	/* Cannot exec a shared library directly */
+#define	EILSEQ		84	/* Illegal byte sequence */
+#define	ERESTART	85	/* Interrupted system call should be restarted */
+#define	ESTRPIPE	86	/* Streams pipe error */
+#define	EUSERS		87	/* Too many users */
+#define	ENOTSOCK	88	/* Socket operation on non-socket */
+#define	EDESTADDRREQ	89	/* Destination address required */
+#define	EMSGSIZE	90	/* Message too long */
+#define	EPROTOTYPE	91	/* Protocol wrong type for socket */
+#define	ENOPROTOOPT	92	/* Protocol not available */
+#define	EPROTONOSUPPORT	93	/* Protocol not supported */
+#define	ESOCKTNOSUPPORT	94	/* Socket type not supported */
+#define	EOPNOTSUPP	95	/* Operation not supported on transport endpoint */
+#define	EPFNOSUPPORT	96	/* Protocol family not supported */
+#define	EAFNOSUPPORT	97	/* Address family not supported by protocol */
+#define	EADDRINUSE	98	/* Address already in use */
+#define	EADDRNOTAVAIL	99	/* Cannot assign requested address */
+#define	ENETDOWN	100	/* Network is down */
+#define	ENETUNREACH	101	/* Network is unreachable */
+#define	ENETRESET	102	/* Network dropped connection because of reset */
+#define	ECONNABORTED	103	/* Software caused connection abort */
+#define	ECONNRESET	104	/* Connection reset by peer */
+#define	ENOBUFS		105	/* No buffer space available */
+#define	EISCONN		106	/* Transport endpoint is already connected */
+#define	ENOTCONN	107	/* Transport endpoint is not connected */
+#define	ESHUTDOWN	108	/* Cannot send after transport endpoint shutdown */
+#define	ETOOMANYREFS	109	/* Too many references: cannot splice */
+#define	ETIMEDOUT	110	/* Connection timed out */
+#define	ECONNREFUSED	111	/* Connection refused */
+#define	EHOSTDOWN	112	/* Host is down */
+#define	EHOSTUNREACH	113	/* No route to host */
+#define	EALREADY	114	/* Operation already in progress */
+#define	EINPROGRESS	115	/* Operation now in progress */
+#define	ESTALE		116	/* Stale NFS file handle */
+#define	EUCLEAN		117	/* Structure needs cleaning */
+#define	ENOTNAM		118	/* Not a XENIX named type file */
+#define	ENAVAIL		119	/* No XENIX semaphores available */
+#define	EISNAM		120	/* Is a named type file */
+#define	EREMOTEIO	121	/* Remote I/O error */
+#define	EDQUOT		122	/* Quota exceeded */
+
+#define	ENOMEDIUM	123	/* No medium found */
+#define	EMEDIUMTYPE	124	/* Wrong medium type */
+

File include/low/fcntl.h

+/* $Id: fcntl.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+/* open/fcntl - O_SYNC is only implemented on blocks devices and on files
+   located on an ext2 file system */
+#define O_ACCMODE	   0003
+#define O_RDONLY	     00
+#define O_WRONLY	     01
+#define O_RDWR		     02
+#define O_CREAT		   0100	/* not fcntl */
+#define O_EXCL		   0200	/* not fcntl */
+#define O_NOCTTY	   0400	/* not fcntl */
+#define O_TRUNC		  01000	/* not fcntl */
+#define O_APPEND	  02000
+#define O_NONBLOCK	  04000
+#define O_NDELAY	O_NONBLOCK
+#define O_SYNC		 010000
+#define FASYNC		 020000	/* fcntl, for BSD compatibility */
+#define O_DIRECT	 040000	/* direct disk access hint */
+#define O_LARGEFILE	0100000
+#define O_DIRECTORY	0200000	/* must be a directory */
+#define O_NOFOLLOW	0400000 /* don't follow links */
+
+#define F_DUPFD		0	/* dup */
+#define F_GETFD		1	/* get close_on_exec */
+#define F_SETFD		2	/* set/clear close_on_exec */
+#define F_GETFL		3	/* get file->f_flags */
+#define F_SETFL		4	/* set file->f_flags */
+#define F_GETLK		5
+#define F_SETLK		6
+#define F_SETLKW	7
+
+#define F_SETOWN	8	/*  for sockets. */
+#define F_GETOWN	9	/*  for sockets. */
+#define F_SETSIG	10	/*  for sockets. */
+#define F_GETSIG	11	/*  for sockets. */
+
+#define F_GETLK64	12	/*  using 'struct flock64' */
+#define F_SETLK64	13
+#define F_SETLKW64	14
+
+/* for F_[GET|SET]FL */
+#define FD_CLOEXEC	1	/* actually anything with low bit set goes */
+
+/* for posix fcntl() and lockf() */
+#define F_RDLCK		0
+#define F_WRLCK		1
+#define F_UNLCK		2
+
+/* for old implementation of bsd flock () */
+#define F_EXLCK		4	/* or 3 */
+#define F_SHLCK		8	/* or 4 */
+
+/* for leases */
+#define F_INPROGRESS	16
+
+/* operations for bsd flock(), also used by the kernel implementation */
+#define LOCK_SH		1	/* shared lock */
+#define LOCK_EX		2	/* exclusive lock */
+#define LOCK_NB		4	/* or'd with one of the above to prevent
+				   blocking */
+#define LOCK_UN		8	/* remove lock */
+
+#define LOCK_MAND	32	/* This is a mandatory flock */
+#define LOCK_READ	64	/* ... Which allows concurrent read operations */
+#define LOCK_WRITE	128	/* ... Which allows concurrent write operations */
+#define LOCK_RW		192	/* ... Which allows concurrent read & write ops */
+
+#if 0
+struct flock {
+	short l_type;
+	short l_whence;
+	off_t l_start;
+	off_t l_len;
+	pid_t l_pid;
+};
+
+struct flock64 {
+	short  l_type;
+	short  l_whence;
+	loff_t l_start;
+	loff_t l_len;
+	pid_t  l_pid;
+};
+#endif
+
+#define F_LINUX_SPECIFIC_BASE	1024

File include/low/file.h

+/* file descriptors */
+/* $Id: file.h,v 1.2 2004/01/22 12:37:09 Wez Exp $ */
+
+struct iovec {
+	void *iov_base;
+	unsigned long iov_len;
+};
+
+struct __old_kernel_stat {
+    unsigned short st_dev;
+    unsigned short st_ino;
+    unsigned short st_mode;
+    unsigned short st_nlink;
+    unsigned short st_uid;
+    unsigned short st_gid;
+    unsigned short st_rdev;
+    unsigned long  st_size;
+    unsigned long  st_atime;
+    unsigned long  st_mtime;
+    unsigned long  st_ctime;
+};
+
+struct stat {
+    unsigned long  st_dev;
+    unsigned long  st_ino;
+    unsigned short st_mode;
+    unsigned short st_nlink;
+    unsigned short st_uid;
+    unsigned short st_gid;
+    unsigned long  st_rdev;
+    unsigned long  st_size;
+    unsigned long  st_blksize;
+    unsigned long  st_blocks;
+    unsigned long  st_atime;
+    unsigned long  st_atime_nsec;
+    unsigned long  st_mtime;
+    unsigned long  st_mtime_nsec;
+    unsigned long  st_ctime;
+    unsigned long  st_ctime_nsec;
+    unsigned long  __unused4;
+    unsigned long  __unused5;
+};
+
+struct stat64 {
+    UINT64  st_dev;
+    unsigned char   __pad0[4];
+
+#define STAT64_HAS_BROKEN_ST_INO    1
+    unsigned long   __st_ino;
+
+    unsigned int    st_mode;
+    unsigned int    st_nlink;
+
+    unsigned long   st_uid;
+    unsigned long   st_gid;
+
+    UINT64  st_rdev;
+    unsigned char   __pad3[4];
+
+    INT64 st_size;
+    unsigned long   st_blksize;
+
+    unsigned long   st_blocks;  /* Number 512-byte blocks allocated. */
+    unsigned long   __pad4;     /* future possible st_blocks high bits */
+
+    unsigned long   st_atime;
+    unsigned long   st_atime_nsec;
+
+    unsigned long   st_mtime;
+    unsigned int    st_mtime_nsec;
+
+    unsigned long   st_ctime;
+    unsigned long   st_ctime_nsec;
+
+    UINT64  st_ino;
+};
+
+#include <low/dirent.h>
+/*
+ * File types
+ *
+ * NOTE! These match bits 12..15 of stat.st_mode
+ * (ie "(i_mode >> 12) & 15").
+ */
+#define DT_UNKNOWN  0
+#define DT_FIFO     1
+#define DT_CHR      2
+#define DT_DIR      4
+#define DT_BLK      6
+#define DT_REG      8
+#define DT_LNK      10
+#define DT_SOCK     12
+#define DT_WHT      14
+
+
+struct file_handler {
+	int (*reader)(struct file_descriptor *file, char *buf, int len);
+	int (*writer)(struct file_descriptor *file, char *buf, int len);
+	int (*closer)(struct file_descriptor *file);
+	int (*stat64)(struct file_descriptor *file, struct stat64 *sb);
+	int (*fcntl64)(struct file_descriptor *file, int cmd, long arg);
+	int (*lseek)(struct file_descriptor *file, long offset, unsigned int origin);
+	int (*getdents64)(struct file_descriptor *file, struct linux_dirent64 *dirent, unsigned int count);
+};
+
+struct file_descriptor {
+	struct file_descriptor *next, *prev;
+	unsigned long refcount;
+	int fd;
+	int 	type;		// S_IFxxxx
+	HANDLE	handle;
+
+	int flags;		// flags used when opened
+	unsigned close_on_exec:1;
+
+	struct file_handler *funcs;
+	void *data;
+	char *full_path;
+};
+
+
+extern struct file_descriptor *get_file(int fd);
+
+
+int win32_handle_reader(struct file_descriptor *file, char *buf, int len);
+int win32_handle_writer(struct file_descriptor *file, char *buf, int len);
+int win32_handle_closer(struct file_descriptor *file);
+int win32_handle_lseeker(struct file_descriptor *file, long offset, unsigned int origin);
+int win32_handle_stat64(struct file_descriptor *file, struct stat64 *sb);
+
+extern struct file_handler fd_win32_handler;
+extern struct file_handler fd_dir_handler;
+
+int close_file(struct file_descriptor *file);
+int close_fd(int fd);
+struct file_descriptor *allocate_file(void);
+struct file_descriptor *import_handle(HANDLE h, int fd);
+int set_file_fd(struct file_descriptor *file, int fd);
+
+#include <low/fcntl.h>
+

File include/low/low.h

+#ifndef _LOW_LOW_H_
+#define _LOW_LOW_H_
+/* $Id: low.h,v 1.2 2004/01/22 12:37:09 Wez Exp $ */
+
+#ifdef LOW_IMPORTS
+# define LOWAPI __declspec(dllimport)
+#else
+# define LOWAPI __declspec(dllexport)
+#endif
+
+#define WINVER			0x0500
+#define _WIN32_WINNT	0x0500
+#include <windows.h>
+#include <psapi.h>
+
+#include <low/buildutil.h>
+#include <low/mem.h>
+#include <low/syscall.h>
+#include <low/mgr_thread.h>
+#include <low/errno.h>
+#include <low/stat.h>
+#include <low/file.h>
+#include <low/proc.h>
+#include <low/elf.h>
+#include <low/utsname.h>
+
+#include <stdarg.h>
+LOWAPI void kprintf(const char *fmt, ...);
+extern __declspec(noreturn) void exit_proc(int exit_code);
+LOWAPI int low_start_interp_proc(void);
+extern int win32_to_errno(unsigned long oserrno);
+
+
+#define printf	printf is a function from libc, use kprintf instead
+
+#endif
+

File include/low/mem.h

+/* $Id: mem.h,v 1.2 2004/01/22 12:37:09 Wez Exp $ */
+
+extern void *kmalloc(unsigned long size);
+extern void kfree(void *mem);
+extern char *kstrdup(char *str);
+
+void * __cdecl _alloca(unsigned long len);
+
+extern DWORD do_mmap(struct file_descriptor *file, DWORD addr, DWORD size, int prot, int type, DWORD offset);
+int mman_page_in(DWORD addr, int is_write);
+extern void load_all_mmap(void);
+extern void show_memory_map(void);
+DWORD mmap_dynamic_file_mapping(HANDLE file, DWORD offset, DWORD size);
+
+#include <low/mman.h>
+
+extern DWORD *top_of_user_stack;
+

File include/low/mgr_thread.h

+
+#define LOW_MGR_RUN_SYSCALL		(WM_USER + 1)
+

File include/low/mman.h

+/* $Id: mman.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#define PROT_READ	0x1		/* page can be read */
+#define PROT_WRITE	0x2		/* page can be written */
+#define PROT_EXEC	0x4		/* page can be executed */
+#define PROT_SEM	0x8		/* page may be used for atomic ops */
+#define PROT_NONE	0x0		/* page can not be accessed */
+#define PROT_GROWSDOWN	0x01000000	/* mprotect flag: extend change to start of growsdown vma */
+#define PROT_GROWSUP	0x02000000	/* mprotect flag: extend change to end of growsup vma */
+
+#define MAP_SHARED	0x01		/* Share changes */
+#define MAP_PRIVATE	0x02		/* Changes are private */
+#define MAP_TYPE	0x0f		/* Mask for type of mapping */
+#define MAP_FIXED	0x10		/* Interpret addr exactly */
+#define MAP_ANONYMOUS	0x20		/* don't use a file */
+
+#define MAP_GROWSDOWN	0x0100		/* stack-like segment */
+#define MAP_DENYWRITE	0x0800		/* ETXTBSY */
+#define MAP_EXECUTABLE	0x1000		/* mark it as an executable */
+#define MAP_LOCKED	0x2000		/* pages are locked */
+#define MAP_NORESERVE	0x4000		/* don't check for reservations */
+#define MAP_POPULATE	0x8000		/* populate (prefault) pagetables */
+#define MAP_NONBLOCK	0x10000		/* do not block on IO */
+
+#define MS_ASYNC	1		/* sync memory asynchronously */
+#define MS_INVALIDATE	2		/* invalidate the caches */
+#define MS_SYNC		4		/* synchronous memory sync */
+
+#define MCL_CURRENT	1		/* lock all current mappings */
+#define MCL_FUTURE	2		/* lock all future mappings */
+
+#define MADV_NORMAL	0x0		/* default page-in behavior */
+#define MADV_RANDOM	0x1		/* page-in minimum required */
+#define MADV_SEQUENTIAL	0x2		/* read-ahead aggressively */
+#define MADV_WILLNEED	0x3		/* pre-fault pages */
+#define MADV_DONTNEED	0x4		/* discard these pages */
+
+/* compatibility flags */
+#define MAP_ANON	MAP_ANONYMOUS
+#define MAP_FILE	0
+

File include/low/proc.h

+/* $Id: proc.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+struct process_info {
+	int umask;
+	int uid, gid, euid, egid;
+
+	DWORD data_start, data_top, brk;
+};
+
+extern struct process_info current;
+

File include/low/stat.h

+/* $Id: stat.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#define S_IFMT  00170000
+#define S_IFSOCK 0140000
+#define S_IFLNK	 0120000
+#define S_IFREG  0100000
+#define S_IFBLK  0060000
+#define S_IFDIR  0040000
+#define S_IFCHR  0020000
+#define S_IFIFO  0010000
+#define S_ISUID  0004000
+#define S_ISGID  0002000
+#define S_ISVTX  0001000
+
+#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
+#define S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
+#define S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
+#define S_ISSOCK(m)	(((m) & S_IFMT) == S_IFSOCK)
+
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+
+#define S_IRWXUGO	(S_IRWXU|S_IRWXG|S_IRWXO)
+#define S_IALLUGO	(S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
+#define S_IRUGO		(S_IRUSR|S_IRGRP|S_IROTH)
+#define S_IWUGO		(S_IWUSR|S_IWGRP|S_IWOTH)
+#define S_IXUGO		(S_IXUSR|S_IXGRP|S_IXOTH)
+
+#if 0
+#include <linux/types.h>
+#include <linux/time.h>
+
+struct kstat {
+	unsigned long	ino;
+	dev_t		dev;
+	umode_t		mode;
+	nlink_t		nlink;
+	uid_t		uid;
+	gid_t		gid;
+	dev_t		rdev;
+	loff_t		size;
+	struct timespec  atime;
+	struct timespec	mtime;
+	struct timespec	ctime;
+	unsigned long	blksize;
+	unsigned long	blocks;
+};
+#endif
+

File include/low/syscall-numbers.h

+/*
+ * This file contains the system call numbers.
+ */
+/* $Id: syscall-numbers.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#define __NR_restart_syscall      0
+#define __NR_exit		  1
+#define __NR_fork		  2
+#define __NR_read		  3
+#define __NR_write		  4
+#define __NR_open		  5
+#define __NR_close		  6
+#define __NR_waitpid		  7
+#define __NR_creat		  8
+#define __NR_link		  9
+#define __NR_unlink		 10
+#define __NR_execve		 11
+#define __NR_chdir		 12
+#define __NR_time		 13
+#define __NR_mknod		 14
+#define __NR_chmod		 15
+#define __NR_lchown		 16
+#define __NR_break		 17
+#define __NR_oldstat		 18
+#define __NR_lseek		 19
+#define __NR_getpid		 20
+#define __NR_mount		 21
+#define __NR_umount		 22
+#define __NR_setuid		 23
+#define __NR_getuid		 24
+#define __NR_stime		 25
+#define __NR_ptrace		 26
+#define __NR_alarm		 27
+#define __NR_oldfstat		 28
+#define __NR_pause		 29
+#define __NR_utime		 30
+#define __NR_stty		 31
+#define __NR_gtty		 32
+#define __NR_access		 33
+#define __NR_nice		 34
+#define __NR_ftime		 35
+#define __NR_sync		 36
+#define __NR_kill		 37
+#define __NR_rename		 38
+#define __NR_mkdir		 39
+#define __NR_rmdir		 40
+#define __NR_dup		 41
+#define __NR_pipe		 42
+#define __NR_times		 43
+#define __NR_prof		 44
+#define __NR_brk		 45
+#define __NR_setgid		 46
+#define __NR_getgid		 47
+#define __NR_signal		 48
+#define __NR_geteuid		 49
+#define __NR_getegid		 50
+#define __NR_acct		 51
+#define __NR_umount2		 52
+#define __NR_lock		 53
+#define __NR_ioctl		 54
+#define __NR_fcntl		 55
+#define __NR_mpx		 56
+#define __NR_setpgid		 57
+#define __NR_ulimit		 58
+#define __NR_oldolduname	 59
+#define __NR_umask		 60
+#define __NR_chroot		 61
+#define __NR_ustat		 62
+#define __NR_dup2		 63
+#define __NR_getppid		 64
+#define __NR_getpgrp		 65
+#define __NR_setsid		 66
+#define __NR_sigaction		 67
+#define __NR_sgetmask		 68
+#define __NR_ssetmask		 69
+#define __NR_setreuid		 70
+#define __NR_setregid		 71
+#define __NR_sigsuspend		 72
+#define __NR_sigpending		 73
+#define __NR_sethostname	 74
+#define __NR_setrlimit		 75
+#define __NR_getrlimit		 76	/* Back compatible 2Gig limited rlimit */
+#define __NR_getrusage		 77
+#define __NR_gettimeofday	 78
+#define __NR_settimeofday	 79
+#define __NR_getgroups		 80
+#define __NR_setgroups		 81
+#define __NR_select		 82
+#define __NR_symlink		 83
+#define __NR_oldlstat		 84
+#define __NR_readlink		 85
+#define __NR_uselib		 86
+#define __NR_swapon		 87
+#define __NR_reboot		 88
+#define __NR_readdir		 89
+#define __NR_mmap		 90
+#define __NR_munmap		 91
+#define __NR_truncate		 92
+#define __NR_ftruncate		 93
+#define __NR_fchmod		 94
+#define __NR_fchown		 95
+#define __NR_getpriority	 96
+#define __NR_setpriority	 97
+#define __NR_profil		 98
+#define __NR_statfs		 99
+#define __NR_fstatfs		100
+#define __NR_ioperm		101
+#define __NR_socketcall		102
+#define __NR_syslog		103
+#define __NR_setitimer		104
+#define __NR_getitimer		105
+#define __NR_stat		106
+#define __NR_lstat		107
+#define __NR_fstat		108
+#define __NR_olduname		109
+#define __NR_iopl		110
+#define __NR_vhangup		111
+#define __NR_idle		112
+#define __NR_vm86old		113
+#define __NR_wait4		114
+#define __NR_swapoff		115
+#define __NR_sysinfo		116
+#define __NR_ipc		117
+#define __NR_fsync		118
+#define __NR_sigreturn		119
+#define __NR_clone		120
+#define __NR_setdomainname	121
+#define __NR_uname		122
+#define __NR_modify_ldt		123
+#define __NR_adjtimex		124
+#define __NR_mprotect		125
+#define __NR_sigprocmask	126
+#define __NR_create_module	127
+#define __NR_init_module	128
+#define __NR_delete_module	129
+#define __NR_get_kernel_syms	130
+#define __NR_quotactl		131
+#define __NR_getpgid		132
+#define __NR_fchdir		133
+#define __NR_bdflush		134
+#define __NR_sysfs		135
+#define __NR_personality	136
+#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
+#define __NR_setfsuid		138
+#define __NR_setfsgid		139
+#define __NR__llseek		140
+#define __NR_getdents		141
+#define __NR__newselect		142
+#define __NR_flock		143
+#define __NR_msync		144
+#define __NR_readv		145
+#define __NR_writev		146
+#define __NR_getsid		147
+#define __NR_fdatasync		148
+#define __NR__sysctl		149
+#define __NR_mlock		150
+#define __NR_munlock		151
+#define __NR_mlockall		152
+#define __NR_munlockall		153
+#define __NR_sched_setparam		154
+#define __NR_sched_getparam		155
+#define __NR_sched_setscheduler		156
+#define __NR_sched_getscheduler		157
+#define __NR_sched_yield		158
+#define __NR_sched_get_priority_max	159
+#define __NR_sched_get_priority_min	160
+#define __NR_sched_rr_get_interval	161
+#define __NR_nanosleep		162
+#define __NR_mremap		163
+#define __NR_setresuid		164
+#define __NR_getresuid		165
+#define __NR_vm86		166
+#define __NR_query_module	167
+#define __NR_poll		168
+#define __NR_nfsservctl		169
+#define __NR_setresgid		170
+#define __NR_getresgid		171
+#define __NR_prctl              172
+#define __NR_rt_sigreturn	173
+#define __NR_rt_sigaction	174
+#define __NR_rt_sigprocmask	175
+#define __NR_rt_sigpending	176
+#define __NR_rt_sigtimedwait	177
+#define __NR_rt_sigqueueinfo	178
+#define __NR_rt_sigsuspend	179
+#define __NR_pread64		180
+#define __NR_pwrite64		181
+#define __NR_chown		182
+#define __NR_getcwd		183
+#define __NR_capget		184
+#define __NR_capset		185
+#define __NR_sigaltstack	186
+#define __NR_sendfile		187
+#define __NR_getpmsg		188	/* some people actually want streams */
+#define __NR_putpmsg		189	/* some people actually want streams */
+#define __NR_vfork		190
+#define __NR_ugetrlimit		191	/* SuS compliant getrlimit */
+#define __NR_mmap2		192
+#define __NR_truncate64		193
+#define __NR_ftruncate64	194
+#define __NR_stat64		195
+#define __NR_lstat64		196
+#define __NR_fstat64		197
+#define __NR_lchown32		198
+#define __NR_getuid32		199
+#define __NR_getgid32		200
+#define __NR_geteuid32		201
+#define __NR_getegid32		202
+#define __NR_setreuid32		203
+#define __NR_setregid32		204
+#define __NR_getgroups32	205
+#define __NR_setgroups32	206
+#define __NR_fchown32		207
+#define __NR_setresuid32	208
+#define __NR_getresuid32	209
+#define __NR_setresgid32	210
+#define __NR_getresgid32	211
+#define __NR_chown32		212
+#define __NR_setuid32		213
+#define __NR_setgid32		214
+#define __NR_setfsuid32		215
+#define __NR_setfsgid32		216
+#define __NR_pivot_root		217
+#define __NR_mincore		218
+#define __NR_madvise		219
+#define __NR_madvise1		219	/* delete when C lib stub is removed */
+#define __NR_getdents64		220
+#define __NR_fcntl64		221
+/* 223 is unused */
+#define __NR_gettid		224
+#define __NR_readahead		225
+#define __NR_setxattr		226
+#define __NR_lsetxattr		227
+#define __NR_fsetxattr		228
+#define __NR_getxattr		229
+#define __NR_lgetxattr		230
+#define __NR_fgetxattr		231
+#define __NR_listxattr		232
+#define __NR_llistxattr		233
+#define __NR_flistxattr		234
+#define __NR_removexattr	235
+#define __NR_lremovexattr	236
+#define __NR_fremovexattr	237
+#define __NR_tkill		238
+#define __NR_sendfile64		239
+#define __NR_futex		240
+#define __NR_sched_setaffinity	241
+#define __NR_sched_getaffinity	242
+#define __NR_set_thread_area	243
+#define __NR_get_thread_area	244
+#define __NR_io_setup		245
+#define __NR_io_destroy		246
+#define __NR_io_getevents	247
+#define __NR_io_submit		248
+#define __NR_io_cancel		249
+#define __NR_fadvise64		250
+
+#define __NR_exit_group		252
+#define __NR_lookup_dcookie	253
+#define __NR_epoll_create	254
+#define __NR_epoll_ctl		255
+#define __NR_epoll_wait		256
+#define __NR_remap_file_pages	257
+#define __NR_set_tid_address	258
+#define __NR_timer_create	259
+#define __NR_timer_settime	260
+#define __NR_timer_gettime	261
+#define __NR_timer_getoverrun	262
+#define __NR_timer_delete	263
+#define __NR_clock_settime	264
+#define __NR_clock_gettime	265
+#define __NR_clock_getres	266
+#define __NR_clock_nanosleep 267
+#define __NR_statfs64		268
+#define __NR_fstatfs64		269
+#define __NR_tgkill		270
+#define __NR_utimes		271
+#define __NR_fadvise64_64	272
+#define __NR_vserver		273
+
+

File include/low/syscall.h

+/* $Id: syscall.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#define SYSCALL(name)	sys_##name
+typedef long (*syscall_func)();
+
+#include <low/syscall-numbers.h>
+#include <low/systrap.h>
+
+#define LOW_EXCEPTION_SYSCALL_ALT_STACK	0x00006942
+
+struct low_exc_ctx {
+	struct regs *r; /* original regs */
+	unsigned long *sp; /* stack */
+};
+
+extern struct low_exc_ctx CTX;
+
+extern int __syscall_max;
+extern syscall_func __syscall_table[];
+extern char * __syscall_name_table[];
+

File include/low/systrap.h

+		
+/* this structure is used to communicate
+ * with the kernel hook about the trap
+ * entry point and it's stack. */
+struct low_systrap_info {
+	unsigned long handler_addr;
+	unsigned long process_id;
+};
+
+#define IOCTL_PENGWIN_SET_TRAP		CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, 0, FILE_ANY_ACCESS)
+#define IOCTL_PENGWIN_CLEAR_TRAP	CTL_CODE(FILE_DEVICE_UNKNOWN, 0x802, 0, FILE_ANY_ACCESS)
+
+struct regs {
+   unsigned long edi, esi, ebp, esp, ebx, edx, ecx, eax;
+};
+
+struct frame {
+	struct regs r; /* from pusha */
+	unsigned long user_eip; // saved insn address of insn after the INT insn
+	unsigned long user_cs, eflags;
+	unsigned long *user_stack;
+	unsigned long *user_ss;
+};
+
+

File include/low/utsname.h

+/* $Id: utsname.h,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+#define __OLD_UTS_LEN 8
+
+struct oldold_utsname {
+	char sysname[9];
+	char nodename[9];
+	char release[9];
+	char version[9];
+	char machine[9];
+};
+
+#define __NEW_UTS_LEN 64
+
+struct old_utsname {
+	char sysname[65];
+	char nodename[65];
+	char release[65];
+	char version[65];
+	char machine[65];
+};
+
+struct new_utsname {
+	char sysname[65];
+	char nodename[65];
+	char release[65];
+	char version[65];
+	char machine[65];
+	char domainname[65];
+};
+

File interp/boot.c

+/* bootstrap linux environment */
+/* $Id: boot.c,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+
+#include <low/low.h>
+
+int startup(void)
+{
+	return low_start_interp_proc();
+}
+

File kernel/.cvsignore

+initfuncs.c
+syscalltable.c

File kernel/boot.c

+/* $Id: boot.c,v 1.3 2004/01/22 12:37:09 Wez Exp $ */
+#include <low/low.h>
+
+DWORD *top_of_user_stack;
+
+extern low_system_init_func __init_proc_func_table[];
+extern low_system_fini_func __fini_proc_func_table[];
+extern int strace_mode;
+
+__declspec(noreturn) void exit_proc(int exit_code)
+{
+	int i;
+
+	kprintf("I'm the exit proc\n");
+	/* call the various process shut-down functions */
+	for (i = 0; __fini_proc_func_table[i]; i++) {
+		kprintf("calling fini %d ... ", i);
+		__fini_proc_func_table[i]();
+		kprintf("done\n");
+	}
+
+	/* and the process goes away */
+	ExitProcess(exit_code);
+}
+
+long SYSCALL(exit)(long exitcode)
+{
+	exit_proc(exitcode);
+}
+
+long SYSCALL(exit_group)(long exitcode)
+{
+	/* kill every thread in the thread group */
+	exit_proc(exitcode);
+}
+
+
+/* convert system command line into traditional argv array */
+#define NULCHAR    '\0'
+#define SPACECHAR  ' '
+#define TABCHAR    '\t'
+#define DQUOTECHAR '\"'
+#define SLASHCHAR  '\\'
+
+static void parse_command_line(char *cmdstart, char **argv, char *args, int *numargs, int *numchars)
+{
+	char *p;
+	unsigned char c;
+	int inquote;                    /* 1 = inside quotes */
+	int copychar;                   /* 1 = copy char to *args */
+	unsigned numslash;              /* num of backslashes seen */
+
+	*numchars = 0;
+	*numargs = 1;                   /* the program name at least */
+
+	/* first scan the program name, copy it, and count the bytes */
+	p = cmdstart;
+	if (argv)
+		*argv++ = args;
+
+	/* A quoted program name is handled here. The handling is much
+	   simpler than for other arguments. Basically, whatever lies
+	   between the leading double-quote and next one, or a terminal null
+	   character is simply accepted. Fancier handling is not required
+	   because the program name must be a legal NTFS/HPFS file name.
+	   Note that the double-quote characters are not copied, nor do they
+	   contribute to numchars. */
+	inquote = FALSE;
+	do {
+		if (*p == DQUOTECHAR )
+		{
+			inquote = !inquote;
+			c = (unsigned char) *p++;
+			continue;
+		}
+		++*numchars;
+		if (args)
+			*args++ = *p;
+
+		c = (unsigned char) *p++;
+		if (IsDBCSLeadByte(c)) {
+			++*numchars;
+			if (args)
+				*args++ = *p;   /* copy 2nd byte too */
+			p++;  /* skip over trail byte */
+		}
+
+	} while ( (c != NULCHAR && (inquote || (c !=SPACECHAR && c != TABCHAR))) );
+
+	if ( c == NULCHAR ) {
+		p--;
+	} else {
+		if (args)
+			*(args-1) = NULCHAR;
+	}
+
+	inquote = 0;
+
+	/* loop on each argument */
+	for(;;) {
+
+		while (*p == SPACECHAR || *p == TABCHAR)
+			++p;
+
+		if (*p == NULCHAR)
+			break;              /* end of args */
+
+		/* scan an argument */
+		if (argv)
+			*argv++ = args;     /* store ptr to arg */
+		++*numargs;
+
+		/* loop through scanning one argument */
+		for (;;) {
+			copychar = 1;
+			/* Rules: 2N backslashes + " ==> N backslashes and begin/end quote
+			   2N+1 backslashes + " ==> N backslashes + literal "
+			   N backslashes ==> N backslashes */
+			numslash = 0;
+			while (*p == SLASHCHAR) {
+				/* count number of backslashes for use below */
+				++p;
+				++numslash;
+			}
+			if (*p == DQUOTECHAR) {
+				/* if 2N backslashes before, start/end quote, otherwise
+				   copy literally */
+				if (numslash % 2 == 0) {
+					if (inquote) {
+						if (p[1] == DQUOTECHAR)
+							p++;    /* Double quote inside quoted string */
+						else        /* skip first quote char and copy second */
+							copychar = 0;
+					} else
+						copychar = 0;       /* don't copy quote */
+
+					inquote = !inquote;
+				}
+				numslash /= 2;          /* divide numslash by two */
+			}
+
+			/* copy slashes */
+			while (numslash--) {
+				if (args)
+					*args++ = SLASHCHAR;
+				++*numchars;
+			}
+
+			/* if at end of arg, break loop */
+			if (*p == NULCHAR || (!inquote && (*p == SPACECHAR || *p == TABCHAR)))
+				break;
+
+			/* copy character into argument */
+#if 0
+			if (copychar) {
+				if (args) {
+					if (IsDBCSLeadByte(*p)) {
+						*args++ = *p++;
+						++*numchars;
+					}
+					*args++ = *p;
+				} else {
+					if (IsDBCSLeadByte(*p)) {
+						++p;
+						++*numchars;
+					}
+				}
+				++*numchars;
+			}
+			++p;
+#endif
+			if (copychar) {
+				if (args)
+					*args++ = *p;
+				++*numchars;
+			}
+			++p;
+		}
+
+		/* null-terminate the argument */
+
+		if (args)
+			*args++ = NULCHAR;          /* terminate string */
+		++*numchars;
+	}
+
+	/* We put one last argument in -- a null ptr */
+	if (argv)
+		*argv++ = NULL;
+	++*numargs;
+
+}
+
+static void parse_environment(char **outenv, int *out_numstrings)
+{
+	int numstrings = 0;
+	char *atmp;
+
+	atmp = GetEnvironmentStrings();
+
+	while (*atmp != '\0') {
+		/* don't count "=..." stuff for drive letters */
+		if (*atmp != '=') {
+			if (outenv) {
+				outenv[numstrings] = atmp;
+			//	kprintf("env[%d]: %s\n", numstrings, atmp);
+			}
+			++numstrings;
+		}
+		atmp += strlen(atmp) + 1;
+	}
+	*out_numstrings = numstrings;
+}
+
+/* This is the entry point for our stub interpreter
+ * executable.  Absolutely nothing has been initialized
+ * at this point: we have a "clean" process to play with */
+LOWAPI int low_start_interp_proc(void)
+{
+	int i;
+	char *commandline;
+	int argc, numchars;
+	char **argv, **envp;
+	MEMORY_BASIC_INFORMATION info;
+
+kprintf("stack is @ approx %p\n", &i);
+	if (VirtualQuery(&info, &info, sizeof(info))) {
+		kprintf("query says base=%p size=%x\n", info.BaseAddress, info.RegionSize);
+		top_of_user_stack = (DWORD*)((char*)info.BaseAddress + info.RegionSize - 4);
+	}
+	
+	/* call the various process boot-up functions */
+	for (i = 0; __init_proc_func_table[i]; i++) {
+		if (!__init_proc_func_table[i]()) {
+			exit_proc(-1);
+		}
+	}
+	
+	/* now we want to parse the args and call execve syscall
+	 * to run the image */
+	commandline = GetCommandLine();
+	kprintf("commandline %s\n", commandline);
+
+	parse_command_line(commandline, NULL, NULL, &argc, &numchars);
+	argv = _alloca(argc * sizeof(char *) + numchars * sizeof(char));
+
+	parse_command_line(commandline, argv, ((char*)argv) + argc * sizeof(char*), &argc, &numchars);
+	argv++;
+
+	/* check for kernel args */
+	do {
+		if (argv[0] && strcmp(argv[0], "-strace") == 0) {
+			strace_mode = 1;
+			argv++;
+			continue;
+		}
+		if (argv[0] && strcmp(argv[0], "-dump-mmap") == 0) {
+			show_memory_map();
+			argv++;
+			continue;
+		}
+		break;
+	} while (1);
+	
+	/* we want the environment now too */
+	parse_environment(NULL, &i);
+	envp = _alloca((i + 1) * sizeof(char *));
+	parse_environment(envp, &i);
+
+	kprintf("strapping into exec\n");
+	
+	/* now we are ready to exec */
+	__asm {
+		mov ecx, argv
+		mov ebx, [ecx]
+		mov edx, envp
+		mov eax, __NR_execve
+		int 0x80
+	}
+	
+	exit_proc(0);
+	/* NOTREACHED */
+	return 1;
+}
+

File kernel/dllboot.c

+/* bootstrap DLL stuff */
+/* $Id: dllboot.c,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+#include <low/low.h>
+
+extern low_system_init_func __init_func_table[];
+extern low_system_fini_func __fini_func_table[];
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
+{
+	int i;
+	BOOL ret = TRUE;
+	
+	if (dwReason == DLL_PROCESS_ATTACH) {
+		for (i = 0; __init_func_table[i]; i++) {
+			if (!__init_func_table[i]()) {
+				ret = FALSE;
+				break;
+			}
+		}
+	} else if (dwReason == DLL_PROCESS_DETACH) {
+		for (i = 0; __fini_func_table[i]; i++) {
+			__fini_func_table[i]();
+		}
+	}
+	return ret;
+}
+
+

File kernel/driver_install.c

+#include <windows.h>
+
+static char driver_name[1024];
+
+#define SVC_NAME	"PengWin Syscall Hook"
+
+static int get_driver_name(void)
+{
+	HANDLE f;
+	DWORD len;
+	char local_name[1024];
+
+	len = GetModuleFileName(GetModuleHandle(KERNEL_DLL), local_name, sizeof(local_name));
+	strcpy(&local_name[len - sizeof(KERNEL_DLL) + 1], DRIVER_SYS);
+
+	/* sanity check */
+	f = CreateFile(local_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
+	if (f == INVALID_HANDLE_VALUE) {
+		kprintf("Could not find `%s'\n", local_name);
+		return 0;
+	}
+
+	CloseHandle(f);
+
+	GetSystemDirectory(driver_name, sizeof(driver_name));
+	strcat(driver_name, "\\" DRIVER_SYS);
+
+	kprintf("Copying %s -> %s\n", local_name, driver_name);
+	
+	return CopyFile(local_name, driver_name, FALSE);
+}
+
+int win32_install_and_start_driver(void)
+{
+	SC_HANDLE srv, mgr;
+	DWORD err;
+	int ret = FALSE;
+
+	mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+	if (!mgr)
+		return FALSE;
+
+	if (!get_driver_name()) {
+		CloseServiceHandle(mgr);
+		return 0;
+	}
+
+	kprintf("device: %s\n", driver_name);
+	srv = CreateService(mgr, SVC_NAME, SVC_NAME, SERVICE_ALL_ACCESS,
+			SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
+			driver_name, NULL, NULL, NULL, NULL, NULL);
+
+	if (srv == NULL && GetLastError() == ERROR_SERVICE_EXISTS) {
+		kprintf("service already exists; opening a handle to it then\n");
+		srv = OpenService(mgr, SVC_NAME, SERVICE_ALL_ACCESS);
+	}
+
+	if (srv) {
+		if (!StartService(srv, 0, NULL) && GetLastError() != ERROR_SERVICE_ALREADY_RUNNING) {
+			ret = FALSE;
+			kprintf("failed to start service %s\n", win32_error(GetLastError()));
+		} else {
+			kprintf("service started OK!\n");
+			ret = TRUE;
+		}
+	}
+
+	if (srv) {
+		CloseServiceHandle(srv);
+	}
+	CloseServiceHandle(mgr);
+	kprintf("startup: %d\n", ret);
+	return ret;
+}
+
+int win32_remove_driver(void)
+{
+	SC_HANDLE srv, mgr;
+	SERVICE_STATUS err;
+	int ret = FALSE;
+
+	mgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
+	if (!mgr)
+		return FALSE;
+
+	srv = OpenService(mgr, SVC_NAME, SERVICE_ALL_ACCESS);
+
+	if (srv) {
+		ControlService(srv, SERVICE_CONTROL_STOP, &err);
+		DeleteService(srv);
+		CloseServiceHandle(srv);
+	}
+	CloseServiceHandle(mgr);
+	return ret;	
+}
+

File kernel/errno.c

+/* $Id: errno.c,v 1.1 2004/01/20 13:21:14 Wez Exp $ */
+#include <low/low.h>
+
+/* This is the error table that defines the mapping between OS error
+   codes and errno values */
+
+struct errentry {
+        unsigned long oscode;           /* OS return value */
+        int errnocode;  /* System V error code */
+};
+
+static struct errentry errtable[] = {
+	{  ERROR_INVALID_FUNCTION,       EINVAL    },  /* 1 */
+	{  ERROR_FILE_NOT_FOUND,         ENOENT    },  /* 2 */
+	{  ERROR_PATH_NOT_FOUND,         ENOENT    },  /* 3 */
+	{  ERROR_TOO_MANY_OPEN_FILES,    EMFILE    },  /* 4 */
+	{  ERROR_ACCESS_DENIED,          EACCES    },  /* 5 */
+	{  ERROR_INVALID_HANDLE,         EBADF     },  /* 6 */
+	{  ERROR_ARENA_TRASHED,          ENOMEM    },  /* 7 */
+	{  ERROR_NOT_ENOUGH_MEMORY,      ENOMEM    },  /* 8 */
+	{  ERROR_INVALID_BLOCK,          ENOMEM    },  /* 9 */
+	{  ERROR_BAD_ENVIRONMENT,        E2BIG     },  /* 10 */
+	{  ERROR_BAD_FORMAT,             ENOEXEC   },  /* 11 */
+	{  ERROR_INVALID_ACCESS,         EINVAL    },  /* 12 */
+	{  ERROR_INVALID_DATA,           EINVAL    },  /* 13 */
+	{  ERROR_INVALID_DRIVE,          ENOENT    },  /* 15 */
+	{  ERROR_CURRENT_DIRECTORY,      EACCES    },  /* 16 */
+	{  ERROR_NOT_SAME_DEVICE,        EXDEV     },  /* 17 */
+	{  ERROR_NO_MORE_FILES,          ENOENT    },  /* 18 */
+	{  ERROR_LOCK_VIOLATION,         EACCES    },  /* 33 */
+	{  ERROR_BAD_NETPATH,            ENOENT    },  /* 53 */
+	{  ERROR_NETWORK_ACCESS_DENIED,  EACCES    },  /* 65 */
+	{  ERROR_BAD_NET_NAME,           ENOENT    },  /* 67 */
+	{  ERROR_FILE_EXISTS,            EEXIST    },  /* 80 */
+	{  ERROR_CANNOT_MAKE,            EACCES    },  /* 82 */
+	{  ERROR_FAIL_I24,               EACCES    },  /* 83 */
+	{  ERROR_INVALID_PARAMETER,      EINVAL    },  /* 87 */
+	{  ERROR_NO_PROC_SLOTS,          EAGAIN    },  /* 89 */
+	{  ERROR_DRIVE_LOCKED,           EACCES    },  /* 108 */
+	{  ERROR_BROKEN_PIPE,            EPIPE     },  /* 109 */
+	{  ERROR_DISK_FULL,              ENOSPC    },  /* 112 */
+	{  ERROR_INVALID_TARGET_HANDLE,  EBADF     },  /* 114 */
+	{  ERROR_INVALID_HANDLE,         EINVAL    },  /* 124 */
+	{  ERROR_WAIT_NO_CHILDREN,       ECHILD    },  /* 128 */
+	{  ERROR_CHILD_NOT_COMPLETE,     ECHILD    },  /* 129 */
+	{  ERROR_DIRECT_ACCESS_HANDLE,   EBADF     },  /* 130 */
+	{  ERROR_NEGATIVE_SEEK,          EINVAL    },  /* 131 */
+	{  ERROR_SEEK_ON_DEVICE,         EACCES    },  /* 132 */
+	{  ERROR_DIR_NOT_EMPTY,          ENOTEMPTY },  /* 145 */
+	{  ERROR_NOT_LOCKED,             EACCES    },  /* 158 */