debuggers.hg

changeset 634:681598b3259f

bitkeeper revision 1.331 (3f0d4822DGZPrG8hjrH_59XaPHWQGA)

Merge labyrinth.cl.cam.ac.uk:/auto/groups/xeno/users/rac61/xeno.bk
into labyrinth.cl.cam.ac.uk:/auto/groups/xeno/users/sos22/xeno.bk
author sos22@labyrinth.cl.cam.ac.uk
date Thu Jul 10 11:04:02 2003 +0000 (2003-07-10)
parents 11399488a825 884c96cebace
children 6e6c86f3a177 f33864f401d8
files tools/internal/xi_build.c xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_segment_proc.c xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c
line diff
     1.1 --- a/tools/internal/xi_build.c	Thu Jul 10 10:17:15 2003 +0000
     1.2 +++ b/tools/internal/xi_build.c	Thu Jul 10 11:04:02 2003 +0000
     1.3 @@ -24,6 +24,10 @@
     1.4  #define GUEST_SIG   "XenoGues"
     1.5  #define SIG_LEN    8
     1.6  
     1.7 +/* Watch for precedence when using thses ones... */
     1.8 +#define PROC_XENO_DOM0_CMD "/proc/" PROC_XENO_ROOT "/" PROC_CMD
     1.9 +#define PROC_XENO_DOMAINS "/proc" PROC_XENO_ROOT "/" PROC_DOMAINS
    1.10 +
    1.11  /*
    1.12   * NB. No ring-3 access in initial guestOS pagetables. Note that we allow
    1.13   * ring-3 privileges in the page directories, so that the guestOS may later
    1.14 @@ -53,7 +57,8 @@ static void dom_mem_cleanup(dom_mem_t * 
    1.15  	    
    1.16      fd = open("/proc/xeno/dom0_cmd", O_WRONLY);
    1.17      if(fd < 0){
    1.18 -        perror(PERR_STRING);
    1.19 +        perror("openning /proc/xeno/dom0_cmd");
    1.20 +	return;
    1.21      }
    1.22      
    1.23      argbuf.vaddr = dom_mem->vaddr;
    1.24 @@ -90,62 +95,46 @@ static int map_dom_mem(unsigned long pfn
    1.25      
    1.26      if (dom_mem->vaddr == -1) {
    1.27          perror("mapping domain memory");
    1.28 +	close(fd);
    1.29  	return -1;
    1.30      }
    1.31 +    close(fd);
    1.32  
    1.33      return 0;
    1.34  }
    1.35  
    1.36 -/* open kernel image and do some sanity checks */
    1.37 -static int do_kernel_chcks(char *image, long dom_size, 
    1.38 -                           unsigned long * load_addr, size_t * ksize)
    1.39 +/* read the kernel header, extracting the image size and load address. */
    1.40 +static int read_kernel_header(int fd, long dom_size, 
    1.41 +			      unsigned long * load_addr, size_t * ksize)
    1.42  {
    1.43      char signature[8];
    1.44      char status[MAX_PATH];
    1.45      struct stat stat;
    1.46 -    int fd;
    1.47 -    int ret; 
    1.48      
    1.49 -    fd = open(image, O_RDONLY);
    1.50 -    if(fd < 0){
    1.51 -        perror(PERR_STRING);
    1.52 -        ret = -1;    
    1.53 -        goto out;
    1.54 -    }
    1.55 -
    1.56      if(fstat(fd, &stat) < 0){
    1.57          perror(PERR_STRING);
    1.58 -        ret = -1;
    1.59 -        close(fd);
    1.60 -        goto out;
    1.61 +	return -1;
    1.62      }
    1.63  
    1.64      if(stat.st_size > (dom_size << 10)){
    1.65          sprintf(status, "Kernel image size %ld larger than requested "
    1.66                  "domain size %ld\n Terminated.\n", stat.st_size, dom_size);
    1.67          dberr(status);
    1.68 -        ret = -1;
    1.69 -        close(fd);
    1.70 -        goto out;
    1.71 +	return -1;
    1.72      }
    1.73      
    1.74      read(fd, signature, SIG_LEN);
    1.75      if(strncmp(signature, GUEST_SIG, SIG_LEN)){
    1.76          dberr("Kernel image does not contain required signature. "
    1.77                "Terminating.\n");
    1.78 -        ret = -1;
    1.79 -        close(fd);
    1.80 -        goto out;
    1.81 +	return -1;
    1.82      }
    1.83  
    1.84      read(fd, load_addr, sizeof(unsigned long));
    1.85  
    1.86      *ksize = stat.st_size - SIG_LEN - sizeof(unsigned long);
    1.87  
    1.88 -    ret = fd;
    1.89 -
    1.90 - out:    
    1.91 -    return ret;
    1.92 +    return 0;
    1.93  }
    1.94  
    1.95  /* this is the main guestos setup function,
    1.96 @@ -159,21 +148,24 @@ static int do_kernel_chcks(char *image, 
    1.97  static dom_meminfo_t *setup_guestos(int dom, int kernel_fd, int initrd_fd,
    1.98                                      unsigned long virt_load_addr, size_t ksize, dom_mem_t *dom_mem)
    1.99  {
   1.100 -    dom_meminfo_t *meminfo;
   1.101 -    unsigned long *page_array;
   1.102 -    page_update_request_t *pgt_updates;
   1.103 -    dom_meminfo_t *ret = NULL;
   1.104 +    dom_meminfo_t *meminfo = NULL;
   1.105 +    unsigned long *page_array = NULL;
   1.106 +    page_update_request_t *pgt_updates = NULL;
   1.107      int alloc_index, num_pt_pages;
   1.108      unsigned long l2tab;
   1.109      unsigned long l1tab = 0;
   1.110      unsigned long num_pgt_updates = 0;
   1.111      unsigned long count, pt_start;
   1.112      struct dom0_dopgupdates_args pgupdate_req;
   1.113 -    char cmd_path[MAX_PATH];
   1.114      int cmd_fd;
   1.115 +    int result;
   1.116  
   1.117      meminfo     = (dom_meminfo_t *)malloc(sizeof(dom_meminfo_t));
   1.118      page_array  = malloc(dom_mem->tot_pages * 4);
   1.119 +    if (!meminfo || !page_array) {
   1.120 +	dberr ("Could not allocate memory");
   1.121 +	goto error_out;
   1.122 +    }
   1.123      pgt_updates = (page_update_request_t *)dom_mem->vaddr;
   1.124      alloc_index = dom_mem->tot_pages - 1;
   1.125  
   1.126 @@ -264,42 +256,51 @@ static dom_meminfo_t *setup_guestos(int 
   1.127      meminfo->virt_startinfo_addr = virt_load_addr + nr_2_page(alloc_index - 1);
   1.128      meminfo->domain = dom;
   1.129  
   1.130 +    free(page_array);
   1.131 +
   1.132      /*
   1.133       * Send the page update requests down to the hypervisor.
   1.134       * NB. We must do this before loading the guest OS image!
   1.135       */
   1.136 -    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   1.137 -    if ( (cmd_fd = open(cmd_path, O_WRONLY)) < 0 ) goto out;
   1.138 +    if ( (cmd_fd = open(PROC_XENO_DOM0_CMD, O_WRONLY)) < 0 )
   1.139 +    {
   1.140 +	dberr ("Could not open " PROC_XENO_DOM0_CMD);
   1.141 +	goto error_out;
   1.142 +    }
   1.143 +
   1.144      pgupdate_req.pgt_update_arr  = (unsigned long)dom_mem->vaddr;
   1.145      pgupdate_req.num_pgt_updates = num_pgt_updates;
   1.146 -    if (ioctl(cmd_fd, IOCTL_DOM0_DOPGUPDATES, &pgupdate_req) < 0) goto out;
   1.147 +    result = ioctl(cmd_fd, IOCTL_DOM0_DOPGUPDATES, &pgupdate_req);
   1.148      close(cmd_fd);
   1.149 +    if (result < 0) {
   1.150 +	dberr ("Could not build domain page tables.");
   1.151 +	goto error_out;
   1.152 +    }
   1.153  
   1.154      /* Load the guest OS image. */
   1.155      if( read(kernel_fd, (char *)dom_mem->vaddr, ksize) != ksize )
   1.156      {
   1.157          dberr("Error reading kernel image, could not"
   1.158 -              " read the whole image. Terminating.\n");
   1.159 -        goto out;
   1.160 +              " read the whole image.");
   1.161 +	goto error_out;
   1.162      }
   1.163  
   1.164 -    if( initrd_fd )
   1.165 +    if( initrd_fd >= 0)
   1.166      {
   1.167  	struct stat stat;
   1.168  	unsigned long isize;
   1.169  
   1.170  	if(fstat(initrd_fd, &stat) < 0){
   1.171              perror(PERR_STRING);
   1.172 -            close(initrd_fd);
   1.173 -            goto out;
   1.174 +            goto error_out;
   1.175  	}
   1.176  	isize = stat.st_size;
   1.177  
   1.178  	if( read(initrd_fd, ((char *)dom_mem->vaddr)+ksize, isize) != isize )
   1.179          {
   1.180  	    dberr("Error reading initrd image, could not"
   1.181 -		  " read the whole image. Terminating.\n");
   1.182 -	    goto out;
   1.183 +		  " read the whole image. Terminating.");
   1.184 +	    goto error_out;
   1.185          }
   1.186  
   1.187  	meminfo->virt_mod_addr = virt_load_addr + ksize;
   1.188 @@ -308,20 +309,23 @@ static dom_meminfo_t *setup_guestos(int 
   1.189      }
   1.190  
   1.191  
   1.192 -    ret = meminfo;
   1.193 - out:
   1.194 +    return meminfo;
   1.195  
   1.196 -    return ret;
   1.197 + error_out:
   1.198 +    if (meminfo)
   1.199 +	free(meminfo);
   1.200 +    if (page_array)
   1.201 +	free(page_array);
   1.202 +
   1.203 +    return NULL;
   1.204  }
   1.205  
   1.206  static int launch_domain(dom_meminfo_t  * meminfo)
   1.207  {
   1.208 -    char cmd_path[MAX_PATH];
   1.209      dom0_op_t dop;
   1.210      int cmd_fd;
   1.211  
   1.212 -    sprintf(cmd_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_CMD);
   1.213 -    cmd_fd = open(cmd_path, O_WRONLY);
   1.214 +    cmd_fd = open(PROC_XENO_DOM0_CMD, O_WRONLY);
   1.215      if(cmd_fd < 0){
   1.216          perror(PERR_STRING);
   1.217          return -1;
   1.218 @@ -340,39 +344,37 @@ static int get_domain_info (int domain_i
   1.219                              int *tot_pages)
   1.220  {
   1.221      FILE *f; 
   1.222 -    char domains_path[MAX_PATH];
   1.223      char domains_line[256];
   1.224 -    int rc = -1;
   1.225      int read_id;
   1.226  
   1.227 -    sprintf (domains_path, "%s%s%s%s", "/proc/", PROC_XENO_ROOT, "/", PROC_DOMAINS
   1.228 -        );
   1.229 -
   1.230 -    f = fopen (domains_path, "r");
   1.231 -    if (f == NULL) goto out;
   1.232 +    f = fopen (PROC_XENO_DOMAINS, "r");
   1.233 +    if (f == NULL) return -1;
   1.234  
   1.235      read_id = -1;
   1.236      while (fgets (domains_line, 256, f) != 0)
   1.237      { 
   1.238          int trans;
   1.239 +	read_id = -1;
   1.240          trans = sscanf (domains_line, "%d %*d %*d %*d %*d %*d %x %d %*s", &read_id
   1.241                          , pg_head, tot_pages);
   1.242 -        if (trans == 3) {
   1.243 -            if (read_id == domain_id) {
   1.244 -                rc = 0;
   1.245 -                break;
   1.246 -            }
   1.247 +	if (trans != 3) {
   1.248 +	    dberr ("format of " PROC_XENO_DOMAINS " changed -- wrong kernel version?");
   1.249 +	    read_id = -1;
   1.250 +	    break;
   1.251 +	}
   1.252 +
   1.253 +        if (read_id == domain_id) {
   1.254 +	    break;
   1.255          }
   1.256      }
   1.257  
   1.258 +    fclose (f);
   1.259 +
   1.260      if (read_id == -1) {
   1.261          errno = ESRCH;
   1.262      }
   1.263  
   1.264 -    fclose (f);
   1.265 -
   1.266 - out:
   1.267 -    return rc;
   1.268 +    return 0;
   1.269  }
   1.270  
   1.271  
   1.272 @@ -383,15 +385,15 @@ int main(int argc, char **argv)
   1.273      dom_meminfo_t * meminfo;
   1.274      size_t ksize;
   1.275      unsigned long load_addr;
   1.276 -    int kernel_fd, initrd_fd = 0;
   1.277 +    int kernel_fd, initrd_fd = -1;
   1.278      int count;
   1.279      int cmd_len;
   1.280 -    int rc = -1;
   1.281      int args_start = 4;
   1.282      char initrd_name[1024];
   1.283      int domain_id;
   1.284      int pg_head;
   1.285      int tot_pages;
   1.286 +    int rc;
   1.287  
   1.288      /**** this argument parsing code is really _gross_. rewrite me! ****/
   1.289  
   1.290 @@ -406,21 +408,26 @@ int main(int argc, char **argv)
   1.291      if ( get_domain_info (domain_id, &pg_head, &tot_pages) != 0 ) 
   1.292      {
   1.293          perror ("Could not find domain information");
   1.294 -        rc = -1;
   1.295 -        goto out;
   1.296 +	return -1;
   1.297      }
   1.298  	     
   1.299 -    kernel_fd = do_kernel_chcks(argv[2], 
   1.300 -                                tot_pages << (PAGE_SHIFT - 10), 
   1.301 -                                &load_addr, &ksize);
   1.302 -    if ( kernel_fd < 0 )
   1.303 +    kernel_fd = open(argv[2], O_RDONLY);
   1.304 +    if (kernel_fd < 0) {
   1.305 +        perror ("Could not open kernel image");
   1.306 +	return -1;
   1.307 +    }
   1.308 +
   1.309 +    rc = read_kernel_header(kernel_fd,
   1.310 +			    tot_pages << (PAGE_SHIFT - 10), 
   1.311 +			    &load_addr, &ksize);
   1.312 +    if ( rc < 0 )
   1.313  	return -1;
   1.314      
   1.315  
   1.316      /* map domain's memory */
   1.317      if ( map_dom_mem(pg_head, tot_pages,
   1.318                       domain_id, &dom_os_image) )
   1.319 -        goto out;
   1.320 +	return -1;
   1.321  
   1.322      if( (argc > args_start) && 
   1.323          (strncmp("initrd=", argv[args_start], 7) == 0) )
   1.324 @@ -433,22 +440,23 @@ int main(int argc, char **argv)
   1.325  	initrd_fd = open(initrd_name, O_RDONLY);
   1.326  	if(initrd_fd < 0){
   1.327              perror(PERR_STRING);
   1.328 -            goto out;
   1.329 +	    return -1;
   1.330  	}
   1.331      }
   1.332  
   1.333      /* the following code does the actual domain building */
   1.334      meminfo = setup_guestos(domain_id, kernel_fd, initrd_fd, load_addr, 
   1.335  			    ksize, &dom_os_image); 
   1.336 -    
   1.337 +    if (!meminfo)
   1.338 +	return -1;
   1.339 +
   1.340 +    if (initrd_fd >= 0)
   1.341 +	close(initrd_fd);
   1.342 +    close(kernel_fd);
   1.343 +
   1.344      /* and unmap the new domain's memory image since we no longer need it */
   1.345      dom_mem_cleanup(&dom_os_image);
   1.346  
   1.347 -    if(!meminfo) { 
   1.348 -	printf("Domain Builder: debug: meminfo NULL\n");
   1.349 -        goto out;
   1.350 -    }
   1.351 -
   1.352      meminfo->virt_load_addr = load_addr;
   1.353      meminfo->num_vifs = atoi(argv[3]);
   1.354      meminfo->cmd_line[0] = '\0';
   1.355 @@ -463,19 +471,8 @@ int main(int argc, char **argv)
   1.356          cmd_len += strlen(argv[count] + 1);
   1.357      }
   1.358  
   1.359 -    /*    sprintf(status, 
   1.360 -          "About to launch new domain %d with folowing parameters:\n"
   1.361 -          " * page table base: %lx \n * load address: %lx \n"
   1.362 -          " * shared info address: %lx \n * start info address: %lx \n"
   1.363 -          " * number of vifs: %d \n * cmd line: %s \n", meminfo->domain, 
   1.364 -          meminfo->l2_pgt_addr, meminfo->virt_load_addr, 
   1.365 -          meminfo->virt_shinfo_addr, meminfo->virt_startinfo_addr, 
   1.366 -          meminfo->num_vifs, meminfo->cmd_line);
   1.367 -          dbstatus(status);*/
   1.368 -    
   1.369      /* and launch the domain */
   1.370      rc = launch_domain(meminfo); 
   1.371      
   1.372 - out:
   1.373 -    return rc;
   1.374 +    return 0;
   1.375  }
     2.1 --- a/xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_segment_proc.c	Thu Jul 10 10:17:15 2003 +0000
     2.2 +++ b/xenolinux-2.4.21-sparse/arch/xeno/drivers/block/xl_segment_proc.c	Thu Jul 10 11:04:02 2003 +0000
     2.3 @@ -310,7 +310,7 @@ static struct file_operations proc_vhd_o
     2.4  
     2.5  int __init xlseg_proc_init(void)
     2.6  {
     2.7 -    vhd = create_proc_entry("xeno/dom0/vhd", 0644, NULL);
     2.8 +    vhd = create_proc_entry("xeno/dom0/vhd", 0600, NULL);
     2.9      if (vhd == NULL)
    2.10      {
    2.11          panic ("xlseg_init: unable to create vhd proc entry\n");
     3.1 --- a/xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c	Thu Jul 10 10:17:15 2003 +0000
     3.2 +++ b/xenolinux-2.4.21-sparse/arch/xeno/drivers/dom0/dom0_core.c	Thu Jul 10 11:04:02 2003 +0000
     3.3 @@ -334,6 +334,10 @@ static int handle_dom0_cmd_dopgupdates(u
     3.4  	return -EFAULT;
     3.5  
     3.6      /* argbuf.pgt_update_arr had better be direct mapped... */
     3.7 +    /* Actually, we only *really* need to make sure that all of it's
     3.8 +       pages are in memory and aren't going to get swapped out in the
     3.9 +       mean time, but this is slightly easier than checking all of
    3.10 +       that and is sufficient for the current userspace tools. */
    3.11      entry = find_direct(&current->mm->context.direct_list,
    3.12  			argbuf.pgt_update_arr);
    3.13      if (entry == &current->mm->context.direct_list)