ia64/xen-unstable

changeset 5971:e173a853dc46

Merging with xen-unstable
author djm@kirby.fc.hp.com
date Tue Aug 02 10:20:46 2005 -0700 (2005-08-02)
parents 9be7fe98a556 dcdcec634c2d
children be8fe9b3987c e2127f19861b
files .hgignore Makefile buildconfigs/Rules.mk buildconfigs/mk.linux-2.6-xen buildconfigs/mk.linux-2.6-xen0 buildconfigs/mk.linux-2.6-xenU docs/misc/shype4xen_readme.txt docs/src/user.tex linux-2.4-xen-sparse/arch/xen/Makefile linux-2.4-xen-sparse/arch/xen/kernel/time.c linux-2.4-xen-sparse/include/asm-xen/bugs.h linux-2.4-xen-sparse/include/asm-xen/fixmap.h linux-2.4-xen-sparse/include/asm-xen/highmem.h linux-2.4-xen-sparse/include/asm-xen/hw_irq.h linux-2.4-xen-sparse/include/asm-xen/io.h linux-2.4-xen-sparse/include/asm-xen/irq.h linux-2.4-xen-sparse/include/asm-xen/mmu_context.h linux-2.4-xen-sparse/include/asm-xen/page.h linux-2.4-xen-sparse/include/asm-xen/pci.h linux-2.4-xen-sparse/include/asm-xen/pgalloc.h linux-2.4-xen-sparse/include/asm-xen/pgtable.h linux-2.4-xen-sparse/include/asm-xen/processor.h linux-2.4-xen-sparse/include/asm-xen/segment.h linux-2.4-xen-sparse/include/asm-xen/smp.h linux-2.4-xen-sparse/include/asm-xen/system.h linux-2.4-xen-sparse/include/asm-xen/vga.h linux-2.4-xen-sparse/include/linux/blk.h linux-2.4-xen-sparse/include/linux/highmem.h linux-2.4-xen-sparse/include/linux/irq.h linux-2.4-xen-sparse/include/linux/mm.h linux-2.4-xen-sparse/include/linux/sched.h linux-2.4-xen-sparse/include/linux/skbuff.h linux-2.4-xen-sparse/include/linux/timer.h linux-2.4-xen-sparse/mkbuildtree linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S linux-2.6-xen-sparse/arch/xen/i386/kernel/head.S linux-2.6-xen-sparse/arch/xen/i386/kernel/irq.c linux-2.6-xen-sparse/arch/xen/i386/kernel/mpparse.c linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/i386/pci/irq.c linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c linux-2.6-xen-sparse/arch/xen/kernel/reboot.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile linux-2.6-xen-sparse/drivers/xen/Makefile linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6-xen-sparse/drivers/xen/usbback/usbback.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/io.h linux-2.6-xen-sparse/include/asm-xen/ctrl_if.h linux-2.6-xen-sparse/include/asm-xen/evtchn.h linux-2.6-xen-sparse/include/asm-xen/hypervisor.h linux-2.6-xen-sparse/include/asm-xen/xenbus.h linux-2.6-xen-sparse/include/linux/mm.h linux-2.6-xen-sparse/mm/memory.c patches/linux-2.6.12/smp-alts.patch tools/Makefile tools/Rules.mk tools/consoled/Makefile tools/consoled/io.c tools/consoled/io.h tools/consoled/main.c tools/consoled/utils.c tools/consoled/utils.h tools/consoled/xc_console.c tools/debugger/gdb/gdbbuild tools/debugger/libxendebug/xendebug.c tools/debugger/pdb/Makefile tools/debugger/pdb/PDB.ml tools/debugger/pdb/Process.ml tools/debugger/pdb/Process.mli tools/debugger/pdb/Util.ml tools/debugger/pdb/Xen_domain.ml tools/debugger/pdb/Xen_domain.mli tools/debugger/pdb/debugger.ml tools/debugger/pdb/linux-2.6-module/Makefile tools/debugger/pdb/linux-2.6-module/debug.c tools/debugger/pdb/linux-2.6-module/module.c tools/debugger/pdb/linux-2.6-module/pdb_debug.h tools/debugger/pdb/linux-2.6-module/pdb_module.h tools/debugger/pdb/linux-2.6-patches/Makefile tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch tools/debugger/pdb/linux-2.6-patches/kdebug.patch tools/debugger/pdb/linux-2.6-patches/makefile.patch tools/debugger/pdb/linux-2.6-patches/ptrace.patch tools/debugger/pdb/linux-2.6-patches/traps.patch tools/debugger/pdb/pdb_caml_process.c tools/debugger/pdb/pdb_caml_xcs.c tools/debugger/pdb/pdb_caml_xen.h tools/debugger/pdb/readme tools/debugger/pdb/server.ml tools/examples/xend-config.sxp tools/firmware/rombios/rombios.c tools/ioemu/monitor.c tools/ioemu/target-i386-dm/qemu-dm.debug tools/ioemu/vnc.c tools/libxc/Makefile tools/libxc/xc.h tools/libxc/xc_domain.c tools/libxc/xc_ia64_stubs.c tools/libxc/xc_linux_build.c tools/libxc/xc_load_elf.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_ptrace.c tools/misc/Makefile tools/misc/policyprocessor/Makefile tools/misc/policyprocessor/XmlToBin.java tools/misc/policyprocessor/XmlToBinInterface.java tools/misc/policyprocessor/c2j_include.c tools/misc/policyprocessor/xen_sample_def.xml tools/pygrub/setup.py tools/pygrub/src/fsys/ext2/__init__.py tools/pygrub/src/fsys/ext2/ext2module.c tools/pygrub/src/pygrub tools/python/setup.py tools/python/xen/lowlevel/xc/xc.c tools/python/xen/lowlevel/xs/xs.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/sv/CreateDomain.py tools/python/xen/sv/Daemon.py tools/python/xen/sv/DomInfo.py tools/python/xen/sv/DomList.py tools/python/xen/sv/GenTabbed.py tools/python/xen/sv/HTMLBase.py tools/python/xen/sv/Main.py tools/python/xen/sv/MigrateDomain.py tools/python/xen/sv/NodeInfo.py tools/python/xen/sv/RestoreDomain.py tools/python/xen/sv/SaveDomain.py tools/python/xen/sv/TabView.py tools/python/xen/sv/Wizard.py tools/python/xen/sv/__init__.py tools/python/xen/sv/params.py tools/python/xen/sv/util.py tools/python/xen/util/blkif.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/image.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/channel.py tools/python/xen/xend/xenstore/xsnode.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/security/Makefile tools/security/secpol_tool.c tools/sv/Makefile tools/sv/images/destroy.png tools/sv/images/finish.png tools/sv/images/internet.jpg tools/sv/images/internet.psd tools/sv/images/next.png tools/sv/images/orb_01.jpg tools/sv/images/orb_02.jpg tools/sv/images/pause.png tools/sv/images/previous.png tools/sv/images/reboot.png tools/sv/images/seperator-left-highlight.jpg tools/sv/images/seperator-right-highlight.jpg tools/sv/images/seperator.jpg tools/sv/images/shutdown.png tools/sv/images/small-destroy.png tools/sv/images/small-pause.png tools/sv/images/small-unpause.png tools/sv/images/unpause.png tools/sv/images/xen.png tools/sv/inc/script.js tools/sv/inc/style.css tools/sv/index.psp tools/xcs/xcs.h tools/xenstore/Makefile tools/xenstore/TODO tools/xenstore/testsuite/02directory.sh tools/xenstore/testsuite/07watch.sh tools/xenstore/testsuite/08transaction.sh tools/xenstore/testsuite/09domain.sh tools/xenstore/testsuite/10domain-homedir.sh tools/xenstore/testsuite/11domain-watch.sh tools/xenstore/testsuite/12readonly.sh tools/xenstore/testsuite/13watch-ack.sh tools/xenstore/testsuite/test.sh tools/xenstore/xenstored_core.c tools/xenstore/xenstored_core.h tools/xenstore/xenstored_domain.c tools/xenstore/xenstored_domain.h tools/xenstore/xenstored_transaction.c tools/xenstore/xenstored_transaction.h tools/xenstore/xenstored_watch.c tools/xenstore/xenstored_watch.h tools/xenstore/xs.c tools/xenstore/xs.h tools/xenstore/xs_random.c tools/xenstore/xs_test.c xen/Makefile xen/acm/acm_chinesewall_hooks.c xen/acm/acm_core.c xen/acm/acm_policy.c xen/acm/acm_simple_type_enforcement_hooks.c xen/arch/ia64/Makefile xen/arch/ia64/asm-offsets.c xen/arch/ia64/dom_fw.c xen/arch/ia64/domain.c xen/arch/ia64/hypercall.c xen/arch/ia64/hyperprivop.S xen/arch/ia64/mmio.c xen/arch/ia64/pal_emul.c xen/arch/ia64/patch/linux-2.6.11/irq_ia64.c xen/arch/ia64/patch/linux-2.6.11/kregs.h xen/arch/ia64/pcdp.c xen/arch/ia64/process.c xen/arch/ia64/regionreg.c xen/arch/ia64/vcpu.c xen/arch/ia64/vlsapic.c xen/arch/ia64/vmmu.c xen/arch/ia64/vmx_hypercall.c xen/arch/ia64/vmx_ivt.S xen/arch/ia64/vmx_support.c xen/arch/ia64/vmx_vcpu.c xen/arch/ia64/vmx_virt.c xen/arch/ia64/vtlb.c xen/arch/ia64/xenasm.S xen/arch/ia64/xenmem.c xen/arch/ia64/xenmisc.c xen/arch/ia64/xensetup.c xen/arch/ia64/xentime.c xen/arch/x86/Makefile xen/arch/x86/acpi/boot.c xen/arch/x86/apic.c xen/arch/x86/cpu/common.c xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/genapic/es7000plat.c xen/arch/x86/i8259.c xen/arch/x86/io_apic.c xen/arch/x86/mpparse.c xen/arch/x86/setup.c xen/arch/x86/shadow.c xen/arch/x86/shadow32.c xen/arch/x86/shadow_public.c xen/arch/x86/smpboot.c xen/arch/x86/time.c xen/arch/x86/traps.c xen/arch/x86/vmx.c xen/arch/x86/vmx_intercept.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_platform.c xen/arch/x86/vmx_vmcs.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_32/mm.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/mm.c xen/arch/x86/x86_64/traps.c xen/common/ac_timer.c xen/common/acm_ops.c xen/common/dom_mem_ops.c xen/common/domain.c xen/common/grant_table.c xen/common/page_alloc.c xen/common/sched_sedf.c xen/common/symbols.c xen/common/xmalloc.c xen/drivers/char/console.c xen/include/acm/acm_core.h xen/include/acm/acm_hooks.h xen/include/asm-ia64/config.h xen/include/asm-ia64/domain.h xen/include/asm-ia64/event.h xen/include/asm-ia64/ia64_int.h xen/include/asm-ia64/privop.h xen/include/asm-ia64/regionreg.h xen/include/asm-ia64/vcpu.h xen/include/asm-ia64/vmx.h xen/include/asm-ia64/vmx_uaccess.h xen/include/asm-ia64/vmx_vcpu.h xen/include/asm-ia64/vmx_vpd.h xen/include/asm-ia64/xensystem.h xen/include/asm-x86/apicdef.h xen/include/asm-x86/config.h xen/include/asm-x86/fixmap.h xen/include/asm-x86/genapic.h xen/include/asm-x86/hpet.h xen/include/asm-x86/mach-bigsmp/mach_apic.h xen/include/asm-x86/mach-default/mach_apic.h xen/include/asm-x86/mach-es7000/mach_apic.h xen/include/asm-x86/mach-generic/mach_apic.h xen/include/asm-x86/mach-summit/mach_apic.h xen/include/asm-x86/mach-summit/mach_mpparse.h xen/include/asm-x86/shadow.h xen/include/asm-x86/shadow_64.h xen/include/asm-x86/shadow_public.h xen/include/asm-x86/time.h xen/include/asm-x86/types.h xen/include/asm-x86/vmx.h xen/include/asm-x86/vmx_virpit.h xen/include/asm-x86/vmx_vmcs.h xen/include/public/acm.h xen/include/public/acm_ops.h xen/include/public/arch-ia64.h xen/include/public/grant_table.h xen/include/public/io/blkif.h xen/include/public/io/netif.h xen/include/public/xen.h xen/include/xen/mm.h xen/include/xen/sched.h xen/include/xen/symbols.h xen/include/xen/time.h xen/tools/Makefile xen/tools/symbols.c
line diff
     1.1 --- a/.hgignore	Tue Aug 02 02:47:41 2005 -0800
     1.2 +++ b/.hgignore	Tue Aug 02 10:20:46 2005 -0700
     1.3 @@ -86,6 +86,8 @@
     1.4  ^tools/check/\..*$
     1.5  ^tools/cmdline/.*$
     1.6  ^tools/cmdline/xen/.*$
     1.7 +^tools/consoled/consoled$
     1.8 +^tools/consoled/xc_console$
     1.9  ^tools/debugger/pdb/pdb$
    1.10  ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.ko$
    1.11  ^tools/debugger/pdb/linux-[0-9.]*-module/.*\.mod.c$
    1.12 @@ -128,8 +130,8 @@
    1.13  ^tools/misc/xc_shadow$
    1.14  ^tools/misc/xen_cpuperf$
    1.15  ^tools/misc/xenperf$
    1.16 -^tools/policy/policy_tool$
    1.17 -^tools/policy/xen/.*$
    1.18 +^tools/security/secpol_tool$
    1.19 +^tools/security/xen/.*$
    1.20  ^tools/pygrub/build/.*$
    1.21  ^tools/python/build/.*$
    1.22  ^tools/tests/test_x86_emulator$
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Tue Aug 02 02:47:41 2005 -0800
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Tue Aug 02 10:20:46 2005 -0700
     2.3 @@ -18,8 +18,8 @@ CONFIG_XEN_BLKDEV_GRANT=y
     2.4  CONFIG_XEN_NETDEV_BACKEND=y
     2.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     2.6  CONFIG_XEN_NETDEV_FRONTEND=y
     2.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     2.8 - CONFIG_XEN_NETDEV_GRANT_RX=y
     2.9 +#CONFIG_XEN_NETDEV_GRANT_TX=y
    2.10 +#CONFIG_XEN_NETDEV_GRANT_RX=y
    2.11  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    2.12  # CONFIG_XEN_BLKDEV_TAP is not set
    2.13  # CONFIG_XEN_SHADOW_MODE is not set
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32	Tue Aug 02 02:47:41 2005 -0800
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32	Tue Aug 02 10:20:46 2005 -0700
     3.3 @@ -15,8 +15,8 @@ CONFIG_NO_IDLE_HZ=y
     3.4  CONFIG_XEN_BLKDEV_GRANT=y
     3.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     3.6  CONFIG_XEN_NETDEV_FRONTEND=y
     3.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     3.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     3.9 +#CONFIG_XEN_NETDEV_GRANT_TX=y
    3.10 +#CONFIG_XEN_NETDEV_GRANT_RX=y
    3.11  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    3.12  # CONFIG_XEN_BLKDEV_TAP is not set
    3.13  # CONFIG_XEN_SHADOW_MODE is not set
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Tue Aug 02 02:47:41 2005 -0800
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Tue Aug 02 10:20:46 2005 -0700
     4.3 @@ -204,6 +204,63 @@ static inline int is_prefetch(struct pt_
     4.4  
     4.5  fastcall void do_invalid_op(struct pt_regs *, unsigned long);
     4.6  
     4.7 +#ifdef CONFIG_X86_PAE
     4.8 +static void dump_fault_path(unsigned long address)
     4.9 +{
    4.10 +	unsigned long *p, page;
    4.11 +
    4.12 +        page = __pa(per_cpu(cur_pgd, smp_processor_id()));
    4.13 +	p  = (unsigned long *)__va(page);
    4.14 +	p += (address >> 30) * 2;
    4.15 +	printk(KERN_ALERT "%08lx -> *pde = %08lx:%08lx\n", page, p[1], p[0]);
    4.16 +	if (p[0] & 1) {
    4.17 +		page = p[0] & PAGE_MASK;
    4.18 +		address &= 0x3fffffff;
    4.19 +		page = machine_to_phys(page);
    4.20 +		p  = (unsigned long *)__va(page);
    4.21 +		p += (address >> 21) * 2;
    4.22 +		printk(KERN_ALERT "%08lx -> *pme = %08lx:%08lx\n", page, p[1], p[0]);
    4.23 +#ifndef CONFIG_HIGHPTE
    4.24 +		if (p[0] & 1) {
    4.25 +			page = p[0] & PAGE_MASK;
    4.26 +			address &= 0x001fffff;
    4.27 +			page = machine_to_phys(page);
    4.28 +			p  = (unsigned long *) __va(page);
    4.29 +			p += (address >> 12) * 2;
    4.30 +			printk(KERN_ALERT "%08lx -> *pte = %08lx:%08lx\n", page, p[1], p[0]);
    4.31 +		}
    4.32 +#endif
    4.33 +	}
    4.34 +}
    4.35 +#else
    4.36 +static void dump_fault_path(unsigned long address)
    4.37 +{
    4.38 +	unsigned long page;
    4.39 +
    4.40 +	page = ((unsigned long *) per_cpu(cur_pgd, smp_processor_id()))
    4.41 +	    [address >> 22];
    4.42 +	printk(KERN_ALERT "*pde = ma %08lx pa %08lx\n", page,
    4.43 +	       machine_to_phys(page));
    4.44 +	/*
    4.45 +	 * We must not directly access the pte in the highpte
    4.46 +	 * case, the page table might be allocated in highmem.
    4.47 +	 * And lets rather not kmap-atomic the pte, just in case
    4.48 +	 * it's allocated already.
    4.49 +	 */
    4.50 +#ifndef CONFIG_HIGHPTE
    4.51 +	if (page & 1) {
    4.52 +		page &= PAGE_MASK;
    4.53 +		address &= 0x003ff000;
    4.54 +		page = machine_to_phys(page);
    4.55 +		page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT];
    4.56 +		printk(KERN_ALERT "*pte = ma %08lx pa %08lx\n", page,
    4.57 +		       machine_to_phys(page));
    4.58 +	}
    4.59 +#endif
    4.60 +}
    4.61 +#endif
    4.62 +
    4.63 +
    4.64  /*
    4.65   * This routine handles page faults.  It determines the address,
    4.66   * and the problem, and then passes it off to one of the appropriate
    4.67 @@ -220,7 +277,6 @@ fastcall void do_page_fault(struct pt_re
    4.68  	struct task_struct *tsk;
    4.69  	struct mm_struct *mm;
    4.70  	struct vm_area_struct * vma;
    4.71 -	unsigned long page;
    4.72  	int write;
    4.73  	siginfo_t info;
    4.74  
    4.75 @@ -454,26 +510,7 @@ no_context:
    4.76  	printk(" at virtual address %08lx\n",address);
    4.77  	printk(KERN_ALERT " printing eip:\n");
    4.78  	printk("%08lx\n", regs->eip);
    4.79 -	page = ((unsigned long *) per_cpu(cur_pgd, smp_processor_id()))
    4.80 -	    [address >> 22];
    4.81 -	printk(KERN_ALERT "*pde = ma %08lx pa %08lx\n", page,
    4.82 -	       machine_to_phys(page));
    4.83 -	/*
    4.84 -	 * We must not directly access the pte in the highpte
    4.85 -	 * case, the page table might be allocated in highmem.
    4.86 -	 * And lets rather not kmap-atomic the pte, just in case
    4.87 -	 * it's allocated already.
    4.88 -	 */
    4.89 -#ifndef CONFIG_HIGHPTE
    4.90 -	if (page & 1) {
    4.91 -		page &= PAGE_MASK;
    4.92 -		address &= 0x003ff000;
    4.93 -		page = machine_to_phys(page);
    4.94 -		page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT];
    4.95 -		printk(KERN_ALERT "*pte = ma %08lx pa %08lx\n", page,
    4.96 -		       machine_to_phys(page));
    4.97 -	}
    4.98 -#endif
    4.99 +	dump_fault_path(address);
   4.100  	die("Oops", regs, error_code);
   4.101  	bust_spinlocks(0);
   4.102  	do_exit(SIGKILL);
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 02 02:47:41 2005 -0800
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 02 10:20:46 2005 -0700
     5.3 @@ -5,6 +5,7 @@
     5.4   *
     5.5   * Copyright (c) 2003, B Dragovic
     5.6   * Copyright (c) 2003-2004, M Williamson, K Fraser
     5.7 + * Copyright (c) 2005 Dan M. Smith, IBM Corporation
     5.8   * 
     5.9   * This file may be distributed separately from the Linux kernel, or
    5.10   * incorporated into other software packages, subject to the following license:
    5.11 @@ -42,7 +43,6 @@
    5.12  #include <linux/vmalloc.h>
    5.13  #include <asm-xen/xen_proc.h>
    5.14  #include <asm-xen/hypervisor.h>
    5.15 -#include <asm-xen/ctrl_if.h>
    5.16  #include <asm-xen/balloon.h>
    5.17  #include <asm/pgalloc.h>
    5.18  #include <asm/pgtable.h>
    5.19 @@ -50,6 +50,10 @@
    5.20  #include <asm/tlb.h>
    5.21  #include <linux/list.h>
    5.22  
    5.23 +#include<asm-xen/xenbus.h>
    5.24 +
    5.25 +#define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10))
    5.26 +
    5.27  static struct proc_dir_entry *balloon_pde;
    5.28  
    5.29  static DECLARE_MUTEX(balloon_mutex);
    5.30 @@ -77,11 +81,17 @@ static void balloon_process(void *unused
    5.31  static DECLARE_WORK(balloon_worker, balloon_process, NULL);
    5.32  static struct timer_list balloon_timer;
    5.33  
    5.34 +/* Flag for dom0 xenstore workaround */
    5.35 +static int balloon_xenbus_init=0;
    5.36 +
    5.37 +/* Init Function */
    5.38 +void balloon_init_watcher(void);
    5.39 +
    5.40  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    5.41  /* Use the private and mapping fields of struct page as a list. */
    5.42  #define PAGE_TO_LIST(p) ( (struct list_head *)&p->private )
    5.43  #define LIST_TO_PAGE(l) ( list_entry( ((unsigned long *)l),   \
    5.44 -				      struct page, private ) )
    5.45 +                                      struct page, private ) )
    5.46  #define UNLIST_PAGE(p)  do { list_del(PAGE_TO_LIST(p));       \
    5.47                               p->mapping = NULL;               \
    5.48                               p->private = 0; } while(0)
    5.49 @@ -297,26 +307,97 @@ static void set_new_target(unsigned long
    5.50      schedule_work(&balloon_worker);
    5.51  }
    5.52  
    5.53 -static void balloon_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
    5.54 +static struct xenbus_watch xb_watch =
    5.55  {
    5.56 -    switch ( msg->subtype )
    5.57 -    {
    5.58 -    case CMSG_MEM_REQUEST_SET:
    5.59 +    .node = "memory"
    5.60 +};
    5.61 +
    5.62 +/* FIXME: This is part of a dom0 sequencing workaround */
    5.63 +static struct xenbus_watch root_watch =
    5.64 +{
    5.65 +    .node = "/"
    5.66 +};
    5.67 +
    5.68 +/* React to a change in the target key */
    5.69 +static void watch_target(struct xenbus_watch *watch, const char *node)
    5.70 +{
    5.71 +    unsigned long new_target;
    5.72 +    int err;
    5.73 +
    5.74 +    if(watch == &root_watch)
    5.75      {
    5.76 -        mem_request_t *req = (mem_request_t *)&msg->msg[0];
    5.77 -        set_new_target(req->target);
    5.78 -        req->status = 0;
    5.79 -    }
    5.80 -    break;        
    5.81 -
    5.82 -    default:
    5.83 -        msg->length = 0;
    5.84 -        break;
    5.85 +        /* FIXME: This is part of a dom0 sequencing workaround */
    5.86 +        if(register_xenbus_watch(&xb_watch) == 0)
    5.87 +        {
    5.88 +            /* 
    5.89 +               We successfully set a watch on memory/target:
    5.90 +               now we can stop watching root 
    5.91 +            */
    5.92 +            unregister_xenbus_watch(&root_watch);
    5.93 +            balloon_xenbus_init=1;
    5.94 +        } 
    5.95 +        else 
    5.96 +        {
    5.97 +            return;
    5.98 +        }
    5.99      }
   5.100  
   5.101 -    ctrl_if_send_response(msg);
   5.102 +    err = xenbus_scanf("memory", "target", "%lu", &new_target);
   5.103 +        
   5.104 +    if(err != 1) 
   5.105 +    {
   5.106 +        IPRINTK("Unable to read memory/target\n");
   5.107 +        return;
   5.108 +    } 
   5.109 +        
   5.110 +    set_new_target(new_target >> PAGE_SHIFT);
   5.111 +    
   5.112  }
   5.113  
   5.114 +/* 
   5.115 +   Try to set up our watcher, if not already set
   5.116 +   
   5.117 +*/
   5.118 +void balloon_init_watcher(void) 
   5.119 +{
   5.120 +    int err;
   5.121 +
   5.122 +    if(!xen_start_info.store_evtchn)
   5.123 +    {
   5.124 +        IPRINTK("Delaying watcher init until xenstore is available\n");
   5.125 +        return;
   5.126 +    }
   5.127 +
   5.128 +    down(&xenbus_lock);
   5.129 +
   5.130 +    if(! balloon_xenbus_init) 
   5.131 +    {
   5.132 +        err = register_xenbus_watch(&xb_watch);
   5.133 +        if(err) 
   5.134 +        {
   5.135 +            /* BIG FAT FIXME: dom0 sequencing workaround
   5.136 +             * dom0 can't set a watch on memory/target until
   5.137 +             * after the tools create it.  So, we have to watch
   5.138 +             * the whole store until that happens.
   5.139 +             *
   5.140 +             * This will go away when we have the ability to watch
   5.141 +             * non-existant keys
   5.142 +             */
   5.143 +            register_xenbus_watch(&root_watch);
   5.144 +        } 
   5.145 +        else
   5.146 +        {
   5.147 +            IPRINTK("Balloon xenbus watcher initialized\n");
   5.148 +            balloon_xenbus_init = 1;
   5.149 +        }
   5.150 +    }
   5.151 +
   5.152 +    up(&xenbus_lock);
   5.153 +
   5.154 +}
   5.155 +
   5.156 +EXPORT_SYMBOL(balloon_init_watcher);
   5.157 +
   5.158  static int balloon_write(struct file *file, const char __user *buffer,
   5.159                           unsigned long count, void *data)
   5.160  {
   5.161 @@ -346,7 +427,6 @@ static int balloon_read(char *page, char
   5.162  {
   5.163      int len;
   5.164  
   5.165 -#define K(_p) ((_p)<<(PAGE_SHIFT-10))
   5.166      len = sprintf(
   5.167          page,
   5.168          "Current allocation: %8lu kB\n"
   5.169 @@ -354,13 +434,14 @@ static int balloon_read(char *page, char
   5.170          "Low-mem balloon:    %8lu kB\n"
   5.171          "High-mem balloon:   %8lu kB\n"
   5.172          "Xen hard limit:     ",
   5.173 -        K(current_pages), K(target_pages), K(balloon_low), K(balloon_high));
   5.174 +        PAGES2KB(current_pages), PAGES2KB(target_pages), 
   5.175 +        PAGES2KB(balloon_low), PAGES2KB(balloon_high));
   5.176  
   5.177      if ( hard_limit != ~0UL )
   5.178          len += sprintf(
   5.179              page + len, 
   5.180              "%8lu kB (inc. %8lu kB driver headroom)\n",
   5.181 -            K(hard_limit), K(driver_pages));
   5.182 +            PAGES2KB(hard_limit), PAGES2KB(driver_pages));
   5.183      else
   5.184          len += sprintf(
   5.185              page + len,
   5.186 @@ -396,9 +477,7 @@ static int __init balloon_init(void)
   5.187  
   5.188      balloon_pde->read_proc  = balloon_read;
   5.189      balloon_pde->write_proc = balloon_write;
   5.190 -
   5.191 -    (void)ctrl_if_register_receiver(CMSG_MEM_REQUEST, balloon_ctrlif_rx, 0);
   5.192 -
   5.193 +    
   5.194      /* Initialise the balloon with excess memory space. */
   5.195      for ( pfn = xen_start_info.nr_pages; pfn < max_pfn; pfn++ )
   5.196      {
   5.197 @@ -407,6 +486,11 @@ static int __init balloon_init(void)
   5.198              balloon_append(page);
   5.199      }
   5.200  
   5.201 +    xb_watch.callback = watch_target;
   5.202 +    root_watch.callback = watch_target;
   5.203 +
   5.204 +    balloon_init_watcher();
   5.205 +
   5.206      return 0;
   5.207  }
   5.208  
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Aug 02 02:47:41 2005 -0800
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Aug 02 10:20:46 2005 -0700
     6.3 @@ -309,6 +309,9 @@ int do_xenbus_probe(void *unused)
     6.4  		return err;
     6.5  	}
     6.6  
     6.7 +	/* Initialize non-xenbus drivers */
     6.8 +	balloon_init_watcher();
     6.9 +
    6.10  	down(&xenbus_lock);
    6.11  	/* Enumerate devices in xenstore. */
    6.12  	xenbus_probe_devices("device");
     7.1 --- a/linux-2.6-xen-sparse/kernel/ptrace.c	Tue Aug 02 02:47:41 2005 -0800
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,391 +0,0 @@
     7.4 -/*
     7.5 - * linux/kernel/ptrace.c
     7.6 - *
     7.7 - * (C) Copyright 1999 Linus Torvalds
     7.8 - *
     7.9 - * Common interfaces for "ptrace()" which we do not want
    7.10 - * to continually duplicate across every architecture.
    7.11 - */
    7.12 -
    7.13 -#include <linux/module.h>
    7.14 -#include <linux/sched.h>
    7.15 -#include <linux/errno.h>
    7.16 -#include <linux/mm.h>
    7.17 -#include <linux/highmem.h>
    7.18 -#include <linux/pagemap.h>
    7.19 -#include <linux/smp_lock.h>
    7.20 -#include <linux/ptrace.h>
    7.21 -#include <linux/security.h>
    7.22 -#include <linux/signal.h>
    7.23 -
    7.24 -#include <asm/pgtable.h>
    7.25 -#include <asm/uaccess.h>
    7.26 -
    7.27 -/*
    7.28 - * ptrace a task: make the debugger its new parent and
    7.29 - * move it to the ptrace list.
    7.30 - *
    7.31 - * Must be called with the tasklist lock write-held.
    7.32 - */
    7.33 -void __ptrace_link(task_t *child, task_t *new_parent)
    7.34 -{
    7.35 -	if (!list_empty(&child->ptrace_list))
    7.36 -		BUG();
    7.37 -	if (child->parent == new_parent)
    7.38 -		return;
    7.39 -	list_add(&child->ptrace_list, &child->parent->ptrace_children);
    7.40 -	REMOVE_LINKS(child);
    7.41 -	child->parent = new_parent;
    7.42 -	SET_LINKS(child);
    7.43 -}
    7.44 - 
    7.45 -/*
    7.46 - * Turn a tracing stop into a normal stop now, since with no tracer there
    7.47 - * would be no way to wake it up with SIGCONT or SIGKILL.  If there was a
    7.48 - * signal sent that would resume the child, but didn't because it was in
    7.49 - * TASK_TRACED, resume it now.
    7.50 - * Requires that irqs be disabled.
    7.51 - */
    7.52 -void ptrace_untrace(task_t *child)
    7.53 -{
    7.54 -	spin_lock(&child->sighand->siglock);
    7.55 -	if (child->state == TASK_TRACED) {
    7.56 -		if (child->signal->flags & SIGNAL_STOP_STOPPED) {
    7.57 -			child->state = TASK_STOPPED;
    7.58 -		} else {
    7.59 -			signal_wake_up(child, 1);
    7.60 -		}
    7.61 -	}
    7.62 -	spin_unlock(&child->sighand->siglock);
    7.63 -}
    7.64 -
    7.65 -/*
    7.66 - * unptrace a task: move it back to its original parent and
    7.67 - * remove it from the ptrace list.
    7.68 - *
    7.69 - * Must be called with the tasklist lock write-held.
    7.70 - */
    7.71 -void __ptrace_unlink(task_t *child)
    7.72 -{
    7.73 -	if (!child->ptrace)
    7.74 -		BUG();
    7.75 -	child->ptrace = 0;
    7.76 -	if (!list_empty(&child->ptrace_list)) {
    7.77 -		list_del_init(&child->ptrace_list);
    7.78 -		REMOVE_LINKS(child);
    7.79 -		child->parent = child->real_parent;
    7.80 -		SET_LINKS(child);
    7.81 -	}
    7.82 -
    7.83 -	if (child->state == TASK_TRACED)
    7.84 -		ptrace_untrace(child);
    7.85 -}
    7.86 -
    7.87 -/*
    7.88 - * Check that we have indeed attached to the thing..
    7.89 - */
    7.90 -int ptrace_check_attach(struct task_struct *child, int kill)
    7.91 -{
    7.92 -	int ret = -ESRCH;
    7.93 -
    7.94 -	/*
    7.95 -	 * We take the read lock around doing both checks to close a
    7.96 -	 * possible race where someone else was tracing our child and
    7.97 -	 * detached between these two checks.  After this locked check,
    7.98 -	 * we are sure that this is our traced child and that can only
    7.99 -	 * be changed by us so it's not changing right after this.
   7.100 -	 */
   7.101 -	read_lock(&tasklist_lock);
   7.102 -	if ((child->ptrace & PT_PTRACED) && child->parent == current &&
   7.103 -	    (!(child->ptrace & PT_ATTACHED) || child->real_parent != current)
   7.104 -	    && child->signal != NULL) {
   7.105 -		ret = 0;
   7.106 -		spin_lock_irq(&child->sighand->siglock);
   7.107 -		if (child->state == TASK_STOPPED) {
   7.108 -			child->state = TASK_TRACED;
   7.109 -		} else if (child->state != TASK_TRACED && !kill) {
   7.110 -			ret = -ESRCH;
   7.111 -		}
   7.112 -		spin_unlock_irq(&child->sighand->siglock);
   7.113 -	}
   7.114 -	read_unlock(&tasklist_lock);
   7.115 -
   7.116 -	if (!ret && !kill) {
   7.117 -		wait_task_inactive(child);
   7.118 -	}
   7.119 -
   7.120 -	/* All systems go.. */
   7.121 -	return ret;
   7.122 -}
   7.123 -
   7.124 -int ptrace_attach(struct task_struct *task)
   7.125 -{
   7.126 -	int retval;
   7.127 -	task_lock(task);
   7.128 -	retval = -EPERM;
   7.129 -	if (task->pid <= 1)
   7.130 -		goto bad;
   7.131 -	if (task == current)
   7.132 -		goto bad;
   7.133 -	if (!task->mm)
   7.134 -		goto bad;
   7.135 -	if(((current->uid != task->euid) ||
   7.136 -	    (current->uid != task->suid) ||
   7.137 -	    (current->uid != task->uid) ||
   7.138 - 	    (current->gid != task->egid) ||
   7.139 - 	    (current->gid != task->sgid) ||
   7.140 - 	    (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
   7.141 -		goto bad;
   7.142 -	smp_rmb();
   7.143 -	if (!task->mm->dumpable && !capable(CAP_SYS_PTRACE))
   7.144 -		goto bad;
   7.145 -	/* the same process cannot be attached many times */
   7.146 -	if (task->ptrace & PT_PTRACED)
   7.147 -		goto bad;
   7.148 -	retval = security_ptrace(current, task);
   7.149 -	if (retval)
   7.150 -		goto bad;
   7.151 -
   7.152 -	/* Go */
   7.153 -	task->ptrace |= PT_PTRACED | ((task->real_parent != current)
   7.154 -				      ? PT_ATTACHED : 0);
   7.155 -	if (capable(CAP_SYS_PTRACE))
   7.156 -		task->ptrace |= PT_PTRACE_CAP;
   7.157 -	task_unlock(task);
   7.158 -
   7.159 -	write_lock_irq(&tasklist_lock);
   7.160 -	__ptrace_link(task, current);
   7.161 -	write_unlock_irq(&tasklist_lock);
   7.162 -
   7.163 -	force_sig_specific(SIGSTOP, task);
   7.164 -	return 0;
   7.165 -
   7.166 -bad:
   7.167 -	task_unlock(task);
   7.168 -	return retval;
   7.169 -}
   7.170 -
   7.171 -int ptrace_detach(struct task_struct *child, unsigned int data)
   7.172 -{
   7.173 -	if (!valid_signal(data))
   7.174 -		return	-EIO;
   7.175 -
   7.176 -	/* Architecture-specific hardware disable .. */
   7.177 -	ptrace_disable(child);
   7.178 -
   7.179 -	/* .. re-parent .. */
   7.180 -	child->exit_code = data;
   7.181 -
   7.182 -	write_lock_irq(&tasklist_lock);
   7.183 -	__ptrace_unlink(child);
   7.184 -	/* .. and wake it up. */
   7.185 -	if (child->exit_state != EXIT_ZOMBIE)
   7.186 -		wake_up_process(child);
   7.187 -	write_unlock_irq(&tasklist_lock);
   7.188 -
   7.189 -	return 0;
   7.190 -}
   7.191 -
   7.192 -/*
   7.193 - * Access another process' address space.
   7.194 - * Source/target buffer must be kernel space, 
   7.195 - * Do not walk the page table directly, use get_user_pages
   7.196 - */
   7.197 -
   7.198 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
   7.199 -{
   7.200 -	struct mm_struct *mm;
   7.201 -	struct vm_area_struct *vma;
   7.202 -	struct page *page;
   7.203 -	void *old_buf = buf;
   7.204 -
   7.205 -	mm = get_task_mm(tsk);
   7.206 -	if (!mm)
   7.207 -		return 0;
   7.208 -
   7.209 -	down_read(&mm->mmap_sem);
   7.210 -	/* ignore errors, just check how much was sucessfully transfered */
   7.211 -	while (len) {
   7.212 -		int bytes, ret, offset;
   7.213 -		void *maddr;
   7.214 -
   7.215 -		ret = get_user_pages(tsk, mm, addr, 1,
   7.216 -				write, 1, &page, &vma);
   7.217 -		if (ret <= 0)
   7.218 -			break;
   7.219 -
   7.220 -		bytes = len;
   7.221 -		offset = addr & (PAGE_SIZE-1);
   7.222 -		if (bytes > PAGE_SIZE-offset)
   7.223 -			bytes = PAGE_SIZE-offset;
   7.224 -
   7.225 -		maddr = kmap(page);
   7.226 -		if (write) {
   7.227 -			copy_to_user_page(vma, page, addr,
   7.228 -					  maddr + offset, buf, bytes);
   7.229 -			set_page_dirty_lock(page);
   7.230 -		} else {
   7.231 -			copy_from_user_page(vma, page, addr,
   7.232 -					    buf, maddr + offset, bytes);
   7.233 -		}
   7.234 -		kunmap(page);
   7.235 -		page_cache_release(page);
   7.236 -		len -= bytes;
   7.237 -		buf += bytes;
   7.238 -		addr += bytes;
   7.239 -	}
   7.240 -	up_read(&mm->mmap_sem);
   7.241 -	mmput(mm);
   7.242 -	
   7.243 -	return buf - old_buf;
   7.244 -}
   7.245 -EXPORT_SYMBOL(access_process_vm);
   7.246 -
   7.247 -int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len)
   7.248 -{
   7.249 -	int copied = 0;
   7.250 -
   7.251 -	while (len > 0) {
   7.252 -		char buf[128];
   7.253 -		int this_len, retval;
   7.254 -
   7.255 -		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
   7.256 -		retval = access_process_vm(tsk, src, buf, this_len, 0);
   7.257 -		if (!retval) {
   7.258 -			if (copied)
   7.259 -				break;
   7.260 -			return -EIO;
   7.261 -		}
   7.262 -		if (copy_to_user(dst, buf, retval))
   7.263 -			return -EFAULT;
   7.264 -		copied += retval;
   7.265 -		src += retval;
   7.266 -		dst += retval;
   7.267 -		len -= retval;			
   7.268 -	}
   7.269 -	return copied;
   7.270 -}
   7.271 -
   7.272 -int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len)
   7.273 -{
   7.274 -	int copied = 0;
   7.275 -
   7.276 -	while (len > 0) {
   7.277 -		char buf[128];
   7.278 -		int this_len, retval;
   7.279 -
   7.280 -		this_len = (len > sizeof(buf)) ? sizeof(buf) : len;
   7.281 -		if (copy_from_user(buf, src, this_len))
   7.282 -			return -EFAULT;
   7.283 -		retval = access_process_vm(tsk, dst, buf, this_len, 1);
   7.284 -		if (!retval) {
   7.285 -			if (copied)
   7.286 -				break;
   7.287 -			return -EIO;
   7.288 -		}
   7.289 -		copied += retval;
   7.290 -		src += retval;
   7.291 -		dst += retval;
   7.292 -		len -= retval;			
   7.293 -	}
   7.294 -	return copied;
   7.295 -}
   7.296 -
   7.297 -static int ptrace_setoptions(struct task_struct *child, long data)
   7.298 -{
   7.299 -	child->ptrace &= ~PT_TRACE_MASK;
   7.300 -
   7.301 -	if (data & PTRACE_O_TRACESYSGOOD)
   7.302 -		child->ptrace |= PT_TRACESYSGOOD;
   7.303 -
   7.304 -	if (data & PTRACE_O_TRACEFORK)
   7.305 -		child->ptrace |= PT_TRACE_FORK;
   7.306 -
   7.307 -	if (data & PTRACE_O_TRACEVFORK)
   7.308 -		child->ptrace |= PT_TRACE_VFORK;
   7.309 -
   7.310 -	if (data & PTRACE_O_TRACECLONE)
   7.311 -		child->ptrace |= PT_TRACE_CLONE;
   7.312 -
   7.313 -	if (data & PTRACE_O_TRACEEXEC)
   7.314 -		child->ptrace |= PT_TRACE_EXEC;
   7.315 -
   7.316 -	if (data & PTRACE_O_TRACEVFORKDONE)
   7.317 -		child->ptrace |= PT_TRACE_VFORK_DONE;
   7.318 -
   7.319 -	if (data & PTRACE_O_TRACEEXIT)
   7.320 -		child->ptrace |= PT_TRACE_EXIT;
   7.321 -
   7.322 -	return (data & ~PTRACE_O_MASK) ? -EINVAL : 0;
   7.323 -}
   7.324 -
   7.325 -static int ptrace_getsiginfo(struct task_struct *child, siginfo_t __user * data)
   7.326 -{
   7.327 -	siginfo_t lastinfo;
   7.328 -	int error = -ESRCH;
   7.329 -
   7.330 -	read_lock(&tasklist_lock);
   7.331 -	if (likely(child->sighand != NULL)) {
   7.332 -		error = -EINVAL;
   7.333 -		spin_lock_irq(&child->sighand->siglock);
   7.334 -		if (likely(child->last_siginfo != NULL)) {
   7.335 -			lastinfo = *child->last_siginfo;
   7.336 -			error = 0;
   7.337 -		}
   7.338 -		spin_unlock_irq(&child->sighand->siglock);
   7.339 -	}
   7.340 -	read_unlock(&tasklist_lock);
   7.341 -	if (!error)
   7.342 -		return copy_siginfo_to_user(data, &lastinfo);
   7.343 -	return error;
   7.344 -}
   7.345 -
   7.346 -static int ptrace_setsiginfo(struct task_struct *child, siginfo_t __user * data)
   7.347 -{
   7.348 -	siginfo_t newinfo;
   7.349 -	int error = -ESRCH;
   7.350 -
   7.351 -	if (copy_from_user(&newinfo, data, sizeof (siginfo_t)))
   7.352 -		return -EFAULT;
   7.353 -
   7.354 -	read_lock(&tasklist_lock);
   7.355 -	if (likely(child->sighand != NULL)) {
   7.356 -		error = -EINVAL;
   7.357 -		spin_lock_irq(&child->sighand->siglock);
   7.358 -		if (likely(child->last_siginfo != NULL)) {
   7.359 -			*child->last_siginfo = newinfo;
   7.360 -			error = 0;
   7.361 -		}
   7.362 -		spin_unlock_irq(&child->sighand->siglock);
   7.363 -	}
   7.364 -	read_unlock(&tasklist_lock);
   7.365 -	return error;
   7.366 -}
   7.367 -
   7.368 -int ptrace_request(struct task_struct *child, long request,
   7.369 -		   long addr, long data)
   7.370 -{
   7.371 -	int ret = -EIO;
   7.372 -
   7.373 -	switch (request) {
   7.374 -#ifdef PTRACE_OLDSETOPTIONS
   7.375 -	case PTRACE_OLDSETOPTIONS:
   7.376 -#endif
   7.377 -	case PTRACE_SETOPTIONS:
   7.378 -		ret = ptrace_setoptions(child, data);
   7.379 -		break;
   7.380 -	case PTRACE_GETEVENTMSG:
   7.381 -		ret = put_user(child->ptrace_message, (unsigned long __user *) data);
   7.382 -		break;
   7.383 -	case PTRACE_GETSIGINFO:
   7.384 -		ret = ptrace_getsiginfo(child, (siginfo_t __user *) data);
   7.385 -		break;
   7.386 -	case PTRACE_SETSIGINFO:
   7.387 -		ret = ptrace_setsiginfo(child, (siginfo_t __user *) data);
   7.388 -		break;
   7.389 -	default:
   7.390 -		break;
   7.391 -	}
   7.392 -
   7.393 -	return ret;
   7.394 -}
     8.1 --- a/linux-2.6-xen-sparse/mm/memory.c	Tue Aug 02 02:47:41 2005 -0800
     8.2 +++ b/linux-2.6-xen-sparse/mm/memory.c	Tue Aug 02 10:20:46 2005 -0700
     8.3 @@ -1814,12 +1814,12 @@ do_anonymous_page(struct mm_struct *mm, 
     8.4  		page_add_anon_rmap(page, vma, addr);
     8.5  	}
     8.6  
     8.7 -	set_pte_at(vma, addr, page_table, entry);
     8.8 +	set_pte_at(mm, addr, page_table, entry);
     8.9  	pte_unmap(page_table);
    8.10  
    8.11  	/* No need to invalidate - it was non-present before */
    8.12  	update_mmu_cache(vma, addr, entry);
    8.13 - 	lazy_mmu_prot_update(entry);
    8.14 +	lazy_mmu_prot_update(entry);
    8.15  	spin_unlock(&mm->page_table_lock);
    8.16  out:
    8.17  	return VM_FAULT_MINOR;
    8.18 @@ -1928,7 +1928,7 @@ retry:
    8.19  		entry = mk_pte(new_page, vma->vm_page_prot);
    8.20  		if (write_access)
    8.21  			entry = maybe_mkwrite(pte_mkdirty(entry), vma);
    8.22 -		set_pte_at(vma, address, page_table, entry);
    8.23 +		set_pte_at(mm, address, page_table, entry);
    8.24  		if (anon) {
    8.25  			lru_cache_add_active(new_page);
    8.26  			page_add_anon_rmap(new_page, vma, address);
     9.1 --- a/tools/Makefile	Tue Aug 02 02:47:41 2005 -0800
     9.2 +++ b/tools/Makefile	Tue Aug 02 10:20:46 2005 -0700
     9.3 @@ -10,9 +10,10 @@ SUBDIRS += xentrace
     9.4  SUBDIRS += python
     9.5  SUBDIRS += xcs
     9.6  SUBDIRS += xcutils
     9.7 -SUBDIRS += pygrub
     9.8 +#SUBDIRS += pygrub
     9.9  SUBDIRS += firmware
    9.10 -SUBDIRS += policy
    9.11 +SUBDIRS += security
    9.12 +#SUBDIRS += consoled
    9.13  
    9.14  .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean
    9.15  
    10.1 --- a/tools/Rules.mk	Tue Aug 02 02:47:41 2005 -0800
    10.2 +++ b/tools/Rules.mk	Tue Aug 02 10:20:46 2005 -0700
    10.3 @@ -4,6 +4,8 @@ include $(XEN_ROOT)/Config.mk
    10.4  
    10.5  XEN_XC             = $(XEN_ROOT)/tools/python/xen/lowlevel/xc
    10.6  XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
    10.7 +XEN_XCS            = $(XEN_ROOT)/tools/xcs
    10.8 +XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
    10.9  
   10.10  ifeq ($(XEN_TARGET_ARCH),x86_32)
   10.11  CFLAGS  += -m32 -march=i686
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/consoled/Makefile	Tue Aug 02 10:20:46 2005 -0700
    11.3 @@ -0,0 +1,48 @@
    11.4 +# Makefile for consoled
    11.5 +# based on xcs Makefile
    11.6 +# Anthony Liguori 2005
    11.7 +
    11.8 +XEN_ROOT=../..
    11.9 +include $(XEN_ROOT)/tools/Rules.mk
   11.10 +
   11.11 +CONSOLED_INSTALL_DIR = /usr/sbin
   11.12 +XC_CONSOLE_INSTALL_DIR = /usr/libexec/xen
   11.13 +
   11.14 +INSTALL         = install
   11.15 +INSTALL_PROG    = $(INSTALL) -m0755
   11.16 +INSTALL_DIR     = $(INSTALL) -d -m0755
   11.17 +
   11.18 +CC       = gcc
   11.19 +CFLAGS   = -Wall -Werror -g3
   11.20 +
   11.21 +CFLAGS  += -I $(XEN_XCS)
   11.22 +CFLAGS  += -I $(XEN_LIBXC)
   11.23 +CFLAGS  += -I $(XEN_XENSTORE)
   11.24 +
   11.25 +SRCS    :=
   11.26 +SRCS    += main.c utils.c io.c
   11.27 +
   11.28 +HDRS     = $(wildcard *.h)
   11.29 +OBJS     = $(patsubst %.c,%.o,$(SRCS))
   11.30 +BIN      = consoled xc_console
   11.31 +
   11.32 +all: $(BIN)
   11.33 +
   11.34 +clean:
   11.35 +	$(RM) *.a *.so *.o *.rpm $(BIN)
   11.36 +
   11.37 +consoled: $(OBJS)
   11.38 +	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
   11.39 +              -lxc -lxenstore
   11.40 +
   11.41 +xc_console: xc_console.o
   11.42 +	$(CC) $(CFLAGS) $^ -o $@ -L$(XEN_LIBXC) -L$(XEN_XENSTORE) \
   11.43 +	      -lxc -lxenstore
   11.44 +
   11.45 +$(OBJS): $(HDRS)
   11.46 +
   11.47 +install: $(BIN)
   11.48 +	$(INSTALL_DIR) -p $(DESTDIR)/$(CONSOLED_INSTALL_DIR)
   11.49 +	$(INSTALL_PROG) consoled $(DESTDIR)/$(CONSOLED_INSTALL_DIR)
   11.50 +	$(INSTALL_DIR) -p $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR)
   11.51 +	$(INSTALL_PROG) xc_console $(DESTDIR)/$(XC_CONSOLE_INSTALL_DIR)
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/consoled/io.c	Tue Aug 02 10:20:46 2005 -0700
    12.3 @@ -0,0 +1,328 @@
    12.4 +/*\
    12.5 + *  Copyright (C) International Business Machines  Corp., 2005
    12.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    12.7 + *
    12.8 + *  Xen Console Daemon
    12.9 + *
   12.10 + *  This program is free software; you can redistribute it and/or modify
   12.11 + *  it under the terms of the GNU General Public License as published by
   12.12 + *  the Free Software Foundation; under version 2 of the License.
   12.13 + * 
   12.14 + *  This program is distributed in the hope that it will be useful,
   12.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.17 + *  GNU General Public License for more details.
   12.18 + * 
   12.19 + *  You should have received a copy of the GNU General Public License
   12.20 + *  along with this program; if not, write to the Free Software
   12.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.22 +\*/
   12.23 +
   12.24 +#define _GNU_SOURCE
   12.25 +
   12.26 +#include "utils.h"
   12.27 +#include "io.h"
   12.28 +
   12.29 +#include "xc.h"
   12.30 +#include "xs.h"
   12.31 +#include "xen/io/domain_controller.h"
   12.32 +#include "xcs_proto.h"
   12.33 +
   12.34 +#include <malloc.h>
   12.35 +#include <stdlib.h>
   12.36 +#include <errno.h>
   12.37 +#include <string.h>
   12.38 +#include <sys/select.h>
   12.39 +#include <fcntl.h>
   12.40 +#include <unistd.h>
   12.41 +#include <termios.h>
   12.42 +
   12.43 +#define MAX(a, b) (((a) > (b)) ? (a) : (b))
   12.44 +#define MIN(a, b) (((a) < (b)) ? (a) : (b))
   12.45 +
   12.46 +struct buffer
   12.47 +{
   12.48 +	char *data;
   12.49 +	size_t size;
   12.50 +	size_t capacity;
   12.51 +	size_t max_capacity;
   12.52 +};
   12.53 +
   12.54 +void buffer_append(struct buffer *buffer, const void *data, size_t size)
   12.55 +{
   12.56 +	if ((buffer->capacity - buffer->size) < size) {
   12.57 +		buffer->capacity += (size + 1024);
   12.58 +		buffer->data = realloc(buffer->data, buffer->capacity);
   12.59 +		if (buffer->data == NULL) {
   12.60 +			dolog(LOG_ERR, "Memory allocation failed");
   12.61 +			exit(ENOMEM);
   12.62 +		}
   12.63 +	}
   12.64 +
   12.65 +	memcpy(buffer->data + buffer->size, data, size);
   12.66 +	buffer->size += size;
   12.67 +
   12.68 +	if (buffer->max_capacity &&
   12.69 +	    buffer->size > buffer->max_capacity) {
   12.70 +		memmove(buffer->data + (buffer->size - buffer->max_capacity),
   12.71 +			buffer->data, buffer->max_capacity);
   12.72 +		buffer->data = realloc(buffer->data, buffer->max_capacity);
   12.73 +		buffer->capacity = buffer->max_capacity;
   12.74 +	}
   12.75 +}
   12.76 +
   12.77 +bool buffer_empty(struct buffer *buffer)
   12.78 +{
   12.79 +	return buffer->size == 0;
   12.80 +}
   12.81 +
   12.82 +void buffer_advance(struct buffer *buffer, size_t size)
   12.83 +{
   12.84 +	size = MIN(size, buffer->size);
   12.85 +	memmove(buffer->data, buffer + size, buffer->size - size);
   12.86 +	buffer->size -= size;
   12.87 +}
   12.88 +
   12.89 +struct domain
   12.90 +{
   12.91 +	int domid;
   12.92 +	int tty_fd;
   12.93 +	struct buffer buffer;
   12.94 +	struct domain *next;
   12.95 +};
   12.96 +
   12.97 +static struct domain *dom_head;
   12.98 +
   12.99 +bool domain_is_valid(int domid)
  12.100 +{
  12.101 +	bool ret;
  12.102 +	xc_dominfo_t info;
  12.103 +
  12.104 +	ret = (xc_domain_getinfo(xc, domid, 1, &info) == 1 &&
  12.105 +	       info.domid == domid);
  12.106 +		
  12.107 +	return ret;
  12.108 +}
  12.109 +
  12.110 +int domain_create_tty(int domid)
  12.111 +{
  12.112 +	char path[1024];
  12.113 +	int master;
  12.114 +
  12.115 +	if ((master = getpt()) == -1 ||
  12.116 +	    grantpt(master) == -1 || unlockpt(master) == -1) {
  12.117 +		dolog(LOG_ERR, "Failed to create tty for domain-%d", domid);
  12.118 +		master = -1;
  12.119 +	} else {
  12.120 +		const char *slave = ptsname(master);
  12.121 +		struct termios term;
  12.122 +
  12.123 +		if (tcgetattr(master, &term) != -1) {
  12.124 +			cfmakeraw(&term);
  12.125 +			tcsetattr(master, TCSAFLUSH, &term);
  12.126 +		}
  12.127 +
  12.128 +		xs_mkdir(xs, "/console");
  12.129 +		snprintf(path, sizeof(path), "/console/%d", domid);
  12.130 +		xs_mkdir(xs, path);
  12.131 +		strcat(path, "/tty");
  12.132 +
  12.133 +		xs_write(xs, path, slave, strlen(slave), O_CREAT);
  12.134 +	}
  12.135 +
  12.136 +	return master;
  12.137 +}
  12.138 +
  12.139 +struct domain *create_domain(int domid)
  12.140 +{
  12.141 +	struct domain *dom;
  12.142 +	char *data;
  12.143 +	unsigned int len;
  12.144 +	char path[1024];
  12.145 +
  12.146 +	dom = (struct domain *)malloc(sizeof(struct domain));
  12.147 +	if (dom == NULL) {
  12.148 +		dolog(LOG_ERR, "Out of memory %s:%s():L%d",
  12.149 +		      __FILE__, __FUNCTION__, __LINE__);
  12.150 +		exit(ENOMEM);
  12.151 +	}
  12.152 +
  12.153 +	dom->domid = domid;
  12.154 +	dom->tty_fd = domain_create_tty(domid);
  12.155 +	dom->buffer.data = 0;
  12.156 +	dom->buffer.size = 0;
  12.157 +	dom->buffer.capacity = 0;
  12.158 +	dom->buffer.max_capacity = 0;
  12.159 +
  12.160 +	snprintf(path, sizeof(path), "/console/%d/limit", domid);
  12.161 +	data = xs_read(xs, path, &len);
  12.162 +	if (data) {
  12.163 +		dom->buffer.max_capacity = strtoul(data, 0, 0);
  12.164 +		free(data);
  12.165 +	}
  12.166 +
  12.167 +	dolog(LOG_DEBUG, "New domain %d", domid);
  12.168 +
  12.169 +	return dom;
  12.170 +}
  12.171 +
  12.172 +struct domain *lookup_domain(int domid)
  12.173 +{
  12.174 +	struct domain **pp;
  12.175 +
  12.176 +	for (pp = &dom_head; *pp; pp = &(*pp)->next) {
  12.177 +		struct domain *dom = *pp;
  12.178 +
  12.179 +		if (dom->domid == domid) {
  12.180 +			return dom;
  12.181 +		} else if (dom->domid > domid) {
  12.182 +			*pp = create_domain(domid);
  12.183 +			(*pp)->next = dom;
  12.184 +			return *pp;
  12.185 +		}
  12.186 +	}
  12.187 +
  12.188 +	*pp = create_domain(domid);
  12.189 +	return *pp;
  12.190 +}
  12.191 +
  12.192 +void remove_domain(struct domain *dom)
  12.193 +{
  12.194 +	struct domain **pp;
  12.195 +
  12.196 +	dolog(LOG_DEBUG, "Removing domain-%d", dom->domid);
  12.197 +
  12.198 +	for (pp = &dom_head; *pp; pp = &(*pp)->next) {
  12.199 +		struct domain *d = *pp;
  12.200 +
  12.201 +		if (dom->domid == d->domid) {
  12.202 +			*pp = d->next;
  12.203 +			free(d);
  12.204 +			break;
  12.205 +		}
  12.206 +	}
  12.207 +}
  12.208 +
  12.209 +void handle_tty_read(struct domain *dom)
  12.210 +{
  12.211 +	ssize_t len;
  12.212 +	xcs_msg_t msg;
  12.213 +
  12.214 +	msg.type = XCS_REQUEST;
  12.215 +	msg.u.control.remote_dom = dom->domid;
  12.216 +	msg.u.control.msg.type = CMSG_CONSOLE;
  12.217 +	msg.u.control.msg.subtype = CMSG_CONSOLE_DATA;
  12.218 +	msg.u.control.msg.id = 1;
  12.219 +
  12.220 +	len = read(dom->tty_fd, msg.u.control.msg.msg, 60);
  12.221 +	if (len < 1) {
  12.222 +		close(dom->tty_fd);
  12.223 +
  12.224 +		if (domain_is_valid(dom->domid)) {
  12.225 +			dom->tty_fd = domain_create_tty(dom->domid);
  12.226 +		} else {
  12.227 +			remove_domain(dom);
  12.228 +		}
  12.229 +	} else if (domain_is_valid(dom->domid)) {
  12.230 +		msg.u.control.msg.length = len;
  12.231 +
  12.232 +		if (!write_sync(xcs_data_fd, &msg, sizeof(msg))) {
  12.233 +			dolog(LOG_ERR, "Write to xcs failed: %m");
  12.234 +		}
  12.235 +	} else {
  12.236 +		close(dom->tty_fd);
  12.237 +		remove_domain(dom);
  12.238 +	}
  12.239 +}
  12.240 +
  12.241 +void handle_tty_write(struct domain *dom)
  12.242 +{
  12.243 +	ssize_t len;
  12.244 +
  12.245 +	len = write(dom->tty_fd, dom->buffer.data, dom->buffer.size);
  12.246 +	if (len < 1) {
  12.247 +		close(dom->tty_fd);
  12.248 +
  12.249 +		if (domain_is_valid(dom->domid)) {
  12.250 +			dom->tty_fd = domain_create_tty(dom->domid);
  12.251 +		} else {
  12.252 +			remove_domain(dom);
  12.253 +		}
  12.254 +	} else {
  12.255 +		buffer_advance(&dom->buffer, len);
  12.256 +	}
  12.257 +}
  12.258 +
  12.259 +void handle_xcs_msg(int fd)
  12.260 +{
  12.261 +	xcs_msg_t msg;
  12.262 +
  12.263 +	if (!read_sync(fd, &msg, sizeof(msg))) {
  12.264 +		dolog(LOG_ERR, "read from xcs failed! %m");
  12.265 +	} else if (msg.type == XCS_REQUEST) {
  12.266 +		struct domain *dom;
  12.267 +
  12.268 +		dom = lookup_domain(msg.u.control.remote_dom);
  12.269 +		buffer_append(&dom->buffer,
  12.270 +			      msg.u.control.msg.msg,
  12.271 +			      msg.u.control.msg.length);
  12.272 +	}
  12.273 +}
  12.274 +
  12.275 +static void enum_domains(void)
  12.276 +{
  12.277 +	int domid = 0;
  12.278 +	xc_dominfo_t dominfo;
  12.279 +
  12.280 +	while (xc_domain_getinfo(xc, domid, 1, &dominfo) == 1) {
  12.281 +		lookup_domain(dominfo.domid);
  12.282 +		domid = dominfo.domid + 1;
  12.283 +	}
  12.284 +}
  12.285 +
  12.286 +void handle_io(void)
  12.287 +{
  12.288 +	fd_set readfds, writefds;
  12.289 +	int ret;
  12.290 +	int max_fd = -1;
  12.291 +
  12.292 +	do {
  12.293 +		struct domain *d;
  12.294 +		struct timeval tv = { 1, 0 };
  12.295 +
  12.296 +		FD_ZERO(&readfds);
  12.297 +		FD_ZERO(&writefds);
  12.298 +
  12.299 +		FD_SET(xcs_data_fd, &readfds);
  12.300 +		max_fd = MAX(xcs_data_fd, max_fd);
  12.301 +
  12.302 +		for (d = dom_head; d; d = d->next) {
  12.303 +			if (d->tty_fd != -1) {
  12.304 +				FD_SET(d->tty_fd, &readfds);
  12.305 +			}
  12.306 +
  12.307 +			if (d->tty_fd != -1 && !buffer_empty(&d->buffer)) {
  12.308 +				FD_SET(d->tty_fd, &writefds);
  12.309 +			}
  12.310 +
  12.311 +			max_fd = MAX(d->tty_fd, max_fd);
  12.312 +		}
  12.313 +
  12.314 +		ret = select(max_fd + 1, &readfds, &writefds, 0, &tv);
  12.315 +		enum_domains();
  12.316 +
  12.317 +		if (FD_ISSET(xcs_data_fd, &readfds)) {
  12.318 +			handle_xcs_msg(xcs_data_fd);
  12.319 +		}
  12.320 +
  12.321 +		for (d = dom_head; d; d = d->next) {
  12.322 +			if (FD_ISSET(d->tty_fd, &readfds)) {
  12.323 +				handle_tty_read(d);
  12.324 +			}
  12.325 +
  12.326 +			if (FD_ISSET(d->tty_fd, &writefds)) {
  12.327 +				handle_tty_write(d);
  12.328 +			}
  12.329 +		}
  12.330 +	} while (ret > -1);
  12.331 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/consoled/io.h	Tue Aug 02 10:20:46 2005 -0700
    13.3 @@ -0,0 +1,26 @@
    13.4 +/*\
    13.5 + *  Copyright (C) International Business Machines  Corp., 2005
    13.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    13.7 + *
    13.8 + *  Xen Console Daemon
    13.9 + *
   13.10 + *  This program is free software; you can redistribute it and/or modify
   13.11 + *  it under the terms of the GNU General Public License as published by
   13.12 + *  the Free Software Foundation; under version 2 of the License.
   13.13 + * 
   13.14 + *  This program is distributed in the hope that it will be useful,
   13.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.17 + *  GNU General Public License for more details.
   13.18 + * 
   13.19 + *  You should have received a copy of the GNU General Public License
   13.20 + *  along with this program; if not, write to the Free Software
   13.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.22 +\*/
   13.23 +
   13.24 +#ifndef CONSOLED_IO_H
   13.25 +#define CONSOLED_IO_H
   13.26 +
   13.27 +void handle_io(void);
   13.28 +
   13.29 +#endif
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/consoled/main.c	Tue Aug 02 10:20:46 2005 -0700
    14.3 @@ -0,0 +1,93 @@
    14.4 +/*\
    14.5 + *  Copyright (C) International Business Machines  Corp., 2005
    14.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    14.7 + *
    14.8 + *  Xen Console Daemon
    14.9 + *
   14.10 + *  This program is free software; you can redistribute it and/or modify
   14.11 + *  it under the terms of the GNU General Public License as published by
   14.12 + *  the Free Software Foundation; under version 2 of the License.
   14.13 + * 
   14.14 + *  This program is distributed in the hope that it will be useful,
   14.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14.17 + *  GNU General Public License for more details.
   14.18 + * 
   14.19 + *  You should have received a copy of the GNU General Public License
   14.20 + *  along with this program; if not, write to the Free Software
   14.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   14.22 +\*/
   14.23 +
   14.24 +#include <getopt.h>
   14.25 +#include <stdlib.h>
   14.26 +#include <stdio.h>
   14.27 +#include <errno.h>
   14.28 +#include <unistd.h>
   14.29 +#include <sys/types.h>
   14.30 +
   14.31 +#include "xc.h"
   14.32 +#include "xen/io/domain_controller.h"
   14.33 +#include "xcs_proto.h"
   14.34 +
   14.35 +#include "utils.h"
   14.36 +#include "io.h"
   14.37 +
   14.38 +int main(int argc, char **argv)
   14.39 +{
   14.40 +	const char *sopts = "hVvi";
   14.41 +	struct option lopts[] = {
   14.42 +		{ "help", 0, 0, 'h' },
   14.43 +		{ "version", 0, 0, 'V' },
   14.44 +		{ "verbose", 0, 0, 'v' },
   14.45 +		{ "interactive", 0, 0, 'i' },
   14.46 +		{ 0 },
   14.47 +	};
   14.48 +	bool is_interactive = false;
   14.49 +	int ch;
   14.50 +	int syslog_option = LOG_CONS;
   14.51 +	int syslog_mask = LOG_WARNING;
   14.52 +	int opt_ind = 0;
   14.53 +
   14.54 +	while ((ch = getopt_long(argc, argv, sopts, lopts, &opt_ind)) != -1) {
   14.55 +		switch (ch) {
   14.56 +		case 'h':
   14.57 +			//usage(argv[0]);
   14.58 +			exit(0);
   14.59 +		case 'V':
   14.60 +			//version(argv[0]);
   14.61 +			exit(0);
   14.62 +		case 'v':
   14.63 +			syslog_option |= LOG_PERROR;
   14.64 +			syslog_mask = LOG_DEBUG;
   14.65 +			break;
   14.66 +		case 'i':
   14.67 +			is_interactive = true;
   14.68 +			break;
   14.69 +		case '?':
   14.70 +			fprintf(stderr,
   14.71 +				"Try `%s --help' for more information\n",
   14.72 +				argv[0]);
   14.73 +			exit(EINVAL);
   14.74 +		}
   14.75 +	}
   14.76 +
   14.77 +	if (geteuid() != 0) {
   14.78 +		fprintf(stderr, "%s requires root to run.\n", argv[0]);
   14.79 +		exit(EPERM);
   14.80 +	}
   14.81 +
   14.82 +	openlog("consoled", syslog_option, LOG_DAEMON);
   14.83 +	setlogmask(syslog_mask);
   14.84 +
   14.85 +	if (!is_interactive) {
   14.86 +		daemonize("/var/run/consoled.pid");
   14.87 +	}
   14.88 +
   14.89 +	xen_setup();
   14.90 +
   14.91 +	handle_io();
   14.92 +
   14.93 +	closelog();
   14.94 +
   14.95 +	return 0;
   14.96 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/consoled/utils.c	Tue Aug 02 10:20:46 2005 -0700
    15.3 @@ -0,0 +1,251 @@
    15.4 +/*\
    15.5 + *  Copyright (C) International Business Machines  Corp., 2005
    15.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    15.7 + *
    15.8 + *  Xen Console Daemon
    15.9 + *
   15.10 + *  This program is free software; you can redistribute it and/or modify
   15.11 + *  it under the terms of the GNU General Public License as published by
   15.12 + *  the Free Software Foundation; under version 2 of the License.
   15.13 + * 
   15.14 + *  This program is distributed in the hope that it will be useful,
   15.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.17 + *  GNU General Public License for more details.
   15.18 + * 
   15.19 + *  You should have received a copy of the GNU General Public License
   15.20 + *  along with this program; if not, write to the Free Software
   15.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   15.22 +\*/
   15.23 +
   15.24 +#include <sys/types.h>
   15.25 +#include <sys/stat.h>
   15.26 +#include <sys/wait.h>
   15.27 +#include <unistd.h>
   15.28 +#include <stdlib.h>
   15.29 +#include <fcntl.h>
   15.30 +#include <err.h>
   15.31 +#include <errno.h>
   15.32 +#include <stdio.h>
   15.33 +#include <getopt.h>
   15.34 +#include <stdbool.h>
   15.35 +#include <sys/socket.h>
   15.36 +#include <sys/un.h>
   15.37 +#include <string.h>
   15.38 +
   15.39 +#include "xc.h"
   15.40 +#include "xen/io/domain_controller.h"
   15.41 +#include "xcs_proto.h"
   15.42 +
   15.43 +#include "utils.h"
   15.44 +
   15.45 +struct xs_handle *xs;
   15.46 +int xc;
   15.47 +
   15.48 +int xcs_ctrl_fd = -1;
   15.49 +int xcs_data_fd = -1;
   15.50 +
   15.51 +bool _read_write_sync(int fd, void *data, size_t size, bool do_read)
   15.52 +{
   15.53 +	size_t offset = 0;
   15.54 +	ssize_t len;
   15.55 +
   15.56 +	while (offset < size) {
   15.57 +		if (do_read) {
   15.58 +			len = read(fd, data + offset, size - offset);
   15.59 +		} else {
   15.60 +			len = write(fd, data + offset, size - offset);
   15.61 +		}
   15.62 +
   15.63 +		if (len < 1) {
   15.64 +			if (len == -1 && (errno == EAGAIN || errno == EINTR)) {
   15.65 +				return false;
   15.66 +			}
   15.67 +		} else {
   15.68 +			offset += len;
   15.69 +		}
   15.70 +	}
   15.71 +
   15.72 +	return true;
   15.73 +}
   15.74 +
   15.75 +static int open_domain_socket(const char *path)
   15.76 +{
   15.77 +	struct sockaddr_un addr;
   15.78 +	int sock;
   15.79 +	size_t addr_len;
   15.80 +
   15.81 +	if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) {
   15.82 +		goto out;
   15.83 +	}
   15.84 +
   15.85 +	addr.sun_family = AF_UNIX;
   15.86 +	strcpy(addr.sun_path, path);
   15.87 +	addr_len = sizeof(addr.sun_family) + strlen(XCS_SUN_PATH) + 1;
   15.88 +
   15.89 +	if (connect(sock, (struct sockaddr *)&addr, addr_len) == -1) {
   15.90 +		goto out_close_sock;
   15.91 +	}
   15.92 +
   15.93 +	return sock;
   15.94 +
   15.95 + out_close_sock:
   15.96 +	close(sock);
   15.97 + out:
   15.98 +	return -1;
   15.99 +}
  15.100 +
  15.101 +static void child_exit(int sig)
  15.102 +{
  15.103 +	while (waitpid(-1, NULL, WNOHANG) > 0);
  15.104 +}
  15.105 +
  15.106 +void daemonize(const char *pidfile)
  15.107 +{
  15.108 +	pid_t pid;
  15.109 +	int fd;
  15.110 +	int len;
  15.111 +	int i;
  15.112 +	char buf[100];
  15.113 +
  15.114 +	if (getppid() == 1) {
  15.115 +		return;
  15.116 +	}
  15.117 +
  15.118 +	if ((pid = fork()) > 0) {
  15.119 +		exit(0);
  15.120 +	} else if (pid == -1) {
  15.121 +		err(errno, "fork() failed");
  15.122 +	}
  15.123 +
  15.124 +	setsid();
  15.125 +
  15.126 +	/* redirect fd 0,1,2 to /dev/null */
  15.127 +	if ((fd = open("/dev/null",O_RDWR)) == -1) {
  15.128 +		exit(1);
  15.129 +	}
  15.130 +
  15.131 +	for (i = 0; i <= 2; i++) {
  15.132 +		close(i);
  15.133 +		dup2(fd, i);
  15.134 +	}
  15.135 +
  15.136 +	close(fd);
  15.137 +
  15.138 +	umask(027);
  15.139 +	chdir("/");
  15.140 +
  15.141 +	fd = open(pidfile, O_RDWR | O_CREAT);
  15.142 +	if (fd == -1) {
  15.143 +		exit(1);
  15.144 +	}
  15.145 +
  15.146 +	if (lockf(fd, F_TLOCK, 0) == -1) {
  15.147 +		exit(1);
  15.148 +	}
  15.149 +
  15.150 +	len = sprintf(buf, "%d\n", getpid());
  15.151 +	write(fd, buf, len);
  15.152 +
  15.153 +	signal(SIGCHLD, child_exit);
  15.154 +	signal(SIGTSTP, SIG_IGN);
  15.155 +	signal(SIGTTOU, SIG_IGN);
  15.156 +	signal(SIGTTIN, SIG_IGN);
  15.157 +}
  15.158 +
  15.159 +/* synchronized send/recv strictly for setting up xcs */
  15.160 +/* always use asychronize callbacks any other time */
  15.161 +static bool xcs_send_recv(int fd, xcs_msg_t *msg)
  15.162 +{
  15.163 +	bool ret = false;
  15.164 +
  15.165 +	if (!write_sync(fd, msg, sizeof(*msg))) {
  15.166 +		dolog(LOG_ERR, "Write failed at %s:%s():L%d?  Possible bug.",
  15.167 +		       __FILE__, __FUNCTION__, __LINE__);
  15.168 +		goto out;
  15.169 +	}
  15.170 +
  15.171 +	if (!read_sync(fd, msg, sizeof(*msg))) {
  15.172 +		dolog(LOG_ERR, "Read failed at %s:%s():L%d?  Possible bug.",
  15.173 +		       __FILE__, __FUNCTION__, __LINE__);
  15.174 +		goto out;
  15.175 +	}
  15.176 +
  15.177 +	ret = true;
  15.178 +
  15.179 + out:
  15.180 +	return ret;
  15.181 +}
  15.182 +
  15.183 +bool xen_setup(void)
  15.184 +{
  15.185 +	int sock;
  15.186 +	xcs_msg_t msg;
  15.187 +	
  15.188 +	xs = xs_daemon_open();
  15.189 +	if (xs == NULL) {
  15.190 +		dolog(LOG_ERR,
  15.191 +		      "Failed to contact xenstore (%m).  Is it running?");
  15.192 +		goto out;
  15.193 +	}
  15.194 +
  15.195 +	xc = xc_interface_open();
  15.196 +	if (xc == -1) {
  15.197 +		dolog(LOG_ERR, "Failed to contact hypervisor (%m)");
  15.198 +		goto out;
  15.199 +	}
  15.200 +
  15.201 +	sock = open_domain_socket(XCS_SUN_PATH);
  15.202 +	if (sock == -1) {
  15.203 +		dolog(LOG_ERR, "Failed to contact xcs (%m).  Is it running?");
  15.204 +		goto out_close_store;
  15.205 +	}
  15.206 +
  15.207 +	xcs_ctrl_fd = sock;
  15.208 +
  15.209 +	sock = open_domain_socket(XCS_SUN_PATH);
  15.210 +	if (sock == -1) {
  15.211 +		dolog(LOG_ERR, "Failed to contact xcs (%m).  Is it running?");
  15.212 +		goto out_close_ctrl;
  15.213 +	}
  15.214 +	
  15.215 +	xcs_data_fd = sock;
  15.216 +
  15.217 +	memset(&msg, 0, sizeof(msg));
  15.218 +	msg.type = XCS_CONNECT_CTRL;
  15.219 +	if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) {
  15.220 +		dolog(LOG_ERR, "xcs control connect failed.  Possible bug.");
  15.221 +		goto out_close_data;
  15.222 +	}
  15.223 +
  15.224 +	msg.type = XCS_CONNECT_DATA;
  15.225 +	if (!xcs_send_recv(xcs_data_fd, &msg) || msg.result != XCS_RSLT_OK) {
  15.226 +		dolog(LOG_ERR, "xcs data connect failed.  Possible bug.");
  15.227 +		goto out_close_data;
  15.228 +	}
  15.229 +
  15.230 +	/* Since the vast majority of control messages are console messages
  15.231 +	   it's just easier to ignore other messages that try to bind to 
  15.232 +	   a specific type. */
  15.233 +	msg.type = XCS_MSG_BIND;
  15.234 +	msg.u.bind.port = PORT_WILDCARD;
  15.235 +	msg.u.bind.type = TYPE_WILDCARD;
  15.236 +	if (!xcs_send_recv(xcs_ctrl_fd, &msg) || msg.result != XCS_RSLT_OK) {
  15.237 +		dolog(LOG_ERR, "xcs vind failed.  Possible bug.");
  15.238 +		goto out_close_data;
  15.239 +	}
  15.240 +	
  15.241 +	return true;
  15.242 +
  15.243 + out_close_data:
  15.244 +	close(xcs_ctrl_fd);
  15.245 +	xcs_data_fd = -1;
  15.246 + out_close_ctrl:
  15.247 +	close(xcs_ctrl_fd);
  15.248 +	xcs_ctrl_fd = -1;
  15.249 + out_close_store:
  15.250 +	xs_daemon_close(xs);
  15.251 + out:
  15.252 +	return false;
  15.253 +}
  15.254 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/consoled/utils.h	Tue Aug 02 10:20:46 2005 -0700
    16.3 @@ -0,0 +1,47 @@
    16.4 +/*\
    16.5 + *  Copyright (C) International Business Machines  Corp., 2005
    16.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    16.7 + *
    16.8 + *  Xen Console Daemon
    16.9 + *
   16.10 + *  This program is free software; you can redistribute it and/or modify
   16.11 + *  it under the terms of the GNU General Public License as published by
   16.12 + *  the Free Software Foundation; under version 2 of the License.
   16.13 + * 
   16.14 + *  This program is distributed in the hope that it will be useful,
   16.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16.17 + *  GNU General Public License for more details.
   16.18 + * 
   16.19 + *  You should have received a copy of the GNU General Public License
   16.20 + *  along with this program; if not, write to the Free Software
   16.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   16.22 +\*/
   16.23 +
   16.24 +#ifndef CONSOLED_UTILS_H
   16.25 +#define CONSOLED_UTILS_H
   16.26 +
   16.27 +#include <stdbool.h>
   16.28 +#include <syslog.h>
   16.29 +#include <stdio.h>
   16.30 +
   16.31 +#include "xs.h"
   16.32 +
   16.33 +void daemonize(const char *pidfile);
   16.34 +bool xen_setup(void);
   16.35 +#define read_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, true)
   16.36 +#define write_sync(fd, buffer, size) _read_write_sync(fd, buffer, size, false)
   16.37 +bool _read_write_sync(int fd, void *data, size_t size, bool do_read);
   16.38 +
   16.39 +extern int xcs_ctrl_fd;
   16.40 +extern int xcs_data_fd;
   16.41 +extern struct xs_handle *xs;
   16.42 +extern int xc;
   16.43 +
   16.44 +#if 1
   16.45 +#define dolog(val, fmt, ...) syslog(val, fmt, ## __VA_ARGS__)
   16.46 +#else
   16.47 +#define dolog(val, fmt, ...) fprintf(stderr, fmt "\n", ## __VA_ARGS__)
   16.48 +#endif
   16.49 +
   16.50 +#endif
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/consoled/xc_console.c	Tue Aug 02 10:20:46 2005 -0700
    17.3 @@ -0,0 +1,236 @@
    17.4 +/*\
    17.5 + *  Copyright (C) International Business Machines  Corp., 2005
    17.6 + *  Author(s): Anthony Liguori <aliguori@us.ibm.com>
    17.7 + *
    17.8 + *  Xen Console Daemon
    17.9 + *
   17.10 + *  This program is free software; you can redistribute it and/or modify
   17.11 + *  it under the terms of the GNU General Public License as published by
   17.12 + *  the Free Software Foundation; under version 2 of the License.
   17.13 + * 
   17.14 + *  This program is distributed in the hope that it will be useful,
   17.15 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.16 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.17 + *  GNU General Public License for more details.
   17.18 + * 
   17.19 + *  You should have received a copy of the GNU General Public License
   17.20 + *  along with this program; if not, write to the Free Software
   17.21 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.22 +\*/
   17.23 +
   17.24 +#include <sys/types.h>
   17.25 +#include <sys/socket.h>
   17.26 +#include <sys/un.h>
   17.27 +#include <stdio.h>
   17.28 +#include <unistd.h>
   17.29 +#include <errno.h>
   17.30 +#include <stdlib.h>
   17.31 +#include <time.h>
   17.32 +#include <fcntl.h>
   17.33 +#include <sys/wait.h>
   17.34 +#include <termios.h>
   17.35 +#include <signal.h>
   17.36 +#include <getopt.h>
   17.37 +#include <sys/select.h>
   17.38 +#include <err.h>
   17.39 +#include <errno.h>
   17.40 +#include <pty.h>
   17.41 +
   17.42 +#include "xc.h"
   17.43 +#include "xs.h"
   17.44 +
   17.45 +#define ESCAPE_CHARACTER 0x1d
   17.46 +
   17.47 +static volatile sig_atomic_t received_signal = 0;
   17.48 +
   17.49 +static void sighandler(int signum)
   17.50 +{
   17.51 +	received_signal = 1;
   17.52 +}
   17.53 +
   17.54 +static bool write_sync(int fd, const void *data, size_t size)
   17.55 +{
   17.56 +	size_t offset = 0;
   17.57 +	ssize_t len;
   17.58 +
   17.59 +	while (offset < size) {
   17.60 +		len = write(fd, data + offset, size - offset);
   17.61 +		if (len < 1) {
   17.62 +			return false;
   17.63 +		}
   17.64 +		offset += len;
   17.65 +	}
   17.66 +
   17.67 +	return true;
   17.68 +}
   17.69 +
   17.70 +static void usage(const char *program) {
   17.71 +	printf("Usage: %s [OPTION] DOMID\n"
   17.72 +	       "Attaches to a virtual domain console\n"
   17.73 +	       "\n"
   17.74 +	       "  -h, --help       display this help and exit\n"
   17.75 +	       , program);
   17.76 +}
   17.77 +
   17.78 +/* don't worry too much if setting terminal attributes fail */
   17.79 +static void init_term(int fd, struct termios *old)
   17.80 +{
   17.81 +	struct termios new_term;
   17.82 +
   17.83 +	if (tcgetattr(fd, old) == -1) {
   17.84 +		perror("tcgetattr() failed");
   17.85 +		return;
   17.86 +	}
   17.87 +
   17.88 +	new_term = *old;
   17.89 +	cfmakeraw(&new_term);
   17.90 +
   17.91 +	if (tcsetattr(fd, TCSAFLUSH, &new_term) == -1) {
   17.92 +		perror("tcsetattr() failed");
   17.93 +	}
   17.94 +}
   17.95 +
   17.96 +static void restore_term(int fd, struct termios *old)
   17.97 +{
   17.98 +	if (tcsetattr(fd, TCSAFLUSH, old) == -1) {
   17.99 +		perror("tcsetattr() failed");
  17.100 +	}
  17.101 +}
  17.102 +
  17.103 +static int console_loop(int xc_handle, domid_t domid, int fd)
  17.104 +{
  17.105 +	int ret;
  17.106 +
  17.107 +	do {
  17.108 +		fd_set fds;
  17.109 +
  17.110 +		FD_ZERO(&fds);
  17.111 +		FD_SET(STDIN_FILENO, &fds);
  17.112 +		FD_SET(fd, &fds);
  17.113 +
  17.114 +		ret = select(fd + 1, &fds, NULL, NULL, NULL);
  17.115 +		if (ret == -1) {
  17.116 +			if (errno == EINTR || errno == EAGAIN) {
  17.117 +				continue;
  17.118 +			}
  17.119 +			perror("select() failed");
  17.120 +			return -1;
  17.121 +		}
  17.122 +
  17.123 +		if (FD_ISSET(STDIN_FILENO, &fds)) {
  17.124 +			ssize_t len;
  17.125 +			char msg[60];
  17.126 +
  17.127 +			len = read(STDIN_FILENO, msg, sizeof(msg));
  17.128 +			if (len == 1 && msg[0] == ESCAPE_CHARACTER) {
  17.129 +				return 0;
  17.130 +			} 
  17.131 +
  17.132 +			if (len == 0 && len == -1) {
  17.133 +				if (len == -1 &&
  17.134 +				    (errno == EINTR || errno == EAGAIN)) {
  17.135 +					continue;
  17.136 +				}
  17.137 +				perror("select() failed");
  17.138 +				return -1;
  17.139 +			}
  17.140 +
  17.141 +			if (!write_sync(fd, msg, len)) {
  17.142 +				perror("write() failed");
  17.143 +				return -1;
  17.144 +			}
  17.145 +		}
  17.146 +
  17.147 +		if (FD_ISSET(fd, &fds)) {
  17.148 +			ssize_t len;
  17.149 +			char msg[512];
  17.150 +
  17.151 +			len = read(fd, msg, sizeof(msg));
  17.152 +			if (len == 0 || len == -1) {
  17.153 +				if (len == -1 &&
  17.154 +				    (errno == EINTR || errno == EAGAIN)) {
  17.155 +					continue;
  17.156 +				}
  17.157 +				perror("select() failed");
  17.158 +				return -1;
  17.159 +			}
  17.160 +
  17.161 +			if (!write_sync(STDOUT_FILENO, msg, len)) {
  17.162 +				perror("write() failed");
  17.163 +				return -1;
  17.164 +			}
  17.165 +		}
  17.166 +	} while (received_signal == 0);
  17.167 +
  17.168 +	return 0;
  17.169 +}
  17.170 +
  17.171 +int main(int argc, char **argv)
  17.172 +{
  17.173 +	struct termios attr;
  17.174 +	int domid;
  17.175 +	int xc_handle;
  17.176 +	char *sopt = "hf:pc";
  17.177 +	int ch;
  17.178 +	int opt_ind=0;
  17.179 +	struct option lopt[] = {
  17.180 +		{ "help",    0, 0, 'h' },
  17.181 +		{ "file",    1, 0, 'f' },
  17.182 +		{ "pty",     0, 0, 'p' },
  17.183 +		{ "ctty",    0, 0, 'c' },
  17.184 +		{ 0 },
  17.185 +
  17.186 +	};
  17.187 +	char *str_pty;
  17.188 +	char path[1024];
  17.189 +	int spty;
  17.190 +	unsigned int len = 0;
  17.191 +	struct xs_handle *xs;
  17.192 +
  17.193 +	while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
  17.194 +		switch(ch) {
  17.195 +		case 'h':
  17.196 +			usage(argv[0]);
  17.197 +			exit(0);
  17.198 +			break;
  17.199 +		}
  17.200 +	}
  17.201 +	
  17.202 +	if ((argc - optind) != 1) {
  17.203 +		fprintf(stderr, "Invalid number of arguments\n");
  17.204 +		fprintf(stderr, "Try `%s --help' for more information.\n", 
  17.205 +			argv[0]);
  17.206 +		exit(EINVAL);
  17.207 +	}
  17.208 +	
  17.209 +	domid = atoi(argv[optind]);
  17.210 +
  17.211 +	xs = xs_daemon_open();
  17.212 +	if (xs == NULL) {
  17.213 +		err(errno, "Could not contact XenStore");
  17.214 +	}
  17.215 +
  17.216 +	xc_handle = xc_interface_open();
  17.217 +	if (xc_handle == -1) {
  17.218 +		err(errno, "xc_interface_open()");
  17.219 +	}
  17.220 +	
  17.221 +	signal(SIGTERM, sighandler);
  17.222 +
  17.223 +	snprintf(path, sizeof(path), "/console/%d/tty", domid);
  17.224 +	str_pty = xs_read(xs, path, &len);
  17.225 +	if (str_pty == NULL) {
  17.226 +		err(errno, "Could not read tty from store");
  17.227 +	}
  17.228 +	spty = open(str_pty, O_RDWR | O_NOCTTY);
  17.229 +	if (spty == -1) {
  17.230 +		err(errno, "Could not open tty `%s'", str_pty);
  17.231 +	}
  17.232 +	free(str_pty);
  17.233 +
  17.234 +	init_term(STDIN_FILENO, &attr);
  17.235 +	console_loop(xc_handle, domid, spty);
  17.236 +	restore_term(STDIN_FILENO, &attr);
  17.237 +
  17.238 +	return 0;
  17.239 + }
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/libxc/xc_ia64_stubs.c	Tue Aug 02 10:20:46 2005 -0700
    18.3 @@ -0,0 +1,39 @@
    18.4 +#include "xc_private.h"
    18.5 +
    18.6 +int xc_linux_save(int xc_handle, int io_fd, u32 dom)
    18.7 +{
    18.8 +    PERROR("xc_linux_save not implemented\n");
    18.9 +    return -1;
   18.10 +}
   18.11 +
   18.12 +int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
   18.13 +{
   18.14 +    PERROR("xc_linux_restore not implemented\n");
   18.15 +    return -1;
   18.16 +}
   18.17 +
   18.18 +int xc_vmx_build(int xc_handle,
   18.19 +                   u32 domid,
   18.20 +                   int memsize,
   18.21 +                   const char *image_name,
   18.22 +                   struct mem_map *mem_mapp,
   18.23 +                   const char *ramdisk_name,
   18.24 +                   const char *cmdline,
   18.25 +                   unsigned int control_evtchn,
   18.26 +                   unsigned long flags)
   18.27 +{
   18.28 +    PERROR("xc_vmx_build not implemented\n");
   18.29 +    return -1;
   18.30 +}
   18.31 +
   18.32 +int
   18.33 +xc_plan9_build(int xc_handle,
   18.34 +               u32 domid,
   18.35 +               const char *image_name,
   18.36 +               const char *cmdline,
   18.37 +               unsigned int control_evtchn, unsigned long flags)
   18.38 +{
   18.39 +    PERROR("xc_plan9_build not implemented\n");
   18.40 +    return -1;
   18.41 +}
   18.42 +
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/misc/policyprocessor/Makefile	Tue Aug 02 10:20:46 2005 -0700
    19.3 @@ -0,0 +1,42 @@
    19.4 +XEN_ROOT = ../../..
    19.5 +include $(XEN_ROOT)/tools/Rules.mk
    19.6 +
    19.7 +CFLAGS   += -static
    19.8 +CFLAGS   += -Wall
    19.9 +CFLAGS   += -Werror
   19.10 +CFLAGS   += -O3
   19.11 +CFLAGS   += -fno-strict-aliasing
   19.12 +CFLAGS   += -I.
   19.13 +
   19.14 +all: build
   19.15 +
   19.16 +build: mk-symlinks
   19.17 +	$(MAKE) xml_to_bin
   19.18 +
   19.19 +default: all
   19.20 +
   19.21 +install: all
   19.22 +
   19.23 +xml_to_bin : make_include XmlToBin.java XmlToBinInterface.java SsidsEntry.java SecurityLabel.java myHandler.java
   19.24 +	javac XmlToBin.java
   19.25 +
   19.26 +make_include : c2j_include
   19.27 +	./c2j_include
   19.28 +
   19.29 +c2j_include: c2j_include.c
   19.30 +	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<
   19.31 +
   19.32 +clean:
   19.33 +	rm -rf *.class xen c2j_include policy_version.java *.bin
   19.34 +
   19.35 +
   19.36 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
   19.37 +mk-symlinks:
   19.38 +	[ -e xen/linux ] || mkdir -p xen/linux
   19.39 +	[ -e xen/io ]    || mkdir -p xen/io
   19.40 +	( cd xen >/dev/null ; \
   19.41 +	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   19.42 +	( cd xen/io >/dev/null ; \
   19.43 +	  ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   19.44 +	( cd xen/linux >/dev/null ; \
   19.45 +	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    20.1 --- a/tools/misc/policyprocessor/XmlToBin.java	Tue Aug 02 02:47:41 2005 -0800
    20.2 +++ b/tools/misc/policyprocessor/XmlToBin.java	Tue Aug 02 10:20:46 2005 -0700
    20.3 @@ -5,6 +5,9 @@
    20.4   *
    20.5   * Author: Ray Valdez
    20.6   *
    20.7 + * Contributors:
    20.8 + *         Reiner Sailer - adjust type-lengths
    20.9 + *
   20.10   * This program is free software; you can redistribute it and/or
   20.11   * modify it under the terms of the GNU General Public License as
   20.12   * published by the Free Software Foundation, version 2 of the
   20.13 @@ -490,175 +493,139 @@ public class XmlToBin
   20.14  	
   20.15  
   20.16    try {
   20.17 -	/* Write magic */
   20.18 -	writeIntToStream(binBuffer,ACM_MAGIC,index);
   20.19 -	index = u32Size;
   20.20 +	  index = 0;
   20.21 +	  /* fill in General Policy Version */
   20.22 +	  writeIntToStream(binBuffer, ACM_POLICY_VERSION, index);
   20.23 +	  index += u32Size;
   20.24  
   20.25 -	/* Write policy version */
   20.26 -	writeIntToStream(binBuffer,POLICY_INTERFACE_VERSION,index);
   20.27 -  	index = index + u32Size;
   20.28 +	  /* Write magic */
   20.29 +	  writeIntToStream(binBuffer, ACM_MAGIC, index);
   20.30 +	  index += u32Size;
   20.31  
   20.32 -	/* write len */
   20.33 -	writeIntToStream(binBuffer,binBuffer.length,index);
   20.34 -  	index = index + u32Size;
   20.35 +	  /* write len */
   20.36 +	  writeIntToStream(binBuffer, binBuffer.length, index);
   20.37 +	  index += u32Size;
   20.38  
   20.39    } catch (IOException ee) {
   20.40 -    	System.out.println(" GBPB:: got exception : " + ee); 
   20.41 -	return null;
   20.42 +	  System.out.println(" GBPB:: got exception : " + ee);
   20.43 +	  return null;
   20.44    }
   20.45  
   20.46    int offset, address;
   20.47    address = index;
   20.48  
   20.49    if (null != partMap) 
   20.50 -	offset = binaryBufferHeaderSz + resourceOffsetSz; 
   20.51 +	  offset = binaryBufferHeaderSz + resourceOffsetSz;
   20.52    else
   20.53 -	offset = binaryBufferHeaderSz; 
   20.54 +	  offset = binaryBufferHeaderSz;
   20.55  
   20.56    try {
   20.57 -
   20.58 -	if (null == chwPolicy || null == stePolicy) 
   20.59 -	{
   20.60 -	  writeShortToStream(binBuffer,ACM_NULL_POLICY,index);
   20.61 -  	  index = index + u16Size;
   20.62 -
   20.63 -	  writeShortToStream(binBuffer,(short) 0,index);
   20.64 -  	  index = index + u16Size;
   20.65 -
   20.66 -	  writeShortToStream(binBuffer,ACM_NULL_POLICY,index);
   20.67 -  	  index = index + u16Size;
   20.68 -
   20.69 -	  writeShortToStream(binBuffer,(short) 0,index);
   20.70 -  	  index = index + u16Size;
   20.71 +	  int skip = 0;
   20.72  
   20.73 -	}
   20.74 -    	index = address;
   20.75 -	if (null != chwPolicy) 
   20.76 -	{
   20.77 +	  /* init with NULL policy setting */
   20.78 +	  writeIntToStream(binBuffer, ACM_NULL_POLICY, index);
   20.79 +	  writeIntToStream(binBuffer, 0, index + u32Size);
   20.80 +	  writeIntToStream(binBuffer, ACM_NULL_POLICY, index + 2*u32Size);
   20.81 +	  writeIntToStream(binBuffer, 0, index + 3*u32Size);
   20.82  	  
   20.83 -	  /* Write policy name */
   20.84 -	  writeShortToStream(binBuffer,ACM_CHINESE_WALL_POLICY,index);
   20.85 -  	  index = index + u16Size;
   20.86 +	  index = address;
   20.87 +	  if (null != chwPolicy) {
   20.88 +	  
   20.89 +		  /* Write policy name */
   20.90 +		  writeIntToStream(binBuffer, ACM_CHINESE_WALL_POLICY, index);
   20.91 +		  index += u32Size;
   20.92  
   20.93 -	  /* Write offset */
   20.94 -	  writeShortToStream(binBuffer,(short) offset,index);
   20.95 -  	  index = index + u16Size;
   20.96 +		  /* Write offset */
   20.97 +		  writeIntToStream(binBuffer, offset, index);
   20.98 +		  index += u32Size;
   20.99  
  20.100 -	  /* Write payload. No need increment index */
  20.101 -	  address = offset;
  20.102 -	  System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length);
  20.103 -	  address = address + chwPolicy.length;
  20.104 -	  
  20.105 +		  /* Write payload. No need increment index */
  20.106 +		  address = offset;
  20.107 +		  System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length);
  20.108 +		  address = address + chwPolicy.length;
  20.109 +	  } else
  20.110 +		  skip += 2*u32Size;
  20.111 +
  20.112  	  if (null != stePolicy) 
  20.113  	  {	
  20.114  	  	/* Write policy name */
  20.115 -	  	writeShortToStream(binBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index);
  20.116 -  	  	index = index + u16Size;
  20.117 +	  	writeIntToStream(binBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index);
  20.118 +  	  	index += u32Size;
  20.119  
  20.120  	  	/* Write offset */
  20.121 -	  	writeShortToStream(binBuffer,(short) address,index);
  20.122 -  	  	index = index + u16Size;
  20.123 +	  	writeIntToStream(binBuffer, address, index);
  20.124 +  	  	index += u32Size;
  20.125  
  20.126  		/* Copy array */
  20.127  	  	System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length);
  20.128  		/* Update address */
  20.129  		address = address + stePolicy.length;
  20.130 -	  } else {
  20.131 -	  	/* Skip writing policy name and offset */
  20.132 -  	  	index = index +  2 * u16Size;
  20.133 -
  20.134 -          }
  20.135 -
  20.136 -	} else {
  20.137 -
  20.138 -	  if (null != stePolicy) 
  20.139 -	  {	
  20.140 -	  	/* Write policy name */
  20.141 -	  	writeShortToStream(binBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index);
  20.142 -  	  	index = index + u16Size;
  20.143 -
  20.144 -	  	/* Write offset */
  20.145 -		address = offset;
  20.146 -	  	writeShortToStream(binBuffer, (short) offset,index);
  20.147 -  	  	index = index + u16Size;
  20.148 -		
  20.149 -		/* Copy array */
  20.150 -	  	System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length);
  20.151 -		/* Update address */
  20.152 -		address = address + stePolicy.length;
  20.153 -
  20.154 -		/* Increment index, since there is no secondary */
  20.155 -  	  	index = index + secondaryPolicyCodeSz + secondaryBufferOffsetSz;
  20.156 -		
  20.157 -	  } 
  20.158 -
  20.159 -	}
  20.160 -   	int size;
  20.161 -	/* Assumes that you will always have a partition defined in policy */ 
  20.162 -	if ( 0 < partMap.length)
  20.163 -	{
  20.164 -	  writeShortToStream(binBuffer, (short) address,index);
  20.165 -	  index = address;
  20.166 -
  20.167 -	  /* Compute num of VMs */
  20.168 -	  size = partMap.length / (3 * u16Size);
  20.169 -
  20.170 -	  writeShortToStream(binBuffer, (short)size,index);
  20.171 -  	  index = index + u16Size;
  20.172 -
  20.173 -	  /* part, vlan and slot: each one consists of two entries */
  20.174 -	  offset = 3 * (2 * u16Size); 
  20.175 -	  writeShortToStream(binBuffer, (short) offset,index);
  20.176 +	  } else
  20.177 +		 skip += 2*u32Size;
  20.178  
  20.179 -	  /* Write partition array at offset */
  20.180 -	  System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length);
  20.181 -  	  index = index + u16Size;
  20.182 -	  offset = offset + partMap.length;
  20.183 -	}
  20.184 +	  /* Skip writing policy name and offset for each null policy*/
  20.185 +	  index +=  skip;
  20.186  
  20.187 -	if ( 0 < vlanMap.length)
  20.188 -	{
  20.189 -	  size = vlanMap.length / (2 * u16Size);
  20.190 -	  writeShortToStream(binBuffer, (short) size,index);
  20.191 -  	  index = index + u16Size;
  20.192 +	  int size;
  20.193 +	  /* Assumes that you will always have a partition defined in policy */
  20.194 +	  if ( 0 < partMap.length) {
  20.195 +		  writeIntToStream(binBuffer, address, index);
  20.196 +		  index = address;
  20.197  
  20.198 -	  writeShortToStream(binBuffer, (short) offset,index);
  20.199 -  	  index = index + u16Size;
  20.200 -	  System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length);
  20.201 -	} else {
  20.202 -	  /* Write vlan max */
  20.203 -	  writeShortToStream(binBuffer, (short) 0,index);
  20.204 -  	  index = index + u16Size;
  20.205 +		  /* Compute num of VMs */
  20.206 +		  size = partMap.length / (3 * u16Size);
  20.207 +
  20.208 +		  writeShortToStream(binBuffer, (short)size,index);
  20.209 +		  index = index + u16Size;
  20.210 +
  20.211 +		  /* part, vlan and slot: each one consists of two entries */
  20.212 +		  offset = 3 * (2 * u16Size);
  20.213 +		  writeShortToStream(binBuffer, (short) offset,index);
  20.214 +
  20.215 +		  /* Write partition array at offset */
  20.216 +		  System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length);
  20.217 +		  index = index + u16Size;
  20.218 +		  offset = offset + partMap.length;
  20.219 +	  }
  20.220 +
  20.221 +	  if ( 0 < vlanMap.length) {
  20.222 +		  size = vlanMap.length / (2 * u16Size);
  20.223 +		  writeShortToStream(binBuffer, (short) size,index);
  20.224 +		  index = index + u16Size;
  20.225 +
  20.226 +		  writeShortToStream(binBuffer, (short) offset,index);
  20.227 +		  index = index + u16Size;
  20.228 +		  System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length);
  20.229 +	  } else {
  20.230 +		  /* Write vlan max */
  20.231 +		  writeShortToStream(binBuffer, (short) 0,index);
  20.232 +		  index = index + u16Size;
  20.233   
  20.234 -	  /* Write vlan offset */
  20.235 -	  writeShortToStream(binBuffer, (short) 0,index);
  20.236 -  	  index = index + u16Size;
  20.237 -	  
  20.238 -   	}
  20.239 -
  20.240 -	offset = offset + vlanMap.length;
  20.241 -	if ( 0 < slotMap.length)
  20.242 -	{
  20.243 -	  size = slotMap.length / (3 * u16Size);
  20.244 -	  writeShortToStream(binBuffer, (short) size,index);
  20.245 -  	  index = index + u16Size;
  20.246 +		  /* Write vlan offset */
  20.247 +		  writeShortToStream(binBuffer, (short) 0,index);
  20.248 +		  index = index + u16Size;
  20.249 +	  }
  20.250  
  20.251 -	  writeShortToStream(binBuffer, (short) offset,index);
  20.252 -  	  index = index + u16Size;
  20.253 -	  System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length);
  20.254 -	}
  20.255 +	  offset = offset + vlanMap.length;
  20.256 +	  if ( 0 < slotMap.length) {
  20.257 +		  size = slotMap.length / (3 * u16Size);
  20.258 +		  writeShortToStream(binBuffer, (short) size,index);
  20.259 +		  index = index + u16Size;
  20.260  
  20.261 -     } catch (IOException ee)
  20.262 -    {
  20.263 -    	System.out.println(" GBPB:: got exception : " + ee); 
  20.264 -	return null; 
  20.265 -    }
  20.266 +		  writeShortToStream(binBuffer, (short) offset,index);
  20.267 +		  index = index + u16Size;
  20.268 +		  System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length);
  20.269 +	  }
  20.270 +  } catch (IOException ee) {
  20.271 +	  System.out.println(" GBPB:: got exception : " + ee);
  20.272 +	  return null;
  20.273 +  }
  20.274  
  20.275 -    printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length); 
  20.276 -    if (debug) 
  20.277 -   	printHex(binBuffer,binBuffer.length);
  20.278 +  printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length);
  20.279 +  if (debug)
  20.280 +	  printHex(binBuffer,binBuffer.length);
  20.281  
  20.282 -   return  binBuffer;   
  20.283 +  return  binBuffer;
  20.284   } 
  20.285  
  20.286   public  byte[] generateChwBuffer(Vector Ssids, Vector ConflictSsids, Vector ColorTypes)
  20.287 @@ -668,28 +635,20 @@ public class XmlToBin
  20.288    int position = 0;
  20.289  
  20.290    /* Get number of rTypes */
  20.291 -  short maxTypes = (short) ColorTypes.size();
  20.292 +  int maxTypes = ColorTypes.size();
  20.293  
  20.294    /* Get number of SSids entry */
  20.295 -  short maxSsids = (short) Ssids.size();
  20.296 +  int maxSsids = Ssids.size();
  20.297  
  20.298    /* Get number of conflict sets */
  20.299 -  short maxConflict = (short) ConflictSsids.size();
  20.300 +  int maxConflict = ConflictSsids.size();
  20.301  
  20.302     
  20.303    if (maxTypes * maxSsids == 0)
  20.304  	return null; 
  20.305    /*
  20.306 -     data structure acm_chwall_policy_buffer_t;
  20.307 -    
  20.308 -     uint16 policy_code;
  20.309 -     uint16 chwall_max_types;
  20.310 -     uint16 chwall_max_ssidrefs;
  20.311 -     uint16 chwall_max_conflictsets;
  20.312 -     uint16 chwall_ssid_offset;
  20.313 -     uint16 chwall_conflict_sets_offset;
  20.314 -     uint16 chwall_running_types_offset;
  20.315 -     uint16 chwall_conflict_aggregate_offset;
  20.316 +     data structure acm_chwall_policy_buffer
  20.317 +     se XmlToBinInterface.java
  20.318    */
  20.319    int totalBytes = chwHeaderSize  + u16Size *(maxTypes * (maxSsids + maxConflict)); 
  20.320  
  20.321 @@ -699,34 +658,38 @@ public class XmlToBin
  20.322    printDebug(" gCB:: chwall totalbytes : "+totalBytes); 
  20.323  
  20.324    try {
  20.325 -	index = 0;
  20.326 -	writeShortToStream(chwBuffer,ACM_CHINESE_WALL_POLICY,index);
  20.327 -	index = u16Size; 
  20.328 -
  20.329 -	writeShortToStream(chwBuffer,maxTypes,index);
  20.330 -	index = index + u16Size; 
  20.331 -
  20.332 -	writeShortToStream(chwBuffer,maxSsids,index);
  20.333 -	index = index + u16Size; 
  20.334 -
  20.335 -	writeShortToStream(chwBuffer,maxConflict,index);
  20.336 -	index = index + u16Size; 
  20.337 +	  index = 0;
  20.338 +	  /* fill in General Policy Version */
  20.339 +	  writeIntToStream(chwBuffer, ACM_CHWALL_VERSION, index);
  20.340 +	  index += u32Size;
  20.341  
  20.342 -        /*  Write chwall_ssid_offset */
  20.343 -	writeShortToStream(chwBuffer,chwHeaderSize,index);
  20.344 -	index = index + u16Size; 
  20.345 +	  writeIntToStream(chwBuffer, ACM_CHINESE_WALL_POLICY, index);
  20.346 +	  index += u32Size;
  20.347  
  20.348 -	/* Write chwall_conflict_sets_offset */
  20.349 -	writeShortToStream(chwBuffer,(short) address,index);
  20.350 -	index = index + u16Size; 
  20.351 +	  writeIntToStream(chwBuffer, maxTypes, index);
  20.352 +	  index += u32Size;
  20.353  
  20.354 -	/*  Write chwall_running_types_offset */
  20.355 -	writeShortToStream(chwBuffer,(short) 0,index);
  20.356 -	index = index + u16Size; 
  20.357 +	  writeIntToStream(chwBuffer, maxSsids, index);
  20.358 +	  index += u32Size;
  20.359  
  20.360 -	/*  Write chwall_conflict_aggregate_offset */
  20.361 -	writeShortToStream(chwBuffer,(short) 0,index);
  20.362 -	index = index + u16Size; 
  20.363 +	  writeIntToStream(chwBuffer, maxConflict, index);
  20.364 +	  index += u32Size;
  20.365 +
  20.366 +	  /*  Write chwall_ssid_offset */
  20.367 +	  writeIntToStream(chwBuffer, chwHeaderSize, index);
  20.368 +	  index += u32Size;
  20.369 +
  20.370 +	  /* Write chwall_conflict_sets_offset */
  20.371 +	  writeIntToStream(chwBuffer, address, index);
  20.372 +	  index += u32Size;
  20.373 +
  20.374 +	  /*  Write chwall_running_types_offset */
  20.375 +	  writeIntToStream(chwBuffer, 0, index);
  20.376 +	  index += u32Size;
  20.377 +
  20.378 +	  /*  Write chwall_conflict_aggregate_offset */
  20.379 +	  writeIntToStream(chwBuffer, 0, index);
  20.380 +	  index += u32Size;
  20.381  
  20.382    } catch (IOException ee) {
  20.383      	System.out.println(" gCB:: got exception : " + ee); 
  20.384 @@ -737,7 +700,6 @@ public class XmlToBin
  20.385    /* Create the SSids entry */
  20.386    for (int i = 0; i < maxSsids; i++)
  20.387    {
  20.388 -	
  20.389  	SecurityLabel ssidEntry = (SecurityLabel) Ssids.elementAt(i);
  20.390     	/* Get chwall types */
  20.391  	ssidEntry.chwSsidPosition = i;
  20.392 @@ -821,22 +783,16 @@ public class XmlToBin
  20.393    int position = 0;
  20.394  
  20.395    /* Get number of colorTypes */
  20.396 -  short numColorTypes = (short) ColorTypes.size();
  20.397 +  int numColorTypes = ColorTypes.size();
  20.398  
  20.399    /* Get number of SSids entry */
  20.400 -  short numSsids = (short) Ssids.size();
  20.401 +  int numSsids = Ssids.size();
  20.402     
  20.403    if (numColorTypes * numSsids == 0)
  20.404  	return null; 
  20.405  
  20.406 -  /* data structure: acm_ste_policy_buffer_t
  20.407 -   * 
  20.408 -   * policy code  (uint16)    >
  20.409 -   *  max_types    (uint16)    >
  20.410 -   * max_ssidrefs (uint16)    >  steHeaderSize
  20.411 -   * ssid_offset  (uint16)    >
  20.412 -   * DATA 	(colorTypes(size) * Ssids(size) *unit16)
  20.413 -   * 
  20.414 +  /* data structure: acm_ste_policy_buffer
  20.415 +   * see XmlToBinInterface.java
  20.416     * total bytes: steHeaderSize * 2B + colorTypes(size) * Ssids(size)
  20.417     * 
  20.418    */
  20.419 @@ -844,18 +800,22 @@ public class XmlToBin
  20.420  
  20.421    try {
  20.422  	
  20.423 -	index = 0;
  20.424 -	writeShortToStream(steBuffer,ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY,index);
  20.425 -	index = u16Size; 
  20.426 +	  index = 0;
  20.427 +	  writeIntToStream(steBuffer, ACM_STE_VERSION, index);
  20.428 +	  index += u32Size;
  20.429  
  20.430 -	writeShortToStream(steBuffer,numColorTypes,index);
  20.431 -	index = index + u16Size; 
  20.432 +	  writeIntToStream(steBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index);
  20.433 +	  index += u32Size;
  20.434  
  20.435 -	writeShortToStream(steBuffer,numSsids,index);
  20.436 -	index = index + u16Size; 
  20.437 +	  writeIntToStream(steBuffer, numColorTypes, index);
  20.438 +	  index += u32Size;
  20.439  
  20.440 -	writeShortToStream(steBuffer,(short)steHeaderSize,index);
  20.441 -	index = index + u16Size; 
  20.442 +	  writeIntToStream(steBuffer, numSsids, index);
  20.443 +	  index += u32Size;
  20.444 +
  20.445 +	  writeIntToStream(steBuffer, steHeaderSize, index);
  20.446 +	  index += u32Size;
  20.447 +
  20.448  
  20.449    } catch (IOException ee) {
  20.450  	System.out.println(" gSB:: got exception : " + ee); 
  20.451 @@ -1469,6 +1429,17 @@ public class XmlToBin
  20.452  
  20.453    XmlToBin genObj = new XmlToBin(); 
  20.454  
  20.455 +  policy_version active_policy = new policy_version();
  20.456 +
  20.457 +  if ((active_policy.ACM_POLICY_VERSION != ACM_POLICY_VERSION) ||
  20.458 +      (active_policy.ACM_CHWALL_VERSION != ACM_CHWALL_VERSION) ||
  20.459 +      (active_policy.ACM_STE_VERSION != ACM_STE_VERSION)) {
  20.460 +	  System.out.println("ACM policy versions differ.");
  20.461 +	  System.out.println("Please verify that data structures are correct");
  20.462 +	  System.out.println("and then adjust the version numbers in XmlToBinInterface.java.");
  20.463 +	  return;
  20.464 +  }
  20.465 +
  20.466  
  20.467    for (int i = 0 ; i < args.length ; i++) {
  20.468  
    21.1 --- a/tools/misc/policyprocessor/XmlToBinInterface.java	Tue Aug 02 02:47:41 2005 -0800
    21.2 +++ b/tools/misc/policyprocessor/XmlToBinInterface.java	Tue Aug 02 10:20:46 2005 -0700
    21.3 @@ -19,37 +19,37 @@
    21.4   *
    21.5   *	policy binary structures
    21.6   *
    21.7 - *	typedef struct {
    21.8 - *        u32 magic;
    21.9 - *
   21.10 - *        u32 policyversion;
   21.11 - *        u32 len;
   21.12 - *
   21.13 - *        u16 primary_policy_code;
   21.14 - *        u16 primary_buffer_offset;
   21.15 - *        u16 secondary_policy_code;
   21.16 - *        u16 secondary_buffer_offset;
   21.17 - *	u16 resource_offset;
   21.18 - *
   21.19 - *	} acm_policy_buffer_t;
   21.20 + * struct acm_policy_buffer {
   21.21 + *	u32 policy_version; * ACM_POLICY_VERSION *
   21.22 + *      u32 magic;
   21.23 + *	u32 len;
   21.24 + *	u32 primary_policy_code;
   21.25 + *	u32 primary_buffer_offset;
   21.26 + *	u32 secondary_policy_code;
   21.27 + *	u32 secondary_buffer_offset;
   21.28 + *      +u32 resource offset (not used yet in Xen)
   21.29 + * };
   21.30   *
   21.31 - *	typedef struct {
   21.32 - *        u16 policy_code;
   21.33 - *        u16 ste_max_types;
   21.34 - *        u16 ste_max_ssidrefs;
   21.35 - *        u16 ste_ssid_offset;
   21.36 - *	} acm_ste_policy_buffer_t;
   21.37   *
   21.38 - *  	typedef struct {
   21.39 - *        uint16 policy_code;
   21.40 - *        uint16 chwall_max_types;
   21.41 - *        uint16 chwall_max_ssidrefs;
   21.42 - *        uint16 chwall_max_conflictsets;
   21.43 - *        uint16 chwall_ssid_offset;
   21.44 - *        uint16 chwall_conflict_sets_offset;
   21.45 - *        uint16 chwall_running_types_offset;
   21.46 - *        uint16 chwall_conflict_aggregate_offset;
   21.47 - *	} acm_chwall_policy_buffer_t;
   21.48 + * struct acm_ste_policy_buffer {
   21.49 + *	u32 policy_version; * ACM_STE_VERSION *
   21.50 + *	u32 policy_code;
   21.51 + *	u32 ste_max_types;
   21.52 + *	u32 ste_max_ssidrefs;
   21.53 + *	u32 ste_ssid_offset;
   21.54 + * };
   21.55 + *
   21.56 + * struct acm_chwall_policy_buffer {
   21.57 + *	u32 policy_version; * ACM_CHWALL_VERSION *
   21.58 + *	u32 policy_code;
   21.59 + *	u32 chwall_max_types;
   21.60 + *	u32 chwall_max_ssidrefs;
   21.61 + *	u32 chwall_max_conflictsets;
   21.62 + *	u32 chwall_ssid_offset;
   21.63 + *	u32 chwall_conflict_sets_offset;
   21.64 + *	u32 chwall_running_types_offset;
   21.65 + *	u32 chwall_conflict_aggregate_offset;
   21.66 + * };
   21.67   *
   21.68   *	typedef struct {
   21.69   *	u16 partition_max;
   21.70 @@ -100,16 +100,17 @@ public interface XmlToBinInterface
   21.71    final int u16Size = 2;
   21.72  
   21.73    /* num of bytes for acm_ste_policy_buffer_t */
   21.74 -  final short steHeaderSize = (4 * u16Size); 
   21.75 -  /* byte for acm_chinese_wall_policy_buffer_t */
   21.76 -  final short chwHeaderSize = (8 * u16Size); 
   21.77 +  final int steHeaderSize = (5 * u32Size);
   21.78  
   21.79 -  final short primaryPolicyCodeSize = u16Size;
   21.80 -  final short primaryBufferOffsetSize = u16Size ;
   21.81 +  /* byte for acm_chinese_wall_policy_buffer_t */
   21.82 +  final int chwHeaderSize = (9 * u32Size);
   21.83  
   21.84 -  final int secondaryPolicyCodeSz = u16Size;
   21.85 -  final int secondaryBufferOffsetSz = u16Size;
   21.86 -  final short resourceOffsetSz = u16Size;
   21.87 +  final int primaryPolicyCodeSize = u32Size;
   21.88 +  final int primaryBufferOffsetSize = u32Size ;
   21.89 +
   21.90 +  final int secondaryPolicyCodeSz = u32Size;
   21.91 +  final int secondaryBufferOffsetSz = u32Size;
   21.92 +  final int resourceOffsetSz = u32Size;
   21.93  
   21.94    final short partitionBufferSz = (2 * u16Size);
   21.95    final short partitionEntrySz = (3 * u16Size);
   21.96 @@ -120,16 +121,18 @@ public interface XmlToBinInterface
   21.97    final short vlanBufferSz = (2 * u16Size);
   21.98    final short vlanEntrySz = (2 * u16Size);
   21.99  
  21.100 -  final short binaryBufferHeaderSz = (3 * u32Size + 4* u16Size);
  21.101 -
  21.102 -  /* copied directlty from policy_ops.h */
  21.103 -  final int POLICY_INTERFACE_VERSION = 0xAAAA0003;
  21.104 +  final int binaryBufferHeaderSz = (8 * u32Size); /* 8th not used in Xen */
  21.105  
  21.106    /* copied directly from acm.h */
  21.107    final int ACM_MAGIC  =  0x0001debc;
  21.108 -  final short ACM_NULL_POLICY = 0;
  21.109 -  final short ACM_CHINESE_WALL_POLICY = 1;
  21.110 -  final short ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2;
  21.111 -  final short ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3;
  21.112 -  final short ACM_EMPTY_POLICY = 4;
  21.113 +  final int ACM_NULL_POLICY = 0;
  21.114 +  final int ACM_CHINESE_WALL_POLICY = 1;
  21.115 +  final int ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2;
  21.116 +  final int ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3;
  21.117 +  final int ACM_EMPTY_POLICY = 4;
  21.118 +
  21.119 +  /* version for compatibility check */
  21.120 +  final int ACM_POLICY_VERSION = 1;
  21.121 +  final int ACM_STE_VERSION    = 1;
  21.122 +  final int ACM_CHWALL_VERSION = 1;
  21.123  }
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tools/misc/policyprocessor/c2j_include.c	Tue Aug 02 10:20:46 2005 -0700
    22.3 @@ -0,0 +1,57 @@
    22.4 +/****************************************************************
    22.5 + * c2j_include.c
    22.6 + *
    22.7 + * Copyright (C) 2005 IBM Corporation
    22.8 + *
    22.9 + * Authors:
   22.10 + * Reiner Sailer <sailer@watson.ibm.com>
   22.11 + *
   22.12 + * This program is free software; you can redistribute it and/or
   22.13 + * modify it under the terms of the GNU General Public License as
   22.14 + * published by the Free Software Foundation, version 2 of the
   22.15 + * License.
   22.16 + *
   22.17 + * This tool makes some constants from acm.h available to the
   22.18 + * java policyprocessor for version checking.
   22.19 + */
   22.20 +#include <stdio.h>
   22.21 +#include <errno.h>
   22.22 +#include <stdlib.h>
   22.23 +#include <stdint.h>
   22.24 +
   22.25 +typedef uint8_t  u8;
   22.26 +typedef uint16_t u16;
   22.27 +typedef uint32_t u32;
   22.28 +typedef uint64_t u64;
   22.29 +typedef int8_t   s8;
   22.30 +typedef int16_t  s16;
   22.31 +typedef int32_t  s32;
   22.32 +typedef int64_t  s64;
   22.33 +
   22.34 +#include <xen/acm.h>
   22.35 +
   22.36 +char *filename = "policy_version.java";
   22.37 +
   22.38 +int main(int argc, char **argv)
   22.39 +{
   22.40 +
   22.41 +    FILE *fd;
   22.42 +    if ((fd = fopen(filename, "w")) <= 0)
   22.43 +    {
   22.44 +        printf("File %s not found.\n", filename);
   22.45 +        exit(-ENOENT);
   22.46 +    }
   22.47 +
   22.48 +    fprintf(fd, "/*\n * This file was automatically generated\n");
   22.49 +    fprintf(fd, " * Do not change it manually!\n */\n");
   22.50 +    fprintf(fd, "public class policy_version {\n");
   22.51 +    fprintf(fd, "	final int ACM_POLICY_VERSION = %x;\n",
   22.52 +            ACM_POLICY_VERSION);
   22.53 +    fprintf(fd, "	final int ACM_CHWALL_VERSION = %x;\n",
   22.54 +            ACM_CHWALL_VERSION);
   22.55 +    fprintf(fd, "	final int ACM_STE_VERSION = %x;\n",
   22.56 +            ACM_STE_VERSION);
   22.57 +    fprintf(fd, "}\n");
   22.58 +    fclose(fd);
   22.59 +    return 0;
   22.60 +}
    23.1 --- a/tools/misc/policyprocessor/xen_sample_def.xml	Tue Aug 02 02:47:41 2005 -0800
    23.2 +++ b/tools/misc/policyprocessor/xen_sample_def.xml	Tue Aug 02 10:20:46 2005 -0700
    23.3 @@ -37,7 +37,7 @@ xsi:schemaLocation="http://www.ibm.com S
    23.4     </ConflictSet>
    23.5  
    23.6     <ConflictSet>
    23.7 -		 <ChWall>Q-Company</ChWall>
    23.8 +		 <ChWall>R-Company</ChWall>
    23.9  		 <ChWall>V-Company</ChWall>
   23.10  		 <ChWall>W-Company</ChWall>
   23.11     </ConflictSet>
    24.1 --- a/tools/policy/Makefile	Tue Aug 02 02:47:41 2005 -0800
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,36 +0,0 @@
    24.4 -XEN_ROOT = ../..
    24.5 -include $(XEN_ROOT)/tools/Rules.mk
    24.6 -
    24.7 -SRCS     = policy_tool.c
    24.8 -CFLAGS   += -static
    24.9 -CFLAGS   += -Wall
   24.10 -CFLAGS   += -Werror
   24.11 -CFLAGS   += -O3
   24.12 -CFLAGS   += -fno-strict-aliasing
   24.13 -CFLAGS   += -I.
   24.14 -
   24.15 -all: build
   24.16 -build: mk-symlinks
   24.17 -	$(MAKE) policy_tool
   24.18 -
   24.19 -default: all
   24.20 -
   24.21 -install: all
   24.22 -
   24.23 -policy_tool : policy_tool.c
   24.24 -	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<
   24.25 -
   24.26 -clean:
   24.27 -	rm -rf policy_tool xen
   24.28 -
   24.29 -
   24.30 -LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
   24.31 -mk-symlinks:
   24.32 -	[ -e xen/linux ] || mkdir -p xen/linux
   24.33 -	[ -e xen/io ]    || mkdir -p xen/io
   24.34 -	( cd xen >/dev/null ; \
   24.35 -	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   24.36 -	( cd xen/io >/dev/null ; \
   24.37 -	  ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   24.38 -	( cd xen/linux >/dev/null ; \
   24.39 -	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    25.1 --- a/tools/policy/policy_tool.c	Tue Aug 02 02:47:41 2005 -0800
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,552 +0,0 @@
    25.4 -/****************************************************************
    25.5 - * policy_tool.c
    25.6 - * 
    25.7 - * Copyright (C) 2005 IBM Corporation
    25.8 - *
    25.9 - * Authors:
   25.10 - * Reiner Sailer <sailer@watson.ibm.com>
   25.11 - * Stefan Berger <stefanb@watson.ibm.com>
   25.12 - *
   25.13 - * This program is free software; you can redistribute it and/or
   25.14 - * modify it under the terms of the GNU General Public License as
   25.15 - * published by the Free Software Foundation, version 2 of the
   25.16 - * License. 
   25.17 - *
   25.18 - * sHype policy management tool. This code runs in a domain and
   25.19 - *     manages the Xen security policy by interacting with the
   25.20 - *     Xen access control module via a /proc/xen/privcmd proc-ioctl, 
   25.21 - *     which is translated into a policy_op hypercall into Xen.
   25.22 - * 
   25.23 - * todo: implement setpolicy to dynamically set a policy cache.
   25.24 - */
   25.25 -#include <unistd.h>
   25.26 -#include <stdio.h>
   25.27 -#include <errno.h>
   25.28 -#include <fcntl.h>
   25.29 -#include <sys/mman.h>
   25.30 -#include <sys/types.h>
   25.31 -#include <sys/stat.h>
   25.32 -#include <stdlib.h>
   25.33 -#include <sys/ioctl.h>
   25.34 -#include <string.h>
   25.35 -#include <stdint.h>
   25.36 -#include <netinet/in.h>
   25.37 -
   25.38 -typedef uint8_t            u8;
   25.39 -typedef uint16_t           u16;
   25.40 -typedef uint32_t           u32;
   25.41 -typedef uint64_t           u64;
   25.42 -typedef int8_t             s8;
   25.43 -typedef int16_t            s16;
   25.44 -typedef int32_t            s32;
   25.45 -typedef int64_t            s64;
   25.46 -
   25.47 -#include <xen/acm.h>
   25.48 -
   25.49 -#include <xen/policy_ops.h>
   25.50 -
   25.51 -#include <xen/linux/privcmd.h>
   25.52 -
   25.53 -#define ERROR(_m, _a...)	\
   25.54 -	fprintf(stderr, "ERROR: " _m "\n" , ## _a )
   25.55 -
   25.56 -#define PERROR(_m, _a...) \
   25.57 -	fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,	\
   25.58 -            errno, strerror(errno))
   25.59 -
   25.60 -static inline int do_policycmd(int xc_handle,
   25.61 -                             unsigned int cmd, 
   25.62 -                             unsigned long data)
   25.63 -{
   25.64 -    return ioctl(xc_handle, cmd, data);
   25.65 -}
   25.66 -
   25.67 -static inline int do_xen_hypercall(int xc_handle,
   25.68 -                                   privcmd_hypercall_t *hypercall)
   25.69 -{
   25.70 -    return do_policycmd(xc_handle,
   25.71 -                      IOCTL_PRIVCMD_HYPERCALL, 
   25.72 -                      (unsigned long)hypercall);
   25.73 -}
   25.74 -
   25.75 -static inline int do_policy_op(int xc_handle, policy_op_t *op)
   25.76 -{
   25.77 -    int ret = -1;
   25.78 -    privcmd_hypercall_t hypercall;
   25.79 -
   25.80 -    op->interface_version = POLICY_INTERFACE_VERSION;
   25.81 -
   25.82 -    hypercall.op     = __HYPERVISOR_policy_op;
   25.83 -    hypercall.arg[0] = (unsigned long)op;
   25.84 -
   25.85 -    if ( mlock(op, sizeof(*op)) != 0 )
   25.86 -    {
   25.87 -        PERROR("Could not lock memory for Xen policy hypercall");
   25.88 -        goto out1;
   25.89 -    }
   25.90 -
   25.91 -    if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   25.92 -    {
   25.93 -        if ( errno == EACCES )
   25.94 -            fprintf(stderr, "POLICY operation failed -- need to"
   25.95 -                    " rebuild the user-space tool set?\n");
   25.96 -        goto out2;
   25.97 -    }
   25.98 -
   25.99 - out2: (void)munlock(op, sizeof(*op));
  25.100 - out1: return ret;
  25.101 -}
  25.102 -
  25.103 -/*************************** DUMPS *******************************/
  25.104 -
  25.105 -void acm_dump_chinesewall_buffer(void *buf, int buflen) {
  25.106 -
  25.107 -	struct acm_chwall_policy_buffer *cwbuf = (struct acm_chwall_policy_buffer *)buf;
  25.108 -	domaintype_t *ssids, *conflicts, *running_types, *conflict_aggregate;
  25.109 -	int i,j;
  25.110 -
  25.111 -       
  25.112 -	if (htons(cwbuf->policy_code) != ACM_CHINESE_WALL_POLICY) {
  25.113 -		printf("CHINESE WALL POLICY CODE not found ERROR!!\n");
  25.114 -		return;
  25.115 -	}
  25.116 -	printf("\n\nChinese Wall policy:\n");
  25.117 -	printf("====================\n");
  25.118 -	printf("Max Types     = %x.\n", ntohs(cwbuf->chwall_max_types));
  25.119 -	printf("Max Ssidrefs  = %x.\n", ntohs(cwbuf->chwall_max_ssidrefs));
  25.120 -	printf("Max ConfSets  = %x.\n", ntohs(cwbuf->chwall_max_conflictsets));
  25.121 -	printf("Ssidrefs Off  = %x.\n", ntohs(cwbuf->chwall_ssid_offset));
  25.122 -	printf("Conflicts Off = %x.\n", ntohs(cwbuf->chwall_conflict_sets_offset));
  25.123 -	printf("Runing T. Off = %x.\n", ntohs(cwbuf->chwall_running_types_offset));
  25.124 -	printf("C. Agg. Off   = %x.\n", ntohs(cwbuf->chwall_conflict_aggregate_offset));
  25.125 -	printf("\nSSID To CHWALL-Type matrix:\n");
  25.126 -
  25.127 -	ssids = (domaintype_t *)(buf + ntohs(cwbuf->chwall_ssid_offset));
  25.128 -	for(i=0; i< ntohs(cwbuf->chwall_max_ssidrefs); i++) {
  25.129 -		printf("\n   ssidref%2x:  ", i);
  25.130 -		for(j=0; j< ntohs(cwbuf->chwall_max_types); j++)
  25.131 -			printf("%02x ", ntohs(ssids[i*ntohs(cwbuf->chwall_max_types) + j]));
  25.132 -	}
  25.133 -	printf("\n\nConfict Sets:\n");
  25.134 -	conflicts = (domaintype_t *)(buf + ntohs(cwbuf->chwall_conflict_sets_offset));
  25.135 -	for(i=0; i< ntohs(cwbuf->chwall_max_conflictsets); i++) {
  25.136 -		printf("\n   c-set%2x:    ", i);
  25.137 -		for(j=0; j< ntohs(cwbuf->chwall_max_types); j++)
  25.138 -			printf("%02x ", ntohs(conflicts[i*ntohs(cwbuf->chwall_max_types) +j]));
  25.139 -	}
  25.140 -	printf("\n");
  25.141 -
  25.142 -	printf("\nRunning\nTypes:         ");
  25.143 -	if (ntohs(cwbuf->chwall_running_types_offset)) {
  25.144 -		running_types = (domaintype_t *)(buf + ntohs(cwbuf->chwall_running_types_offset));
  25.145 -		for(i=0; i< ntohs(cwbuf->chwall_max_types); i++) {
  25.146 -			printf("%02x ", ntohs(running_types[i]));
  25.147 -		}
  25.148 -		printf("\n");
  25.149 -	} else {
  25.150 -		printf("Not Reported!\n");
  25.151 -	}
  25.152 -	printf("\nConflict\nAggregate Set: ");
  25.153 -	if (ntohs(cwbuf->chwall_conflict_aggregate_offset)) {
  25.154 -		conflict_aggregate = (domaintype_t *)(buf + ntohs(cwbuf->chwall_conflict_aggregate_offset));
  25.155 -		for(i=0; i< ntohs(cwbuf->chwall_max_types); i++) {
  25.156 -			printf("%02x ", ntohs(conflict_aggregate[i]));
  25.157 -		}
  25.158 -		printf("\n\n");
  25.159 -	} else {
  25.160 -		printf("Not Reported!\n");
  25.161 -	}
  25.162 -}
  25.163 -
  25.164 -void acm_dump_ste_buffer(void *buf, int buflen) {
  25.165 -
  25.166 -	struct acm_ste_policy_buffer *stebuf = (struct acm_ste_policy_buffer *)buf;
  25.167 -	domaintype_t *ssids;
  25.168 -	int i,j;
  25.169 -
  25.170 -       
  25.171 -	if (ntohs(stebuf->policy_code) != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) {
  25.172 -		printf("SIMPLE TYPE ENFORCEMENT POLICY CODE not found ERROR!!\n");
  25.173 -		return;
  25.174 -	}
  25.175 -	printf("\nSimple Type Enforcement policy:\n");
  25.176 -	printf("===============================\n");
  25.177 -	printf("Max Types     = %x.\n", ntohs(stebuf->ste_max_types));
  25.178 -	printf("Max Ssidrefs  = %x.\n", ntohs(stebuf->ste_max_ssidrefs));
  25.179 -	printf("Ssidrefs Off  = %x.\n", ntohs(stebuf->ste_ssid_offset));
  25.180 -	printf("\nSSID To STE-Type matrix:\n");
  25.181 -	
  25.182 -	ssids = (domaintype_t *)(buf + ntohs(stebuf->ste_ssid_offset));
  25.183 -	for(i=0; i< ntohs(stebuf->ste_max_ssidrefs); i++) {
  25.184 -		printf("\n   ssidref%2x: ", i);
  25.185 -		for(j=0; j< ntohs(stebuf->ste_max_types); j++)
  25.186 -			printf("%02x ", ntohs(ssids[i*ntohs(stebuf->ste_max_types) +j]));
  25.187 -	}
  25.188 -	printf("\n\n");
  25.189 -}
  25.190 -
  25.191 -void acm_dump_policy_buffer(void *buf, int buflen) {
  25.192 -	struct acm_policy_buffer *pol = (struct acm_policy_buffer *)buf;
  25.193 -
  25.194 -	printf("\nPolicy dump:\n");
  25.195 -	printf("============\n");
  25.196 -	printf("Magic     = %x.\n", ntohl(pol->magic));
  25.197 -	printf("PolVer    = %x.\n", ntohl(pol->policyversion));
  25.198 -	printf("Len       = %x.\n", ntohl(pol->len));
  25.199 -	printf("Primary   = %s (c=%x, off=%x).\n",
  25.200 -	       ACM_POLICY_NAME(ntohs(pol->primary_policy_code)),
  25.201 -	       ntohs(pol->primary_policy_code), ntohs(pol->primary_buffer_offset));
  25.202 -	printf("Secondary = %s (c=%x, off=%x).\n",
  25.203 -	       ACM_POLICY_NAME(ntohs(pol->secondary_policy_code)),
  25.204 -	       ntohs(pol->secondary_policy_code), ntohs(pol->secondary_buffer_offset));
  25.205 -	switch (ntohs(pol->primary_policy_code)) {
  25.206 -	case ACM_CHINESE_WALL_POLICY:
  25.207 -		acm_dump_chinesewall_buffer(buf+ntohs(pol->primary_buffer_offset), 
  25.208 -					     ntohl(pol->len) - ntohs(pol->primary_buffer_offset));
  25.209 -		break;
  25.210 -	case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  25.211 -		acm_dump_ste_buffer(buf+ntohs(pol->primary_buffer_offset), 
  25.212 -				    ntohl(pol->len) - ntohs(pol->primary_buffer_offset));
  25.213 -		break;
  25.214 -	case ACM_NULL_POLICY:
  25.215 -		printf("Primary policy is NULL Policy (n/a).\n");
  25.216 -		break;
  25.217 -	default:
  25.218 -		printf("UNKNOWN POLICY!\n");
  25.219 -	}
  25.220 -	switch (ntohs(pol->secondary_policy_code)) {
  25.221 -	case ACM_CHINESE_WALL_POLICY:
  25.222 -		acm_dump_chinesewall_buffer(buf+ntohs(pol->secondary_buffer_offset), 
  25.223 -					     ntohl(pol->len) - ntohs(pol->secondary_buffer_offset));
  25.224 -		break;
  25.225 -	case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  25.226 -		acm_dump_ste_buffer(buf+ntohs(pol->secondary_buffer_offset), 
  25.227 -				    ntohl(pol->len) - ntohs(pol->secondary_buffer_offset));
  25.228 -		break;
  25.229 -	case ACM_NULL_POLICY:
  25.230 -		printf("Secondary policy is NULL Policy (n/a).\n");
  25.231 -		break;
  25.232 -	default:
  25.233 -		printf("UNKNOWN POLICY!\n");
  25.234 -	}
  25.235 -}
  25.236 -
  25.237 -/*************************** set policy ****************************/
  25.238 -
  25.239 -int acm_domain_set_chwallpolicy(void *bufstart, int buflen) {
  25.240 -#define CWALL_MAX_SSIDREFS      	6
  25.241 -#define CWALL_MAX_TYPES  		10
  25.242 -#define CWALL_MAX_CONFLICTSETS		2
  25.243 -
  25.244 -     struct acm_chwall_policy_buffer *chwall_bin_pol = (struct acm_chwall_policy_buffer *)bufstart;
  25.245 -     domaintype_t *ssidrefs, *conflicts;
  25.246 -     int ret = 0;
  25.247 -     int j;
  25.248 -
  25.249 -     chwall_bin_pol->chwall_max_types = htons(CWALL_MAX_TYPES);
  25.250 -     chwall_bin_pol->chwall_max_ssidrefs = htons(CWALL_MAX_SSIDREFS);
  25.251 -     chwall_bin_pol->policy_code = htons(ACM_CHINESE_WALL_POLICY);
  25.252 -     chwall_bin_pol->chwall_ssid_offset = htons(sizeof(struct acm_chwall_policy_buffer));
  25.253 -     chwall_bin_pol->chwall_max_conflictsets = htons(CWALL_MAX_CONFLICTSETS);
  25.254 -     chwall_bin_pol->chwall_conflict_sets_offset =
  25.255 -	 htons(
  25.256 -	     ntohs(chwall_bin_pol->chwall_ssid_offset) + 
  25.257 -	     sizeof(domaintype_t)*CWALL_MAX_SSIDREFS*CWALL_MAX_TYPES);
  25.258 -     chwall_bin_pol->chwall_running_types_offset = 0; /* not set */
  25.259 -     chwall_bin_pol->chwall_conflict_aggregate_offset = 0; /* not set */
  25.260 -     ret += sizeof(struct acm_chwall_policy_buffer);
  25.261 -     /* now push example ssids into the buffer (max_ssidrefs x max_types entries) */
  25.262 -     /* check buffer size */
  25.263 -     if ((buflen - ret) < (CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t)))
  25.264 -			   return -1; /* not enough space */
  25.265 -
  25.266 -     ssidrefs = (domaintype_t *)(bufstart+ntohs(chwall_bin_pol->chwall_ssid_offset));
  25.267 -     memset(ssidrefs, 0, CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t));
  25.268 -
  25.269 -     /* now set type j-1 for ssidref i+1 */
  25.270 -     for(j=0; j<= CWALL_MAX_SSIDREFS; j++)
  25.271 -         if ((0 < j) &&( j <= CWALL_MAX_TYPES))
  25.272 -             ssidrefs[j*CWALL_MAX_TYPES + j - 1] = htons(1);
  25.273 -
  25.274 -     ret += CWALL_MAX_TYPES*CWALL_MAX_SSIDREFS*sizeof(domaintype_t);
  25.275 -     if ((buflen - ret) < (CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES*sizeof(domaintype_t)))
  25.276 -			   return -1; /* not enough space */
  25.277 -
  25.278 -     /* now the chinese wall policy conflict sets*/
  25.279 -     conflicts = (domaintype_t *)(bufstart + 
  25.280 -				  ntohs(chwall_bin_pol->chwall_conflict_sets_offset));
  25.281 -     memset((void *)conflicts, 0, CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES*sizeof(domaintype_t));
  25.282 -     /* just 1 conflict set [0]={2,3}, [1]={1,5,6} */
  25.283 -     if (CWALL_MAX_TYPES > 3) {
  25.284 -	     conflicts[2] = htons(1); conflicts[3] = htons(1); /* {2,3} */
  25.285 -	     conflicts[CWALL_MAX_TYPES+1] = htons(1); conflicts[CWALL_MAX_TYPES+5] = htons(1); 
  25.286 -	     conflicts[CWALL_MAX_TYPES+6] = htons(1);/* {0,5,6} */
  25.287 -     }
  25.288 -     ret += sizeof(domaintype_t)*CWALL_MAX_CONFLICTSETS*CWALL_MAX_TYPES;
  25.289 -     return ret;
  25.290 -}
  25.291 -
  25.292 -int acm_domain_set_stepolicy(void *bufstart, int buflen) {
  25.293 -#define STE_MAX_SSIDREFS        6
  25.294 -#define STE_MAX_TYPES  	        5
  25.295 -	
  25.296 -    struct acm_ste_policy_buffer *ste_bin_pol = (struct acm_ste_policy_buffer *)bufstart;
  25.297 -    domaintype_t *ssidrefs;
  25.298 -    int j, ret = 0;
  25.299 -
  25.300 -    ste_bin_pol->ste_max_types = htons(STE_MAX_TYPES);
  25.301 -    ste_bin_pol->ste_max_ssidrefs = htons(STE_MAX_SSIDREFS);
  25.302 -    ste_bin_pol->policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  25.303 -    ste_bin_pol->ste_ssid_offset = htons(sizeof(struct acm_ste_policy_buffer));
  25.304 -    ret += sizeof(struct acm_ste_policy_buffer);
  25.305 -    /* check buffer size */
  25.306 -    if ((buflen - ret) < (STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t)))
  25.307 -	    return -1; /* not enough space */
  25.308 -
  25.309 -     ssidrefs = (domaintype_t *)(bufstart+ntohs(ste_bin_pol->ste_ssid_offset));
  25.310 -     memset(ssidrefs, 0, STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t));
  25.311 -     /* all types 1 for ssidref 1 */
  25.312 -     for(j=0; j< STE_MAX_TYPES; j++)
  25.313 -	 ssidrefs[1*STE_MAX_TYPES +j] = htons(1);
  25.314 -     /* now set type j-1 for ssidref j */
  25.315 -     for(j=0; j< STE_MAX_SSIDREFS; j++)
  25.316 -	     if ((0 < j) &&( j <= STE_MAX_TYPES))
  25.317 -		     ssidrefs[j*STE_MAX_TYPES + j - 1] = htons(1);
  25.318 -     ret += STE_MAX_TYPES*STE_MAX_SSIDREFS*sizeof(domaintype_t);
  25.319 -     return ret;
  25.320 -}
  25.321 -
  25.322 -#define MAX_PUSH_BUFFER 	16384
  25.323 -u8 push_buffer[MAX_PUSH_BUFFER];
  25.324 -
  25.325 -int acm_domain_setpolicy(int xc_handle)
  25.326 -{
  25.327 -     int ret;
  25.328 -     struct acm_policy_buffer *bin_pol;
  25.329 -     policy_op_t op;
  25.330 -
  25.331 -     /* future: read policy from file and set it */
  25.332 -     bin_pol = (struct acm_policy_buffer *)push_buffer;
  25.333 -     bin_pol->magic = htonl(ACM_MAGIC);
  25.334 -     bin_pol->policyversion = htonl(POLICY_INTERFACE_VERSION);
  25.335 -     bin_pol->primary_policy_code = htons(ACM_CHINESE_WALL_POLICY);
  25.336 -     bin_pol->secondary_policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  25.337 -
  25.338 -     bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  25.339 -     bin_pol->primary_buffer_offset = htons(ntohl(bin_pol->len));
  25.340 -     ret = acm_domain_set_chwallpolicy(push_buffer + ntohs(bin_pol->primary_buffer_offset), 
  25.341 -				       MAX_PUSH_BUFFER - ntohs(bin_pol->primary_buffer_offset));
  25.342 -     if (ret < 0) {
  25.343 -	     printf("ERROR creating chwallpolicy buffer.\n");
  25.344 -	     return -1;
  25.345 -     }
  25.346 -     bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  25.347 -     bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len));
  25.348 -     ret = acm_domain_set_stepolicy(push_buffer + ntohs(bin_pol->secondary_buffer_offset), 
  25.349 -				    MAX_PUSH_BUFFER - ntohs(bin_pol->secondary_buffer_offset));
  25.350 -     if (ret < 0) {
  25.351 -	     printf("ERROR creating chwallpolicy buffer.\n");
  25.352 -	     return -1;
  25.353 -     }
  25.354 -     bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  25.355 -
  25.356 -     /* dump it and then push it down into xen/acm */
  25.357 -     acm_dump_policy_buffer(push_buffer, ntohl(bin_pol->len));
  25.358 -     op.cmd = POLICY_SETPOLICY;
  25.359 -     op.u.setpolicy.pushcache = (void *)push_buffer;
  25.360 -     op.u.setpolicy.pushcache_size = ntohl(bin_pol->len);
  25.361 -     op.u.setpolicy.policy_type = ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  25.362 -     ret = do_policy_op(xc_handle, &op);
  25.363 -
  25.364 -     if (ret)
  25.365 -	     printf("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  25.366 -     else
  25.367 -	     printf("Successfully changed policy.\n");
  25.368 -     return ret;
  25.369 -}
  25.370 -
  25.371 -/******************************* get policy ******************************/
  25.372 -
  25.373 -#define PULL_CACHE_SIZE		8192
  25.374 -u8 pull_buffer[PULL_CACHE_SIZE];
  25.375 -int acm_domain_getpolicy(int xc_handle)
  25.376 -{
  25.377 -     policy_op_t op;
  25.378 -     int ret;
  25.379 -
  25.380 -     memset(pull_buffer, 0x00, sizeof(pull_buffer));
  25.381 -     op.cmd = POLICY_GETPOLICY;
  25.382 -     op.u.getpolicy.pullcache = (void *)pull_buffer;
  25.383 -     op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
  25.384 -     ret = do_policy_op(xc_handle, &op);
  25.385 -     /* dump policy  */
  25.386 -     acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer));
  25.387 -     return ret;
  25.388 -}
  25.389 -
  25.390 -/************************ load binary policy ******************************/
  25.391 -
  25.392 -int acm_domain_loadpolicy(int xc_handle,
  25.393 -                          const char *filename)
  25.394 -{
  25.395 -     struct stat mystat;
  25.396 -     int ret, fd;
  25.397 -     off_t len;
  25.398 -     u8 *buffer;
  25.399 -
  25.400 -     if ((ret = stat(filename, &mystat))) {
  25.401 -	     printf("File %s not found.\n",filename);
  25.402 -	     goto out;
  25.403 -     }
  25.404 -
  25.405 -     len = mystat.st_size;
  25.406 -     if ((buffer = malloc(len)) == NULL) {
  25.407 -	     ret = -ENOMEM;
  25.408 -	     goto out;
  25.409 -     }
  25.410 -     if ((fd = open(filename, O_RDONLY)) <= 0) {
  25.411 -	     ret = -ENOENT;
  25.412 -	     printf("File %s not found.\n",filename);
  25.413 -	     goto free_out;
  25.414 -     }
  25.415 -     if (len == read(fd, buffer, len)) {
  25.416 -	     policy_op_t op;
  25.417 -	     /* dump it and then push it down into xen/acm */
  25.418 -	     acm_dump_policy_buffer(buffer, len);
  25.419 -	     op.cmd = POLICY_SETPOLICY;
  25.420 -	     op.u.setpolicy.pushcache = (void *)buffer;
  25.421 -	     op.u.setpolicy.pushcache_size = len;
  25.422 -	     op.u.setpolicy.policy_type = ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  25.423 -	     ret = do_policy_op(xc_handle, &op);
  25.424 -                     
  25.425 -	     if (ret)
  25.426 -		     printf("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  25.427 -	     else
  25.428 -		     printf("Successfully changed policy.\n");
  25.429 -                     
  25.430 -     } else {
  25.431 -	     ret = -1;
  25.432 -     }
  25.433 -     close(fd);
  25.434 - free_out:
  25.435 -     free(buffer);
  25.436 - out:
  25.437 -     return ret;
  25.438 -}
  25.439 -
  25.440 -/************************ dump hook statistics ******************************/
  25.441 -void 
  25.442 -dump_ste_stats(struct acm_ste_stats_buffer *ste_stats)
  25.443 -{
  25.444 -    printf("STE-Policy Security Hook Statistics:\n");
  25.445 -    printf("ste: event_channel eval_count      = %d\n", ntohl(ste_stats->ec_eval_count));
  25.446 -    printf("ste: event_channel denied_count    = %d\n", ntohl(ste_stats->ec_denied_count)); 
  25.447 -    printf("ste: event_channel cache_hit_count = %d\n", ntohl(ste_stats->ec_cachehit_count));
  25.448 -    printf("ste:\n");
  25.449 -    printf("ste: grant_table   eval_count      = %d\n", ntohl(ste_stats->gt_eval_count));
  25.450 -    printf("ste: grant_table   denied_count    = %d\n", ntohl(ste_stats->gt_denied_count)); 
  25.451 -    printf("ste: grant_table   cache_hit_count = %d\n", ntohl(ste_stats->gt_cachehit_count));
  25.452 -}
  25.453 -
  25.454 -#define PULL_STATS_SIZE		8192
  25.455 -int acm_domain_dumpstats(int xc_handle)
  25.456 -{
  25.457 -    u8 stats_buffer[PULL_STATS_SIZE];
  25.458 -    policy_op_t op;
  25.459 -    int ret;
  25.460 -    struct acm_stats_buffer *stats;
  25.461 -
  25.462 -    memset(stats_buffer, 0x00, sizeof(stats_buffer));
  25.463 -    op.cmd = POLICY_DUMPSTATS;
  25.464 -    op.u.dumpstats.pullcache = (void *)stats_buffer;
  25.465 -    op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
  25.466 -    ret = do_policy_op(xc_handle, &op);
  25.467 -
  25.468 -    if (ret < 0) {
  25.469 -	printf("ERROR dumping policy stats. Use 'xm dmesg' to see details.\n"); 
  25.470 -	return ret;
  25.471 -    }
  25.472 -    stats = (struct acm_stats_buffer *)stats_buffer;
  25.473 -
  25.474 -    printf("\nPolicy dump:\n");
  25.475 -    printf("============\n");
  25.476 -    printf("Magic     = %x.\n", ntohl(stats->magic));
  25.477 -    printf("PolVer    = %x.\n", ntohl(stats->policyversion));
  25.478 -    printf("Len       = %x.\n", ntohl(stats->len));
  25.479 -
  25.480 -    switch(ntohs(stats->primary_policy_code)) {
  25.481 -    case ACM_NULL_POLICY:
  25.482 -	    printf("NULL Policy: No statistics apply.\n");
  25.483 -	    break;
  25.484 -    case ACM_CHINESE_WALL_POLICY:
  25.485 -	    printf("Chinese Wall Policy: No statistics apply.\n");
  25.486 -	    break;
  25.487 -    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  25.488 -	    dump_ste_stats((struct acm_ste_stats_buffer *)(stats_buffer + ntohs(stats->primary_stats_offset)));
  25.489 -	    break;
  25.490 -    default:
  25.491 -	    printf("UNKNOWN PRIMARY POLICY ERROR!\n");
  25.492 -    }
  25.493 -    switch(ntohs(stats->secondary_policy_code)) {
  25.494 -    case ACM_NULL_POLICY:
  25.495 -	    printf("NULL Policy: No statistics apply.\n");
  25.496 -	    break;
  25.497 -    case ACM_CHINESE_WALL_POLICY:
  25.498 -	    printf("Chinese Wall Policy: No statistics apply.\n");
  25.499 -	    break;
  25.500 -    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  25.501 -	    dump_ste_stats((struct acm_ste_stats_buffer *)(stats_buffer + ntohs(stats->secondary_stats_offset)));
  25.502 -	    break;
  25.503 -    default:
  25.504 -	    printf("UNKNOWN SECONDARY POLICY ERROR!\n");
  25.505 -    }                
  25.506 -    return ret;
  25.507 -}
  25.508 -
  25.509 -/***************************** main **************************************/
  25.510 -
  25.511 -void
  25.512 -usage(char *progname){
  25.513 -	printf("Use: %s \n"
  25.514 -	       "\t setpolicy\n"
  25.515 -	       "\t getpolicy\n"
  25.516 -	       "\t dumpstats\n"
  25.517 -	       "\t loadpolicy <binary policy file>\n", progname);
  25.518 -	exit(-1);
  25.519 -}
  25.520 -
  25.521 -int
  25.522 -main(int argc, char **argv) {
  25.523 -
  25.524 -	int policycmd_fd, ret;
  25.525 -
  25.526 -	if (argc < 2) 
  25.527 -		usage(argv[0]);
  25.528 -		
  25.529 -	if ((policycmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
  25.530 -		    printf("ERROR: Could not open xen privcmd device!\n");
  25.531 -		    exit(-1);
  25.532 -	}
  25.533 -	    
  25.534 -	if (!strcmp(argv[1], "setpolicy")) {
  25.535 -		if (argc != 2)
  25.536 -			usage(argv[0]);
  25.537 -		ret = acm_domain_setpolicy(policycmd_fd);
  25.538 -	} else if (!strcmp(argv[1], "getpolicy")) {
  25.539 -		if (argc != 2)
  25.540 -			usage(argv[0]);
  25.541 -		ret = acm_domain_getpolicy(policycmd_fd);
  25.542 -	} else if (!strcmp(argv[1], "loadpolicy")) {
  25.543 -		if (argc != 3) 
  25.544 -			usage(argv[0]);
  25.545 -		ret = acm_domain_loadpolicy(policycmd_fd, argv[2]);
  25.546 -	} else if (!strcmp(argv[1], "dumpstats")) {
  25.547 -		if (argc != 2) 
  25.548 -			usage(argv[0]);
  25.549 -		ret = acm_domain_dumpstats(policycmd_fd);
  25.550 -	} else
  25.551 -		usage(argv[0]);
  25.552 -
  25.553 -	close(policycmd_fd);
  25.554 -	return ret;
  25.555 -}
    26.1 --- a/tools/pygrub/setup.py	Tue Aug 02 02:47:41 2005 -0800
    26.2 +++ b/tools/pygrub/setup.py	Tue Aug 02 10:20:46 2005 -0700
    26.3 @@ -23,7 +23,7 @@ if os.path.exists("/usr/include/reiserfs
    26.4      fsys_pkgs.append("grub.fsys.reiser")
    26.5  
    26.6  setup(name='pygrub',
    26.7 -      version='0.2',
    26.8 +      version='0.3',
    26.9        description='Boot loader that looks a lot like grub for Xen',
   26.10        author='Jeremy Katz',
   26.11        author_email='katzj@redhat.com',
    27.1 --- a/tools/pygrub/src/fsys/ext2/__init__.py	Tue Aug 02 02:47:41 2005 -0800
    27.2 +++ b/tools/pygrub/src/fsys/ext2/__init__.py	Tue Aug 02 10:20:46 2005 -0700
    27.3 @@ -32,7 +32,7 @@ class Ext2FileSystemType(FileSystemType)
    27.4      def open_fs(self, fn, offset = 0):
    27.5          if not self.sniff_magic(fn, offset):
    27.6              raise ValueError, "Not an ext2 filesystem"
    27.7 -        return Ext2Fs(fn)
    27.8 +        return Ext2Fs(fn, offset = offset)
    27.9  
   27.10  register_fstype(Ext2FileSystemType())
   27.11  
    28.1 --- a/tools/pygrub/src/fsys/ext2/ext2module.c	Tue Aug 02 02:47:41 2005 -0800
    28.2 +++ b/tools/pygrub/src/fsys/ext2/ext2module.c	Tue Aug 02 10:20:46 2005 -0700
    28.3 @@ -208,23 +208,29 @@ static PyObject *
    28.4  ext2_fs_open (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
    28.5  {
    28.6      static char *kwlist[] = { "name", "flags", "superblock", 
    28.7 -                              "block_size", NULL };
    28.8 +                              "block_size", "offset", NULL };
    28.9      char * name;
   28.10 -    int flags = 0, superblock = 0, err;
   28.11 +    int flags = 0, superblock = 0, offset = 0, err;
   28.12      unsigned int block_size = 0;
   28.13      ext2_filsys efs;
   28.14 +    char offsetopt[30];
   28.15  
   28.16 -    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iii", kwlist, 
   28.17 -                                     &name, &flags, &superblock, &block_size))
   28.18 -                                     return NULL;
   28.19 +    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 
   28.20 +                                     &name, &flags, &superblock, 
   28.21 +                                     &block_size, &offset))
   28.22 +        return NULL;
   28.23  
   28.24      if (fs->fs != NULL) {
   28.25          PyErr_SetString(PyExc_ValueError, "already have an fs object");
   28.26          return NULL;
   28.27      }
   28.28  
   28.29 -    err = ext2fs_open(name, flags, superblock, block_size, 
   28.30 -                      unix_io_manager, &efs);
   28.31 +    if (offset != 0) {
   28.32 +        snprintf(offsetopt, 29, "offset=%d", offset);
   28.33 +    }
   28.34 +
   28.35 +    err = ext2fs_open2(name, offsetopt, flags, superblock, block_size, 
   28.36 +                       unix_io_manager, &efs);
   28.37      if (err) {
   28.38          PyErr_SetString(PyExc_ValueError, "unable to open file");
   28.39          return NULL;
   28.40 @@ -323,14 +329,15 @@ static PyObject *
   28.41  ext2_fs_new(PyObject *o, PyObject *args, PyObject *kwargs) 
   28.42  {
   28.43      static char *kwlist[] = { "name", "flags", "superblock", 
   28.44 -                              "block_size", NULL };
   28.45 +                              "block_size", "offset", NULL };
   28.46      char * name;
   28.47 -    int flags = 0, superblock = 0;
   28.48 +    int flags = 0, superblock = 0, offset;
   28.49      unsigned int block_size = 0;
   28.50      Ext2Fs *pfs;
   28.51  
   28.52 -    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iii", kwlist, 
   28.53 -                                     &name, &flags, &superblock, &block_size))
   28.54 +    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|iiii", kwlist, 
   28.55 +                                     &name, &flags, &superblock, &block_size,
   28.56 +                                     &offset))
   28.57          return NULL;
   28.58  
   28.59      pfs = (Ext2Fs *) PyObject_NEW(Ext2Fs, &Ext2FsType);
   28.60 @@ -339,8 +346,8 @@ ext2_fs_new(PyObject *o, PyObject *args,
   28.61      pfs->fs = NULL;
   28.62  
   28.63      if (!ext2_fs_open(pfs, 
   28.64 -                      Py_BuildValue("siii", name, flags, superblock, block_size),
   28.65 -                      NULL))
   28.66 +                      Py_BuildValue("siiii", name, flags, superblock, 
   28.67 +                                    block_size, offset), NULL))
   28.68          return NULL;
   28.69  
   28.70      return (PyObject *)pfs;
    29.1 --- a/tools/pygrub/src/pygrub	Tue Aug 02 02:47:41 2005 -0800
    29.2 +++ b/tools/pygrub/src/pygrub	Tue Aug 02 10:20:46 2005 -0700
    29.3 @@ -24,7 +24,7 @@ sys.path = [ '/usr/lib/python' ] + sys.p
    29.4  import grub.GrubConf
    29.5  import grub.fsys
    29.6  
    29.7 -PYGRUB_VER = 0.02
    29.8 +PYGRUB_VER = 0.3
    29.9  
   29.10  
   29.11  def draw_window():
   29.12 @@ -77,24 +77,39 @@ def is_disk_image(file):
   29.13      buf = os.read(fd, 512)
   29.14      os.close(fd)
   29.15  
   29.16 -    if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaaff):
   29.17 +    if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,):
   29.18          return True
   29.19      return False
   29.20  
   29.21 +SECTOR_SIZE=512
   29.22 +def get_active_offset(file):
   29.23 +    """Find the offset for the start of the first active partition in the
   29.24 +    disk image file."""
   29.25 +    fd = os.open(file, os.O_RDONLY)
   29.26 +    buf = os.read(fd, 512)
   29.27 +    for poff in (446, 462, 478, 494): # partition offsets
   29.28 +        # active partition has 0x80 as the first byte
   29.29 +        if struct.unpack("<c", buf[p:p+1]) == ('\x80',):
   29.30 +            return struct.unpack("<", buf[p+8:p+12])[0] * SECTOR_SIZE
   29.31 +    return -1
   29.32 +
   29.33  def get_config(fn):
   29.34      if not os.access(fn, os.R_OK):
   29.35          raise RuntimeError, "Unable to access %s" %(fn,)
   29.36  
   29.37      cf = grub.GrubConf.GrubConfigFile()
   29.38  
   29.39 +    offset = 0
   29.40      if is_disk_image(fn):
   29.41 -        raise RuntimeError, "appears to be a full disk image... unable to handle this yet"
   29.42 +        offset = get_active_offset(fn)
   29.43 +        if offset == -1:
   29.44 +            raise RuntimeError, "Unable to find active partition on disk"
   29.45  
   29.46      # open the image and read the grub config
   29.47      fs = None
   29.48      for fstype in grub.fsys.fstypes.values():
   29.49 -        if fstype.sniff_magic(fn):
   29.50 -            fs = fstype.open_fs(fn)
   29.51 +        if fstype.sniff_magic(fn, offset):
   29.52 +            fs = fstype.open_fs(fn, offset)
   29.53              break
   29.54  
   29.55      if fs is not None:
   29.56 @@ -244,14 +259,17 @@ if __name__ == "__main__":
   29.57      if img.initrd:
   29.58          print "  initrd: %s" %(img.initrd[1],)
   29.59  
   29.60 +    offset = 0
   29.61      if is_disk_image(file):
   29.62 -        raise RuntimeError, "unable to handle full disk images yet"
   29.63 +        offset = get_active_offset(fn)
   29.64 +        if offset == -1:
   29.65 +            raise RuntimeError, "Unable to find active partition on disk"
   29.66  
   29.67      # read the kernel and initrd onto the hostfs
   29.68      fs = None
   29.69      for fstype in grub.fsys.fstypes.values():
   29.70 -        if fstype.sniff_magic(file):
   29.71 -            fs = fstype.open_fs(file)
   29.72 +        if fstype.sniff_magic(file, offset):
   29.73 +            fs = fstype.open_fs(file, offset)
   29.74              break
   29.75  
   29.76      if fs is None:
    30.1 --- a/tools/python/xen/util/blkif.py	Tue Aug 02 02:47:41 2005 -0800
    30.2 +++ b/tools/python/xen/util/blkif.py	Tue Aug 02 10:20:46 2005 -0700
    30.3 @@ -24,8 +24,8 @@ def blkdev_name_to_number(name):
    30.4          log.debug("exception looking up device number for %s: %s", name, ex)
    30.5          pass
    30.6  
    30.7 -    if re.match( '/dev/sd[a-p]([0-9]|1[0-5])', n):
    30.8 -        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:])
    30.9 +    if re.match( '/dev/sd[a-p]([1-9]|1[0-5])?', n):
   30.10 +        return 8 * 256 + 16 * (ord(n[7:8]) - ord('a')) + int(n[8:] or 0)
   30.11  
   30.12      if re.match( '/dev/hd[a-t]([1-9]|[1-5][0-9]|6[0-3])?', n):
   30.13          ide_majors = [ 3, 22, 33, 34, 56, 57, 88, 89, 90, 91 ]
   30.14 @@ -33,6 +33,9 @@ def blkdev_name_to_number(name):
   30.15          minor = ((ord(n[7:8]) - ord('a')) % 2) * 64 + int(n[8:] or 0)
   30.16          return major * 256 + minor
   30.17  
   30.18 +    if re.match( '/dev/xvd[a-p]([1-9]|1[0-5])?', n):
   30.19 +        return 202 * 256 + 16 * (ord(n[8:9]) - ord('a')) + int(n[9:] or 0)
   30.20 +
   30.21      # see if this is a hex device number
   30.22      if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
   30.23          return string.atoi(name,16)
    31.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Aug 02 02:47:41 2005 -0800
    31.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Aug 02 10:20:46 2005 -0700
    31.3 @@ -152,6 +152,9 @@ class XendDomainInfo:
    31.4          vm = cls(db)
    31.5          vm.construct(config)
    31.6          vm.saveToDB(sync=True)
    31.7 +        # Flush info to xenstore immediately
    31.8 +        vm.exportToDB()
    31.9 +
   31.10          return vm
   31.11  
   31.12      create = classmethod(create)
   31.13 @@ -172,6 +175,7 @@ class XendDomainInfo:
   31.14          log.debug('config=' + prettyprintstring(config))
   31.15  
   31.16          vm.memory = info['mem_kb']/1024
   31.17 +        vm.target = info['mem_kb'] * 1024
   31.18  
   31.19          if config:
   31.20              try:
   31.21 @@ -222,6 +226,7 @@ class XendDomainInfo:
   31.22          DBVar('restart_state', ty='str'),
   31.23          DBVar('restart_time',  ty='float'),
   31.24          DBVar('restart_count', ty='int'),
   31.25 +        DBVar('target',        ty='long', path="memory/target"),
   31.26          ]
   31.27      
   31.28      def __init__(self, db):
   31.29 @@ -240,6 +245,8 @@ class XendDomainInfo:
   31.30          self.ssidref = None
   31.31          self.image = None
   31.32  
   31.33 +        self.target = None
   31.34 +
   31.35          self.channel = None
   31.36          self.store_channel = None
   31.37          self.store_mfn = None
   31.38 @@ -315,6 +322,7 @@ class XendDomainInfo:
   31.39          self.info = info
   31.40          self.memory = self.info['mem_kb'] / 1024
   31.41          self.ssidref = self.info['ssidref']
   31.42 +        self.target = self.info['mem_kb'] * 1024
   31.43  
   31.44      def state_set(self, state):
   31.45          self.state_updated.acquire()
   31.46 @@ -399,7 +407,8 @@ class XendDomainInfo:
   31.47                  ['id', self.id],
   31.48                  ['name', self.name],
   31.49                  ['memory', self.memory],
   31.50 -                ['ssidref', self.ssidref] ]
   31.51 +                ['ssidref', self.ssidref],
   31.52 +                ['target', self.target] ]
   31.53          if self.uuid:
   31.54              sxpr.append(['uuid', self.uuid])
   31.55          if self.info:
   31.56 @@ -536,6 +545,7 @@ class XendDomainInfo:
   31.57          self.memory = int(sxp.child_value(config, 'memory'))
   31.58          if self.memory is None:
   31.59              raise VmError('missing memory size')
   31.60 +        self.target = self.memory * (1 << 20)
   31.61          self.ssidref = int(sxp.child_value(config, 'ssidref'))
   31.62          cpu = sxp.child_value(config, 'cpu')
   31.63          if self.recreate and self.id and cpu is not None and int(cpu) >= 0:
   31.64 @@ -947,11 +957,12 @@ class XendDomainInfo:
   31.65              index[field_name] = field_index + 1
   31.66  
   31.67      def mem_target_set(self, target):
   31.68 -        """Set domain memory target in pages.
   31.69 +        """Set domain memory target in bytes.
   31.70          """
   31.71 -        if self.channel:
   31.72 -            msg = messages.packMsg('mem_request_t', { 'target' : target * (1 << 8)} )
   31.73 -            self.channel.writeRequest(msg)
   31.74 +        if target:
   31.75 +            self.target = target * (1 << 20)
   31.76 +            # Commit to XenStore immediately
   31.77 +            self.exportToDB()
   31.78  
   31.79      def vcpu_hotplug(self, vcpu, state):
   31.80          """Disable or enable VCPU in domain.
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/tools/security/Makefile	Tue Aug 02 10:20:46 2005 -0700
    32.3 @@ -0,0 +1,36 @@
    32.4 +XEN_ROOT = ../..
    32.5 +include $(XEN_ROOT)/tools/Rules.mk
    32.6 +
    32.7 +SRCS     = secpol_tool.c
    32.8 +CFLAGS   += -static
    32.9 +CFLAGS   += -Wall
   32.10 +CFLAGS   += -Werror
   32.11 +CFLAGS   += -O3
   32.12 +CFLAGS   += -fno-strict-aliasing
   32.13 +CFLAGS   += -I.
   32.14 +
   32.15 +all: build
   32.16 +build: mk-symlinks
   32.17 +	$(MAKE) secpol_tool
   32.18 +
   32.19 +default: all
   32.20 +
   32.21 +install: all
   32.22 +
   32.23 +secpol_tool : secpol_tool.c
   32.24 +	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<
   32.25 +
   32.26 +clean:
   32.27 +	rm -rf secpol_tool xen
   32.28 +
   32.29 +
   32.30 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
   32.31 +mk-symlinks:
   32.32 +	[ -e xen/linux ] || mkdir -p xen/linux
   32.33 +	[ -e xen/io ]    || mkdir -p xen/io
   32.34 +	( cd xen >/dev/null ; \
   32.35 +	  ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . )
   32.36 +	( cd xen/io >/dev/null ; \
   32.37 +	  ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . )
   32.38 +	( cd xen/linux >/dev/null ; \
   32.39 +	  ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/tools/security/secpol_tool.c	Tue Aug 02 10:20:46 2005 -0700
    33.3 @@ -0,0 +1,648 @@
    33.4 +/****************************************************************
    33.5 + * secpol_tool.c
    33.6 + *
    33.7 + * Copyright (C) 2005 IBM Corporation
    33.8 + *
    33.9 + * Authors:
   33.10 + * Reiner Sailer <sailer@watson.ibm.com>
   33.11 + * Stefan Berger <stefanb@watson.ibm.com>
   33.12 + *
   33.13 + * This program is free software; you can redistribute it and/or
   33.14 + * modify it under the terms of the GNU General Public License as
   33.15 + * published by the Free Software Foundation, version 2 of the
   33.16 + * License.
   33.17 + *
   33.18 + * sHype policy management tool. This code runs in a domain and
   33.19 + *     manages the Xen security policy by interacting with the
   33.20 + *     Xen access control module via a /proc/xen/privcmd proc-ioctl,
   33.21 + *     which is translated into a acm_op hypercall into Xen.
   33.22 + *
   33.23 + * indent -i4 -kr -nut
   33.24 + */
   33.25 +
   33.26 +
   33.27 +#include <unistd.h>
   33.28 +#include <stdio.h>
   33.29 +#include <errno.h>
   33.30 +#include <fcntl.h>
   33.31 +#include <sys/mman.h>
   33.32 +#include <sys/types.h>
   33.33 +#include <sys/stat.h>
   33.34 +#include <stdlib.h>
   33.35 +#include <sys/ioctl.h>
   33.36 +#include <string.h>
   33.37 +#include <stdint.h>
   33.38 +#include <netinet/in.h>
   33.39 +
   33.40 +typedef uint8_t u8;
   33.41 +typedef uint16_t u16;
   33.42 +typedef uint32_t u32;
   33.43 +typedef uint64_t u64;
   33.44 +typedef int8_t s8;
   33.45 +typedef int16_t s16;
   33.46 +typedef int32_t s32;
   33.47 +typedef int64_t s64;
   33.48 +
   33.49 +#include <xen/acm.h>
   33.50 +#include <xen/acm_ops.h>
   33.51 +#include <xen/linux/privcmd.h>
   33.52 +
   33.53 +#define PERROR(_m, _a...) \
   33.54 +fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,	\
   33.55 +                errno, strerror(errno))
   33.56 +
   33.57 +static inline int do_policycmd(int xc_handle, unsigned int cmd,
   33.58 +                               unsigned long data)
   33.59 +{
   33.60 +    return ioctl(xc_handle, cmd, data);
   33.61 +}
   33.62 +
   33.63 +static inline int do_xen_hypercall(int xc_handle,
   33.64 +                                   privcmd_hypercall_t * hypercall)
   33.65 +{
   33.66 +    return do_policycmd(xc_handle,
   33.67 +                        IOCTL_PRIVCMD_HYPERCALL,
   33.68 +                        (unsigned long) hypercall);
   33.69 +}
   33.70 +
   33.71 +static inline int do_acm_op(int xc_handle, acm_op_t * op)
   33.72 +{
   33.73 +    int ret = -1;
   33.74 +    privcmd_hypercall_t hypercall;
   33.75 +
   33.76 +    op->interface_version = ACM_INTERFACE_VERSION;
   33.77 +
   33.78 +    hypercall.op = __HYPERVISOR_acm_op;
   33.79 +    hypercall.arg[0] = (unsigned long) op;
   33.80 +
   33.81 +    if (mlock(op, sizeof(*op)) != 0)
   33.82 +    {
   33.83 +        PERROR("Could not lock memory for Xen policy hypercall");
   33.84 +        goto out1;
   33.85 +    }
   33.86 +
   33.87 +    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0)
   33.88 +    {
   33.89 +        if (errno == EACCES)
   33.90 +            fprintf(stderr, "ACM operation failed -- need to"
   33.91 +                    " rebuild the user-space tool set?\n");
   33.92 +        goto out2;
   33.93 +    }
   33.94 +
   33.95 +  out2:(void) munlock(op, sizeof(*op));
   33.96 +  out1:return ret;
   33.97 +}
   33.98 +
   33.99 +/*************************** DUMPS *******************************/
  33.100 +
  33.101 +void acm_dump_chinesewall_buffer(void *buf, int buflen)
  33.102 +{
  33.103 +
  33.104 +    struct acm_chwall_policy_buffer *cwbuf =
  33.105 +        (struct acm_chwall_policy_buffer *) buf;
  33.106 +    domaintype_t *ssids, *conflicts, *running_types, *conflict_aggregate;
  33.107 +    int i, j;
  33.108 +
  33.109 +
  33.110 +    if (htonl(cwbuf->policy_code) != ACM_CHINESE_WALL_POLICY)
  33.111 +    {
  33.112 +        printf("CHINESE WALL POLICY CODE not found ERROR!!\n");
  33.113 +        return;
  33.114 +    }
  33.115 +    printf("\n\nChinese Wall policy:\n");
  33.116 +    printf("====================\n");
  33.117 +    printf("Policy version= %x.\n", ntohl(cwbuf->policy_version));
  33.118 +    printf("Max Types     = %x.\n", ntohl(cwbuf->chwall_max_types));
  33.119 +    printf("Max Ssidrefs  = %x.\n", ntohl(cwbuf->chwall_max_ssidrefs));
  33.120 +    printf("Max ConfSets  = %x.\n", ntohl(cwbuf->chwall_max_conflictsets));
  33.121 +    printf("Ssidrefs Off  = %x.\n", ntohl(cwbuf->chwall_ssid_offset));
  33.122 +    printf("Conflicts Off = %x.\n",
  33.123 +           ntohl(cwbuf->chwall_conflict_sets_offset));
  33.124 +    printf("Runing T. Off = %x.\n",
  33.125 +           ntohl(cwbuf->chwall_running_types_offset));
  33.126 +    printf("C. Agg. Off   = %x.\n",
  33.127 +           ntohl(cwbuf->chwall_conflict_aggregate_offset));
  33.128 +    printf("\nSSID To CHWALL-Type matrix:\n");
  33.129 +
  33.130 +    ssids = (domaintype_t *) (buf + ntohl(cwbuf->chwall_ssid_offset));
  33.131 +    for (i = 0; i < ntohl(cwbuf->chwall_max_ssidrefs); i++)
  33.132 +    {
  33.133 +        printf("\n   ssidref%2x:  ", i);
  33.134 +        for (j = 0; j < ntohl(cwbuf->chwall_max_types); j++)
  33.135 +            printf("%02x ",
  33.136 +                   ntohs(ssids[i * ntohl(cwbuf->chwall_max_types) + j]));
  33.137 +    }
  33.138 +    printf("\n\nConfict Sets:\n");
  33.139 +    conflicts =
  33.140 +        (domaintype_t *) (buf + ntohl(cwbuf->chwall_conflict_sets_offset));
  33.141 +    for (i = 0; i < ntohl(cwbuf->chwall_max_conflictsets); i++)
  33.142 +    {
  33.143 +        printf("\n   c-set%2x:    ", i);
  33.144 +        for (j = 0; j < ntohl(cwbuf->chwall_max_types); j++)
  33.145 +            printf("%02x ",
  33.146 +                   ntohs(conflicts
  33.147 +                         [i * ntohl(cwbuf->chwall_max_types) + j]));
  33.148 +    }
  33.149 +    printf("\n");
  33.150 +
  33.151 +    printf("\nRunning\nTypes:         ");
  33.152 +    if (ntohl(cwbuf->chwall_running_types_offset))
  33.153 +    {
  33.154 +        running_types =
  33.155 +            (domaintype_t *) (buf +
  33.156 +                              ntohl(cwbuf->chwall_running_types_offset));
  33.157 +        for (i = 0; i < ntohl(cwbuf->chwall_max_types); i++)
  33.158 +        {
  33.159 +            printf("%02x ", ntohs(running_types[i]));
  33.160 +        }
  33.161 +        printf("\n");
  33.162 +    } else {
  33.163 +        printf("Not Reported!\n");
  33.164 +    }
  33.165 +    printf("\nConflict\nAggregate Set: ");
  33.166 +    if (ntohl(cwbuf->chwall_conflict_aggregate_offset))
  33.167 +    {
  33.168 +        conflict_aggregate =
  33.169 +            (domaintype_t *) (buf +
  33.170 +                              ntohl(cwbuf->chwall_conflict_aggregate_offset));
  33.171 +        for (i = 0; i < ntohl(cwbuf->chwall_max_types); i++)
  33.172 +        {
  33.173 +            printf("%02x ", ntohs(conflict_aggregate[i]));
  33.174 +        }
  33.175 +        printf("\n\n");
  33.176 +    } else {
  33.177 +        printf("Not Reported!\n");
  33.178 +    }
  33.179 +}
  33.180 +
  33.181 +void acm_dump_ste_buffer(void *buf, int buflen)
  33.182 +{
  33.183 +
  33.184 +    struct acm_ste_policy_buffer *stebuf =
  33.185 +        (struct acm_ste_policy_buffer *) buf;
  33.186 +    domaintype_t *ssids;
  33.187 +    int i, j;
  33.188 +
  33.189 +
  33.190 +    if (ntohl(stebuf->policy_code) != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) {
  33.191 +        printf("SIMPLE TYPE ENFORCEMENT POLICY CODE not found ERROR!!\n");
  33.192 +        return;
  33.193 +    }
  33.194 +    printf("\nSimple Type Enforcement policy:\n");
  33.195 +    printf("===============================\n");
  33.196 +    printf("Policy version= %x.\n", ntohl(stebuf->policy_version));
  33.197 +    printf("Max Types     = %x.\n", ntohl(stebuf->ste_max_types));
  33.198 +    printf("Max Ssidrefs  = %x.\n", ntohl(stebuf->ste_max_ssidrefs));
  33.199 +    printf("Ssidrefs Off  = %x.\n", ntohl(stebuf->ste_ssid_offset));
  33.200 +    printf("\nSSID To STE-Type matrix:\n");
  33.201 +
  33.202 +    ssids = (domaintype_t *) (buf + ntohl(stebuf->ste_ssid_offset));
  33.203 +    for (i = 0; i < ntohl(stebuf->ste_max_ssidrefs); i++)
  33.204 +    {
  33.205 +        printf("\n   ssidref%2x: ", i);
  33.206 +        for (j = 0; j < ntohl(stebuf->ste_max_types); j++)
  33.207 +            printf("%02x ", ntohs(ssids[i * ntohl(stebuf->ste_max_types) + j]));
  33.208 +    }
  33.209 +    printf("\n\n");
  33.210 +}
  33.211 +
  33.212 +void acm_dump_policy_buffer(void *buf, int buflen)
  33.213 +{
  33.214 +    struct acm_policy_buffer *pol = (struct acm_policy_buffer *) buf;
  33.215 +
  33.216 +    printf("\nPolicy dump:\n");
  33.217 +    printf("============\n");
  33.218 +    printf("PolicyVer = %x.\n", ntohl(pol->policy_version));
  33.219 +    printf("Magic     = %x.\n", ntohl(pol->magic));
  33.220 +    printf("Len       = %x.\n", ntohl(pol->len));
  33.221 +    printf("Primary   = %s (c=%x, off=%x).\n",
  33.222 +           ACM_POLICY_NAME(ntohl(pol->primary_policy_code)),
  33.223 +           ntohl(pol->primary_policy_code),
  33.224 +           ntohl(pol->primary_buffer_offset));
  33.225 +    printf("Secondary = %s (c=%x, off=%x).\n",
  33.226 +           ACM_POLICY_NAME(ntohl(pol->secondary_policy_code)),
  33.227 +           ntohl(pol->secondary_policy_code),
  33.228 +           ntohl(pol->secondary_buffer_offset));
  33.229 +    switch (ntohl(pol->primary_policy_code))
  33.230 +    {
  33.231 +    case ACM_CHINESE_WALL_POLICY:
  33.232 +        acm_dump_chinesewall_buffer(buf +
  33.233 +                                    ntohl(pol->primary_buffer_offset),
  33.234 +                                    ntohl(pol->len) -
  33.235 +                                    ntohl(pol->primary_buffer_offset));
  33.236 +        break;
  33.237 +
  33.238 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  33.239 +        acm_dump_ste_buffer(buf + ntohl(pol->primary_buffer_offset),
  33.240 +                            ntohl(pol->len) -
  33.241 +                            ntohl(pol->primary_buffer_offset));
  33.242 +        break;
  33.243 +
  33.244 +    case ACM_NULL_POLICY:
  33.245 +        printf("Primary policy is NULL Policy (n/a).\n");
  33.246 +        break;
  33.247 +
  33.248 +    default:
  33.249 +        printf("UNKNOWN POLICY!\n");
  33.250 +    }
  33.251 +
  33.252 +    switch (ntohl(pol->secondary_policy_code))
  33.253 +    {
  33.254 +    case ACM_CHINESE_WALL_POLICY:
  33.255 +        acm_dump_chinesewall_buffer(buf +
  33.256 +                                    ntohl(pol->secondary_buffer_offset),
  33.257 +                                    ntohl(pol->len) -
  33.258 +                                    ntohl(pol->secondary_buffer_offset));
  33.259 +        break;
  33.260 +
  33.261 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  33.262 +        acm_dump_ste_buffer(buf + ntohl(pol->secondary_buffer_offset),
  33.263 +                            ntohl(pol->len) -
  33.264 +                            ntohl(pol->secondary_buffer_offset));
  33.265 +        break;
  33.266 +
  33.267 +    case ACM_NULL_POLICY:
  33.268 +        printf("Secondary policy is NULL Policy (n/a).\n");
  33.269 +        break;
  33.270 +
  33.271 +    default:
  33.272 +        printf("UNKNOWN POLICY!\n");
  33.273 +    }
  33.274 +}
  33.275 +
  33.276 +/*************************** set policy ****************************/
  33.277 +
  33.278 +int acm_domain_set_chwallpolicy(void *bufstart, int buflen)
  33.279 +{
  33.280 +#define CWALL_MAX_SSIDREFS      	6
  33.281 +#define CWALL_MAX_TYPES             10
  33.282 +#define CWALL_MAX_CONFLICTSETS		2
  33.283 +
  33.284 +    struct acm_chwall_policy_buffer *chwall_bin_pol =
  33.285 +        (struct acm_chwall_policy_buffer *) bufstart;
  33.286 +    domaintype_t *ssidrefs, *conflicts;
  33.287 +    int ret = 0;
  33.288 +    int j;
  33.289 +
  33.290 +    chwall_bin_pol->chwall_max_types = htonl(CWALL_MAX_TYPES);
  33.291 +    chwall_bin_pol->chwall_max_ssidrefs = htonl(CWALL_MAX_SSIDREFS);
  33.292 +    chwall_bin_pol->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
  33.293 +    chwall_bin_pol->policy_version = htonl(ACM_CHWALL_VERSION);
  33.294 +    chwall_bin_pol->chwall_ssid_offset =
  33.295 +        htonl(sizeof(struct acm_chwall_policy_buffer));
  33.296 +    chwall_bin_pol->chwall_max_conflictsets =
  33.297 +        htonl(CWALL_MAX_CONFLICTSETS);
  33.298 +    chwall_bin_pol->chwall_conflict_sets_offset =
  33.299 +        htonl(ntohl(chwall_bin_pol->chwall_ssid_offset) +
  33.300 +              sizeof(domaintype_t) * CWALL_MAX_SSIDREFS * CWALL_MAX_TYPES);
  33.301 +    chwall_bin_pol->chwall_running_types_offset = 0;    /* not set */
  33.302 +    chwall_bin_pol->chwall_conflict_aggregate_offset = 0;       /* not set */
  33.303 +    ret += sizeof(struct acm_chwall_policy_buffer);
  33.304 +    /* now push example ssids into the buffer (max_ssidrefs x max_types entries) */
  33.305 +    /* check buffer size */
  33.306 +    if ((buflen - ret) <
  33.307 +        (CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t)))
  33.308 +        return -1;              /* not enough space */
  33.309 +
  33.310 +    ssidrefs = (domaintype_t *) (bufstart +
  33.311 +                          ntohl(chwall_bin_pol->chwall_ssid_offset));
  33.312 +    memset(ssidrefs, 0,
  33.313 +           CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t));
  33.314 +
  33.315 +    /* now set type j-1 for ssidref i+1 */
  33.316 +    for (j = 0; j <= CWALL_MAX_SSIDREFS; j++)
  33.317 +        if ((0 < j) && (j <= CWALL_MAX_TYPES))
  33.318 +            ssidrefs[j * CWALL_MAX_TYPES + j - 1] = htons(1);
  33.319 +
  33.320 +    ret += CWALL_MAX_TYPES * CWALL_MAX_SSIDREFS * sizeof(domaintype_t);
  33.321 +    if ((buflen - ret) <
  33.322 +        (CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES * sizeof(domaintype_t)))
  33.323 +        return -1;              /* not enough space */
  33.324 +
  33.325 +    /* now the chinese wall policy conflict sets */
  33.326 +    conflicts = (domaintype_t *) (bufstart +
  33.327 +                                  ntohl(chwall_bin_pol->
  33.328 +                                        chwall_conflict_sets_offset));
  33.329 +    memset((void *) conflicts, 0,
  33.330 +           CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES *
  33.331 +           sizeof(domaintype_t));
  33.332 +    /* just 1 conflict set [0]={2,3}, [1]={1,5,6} */
  33.333 +    if (CWALL_MAX_TYPES > 3)
  33.334 +    {
  33.335 +        conflicts[2] = htons(1);
  33.336 +        conflicts[3] = htons(1);        /* {2,3} */
  33.337 +        conflicts[CWALL_MAX_TYPES + 1] = htons(1);
  33.338 +        conflicts[CWALL_MAX_TYPES + 5] = htons(1);
  33.339 +        conflicts[CWALL_MAX_TYPES + 6] = htons(1);      /* {0,5,6} */
  33.340 +    }
  33.341 +    ret += sizeof(domaintype_t) * CWALL_MAX_CONFLICTSETS * CWALL_MAX_TYPES;
  33.342 +    return ret;
  33.343 +}
  33.344 +
  33.345 +int acm_domain_set_stepolicy(void *bufstart, int buflen)
  33.346 +{
  33.347 +#define STE_MAX_SSIDREFS        6
  33.348 +#define STE_MAX_TYPES  	        5
  33.349 +
  33.350 +    struct acm_ste_policy_buffer *ste_bin_pol =
  33.351 +        (struct acm_ste_policy_buffer *) bufstart;
  33.352 +    domaintype_t *ssidrefs;
  33.353 +    int j, ret = 0;
  33.354 +
  33.355 +    ste_bin_pol->ste_max_types = htonl(STE_MAX_TYPES);
  33.356 +    ste_bin_pol->ste_max_ssidrefs = htonl(STE_MAX_SSIDREFS);
  33.357 +    ste_bin_pol->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  33.358 +    ste_bin_pol->policy_version = htonl(ACM_STE_VERSION);
  33.359 +    ste_bin_pol->ste_ssid_offset =
  33.360 +        htonl(sizeof(struct acm_ste_policy_buffer));
  33.361 +    ret += sizeof(struct acm_ste_policy_buffer);
  33.362 +    /* check buffer size */
  33.363 +    if ((buflen - ret) <
  33.364 +        (STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t)))
  33.365 +        return -1;              /* not enough space */
  33.366 +
  33.367 +    ssidrefs =
  33.368 +        (domaintype_t *) (bufstart + ntohl(ste_bin_pol->ste_ssid_offset));
  33.369 +    memset(ssidrefs, 0,
  33.370 +           STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t));
  33.371 +    /* all types 1 for ssidref 1 */
  33.372 +    for (j = 0; j < STE_MAX_TYPES; j++)
  33.373 +        ssidrefs[1 * STE_MAX_TYPES + j] = htons(1);
  33.374 +    /* now set type j-1 for ssidref j */
  33.375 +    for (j = 0; j < STE_MAX_SSIDREFS; j++)
  33.376 +        if ((0 < j) && (j <= STE_MAX_TYPES))
  33.377 +            ssidrefs[j * STE_MAX_TYPES + j - 1] = htons(1);
  33.378 +    ret += STE_MAX_TYPES * STE_MAX_SSIDREFS * sizeof(domaintype_t);
  33.379 +    return ret;
  33.380 +}
  33.381 +
  33.382 +#define MAX_PUSH_BUFFER 	16384
  33.383 +u8 push_buffer[MAX_PUSH_BUFFER];
  33.384 +
  33.385 +int acm_domain_setpolicy(int xc_handle)
  33.386 +{
  33.387 +    int ret;
  33.388 +    struct acm_policy_buffer *bin_pol;
  33.389 +    acm_op_t op;
  33.390 +
  33.391 +    /* future: read policy from file and set it */
  33.392 +    bin_pol = (struct acm_policy_buffer *) push_buffer;
  33.393 +    bin_pol->policy_version = htonl(ACM_POLICY_VERSION);
  33.394 +    bin_pol->magic = htonl(ACM_MAGIC);
  33.395 +    bin_pol->primary_policy_code = htonl(ACM_CHINESE_WALL_POLICY);
  33.396 +    bin_pol->secondary_policy_code =
  33.397 +        htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  33.398 +
  33.399 +    bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  33.400 +    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
  33.401 +    ret =
  33.402 +        acm_domain_set_chwallpolicy(push_buffer +
  33.403 +                                    ntohl(bin_pol->primary_buffer_offset),
  33.404 +                                    MAX_PUSH_BUFFER -
  33.405 +                                    ntohl(bin_pol->primary_buffer_offset));
  33.406 +    if (ret < 0)
  33.407 +    {
  33.408 +        printf("ERROR creating chwallpolicy buffer.\n");
  33.409 +        return -1;
  33.410 +    }
  33.411 +    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  33.412 +    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  33.413 +    ret = acm_domain_set_stepolicy(push_buffer +
  33.414 +                                 ntohl(bin_pol->secondary_buffer_offset),
  33.415 +                                 MAX_PUSH_BUFFER -
  33.416 +                                 ntohl(bin_pol->secondary_buffer_offset));
  33.417 +    if (ret < 0)
  33.418 +    {
  33.419 +        printf("ERROR creating chwallpolicy buffer.\n");
  33.420 +        return -1;
  33.421 +    }
  33.422 +    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  33.423 +
  33.424 +    /* dump it and then push it down into xen/acm */
  33.425 +    acm_dump_policy_buffer(push_buffer, ntohl(bin_pol->len));
  33.426 +
  33.427 +    op.cmd = ACM_SETPOLICY;
  33.428 +    op.interface_version = ACM_INTERFACE_VERSION;
  33.429 +    op.u.setpolicy.pushcache = (void *) push_buffer;
  33.430 +    op.u.setpolicy.pushcache_size = ntohl(bin_pol->len);
  33.431 +    ret = do_acm_op(xc_handle, &op);
  33.432 +
  33.433 +    if (ret)
  33.434 +        printf("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  33.435 +    else
  33.436 +        printf("Successfully changed policy.\n");
  33.437 +
  33.438 +    return ret;
  33.439 +}
  33.440 +
  33.441 +/******************************* get policy ******************************/
  33.442 +
  33.443 +#define PULL_CACHE_SIZE		8192
  33.444 +u8 pull_buffer[PULL_CACHE_SIZE];
  33.445 +int acm_domain_getpolicy(int xc_handle)
  33.446 +{
  33.447 +    acm_op_t op;
  33.448 +    int ret;
  33.449 +
  33.450 +    memset(pull_buffer, 0x00, sizeof(pull_buffer));
  33.451 +    op.cmd = ACM_GETPOLICY;
  33.452 +    op.interface_version = ACM_INTERFACE_VERSION;
  33.453 +    op.u.getpolicy.pullcache = (void *) pull_buffer;
  33.454 +    op.u.getpolicy.pullcache_size = sizeof(pull_buffer);
  33.455 +    ret = do_acm_op(xc_handle, &op);
  33.456 +    /* dump policy  */
  33.457 +    acm_dump_policy_buffer(pull_buffer, sizeof(pull_buffer));
  33.458 +    return ret;
  33.459 +}
  33.460 +
  33.461 +/************************ load binary policy ******************************/
  33.462 +
  33.463 +int acm_domain_loadpolicy(int xc_handle, const char *filename)
  33.464 +{
  33.465 +    struct stat mystat;
  33.466 +    int ret, fd;
  33.467 +    off_t len;
  33.468 +    u8 *buffer;
  33.469 +
  33.470 +    if ((ret = stat(filename, &mystat)))
  33.471 +    {
  33.472 +        printf("File %s not found.\n", filename);
  33.473 +        goto out;
  33.474 +    }
  33.475 +
  33.476 +    len = mystat.st_size;
  33.477 +    if ((buffer = malloc(len)) == NULL)
  33.478 +    {
  33.479 +        ret = -ENOMEM;
  33.480 +        goto out;
  33.481 +    }
  33.482 +    if ((fd = open(filename, O_RDONLY)) <= 0)
  33.483 +    {
  33.484 +        ret = -ENOENT;
  33.485 +        printf("File %s not found.\n", filename);
  33.486 +        goto free_out;
  33.487 +    }
  33.488 +    if (len == read(fd, buffer, len))
  33.489 +    {
  33.490 +        acm_op_t op;
  33.491 +        /* dump it and then push it down into xen/acm */
  33.492 +        acm_dump_policy_buffer(buffer, len);
  33.493 +        op.cmd = ACM_SETPOLICY;
  33.494 +        op.interface_version = ACM_INTERFACE_VERSION;
  33.495 +        op.u.setpolicy.pushcache = (void *) buffer;
  33.496 +        op.u.setpolicy.pushcache_size = len;
  33.497 +        ret = do_acm_op(xc_handle, &op);
  33.498 +
  33.499 +        if (ret)
  33.500 +            printf
  33.501 +                ("ERROR setting policy. Use 'xm dmesg' to see details.\n");
  33.502 +        else
  33.503 +            printf("Successfully changed policy.\n");
  33.504 +
  33.505 +    } else {
  33.506 +        ret = -1;
  33.507 +    }
  33.508 +    close(fd);
  33.509 +  free_out:
  33.510 +    free(buffer);
  33.511 +  out:
  33.512 +    return ret;
  33.513 +}
  33.514 +
  33.515 +/************************ dump hook statistics ******************************/
  33.516 +void dump_ste_stats(struct acm_ste_stats_buffer *ste_stats)
  33.517 +{
  33.518 +    printf("STE-Policy Security Hook Statistics:\n");
  33.519 +    printf("ste: event_channel eval_count      = %d\n",
  33.520 +           ntohl(ste_stats->ec_eval_count));
  33.521 +    printf("ste: event_channel denied_count    = %d\n",
  33.522 +           ntohl(ste_stats->ec_denied_count));
  33.523 +    printf("ste: event_channel cache_hit_count = %d\n",
  33.524 +           ntohl(ste_stats->ec_cachehit_count));
  33.525 +    printf("ste:\n");
  33.526 +    printf("ste: grant_table   eval_count      = %d\n",
  33.527 +           ntohl(ste_stats->gt_eval_count));
  33.528 +    printf("ste: grant_table   denied_count    = %d\n",
  33.529 +           ntohl(ste_stats->gt_denied_count));
  33.530 +    printf("ste: grant_table   cache_hit_count = %d\n",
  33.531 +           ntohl(ste_stats->gt_cachehit_count));
  33.532 +}
  33.533 +
  33.534 +#define PULL_STATS_SIZE		8192
  33.535 +int acm_domain_dumpstats(int xc_handle)
  33.536 +{
  33.537 +    u8 stats_buffer[PULL_STATS_SIZE];
  33.538 +    acm_op_t op;
  33.539 +    int ret;
  33.540 +    struct acm_stats_buffer *stats;
  33.541 +
  33.542 +    memset(stats_buffer, 0x00, sizeof(stats_buffer));
  33.543 +    op.cmd = ACM_DUMPSTATS;
  33.544 +    op.interface_version = ACM_INTERFACE_VERSION;
  33.545 +    op.u.dumpstats.pullcache = (void *) stats_buffer;
  33.546 +    op.u.dumpstats.pullcache_size = sizeof(stats_buffer);
  33.547 +    ret = do_acm_op(xc_handle, &op);
  33.548 +
  33.549 +    if (ret < 0)
  33.550 +    {
  33.551 +        printf("ERROR dumping policy stats. Use 'xm dmesg' to see details.\n");
  33.552 +        return ret;
  33.553 +    }
  33.554 +    stats = (struct acm_stats_buffer *) stats_buffer;
  33.555 +
  33.556 +    printf("\nPolicy dump:\n");
  33.557 +    printf("============\n");
  33.558 +    printf("Magic     = %x.\n", ntohl(stats->magic));
  33.559 +    printf("Len       = %x.\n", ntohl(stats->len));
  33.560 +
  33.561 +    switch (ntohl(stats->primary_policy_code))
  33.562 +    {
  33.563 +    case ACM_NULL_POLICY:
  33.564 +        printf("NULL Policy: No statistics apply.\n");
  33.565 +        break;
  33.566 +
  33.567 +    case ACM_CHINESE_WALL_POLICY:
  33.568 +        printf("Chinese Wall Policy: No statistics apply.\n");
  33.569 +        break;
  33.570 +
  33.571 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  33.572 +        dump_ste_stats((struct acm_ste_stats_buffer *) (stats_buffer +
  33.573 +                                                        ntohl(stats->
  33.574 +                                                              primary_stats_offset)));
  33.575 +        break;
  33.576 +
  33.577 +    default:
  33.578 +        printf("UNKNOWN PRIMARY POLICY ERROR!\n");
  33.579 +    }
  33.580 +
  33.581 +    switch (ntohl(stats->secondary_policy_code))
  33.582 +    {
  33.583 +    case ACM_NULL_POLICY:
  33.584 +        printf("NULL Policy: No statistics apply.\n");
  33.585 +        break;
  33.586 +
  33.587 +    case ACM_CHINESE_WALL_POLICY:
  33.588 +        printf("Chinese Wall Policy: No statistics apply.\n");
  33.589 +        break;
  33.590 +
  33.591 +    case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  33.592 +        dump_ste_stats((struct acm_ste_stats_buffer *) (stats_buffer +
  33.593 +                                                        ntohl(stats->
  33.594 +                                                              secondary_stats_offset)));
  33.595 +        break;
  33.596 +
  33.597 +    default:
  33.598 +        printf("UNKNOWN SECONDARY POLICY ERROR!\n");
  33.599 +    }
  33.600 +    return ret;
  33.601 +}
  33.602 +
  33.603 +/***************************** main **************************************/
  33.604 +
  33.605 +void usage(char *progname)
  33.606 +{
  33.607 +    printf("Use: %s \n"
  33.608 +           "\t setpolicy\n"
  33.609 +           "\t getpolicy\n"
  33.610 +           "\t dumpstats\n"
  33.611 +           "\t loadpolicy <binary policy file>\n", progname);
  33.612 +    exit(-1);
  33.613 +}
  33.614 +
  33.615 +int main(int argc, char **argv)
  33.616 +{
  33.617 +
  33.618 +    int acm_cmd_fd, ret;
  33.619 +
  33.620 +    if (argc < 2)
  33.621 +        usage(argv[0]);
  33.622 +
  33.623 +    if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0)
  33.624 +    {
  33.625 +        printf("ERROR: Could not open xen privcmd device!\n");
  33.626 +        exit(-1);
  33.627 +    }
  33.628 +
  33.629 +    if (!strcmp(argv[1], "setpolicy"))
  33.630 +    {
  33.631 +        if (argc != 2)
  33.632 +            usage(argv[0]);
  33.633 +        ret = acm_domain_setpolicy(acm_cmd_fd);
  33.634 +    } else if (!strcmp(argv[1], "getpolicy")) {
  33.635 +        if (argc != 2)
  33.636 +            usage(argv[0]);
  33.637 +        ret = acm_domain_getpolicy(acm_cmd_fd);
  33.638 +    } else if (!strcmp(argv[1], "loadpolicy")) {
  33.639 +        if (argc != 3)
  33.640 +            usage(argv[0]);
  33.641 +        ret = acm_domain_loadpolicy(acm_cmd_fd, argv[2]);
  33.642 +    } else if (!strcmp(argv[1], "dumpstats")) {
  33.643 +        if (argc != 2)
  33.644 +            usage(argv[0]);
  33.645 +        ret = acm_domain_dumpstats(acm_cmd_fd);
  33.646 +    } else
  33.647 +        usage(argv[0]);
  33.648 +
  33.649 +    close(acm_cmd_fd);
  33.650 +    return ret;
  33.651 +}
    34.1 --- a/xen/acm/acm_chinesewall_hooks.c	Tue Aug 02 02:47:41 2005 -0800
    34.2 +++ b/xen/acm/acm_chinesewall_hooks.c	Tue Aug 02 10:20:46 2005 -0700
    34.3 @@ -110,45 +110,45 @@ chwall_dump_policy(u8 *buf, u16 buf_size
    34.4       struct acm_chwall_policy_buffer *chwall_buf = (struct acm_chwall_policy_buffer *)buf;
    34.5       int ret = 0;
    34.6  
    34.7 -     chwall_buf->chwall_max_types = htons(chwall_bin_pol.max_types);
    34.8 -     chwall_buf->chwall_max_ssidrefs = htons(chwall_bin_pol.max_ssidrefs);
    34.9 -     chwall_buf->policy_code = htons(ACM_CHINESE_WALL_POLICY);
   34.10 -     chwall_buf->chwall_ssid_offset = htons(sizeof(struct acm_chwall_policy_buffer));
   34.11 -     chwall_buf->chwall_max_conflictsets = htons(chwall_bin_pol.max_conflictsets);
   34.12 +     chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types);
   34.13 +     chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs);
   34.14 +     chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
   34.15 +     chwall_buf->chwall_ssid_offset = htonl(sizeof(struct acm_chwall_policy_buffer));
   34.16 +     chwall_buf->chwall_max_conflictsets = htonl(chwall_bin_pol.max_conflictsets);
   34.17       chwall_buf->chwall_conflict_sets_offset =
   34.18 -	     htons(
   34.19 -		   ntohs(chwall_buf->chwall_ssid_offset) + 
   34.20 +	     htonl(
   34.21 +		   ntohl(chwall_buf->chwall_ssid_offset) +
   34.22  		   sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs * 
   34.23  		   chwall_bin_pol.max_types);
   34.24  
   34.25       chwall_buf->chwall_running_types_offset = 
   34.26 -	     htons(
   34.27 -		   ntohs(chwall_buf->chwall_conflict_sets_offset) +
   34.28 +	     htonl(
   34.29 +		   ntohl(chwall_buf->chwall_conflict_sets_offset) +
   34.30  		   sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets *
   34.31  		   chwall_bin_pol.max_types);
   34.32  
   34.33       chwall_buf->chwall_conflict_aggregate_offset =
   34.34 -	     htons(
   34.35 -		   ntohs(chwall_buf->chwall_running_types_offset) +
   34.36 +	     htonl(
   34.37 +		   ntohl(chwall_buf->chwall_running_types_offset) +
   34.38  		   sizeof(domaintype_t) * chwall_bin_pol.max_types);
   34.39  
   34.40 -     ret = ntohs(chwall_buf->chwall_conflict_aggregate_offset) +
   34.41 +     ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) +
   34.42  	     sizeof(domaintype_t) * chwall_bin_pol.max_types;
   34.43  
   34.44       /* now copy buffers over */
   34.45 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_ssid_offset)),
   34.46 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_ssid_offset)),
   34.47  	      chwall_bin_pol.ssidrefs,
   34.48  	      chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types);
   34.49  
   34.50 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_conflict_sets_offset)),
   34.51 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_sets_offset)),
   34.52  	      chwall_bin_pol.conflict_sets,
   34.53  	      chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types);
   34.54  
   34.55 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_running_types_offset)),
   34.56 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_running_types_offset)),
   34.57  	      chwall_bin_pol.running_types,
   34.58  	      chwall_bin_pol.max_types);
   34.59  
   34.60 -     arrcpy16((u16 *)(buf + ntohs(chwall_buf->chwall_conflict_aggregate_offset)),
   34.61 +     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_aggregate_offset)),
   34.62  	      chwall_bin_pol.conflict_aggregate_set,
   34.63  	      chwall_bin_pol.max_types);
   34.64       return ret;
   34.65 @@ -226,14 +226,20 @@ chwall_set_policy(u8 *buf, u16 buf_size)
   34.66  	void *ssids = NULL, *conflict_sets = NULL, *running_types = NULL, *conflict_aggregate_set = NULL;	
   34.67  
   34.68          /* rewrite the policy due to endianess */
   34.69 -        chwall_buf->policy_code                      = ntohs(chwall_buf->policy_code);
   34.70 -        chwall_buf->chwall_max_types                 = ntohs(chwall_buf->chwall_max_types);
   34.71 -        chwall_buf->chwall_max_ssidrefs              = ntohs(chwall_buf->chwall_max_ssidrefs);
   34.72 -        chwall_buf->chwall_max_conflictsets          = ntohs(chwall_buf->chwall_max_conflictsets);
   34.73 -        chwall_buf->chwall_ssid_offset               = ntohs(chwall_buf->chwall_ssid_offset);
   34.74 -        chwall_buf->chwall_conflict_sets_offset      = ntohs(chwall_buf->chwall_conflict_sets_offset);
   34.75 -        chwall_buf->chwall_running_types_offset      = ntohs(chwall_buf->chwall_running_types_offset);
   34.76 -        chwall_buf->chwall_conflict_aggregate_offset = ntohs(chwall_buf->chwall_conflict_aggregate_offset);
   34.77 +        chwall_buf->policy_code                      = ntohl(chwall_buf->policy_code);
   34.78 +        chwall_buf->policy_version                   = ntohl(chwall_buf->policy_version);
   34.79 +        chwall_buf->chwall_max_types                 = ntohl(chwall_buf->chwall_max_types);
   34.80 +        chwall_buf->chwall_max_ssidrefs              = ntohl(chwall_buf->chwall_max_ssidrefs);
   34.81 +        chwall_buf->chwall_max_conflictsets          = ntohl(chwall_buf->chwall_max_conflictsets);
   34.82 +        chwall_buf->chwall_ssid_offset               = ntohl(chwall_buf->chwall_ssid_offset);
   34.83 +        chwall_buf->chwall_conflict_sets_offset      = ntohl(chwall_buf->chwall_conflict_sets_offset);
   34.84 +        chwall_buf->chwall_running_types_offset      = ntohl(chwall_buf->chwall_running_types_offset);
   34.85 +        chwall_buf->chwall_conflict_aggregate_offset = ntohl(chwall_buf->chwall_conflict_aggregate_offset);
   34.86 +
   34.87 +	/* policy type and version checks */
   34.88 +	if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) ||
   34.89 +	    (chwall_buf->policy_version != ACM_CHWALL_VERSION))
   34.90 +		return -EINVAL;
   34.91  
   34.92  	/* 1. allocate new buffers */
   34.93  	ssids = xmalloc_array(domaintype_t, chwall_buf->chwall_max_types*chwall_buf->chwall_max_ssidrefs);
    35.1 --- a/xen/acm/acm_core.c	Tue Aug 02 02:47:41 2005 -0800
    35.2 +++ b/xen/acm/acm_core.c	Tue Aug 02 10:20:46 2005 -0700
    35.3 @@ -120,7 +120,6 @@ acm_setup(unsigned int *initrdidx,
    35.4          if (ntohl(pol->magic) == ACM_MAGIC) {
    35.5              rc = acm_set_policy((void *)_policy_start,
    35.6                                  (u16)_policy_len,
    35.7 -                                ACM_USE_SECURITY_POLICY,
    35.8                                  0);
    35.9              if (rc == ACM_OK) {
   35.10                  printf("Policy len  0x%lx, start at %p.\n",_policy_len,_policy_start);
    36.1 --- a/xen/acm/acm_policy.c	Tue Aug 02 02:47:41 2005 -0800
    36.2 +++ b/xen/acm/acm_policy.c	Tue Aug 02 10:20:46 2005 -0700
    36.3 @@ -6,9 +6,8 @@
    36.4   * Author:
    36.5   * Reiner Sailer <sailer@watson.ibm.com>
    36.6   *
    36.7 - * Contributions:
    36.8 + * Contributors:
    36.9   * Stefan Berger <stefanb@watson.ibm.com>
   36.10 - *	support for network-byte-order binary policies
   36.11   *
   36.12   * This program is free software; you can redistribute it and/or
   36.13   * modify it under the terms of the GNU General Public License as
   36.14 @@ -27,29 +26,20 @@
   36.15  #include <xen/lib.h>
   36.16  #include <xen/delay.h>
   36.17  #include <xen/sched.h>
   36.18 -#include <public/policy_ops.h>
   36.19 +#include <public/acm_ops.h>
   36.20  #include <acm/acm_core.h>
   36.21  #include <acm/acm_hooks.h>
   36.22  #include <acm/acm_endian.h>
   36.23  
   36.24  int
   36.25 -acm_set_policy(void *buf, u16 buf_size, u16 policy, int isuserbuffer)
   36.26 +acm_set_policy(void *buf, u16 buf_size, int isuserbuffer)
   36.27  {
   36.28  	u8 *policy_buffer = NULL;
   36.29  	struct acm_policy_buffer *pol;
   36.30  	
   36.31 -	if (policy != ACM_USE_SECURITY_POLICY) {
   36.32 -		printk("%s: Loading incompatible policy (running: %s).\n", __func__,
   36.33 -		       ACM_POLICY_NAME(ACM_USE_SECURITY_POLICY));
   36.34 -		return -EFAULT;
   36.35 -	}
   36.36 -	/* now check correct buffer sizes for policy combinations */
   36.37 -	if (policy == ACM_NULL_POLICY) {
   36.38 -		printkd("%s: NULL Policy, no policy needed.\n", __func__);
   36.39 -		goto out;
   36.40 -	}
   36.41       	if (buf_size < sizeof(struct acm_policy_buffer))
   36.42  		return -EFAULT;
   36.43 +
   36.44  	/* 1. copy buffer from domain */
   36.45  	if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
   36.46  	    goto error_free;
   36.47 @@ -58,17 +48,17 @@ acm_set_policy(void *buf, u16 buf_size, 
   36.48  			printk("%s: Error copying!\n",__func__);
   36.49  			goto error_free;
   36.50  		}
   36.51 -	} else {
   36.52 +	} else
   36.53  		memcpy(policy_buffer, buf, buf_size);
   36.54 -	}
   36.55 +
   36.56  	/* 2. some sanity checking */
   36.57  	pol = (struct acm_policy_buffer *)policy_buffer;
   36.58  
   36.59  	if ((ntohl(pol->magic) != ACM_MAGIC) || 
   36.60 -	    (ntohs(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
   36.61 -	    (ntohs(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code) ||
   36.62 -	    (ntohl(pol->policyversion) != POLICY_INTERFACE_VERSION)) {
   36.63 -		printkd("%s: Wrong policy magics!\n", __func__);
   36.64 +	    (ntohl(pol->policy_version) != ACM_POLICY_VERSION) ||
   36.65 +	    (ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
   36.66 +	    (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code)) {
   36.67 +		printkd("%s: Wrong policy magics or versions!\n", __func__);
   36.68  		goto error_free;
   36.69  	}
   36.70  	if (buf_size != ntohl(pol->len)) {
   36.71 @@ -79,21 +69,19 @@ acm_set_policy(void *buf, u16 buf_size, 
   36.72  	/* get bin_policy lock and rewrite policy (release old one) */
   36.73  	write_lock(&acm_bin_pol_rwlock);
   36.74  
   36.75 -	/* 3. now get/set primary policy data */
   36.76 -	if (acm_primary_ops->set_binary_policy(buf + ntohs(pol->primary_buffer_offset), 
   36.77 -                                               ntohs(pol->secondary_buffer_offset) -
   36.78 -					       ntohs(pol->primary_buffer_offset))) {
   36.79 +	/* 3. set primary policy data */
   36.80 +	if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset),
   36.81 +                                               ntohl(pol->secondary_buffer_offset) -
   36.82 +					       ntohl(pol->primary_buffer_offset))) {
   36.83  		goto error_lock_free;
   36.84  	}
   36.85 -	/* 4. now get/set secondary policy data */
   36.86 -	if (acm_secondary_ops->set_binary_policy(buf + ntohs(pol->secondary_buffer_offset),
   36.87 +	/* 4. set secondary policy data */
   36.88 +	if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset),
   36.89  						 ntohl(pol->len) - 
   36.90 -						 ntohs(pol->secondary_buffer_offset))) {
   36.91 +						 ntohl(pol->secondary_buffer_offset))) {
   36.92  		goto error_lock_free;
   36.93  	}
   36.94  	write_unlock(&acm_bin_pol_rwlock);
   36.95 - out:
   36.96 -	printk("%s: Done .\n", __func__);
   36.97  	if (policy_buffer != NULL)
   36.98  		xfree(policy_buffer);
   36.99  	return ACM_OK;
  36.100 @@ -121,26 +109,25 @@ acm_get_policy(void *buf, u16 buf_size)
  36.101       /* future: read policy from file and set it */
  36.102       bin_pol = (struct acm_policy_buffer *)policy_buffer;
  36.103       bin_pol->magic = htonl(ACM_MAGIC);
  36.104 -     bin_pol->policyversion = htonl(POLICY_INTERFACE_VERSION);
  36.105 -     bin_pol->primary_policy_code = htons(acm_bin_pol.primary_policy_code);
  36.106 -     bin_pol->secondary_policy_code = htons(acm_bin_pol.secondary_policy_code);
  36.107 +     bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  36.108 +     bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  36.109  
  36.110       bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  36.111 -     bin_pol->primary_buffer_offset = htons(ntohl(bin_pol->len));
  36.112 -     bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len));
  36.113 +     bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
  36.114 +     bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  36.115       
  36.116 -     ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohs(bin_pol->primary_buffer_offset),
  36.117 -				       buf_size - ntohs(bin_pol->primary_buffer_offset));
  36.118 +     ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset),
  36.119 +				       buf_size - ntohl(bin_pol->primary_buffer_offset));
  36.120       if (ret < 0) {
  36.121  	     printk("%s: ERROR creating chwallpolicy buffer.\n", __func__);
  36.122  	     read_unlock(&acm_bin_pol_rwlock);
  36.123  	     return -1;
  36.124       }
  36.125       bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  36.126 -     bin_pol->secondary_buffer_offset = htons(ntohl(bin_pol->len));
  36.127 +     bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  36.128  
  36.129 -     ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohs(bin_pol->secondary_buffer_offset), 
  36.130 -				    buf_size - ntohs(bin_pol->secondary_buffer_offset));
  36.131 +     ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohl(bin_pol->secondary_buffer_offset),
  36.132 +				    buf_size - ntohl(bin_pol->secondary_buffer_offset));
  36.133       if (ret < 0) {
  36.134  	     printk("%s: ERROR creating chwallpolicy buffer.\n", __func__);
  36.135  	     read_unlock(&acm_bin_pol_rwlock);
  36.136 @@ -178,11 +165,10 @@ acm_dump_statistics(void *buf, u16 buf_s
  36.137  	     goto error_lock_free;
  36.138  
  36.139       acm_stats.magic = htonl(ACM_MAGIC);
  36.140 -     acm_stats.policyversion = htonl(POLICY_INTERFACE_VERSION);
  36.141 -     acm_stats.primary_policy_code = htons(acm_bin_pol.primary_policy_code);
  36.142 -     acm_stats.secondary_policy_code = htons(acm_bin_pol.secondary_policy_code);
  36.143 -     acm_stats.primary_stats_offset = htons(sizeof(struct acm_stats_buffer));
  36.144 -     acm_stats.secondary_stats_offset = htons(sizeof(struct acm_stats_buffer) + len1);
  36.145 +     acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  36.146 +     acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  36.147 +     acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer));
  36.148 +     acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + len1);
  36.149       acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2);
  36.150       memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer));
  36.151  
    37.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c	Tue Aug 02 02:47:41 2005 -0800
    37.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c	Tue Aug 02 10:20:46 2005 -0700
    37.3 @@ -140,15 +140,15 @@ ste_dump_policy(u8 *buf, u16 buf_size) {
    37.4       struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf;
    37.5       int ret = 0;
    37.6  
    37.7 -     ste_buf->ste_max_types = htons(ste_bin_pol.max_types);
    37.8 -     ste_buf->ste_max_ssidrefs = htons(ste_bin_pol.max_ssidrefs);
    37.9 -     ste_buf->policy_code = htons(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
   37.10 -     ste_buf->ste_ssid_offset = htons(sizeof(struct acm_ste_policy_buffer));
   37.11 -     ret = ntohs(ste_buf->ste_ssid_offset) +
   37.12 +     ste_buf->ste_max_types = htonl(ste_bin_pol.max_types);
   37.13 +     ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs);
   37.14 +     ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
   37.15 +     ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer));
   37.16 +     ret = ntohl(ste_buf->ste_ssid_offset) +
   37.17  	     sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types;
   37.18  
   37.19       /* now copy buffer over */
   37.20 -     arrcpy(buf + ntohs(ste_buf->ste_ssid_offset),
   37.21 +     arrcpy(buf + ntohl(ste_buf->ste_ssid_offset),
   37.22  	    ste_bin_pol.ssidrefs,
   37.23  	    sizeof(domaintype_t),
   37.24               ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types);
   37.25 @@ -276,10 +276,16 @@ ste_set_policy(u8 *buf, u16 buf_size)
   37.26       int i;
   37.27  
   37.28       /* Convert endianess of policy */
   37.29 -     ste_buf->policy_code = ntohs(ste_buf->policy_code);
   37.30 -     ste_buf->ste_max_types = ntohs(ste_buf->ste_max_types);
   37.31 -     ste_buf->ste_max_ssidrefs = ntohs(ste_buf->ste_max_ssidrefs);
   37.32 -     ste_buf->ste_ssid_offset = ntohs(ste_buf->ste_ssid_offset);
   37.33 +     ste_buf->policy_code = ntohl(ste_buf->policy_code);
   37.34 +     ste_buf->policy_version = ntohl(ste_buf->policy_version);
   37.35 +     ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types);
   37.36 +     ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs);
   37.37 +     ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset);
   37.38 +
   37.39 +     /* policy type and version checks */
   37.40 +     if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) ||
   37.41 +	 (ste_buf->policy_version != ACM_STE_VERSION))
   37.42 +	     return -EINVAL;
   37.43  
   37.44       /* 1. create and copy-in new ssidrefs buffer */
   37.45       ssidrefsbuf = xmalloc_array(u8, sizeof(domaintype_t)*ste_buf->ste_max_types*ste_buf->ste_max_ssidrefs);
    38.1 --- a/xen/arch/x86/shadow_public.c	Tue Aug 02 02:47:41 2005 -0800
    38.2 +++ b/xen/arch/x86/shadow_public.c	Tue Aug 02 10:20:46 2005 -0700
    38.3 @@ -30,7 +30,7 @@
    38.4  #include <xen/sched.h>
    38.5  #include <xen/trace.h>
    38.6  
    38.7 -#if CONFIG_PAGING_LEVELS >= 4 
    38.8 +#if CONFIG_PAGING_LEVELS >= 3
    38.9  #include <asm/shadow_64.h>
   38.10  
   38.11  extern struct shadow_ops MODE_F_HANDLER;
   38.12 @@ -233,7 +233,20 @@ void free_monitor_pagetable(struct vcpu 
   38.13      v->arch.monitor_vtable = 0;
   38.14  }
   38.15  
   38.16 +#elif CONFIG_PAGING_LEVELS == 3
   38.17 +
   38.18 +static void alloc_monitor_pagetable(struct vcpu *v)
   38.19 +{
   38.20 +    BUG(); /* PAE not implemented yet */
   38.21 +}
   38.22 +
   38.23 +void free_monitor_pagetable(struct vcpu *v)
   38.24 +{
   38.25 +    BUG(); /* PAE not implemented yet */
   38.26 +}
   38.27 +
   38.28  #elif CONFIG_PAGING_LEVELS == 2
   38.29 +
   38.30  static void alloc_monitor_pagetable(struct vcpu *v)
   38.31  {
   38.32      unsigned long mmfn;
    39.1 --- a/xen/arch/x86/x86_32/entry.S	Tue Aug 02 02:47:41 2005 -0800
    39.2 +++ b/xen/arch/x86/x86_32/entry.S	Tue Aug 02 10:20:46 2005 -0700
    39.3 @@ -751,7 +751,7 @@ ENTRY(hypercall_table)
    39.4          .long do_boot_vcpu
    39.5          .long do_ni_hypercall       /* 25 */
    39.6          .long do_mmuext_op
    39.7 -	 .long do_policy_op          /* 27 */
    39.8 +        .long do_acm_op             /* 27 */
    39.9          .rept NR_hypercalls-((.-hypercall_table)/4)
   39.10          .long do_ni_hypercall
   39.11          .endr
    40.1 --- a/xen/arch/x86/x86_64/entry.S	Tue Aug 02 02:47:41 2005 -0800
    40.2 +++ b/xen/arch/x86/x86_64/entry.S	Tue Aug 02 10:20:46 2005 -0700
    40.3 @@ -587,7 +587,7 @@ ENTRY(hypercall_table)
    40.4          .quad do_boot_vcpu
    40.5          .quad do_set_segment_base   /* 25 */
    40.6          .quad do_mmuext_op
    40.7 -        .quad do_policy_op
    40.8 +        .quad do_acm_op
    40.9          .rept NR_hypercalls-((.-hypercall_table)/4)
   40.10          .quad do_ni_hypercall
   40.11          .endr
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/xen/common/acm_ops.c	Tue Aug 02 10:20:46 2005 -0700
    41.3 @@ -0,0 +1,127 @@
    41.4 +/******************************************************************************
    41.5 + * acm_ops.c
    41.6 + *
    41.7 + * Copyright (C) 2005 IBM Corporation
    41.8 + *
    41.9 + * Author:
   41.10 + * Reiner Sailer <sailer@watson.ibm.com>
   41.11 + *
   41.12 + * This program is free software; you can redistribute it and/or
   41.13 + * modify it under the terms of the GNU General Public License as
   41.14 + * published by the Free Software Foundation, version 2 of the
   41.15 + * License.
   41.16 + *
   41.17 + * Process acm command requests from guest OS.
   41.18 + *
   41.19 + */
   41.20 +
   41.21 +#include <xen/config.h>
   41.22 +#include <xen/types.h>
   41.23 +#include <xen/lib.h>
   41.24 +#include <xen/mm.h>
   41.25 +#include <public/acm_ops.h>
   41.26 +#include <xen/sched.h>
   41.27 +#include <xen/event.h>
   41.28 +#include <xen/trace.h>
   41.29 +#include <xen/console.h>
   41.30 +#include <asm/shadow.h>
   41.31 +#include <public/sched_ctl.h>
   41.32 +#include <acm/acm_hooks.h>
   41.33 +
   41.34 +#if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY)
   41.35 +
   41.36 +long do_acm_op(acm_op_t * u_acm_op)
   41.37 +{
   41.38 +    return -ENOSYS;
   41.39 +}
   41.40 +
   41.41 +#else
   41.42 +
   41.43 +typedef enum acm_operation {
   41.44 +    POLICY,                     /* access to policy interface (early drop) */
   41.45 +    GETPOLICY,                  /* dump policy cache */
   41.46 +    SETPOLICY,                  /* set policy cache (controls security) */
   41.47 +    DUMPSTATS                   /* dump policy statistics */
   41.48 +} acm_operation_t;
   41.49 +
   41.50 +int acm_authorize_acm_ops(struct domain *d, acm_operation_t pops)
   41.51 +{
   41.52 +    /* all policy management functions are restricted to privileged domains,
   41.53 +     * soon we will introduce finer-grained privileges for policy operations
   41.54 +     */
   41.55 +    if (!IS_PRIV(d))
   41.56 +    {
   41.57 +        printk("%s: ACM management authorization denied ERROR!\n", __func__);
   41.58 +        return ACM_ACCESS_DENIED;
   41.59 +    }
   41.60 +    return ACM_ACCESS_PERMITTED;
   41.61 +}
   41.62 +
   41.63 +long do_acm_op(acm_op_t * u_acm_op)
   41.64 +{
   41.65 +    long ret = 0;
   41.66 +    acm_op_t curop, *op = &curop;
   41.67 +
   41.68 +    /* check here policy decision for policy commands */
   41.69 +    /* for now allow DOM0 only, later indepedently    */
   41.70 +    if (acm_authorize_acm_ops(current->domain, POLICY))
   41.71 +        return -EACCES;
   41.72 +
   41.73 +    if (copy_from_user(op, u_acm_op, sizeof(*op)))
   41.74 +        return -EFAULT;
   41.75 +
   41.76 +    if (op->interface_version != ACM_INTERFACE_VERSION)
   41.77 +        return -EACCES;
   41.78 +
   41.79 +    switch (op->cmd)
   41.80 +    {
   41.81 +    case ACM_SETPOLICY:
   41.82 +        {
   41.83 +            if (acm_authorize_acm_ops(current->domain, SETPOLICY))
   41.84 +                return -EACCES;
   41.85 +            printkd("%s: setting policy.\n", __func__);
   41.86 +            ret = acm_set_policy(op->u.setpolicy.pushcache,
   41.87 +                                 op->u.setpolicy.pushcache_size, 1);
   41.88 +            if (ret == ACM_OK)
   41.89 +                ret = 0;
   41.90 +            else
   41.91 +                ret = -ESRCH;
   41.92 +        }
   41.93 +        break;
   41.94 +
   41.95 +    case ACM_GETPOLICY:
   41.96 +        {
   41.97 +            if (acm_authorize_acm_ops(current->domain, GETPOLICY))
   41.98 +                return -EACCES;
   41.99 +            printkd("%s: getting policy.\n", __func__);
  41.100 +            ret = acm_get_policy(op->u.getpolicy.pullcache,
  41.101 +                                 op->u.getpolicy.pullcache_size);
  41.102 +            if (ret == ACM_OK)
  41.103 +                ret = 0;
  41.104 +            else
  41.105 +                ret = -ESRCH;
  41.106 +        }
  41.107 +        break;
  41.108 +
  41.109 +    case ACM_DUMPSTATS:
  41.110 +        {
  41.111 +            if (acm_authorize_acm_ops(current->domain, DUMPSTATS))
  41.112 +                return -EACCES;
  41.113 +            printkd("%s: dumping statistics.\n", __func__);
  41.114 +            ret = acm_dump_statistics(op->u.dumpstats.pullcache,
  41.115 +                                      op->u.dumpstats.pullcache_size);
  41.116 +            if (ret == ACM_OK)
  41.117 +                ret = 0;
  41.118 +            else
  41.119 +                ret = -ESRCH;
  41.120 +        }
  41.121 +        break;
  41.122 +
  41.123 +    default:
  41.124 +        ret = -ESRCH;
  41.125 +
  41.126 +    }
  41.127 +    return ret;
  41.128 +}
  41.129 +
  41.130 +#endif
    42.1 --- a/xen/common/policy_ops.c	Tue Aug 02 02:47:41 2005 -0800
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,133 +0,0 @@
    42.4 -/******************************************************************************
    42.5 - * policy_ops.c
    42.6 - * 
    42.7 - * Copyright (C) 2005 IBM Corporation
    42.8 - *
    42.9 - * Author:
   42.10 - * Reiner Sailer <sailer@watson.ibm.com>
   42.11 - *
   42.12 - * This program is free software; you can redistribute it and/or
   42.13 - * modify it under the terms of the GNU General Public License as
   42.14 - * published by the Free Software Foundation, version 2 of the
   42.15 - * License.
   42.16 - *
   42.17 - * Process policy command requests from guest OS.
   42.18 - *
   42.19 - */
   42.20 -
   42.21 -#include <xen/config.h>
   42.22 -#include <xen/types.h>
   42.23 -#include <xen/lib.h>
   42.24 -#include <xen/mm.h>
   42.25 -#include <public/policy_ops.h>
   42.26 -#include <xen/sched.h>
   42.27 -#include <xen/event.h>
   42.28 -#include <xen/trace.h>
   42.29 -#include <xen/console.h>
   42.30 -#include <asm/shadow.h>
   42.31 -#include <public/sched_ctl.h>
   42.32 -#include <acm/acm_hooks.h>
   42.33 -
   42.34 -#if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY)
   42.35 -
   42.36 -long do_policy_op(policy_op_t *u_policy_op)
   42.37 -{
   42.38 -    return -ENOSYS;
   42.39 -}
   42.40 -
   42.41 -#else
   42.42 -
   42.43 -typedef enum policyoperation {
   42.44 -    POLICY,     /* access to policy interface (early drop) */
   42.45 -    GETPOLICY,  /* dump policy cache */
   42.46 -    SETPOLICY,  /* set policy cache (controls security) */
   42.47 -    DUMPSTATS   /* dump policy statistics */
   42.48 -} policyoperation_t;
   42.49 -
   42.50 -int
   42.51 -acm_authorize_policyops(struct domain *d, policyoperation_t pops)
   42.52 -{
   42.53 -    /* all policy management functions are restricted to privileged domains,
   42.54 -     * soon we will introduce finer-grained privileges for policy operations 
   42.55 -     */
   42.56 -    if (!IS_PRIV(d)) {
   42.57 -        printk("%s: Policy management authorization denied ERROR!\n",
   42.58 -               __func__);
   42.59 -        return ACM_ACCESS_DENIED;
   42.60 -    }
   42.61 -    return ACM_ACCESS_PERMITTED;
   42.62 -}
   42.63 -
   42.64 -long do_policy_op(policy_op_t *u_policy_op)
   42.65 -{
   42.66 -    long ret = 0;
   42.67 -    policy_op_t curop, *op = &curop;
   42.68 -
   42.69 -    /* check here policy decision for policy commands */
   42.70 -    /* for now allow DOM0 only, later indepedently    */
   42.71 -    if (acm_authorize_policyops(current->domain, POLICY))
   42.72 -        return -EACCES;
   42.73 -
   42.74 -    if ( copy_from_user(op, u_policy_op, sizeof(*op)) )
   42.75 -        return -EFAULT;
   42.76 -
   42.77 -    if ( op->interface_version != POLICY_INTERFACE_VERSION )
   42.78 -        return -EACCES;
   42.79 -
   42.80 -    switch ( op->cmd )
   42.81 -    {
   42.82 -    case POLICY_SETPOLICY:
   42.83 -    {
   42.84 -        if (acm_authorize_policyops(current->domain, SETPOLICY))
   42.85 -            return -EACCES;
   42.86 -        printkd("%s: setting policy.\n", __func__);
   42.87 -        ret = acm_set_policy(
   42.88 -            op->u.setpolicy.pushcache, 
   42.89 -            op->u.setpolicy.pushcache_size, 
   42.90 -            op->u.setpolicy.policy_type,
   42.91 -            1);
   42.92 -        if (ret == ACM_OK)
   42.93 -            ret = 0;
   42.94 -        else
   42.95 -            ret = -ESRCH;
   42.96 -    }
   42.97 -    break;
   42.98 -
   42.99 -    case POLICY_GETPOLICY:
  42.100 -    {
  42.101 -        if (acm_authorize_policyops(current->domain, GETPOLICY))
  42.102 -            return -EACCES;
  42.103 -        printkd("%s: getting policy.\n", __func__);
  42.104 -        ret = acm_get_policy(
  42.105 -            op->u.getpolicy.pullcache, 
  42.106 -            op->u.getpolicy.pullcache_size);
  42.107 -        if (ret == ACM_OK)
  42.108 -            ret = 0;
  42.109 -        else
  42.110 -            ret = -ESRCH;
  42.111 -    }
  42.112 -    break;
  42.113 -
  42.114 -    case POLICY_DUMPSTATS:
  42.115 -    {
  42.116 -        if (acm_authorize_policyops(current->domain, DUMPSTATS))
  42.117 -            return -EACCES;
  42.118 -        printkd("%s: dumping statistics.\n", __func__);
  42.119 -        ret = acm_dump_statistics(
  42.120 -            op->u.dumpstats.pullcache, 
  42.121 -            op->u.dumpstats.pullcache_size);
  42.122 -        if (ret == ACM_OK)
  42.123 -            ret = 0;
  42.124 -        else
  42.125 -            ret = -ESRCH;
  42.126 -    }
  42.127 -    break;
  42.128 -
  42.129 -    default:
  42.130 -        ret = -ESRCH;
  42.131 -
  42.132 -    }
  42.133 -    return ret;
  42.134 -}
  42.135 -
  42.136 -#endif
    43.1 --- a/xen/include/acm/acm_core.h	Tue Aug 02 02:47:41 2005 -0800
    43.2 +++ b/xen/include/acm/acm_core.h	Tue Aug 02 10:20:46 2005 -0700
    43.3 @@ -21,7 +21,7 @@
    43.4  #include <xen/spinlock.h>
    43.5  #include <public/acm.h>
    43.6  #include <xen/acm_policy.h>
    43.7 -#include <public/policy_ops.h>
    43.8 +#include <public/acm_ops.h>
    43.9  
   43.10  /* Xen-internal representation of the binary policy */
   43.11  struct acm_binary_policy {
   43.12 @@ -113,7 +113,7 @@ struct ste_ssid {
   43.13  /* protos */
   43.14  int acm_init_domain_ssid(domid_t id, ssidref_t ssidref);
   43.15  int acm_free_domain_ssid(struct acm_ssid_domain *ssid);
   43.16 -int acm_set_policy(void *buf, u16 buf_size, u16 policy, int isuserbuffer);
   43.17 +int acm_set_policy(void *buf, u16 buf_size, int isuserbuffer);
   43.18  int acm_get_policy(void *buf, u16 buf_size);
   43.19  int acm_dump_statistics(void *buf, u16 buf_size);
   43.20  
    44.1 --- a/xen/include/public/acm.h	Tue Aug 02 02:47:41 2005 -0800
    44.2 +++ b/xen/include/public/acm.h	Tue Aug 02 10:20:46 2005 -0700
    44.3 @@ -71,6 +71,14 @@
    44.4  	(X == ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY) ? "CHINESE WALL AND SIMPLE TYPE ENFORCEMENT policy" : \
    44.5  	"UNDEFINED policy"
    44.6  
    44.7 +/* the following policy versions must be increased
    44.8 + * whenever the interpretation of the related
    44.9 + * policy's data structure changes
   44.10 + */
   44.11 +#define ACM_POLICY_VERSION	1
   44.12 +#define ACM_CHWALL_VERSION	1
   44.13 +#define ACM_STE_VERSION		1
   44.14 +
   44.15  /* defines a ssid reference used by xen */
   44.16  typedef u32 ssidref_t;
   44.17  
   44.18 @@ -102,46 +110,53 @@ typedef u16 domaintype_t;
   44.19  #define ACM_MAGIC		0x0001debc
   44.20  
   44.21  /* each offset in bytes from start of the struct they
   44.22 - *   the are part of */
   44.23 + * are part of */
   44.24 +
   44.25  /* each buffer consists of all policy information for
   44.26   * the respective policy given in the policy code
   44.27 + *
   44.28 + * acm_policy_buffer, acm_chwall_policy_buffer,
   44.29 + * and acm_ste_policy_buffer need to stay 32-bit aligned
   44.30 + * because we create binary policies also with external
   44.31 + * tools that assume packed representations (e.g. the java tool)
   44.32   */
   44.33  struct acm_policy_buffer {
   44.34 +	u32 policy_version; /* ACM_POLICY_VERSION */
   44.35          u32 magic;
   44.36 -	u32 policyversion;
   44.37  	u32 len;
   44.38 -	u16 primary_policy_code;
   44.39 -	u16 primary_buffer_offset;
   44.40 -	u16 secondary_policy_code;
   44.41 -	u16 secondary_buffer_offset;
   44.42 +	u32 primary_policy_code;
   44.43 +	u32 primary_buffer_offset;
   44.44 +	u32 secondary_policy_code;
   44.45 +	u32 secondary_buffer_offset;
   44.46  };
   44.47  
   44.48  struct acm_chwall_policy_buffer {
   44.49 -	u16 policy_code;
   44.50 -	u16 chwall_max_types;
   44.51 -	u16 chwall_max_ssidrefs;
   44.52 -	u16 chwall_max_conflictsets;
   44.53 -	u16 chwall_ssid_offset;
   44.54 -	u16 chwall_conflict_sets_offset;
   44.55 -	u16 chwall_running_types_offset;
   44.56 -	u16 chwall_conflict_aggregate_offset;
   44.57 +	u32 policy_version; /* ACM_CHWALL_VERSION */
   44.58 +	u32 policy_code;
   44.59 +	u32 chwall_max_types;
   44.60 +	u32 chwall_max_ssidrefs;
   44.61 +	u32 chwall_max_conflictsets;
   44.62 +	u32 chwall_ssid_offset;
   44.63 +	u32 chwall_conflict_sets_offset;
   44.64 +	u32 chwall_running_types_offset;
   44.65 +	u32 chwall_conflict_aggregate_offset;
   44.66  };
   44.67  
   44.68  struct acm_ste_policy_buffer {
   44.69 -	u16 policy_code;
   44.70 -	u16 ste_max_types;
   44.71 -	u16 ste_max_ssidrefs;
   44.72 -	u16 ste_ssid_offset;
   44.73 +	u32 policy_version; /* ACM_STE_VERSION */
   44.74 +	u32 policy_code;
   44.75 +	u32 ste_max_types;
   44.76 +	u32 ste_max_ssidrefs;
   44.77 +	u32 ste_ssid_offset;
   44.78  };
   44.79  
   44.80  struct acm_stats_buffer {
   44.81          u32 magic;
   44.82 -	u32 policyversion;
   44.83  	u32 len;
   44.84 -	u16 primary_policy_code;
   44.85 -	u16 primary_stats_offset;
   44.86 -	u16 secondary_policy_code;
   44.87 -	u16 secondary_stats_offset;
   44.88 +	u32 primary_policy_code;
   44.89 +	u32 primary_stats_offset;
   44.90 +	u32 secondary_policy_code;
   44.91 +	u32 secondary_stats_offset;
   44.92  };
   44.93  
   44.94  struct acm_ste_stats_buffer {
    45.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    45.2 +++ b/xen/include/public/acm_ops.h	Tue Aug 02 10:20:46 2005 -0700
    45.3 @@ -0,0 +1,66 @@
    45.4 +/******************************************************************************
    45.5 + * acm_ops.h
    45.6 + *
    45.7 + * Copyright (C) 2005 IBM Corporation
    45.8 + *
    45.9 + * Author:
   45.10 + * Reiner Sailer <sailer@watson.ibm.com>
   45.11 + *
   45.12 + * This program is free software; you can redistribute it and/or
   45.13 + * modify it under the terms of the GNU General Public License as
   45.14 + * published by the Free Software Foundation, version 2 of the
   45.15 + * License.
   45.16 + *
   45.17 + * Process acm policy command requests from guest OS.
   45.18 + * access checked by policy; not restricted to DOM0
   45.19 + *
   45.20 + */
   45.21 +
   45.22 +#ifndef __XEN_PUBLIC_ACM_OPS_H__
   45.23 +#define __XEN_PUBLIC_ACM_OPS_H__
   45.24 +
   45.25 +#include "xen.h"
   45.26 +#include "sched_ctl.h"
   45.27 +
   45.28 +/*
   45.29 + * Make sure you increment the interface version whenever you modify this file!
   45.30 + * This makes sure that old versions of acm tools will stop working in a
   45.31 + * well-defined way (rather than crashing the machine, for instance).
   45.32 + */
   45.33 +#define ACM_INTERFACE_VERSION   0xAAAA0003
   45.34 +
   45.35 +/************************************************************************/
   45.36 +
   45.37 +#define ACM_SETPOLICY        	4
   45.38 +typedef struct acm_setpolicy {
   45.39 +    /* OUT variables */
   45.40 +    void *pushcache;
   45.41 +    u16 pushcache_size;
   45.42 +} acm_setpolicy_t;
   45.43 +
   45.44 +
   45.45 +#define ACM_GETPOLICY        	5
   45.46 +typedef struct acm_getpolicy {
   45.47 +    /* OUT variables */
   45.48 +    void *pullcache;
   45.49 +    u16 pullcache_size;
   45.50 +} acm_getpolicy_t;
   45.51 +
   45.52 +#define ACM_DUMPSTATS        	6
   45.53 +typedef struct acm_dumpstats {
   45.54 +    void *pullcache;
   45.55 +    u16 pullcache_size;
   45.56 +} acm_dumpstats_t;
   45.57 +
   45.58 +
   45.59 +typedef struct acm_op {
   45.60 +    u32 cmd;
   45.61 +    u32 interface_version;      /* ACM_INTERFACE_VERSION */
   45.62 +    union {
   45.63 +        acm_setpolicy_t setpolicy;
   45.64 +        acm_getpolicy_t getpolicy;
   45.65 +        acm_dumpstats_t dumpstats;
   45.66 +    } u;
   45.67 +} acm_op_t;
   45.68 +
   45.69 +#endif                          /* __XEN_PUBLIC_ACM_OPS_H__ */
    46.1 --- a/xen/include/public/policy_ops.h	Tue Aug 02 02:47:41 2005 -0800
    46.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    46.3 @@ -1,70 +0,0 @@
    46.4 -/******************************************************************************
    46.5 - * policy_ops.h
    46.6 - * 
    46.7 - * Copyright (C) 2005 IBM Corporation
    46.8 - *
    46.9 - * Author:
   46.10 - * Reiner Sailer <sailer@watson.ibm.com>
   46.11 - *
   46.12 - * This program is free software; you can redistribute it and/or
   46.13 - * modify it under the terms of the GNU General Public License as
   46.14 - * published by the Free Software Foundation, version 2 of the
   46.15 - * License. 
   46.16 - *
   46.17 - * Process policy command requests from guest OS.
   46.18 - * access checked by policy; not restricted to DOM0
   46.19 - * 
   46.20 - */
   46.21 -
   46.22 -#ifndef __XEN_PUBLIC_POLICY_OPS_H__
   46.23 -#define __XEN_PUBLIC_POLICY_OPS_H__
   46.24 -
   46.25 -#include "xen.h"
   46.26 -#include "sched_ctl.h"
   46.27 -
   46.28 -/*
   46.29 - * Make sure you increment the interface version whenever you modify this file!
   46.30 - * This makes sure that old versions of policy tools will stop working in a
   46.31 - * well-defined way (rather than crashing the machine, for instance).
   46.32 - */
   46.33 -#define POLICY_INTERFACE_VERSION   0xAAAA0003
   46.34 -
   46.35 -/************************************************************************/
   46.36 -
   46.37 -#define POLICY_SETPOLICY        	4
   46.38 -typedef struct policy_setpolicy {
   46.39 -    /* IN variables. */
   46.40 -    u16           policy_type;
   46.41 -    /* OUT variables */
   46.42 -    void  	  *pushcache;
   46.43 -    u16           pushcache_size;
   46.44 -} policy_setpolicy_t;          
   46.45 -
   46.46 -
   46.47 -#define POLICY_GETPOLICY        	5
   46.48 -typedef struct policy_getpolicy {
   46.49 -    /* IN variables. */
   46.50 -    u16           policy_type;
   46.51 -    /* OUT variables */
   46.52 -    void  	  *pullcache;
   46.53 -    u16           pullcache_size;
   46.54 -} policy_getpolicy_t;       
   46.55 -
   46.56 -#define POLICY_DUMPSTATS        	6
   46.57 -typedef struct policy_dumpstats {
   46.58 -    void  	  *pullcache;
   46.59 -    u16           pullcache_size;
   46.60 -} policy_dumpstats_t;            
   46.61 - 
   46.62 -
   46.63 -typedef struct policy_op {
   46.64 -    u32 cmd;
   46.65 -    u32 interface_version;       /* POLICY_INTERFACE_VERSION */
   46.66 -    union {
   46.67 -	policy_setpolicy_t       setpolicy;
   46.68 -        policy_getpolicy_t       getpolicy;
   46.69 -	policy_dumpstats_t	 dumpstats;
   46.70 -    } u;
   46.71 -} policy_op_t;
   46.72 -
   46.73 -#endif /* __XEN_PUBLIC_POLICY_OPS_H__ */
    47.1 --- a/xen/include/public/xen.h	Tue Aug 02 02:47:41 2005 -0800
    47.2 +++ b/xen/include/public/xen.h	Tue Aug 02 10:20:46 2005 -0700
    47.3 @@ -58,7 +58,7 @@
    47.4  #define __HYPERVISOR_boot_vcpu            24
    47.5  #define __HYPERVISOR_set_segment_base     25 /* x86/64 only */
    47.6  #define __HYPERVISOR_mmuext_op            26
    47.7 -#define __HYPERVISOR_policy_op            27
    47.8 +#define __HYPERVISOR_acm_op               27
    47.9  
   47.10  /* 
   47.11   * VIRTUAL INTERRUPTS