diff options
| author | Jeff Garzik <jeff@garzik.org> | 2006-04-12 16:54:16 -0400 | 
|---|---|---|
| committer | Jeff Garzik <jeff@garzik.org> | 2006-04-12 16:54:16 -0400 | 
| commit | 875999c5539999f61a45620aae0c3e5fb1d2b035 (patch) | |
| tree | 4535032a8a10f5782c0aef6a620b1a624ea9f863 /arch/um/os-Linux/mem.c | |
| parent | 79072f38909e3d9883317238887460c39ddcc4cb (diff) | |
| parent | 26ec634c31a11a003040e10b4d650495158632fd (diff) | |
Merge branch 'upstream'
Diffstat (limited to 'arch/um/os-Linux/mem.c')
| -rw-r--r-- | arch/um/os-Linux/mem.c | 50 | 
1 files changed, 14 insertions, 36 deletions
diff --git a/arch/um/os-Linux/mem.c b/arch/um/os-Linux/mem.c index 9d7d69a523bb..71bb90a7606d 100644 --- a/arch/um/os-Linux/mem.c +++ b/arch/um/os-Linux/mem.c  | |||
| @@ -53,33 +53,36 @@ static void __init find_tempdir(void) | |||
| 53 | */ | 53 | */ | 
| 54 | int make_tempfile(const char *template, char **out_tempname, int do_unlink) | 54 | int make_tempfile(const char *template, char **out_tempname, int do_unlink) | 
| 55 | { | 55 | { | 
| 56 | char tempname[MAXPATHLEN]; | 56 | char *tempname; | 
| 57 | int fd; | 57 | int fd; | 
| 58 | 58 | ||
| 59 | tempname = malloc(MAXPATHLEN); | ||
| 60 | |||
| 59 | find_tempdir(); | 61 | find_tempdir(); | 
| 60 | if (*template != '/') | 62 | if (template[0] != '/') | 
| 61 | strcpy(tempname, tempdir); | 63 | strcpy(tempname, tempdir); | 
| 62 | else | 64 | else | 
| 63 | *tempname = 0; | 65 | tempname[0] = '\0'; | 
| 64 | strcat(tempname, template); | 66 | strcat(tempname, template); | 
| 65 | fd = mkstemp(tempname); | 67 | fd = mkstemp(tempname); | 
| 66 | if(fd < 0){ | 68 | if(fd < 0){ | 
| 67 | fprintf(stderr, "open - cannot create %s: %s\n", tempname, | 69 | fprintf(stderr, "open - cannot create %s: %s\n", tempname, | 
| 68 | strerror(errno)); | 70 | strerror(errno)); | 
| 69 | return -1; | 71 | goto out; | 
| 70 | } | 72 | } | 
| 71 | if(do_unlink && (unlink(tempname) < 0)){ | 73 | if(do_unlink && (unlink(tempname) < 0)){ | 
| 72 | perror("unlink"); | 74 | perror("unlink"); | 
| 73 | return -1; | 75 | goto out; | 
| 74 | } | 76 | } | 
| 75 | if(out_tempname){ | 77 | if(out_tempname){ | 
| 76 | *out_tempname = strdup(tempname); | 78 | *out_tempname = tempname; | 
| 77 | if(*out_tempname == NULL){ | 79 | } else { | 
| 78 | perror("strdup"); | 80 | free(tempname); | 
| 79 | return -1; | ||
| 80 | } | ||
| 81 | } | 81 | } | 
| 82 | return(fd); | 82 | return(fd); | 
| 83 | out: | ||
| 84 | free(tempname); | ||
| 85 | return -1; | ||
| 83 | } | 86 | } | 
| 84 | 87 | ||
| 85 | #define TEMPNAME_TEMPLATE "vm_file-XXXXXX" | 88 | #define TEMPNAME_TEMPLATE "vm_file-XXXXXX" | 
| @@ -121,36 +124,11 @@ int create_tmp_file(unsigned long long len) | |||
| 121 | return(fd); | 124 | return(fd); | 
| 122 | } | 125 | } | 
| 123 | 126 | ||
| 124 | static int create_anon_file(unsigned long long len) | ||
| 125 | { | ||
| 126 | void *addr; | ||
| 127 | int fd; | ||
| 128 | |||
| 129 | fd = open("/dev/anon", O_RDWR); | ||
| 130 | if(fd < 0) { | ||
| 131 | perror("opening /dev/anon"); | ||
| 132 | exit(1); | ||
| 133 | } | ||
| 134 | |||
| 135 | addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); | ||
| 136 | if(addr == MAP_FAILED){ | ||
| 137 | perror("mapping physmem file"); | ||
| 138 | exit(1); | ||
| 139 | } | ||
| 140 | munmap(addr, len); | ||
| 141 | |||
| 142 | return(fd); | ||
| 143 | } | ||
| 144 | |||
| 145 | extern int have_devanon; | ||
| 146 | |||
| 147 | int create_mem_file(unsigned long long len) | 127 | int create_mem_file(unsigned long long len) | 
| 148 | { | 128 | { | 
| 149 | int err, fd; | 129 | int err, fd; | 
| 150 | 130 | ||
| 151 | if(have_devanon) | 131 | fd = create_tmp_file(len); | 
| 152 | fd = create_anon_file(len); | ||
| 153 | else fd = create_tmp_file(len); | ||
| 154 | 132 | ||
| 155 | err = os_set_exec_close(fd, 1); | 133 | err = os_set_exec_close(fd, 1); | 
| 156 | if(err < 0){ | 134 | if(err < 0){ | 
