Skip to content
Snippets Groups Projects
Select Git revision
  • android-msm-flo-3.4-kitkat-mr1
  • master default protected
  • android-msm-bullhead-3.10-nougat_kgdb_less_changes
  • android-msm-bullhead-3.10-nougat_kgdb
  • android-msm-bullhead-3.10-nougat_klist
  • android-4.4
  • android-msm-vega-4.4-oreo-daydream
  • android-msm-wahoo-4.4-p-preview-5
  • android-msm-wahoo-4.4-pie
  • android-msm-marlin-3.18-p-preview-5
  • android-msm-marlin-3.18-pie
  • android-msm-wahoo-2018.07-oreo-m2
  • android-msm-wahoo-2018.07-oreo-m4
  • android-msm-wahoo-4.4-p-preview-4
  • android-msm-bullhead-3.10-oreo-m6
  • android-msm-angler-3.10-oreo-m6
  • android-msm-marlin-3.18-p-preview-4
  • android-msm-stargazer-3.18-oreo-wear-dr
  • android-msm-catshark-3.18-oreo-wear-dr
  • android-msm-wahoo-4.4-oreo-m2
  • android-msm-wahoo-4.4-oreo-m4
  • android-daydreamos-8.0.0_r0.5
  • android-8.1.0_r0.92
  • android-8.1.0_r0.91
  • android-daydreamos-8.0.0_r0.4
  • android-p-preview-5_r0.2
  • android-p-preview-5_r0.1
  • android-9.0.0_r0.5
  • android-9.0.0_r0.4
  • android-9.0.0_r0.2
  • android-9.0.0_r0.1
  • android-8.1.0_r0.81
  • android-8.1.0_r0.80
  • android-8.1.0_r0.78
  • android-8.1.0_r0.76
  • android-8.1.0_r0.75
  • android-8.1.0_r0.72
  • android-8.1.0_r0.70
  • android-p-preview-4_r0.2
  • android-p-preview-4_r0.1
  • android-wear-8.0.0_r0.30
41 results

exec_domain.c

Blame
  • insmod.c 1.76 KiB
    #include <stdio.h>
    #include <string.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <malloc.h>
    #include <errno.h>
    #include <sys/param.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <unistd.h>
    
    extern int init_module(void *, unsigned long, const char *);
    
    static void *read_file(const char *filename, ssize_t *_size)
    {
    	int ret, fd;
    	struct stat sb;
    	ssize_t size;
    	void *buffer = NULL;
    
    	/* open the file */
    	fd = open(filename, O_RDONLY);
    	if (fd < 0)
    		return NULL;
    
    	/* find out how big it is */
    	if (fstat(fd, &sb) < 0)
    		goto bail;
    	size = sb.st_size;
    
    	/* allocate memory for it to be read into */
    	buffer = malloc(size);
    	if (!buffer)
    		goto bail;
    
    	/* slurp it into our buffer */
    	ret = read(fd, buffer, size);
    	if (ret != size)
    		goto bail;
    
    	/* let the caller know how big it is */
    	*_size = size;
    
    bail:
    	close(fd);
    	return buffer;
    }
    
    int insmod_main(int argc, char **argv)
    {
    	void *file;
    	ssize_t size = 0;
    	char opts[1024];
    	int ret;
    
    	/* make sure we've got an argument */
    	if (argc < 2) {
    		fprintf(stderr, "usage: insmod <module.o>\n");
    		return -1;
    	}
    
    	/* read the file into memory */
    	file = read_file(argv[1], &size);
    	if (!file) {
    		fprintf(stderr, "insmod: can't open '%s'\n", argv[1]);
    		return -1;
    	}
    
    	opts[0] = '\0';
    	if (argc > 2) {
    		int i, len;
    		char *end = opts + sizeof(opts) - 1;
    		char *ptr = opts;
    
    		for (i = 2; (i < argc) && (ptr < end); i++) {
    			len = MIN(strlen(argv[i]), (size_t)(end - ptr));
    			memcpy(ptr, argv[i], len);
    			ptr += len;
    			*ptr++ = ' ';
    		}
    		*(ptr - 1) = '\0';
    	}
    
    	/* pass it to the kernel */
    	ret = init_module(file, size, opts);
    	if (ret != 0) {
    		fprintf(stderr,
                    "insmod: init_module '%s' failed (%s)\n",
                    argv[1], strerror(errno));
    	}
    
    	/* free the file buffer */
    	free(file);
    
    	return ret;
    }