Commit f839f849 authored by Jeff Dike's avatar Jeff Dike

Fixed the time locking bug.

The mconsole and switch protocols are now 64-bit clean.
Fixed some smaller bugs.
parent 2ab010ff
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdint.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <sys/time.h> #include <sys/time.h>
...@@ -24,8 +25,8 @@ enum request_type { REQ_NEW_CONTROL }; ...@@ -24,8 +25,8 @@ enum request_type { REQ_NEW_CONTROL };
#define SWITCH_MAGIC 0xfeedface #define SWITCH_MAGIC 0xfeedface
struct request_v3 { struct request_v3 {
unsigned long magic; uint32_t magic;
int version; uint32_t version;
enum request_type type; enum request_type type;
struct sockaddr_un sock; struct sockaddr_un sock;
}; };
......
...@@ -7,30 +7,35 @@ ...@@ -7,30 +7,35 @@
#ifndef __MCONSOLE_H__ #ifndef __MCONSOLE_H__
#define __MCONSOLE_H__ #define __MCONSOLE_H__
#ifndef __KERNEL__
#include <stdint.h>
#define u32 uint32_t
#endif
#define MCONSOLE_MAGIC (0xcafebabe) #define MCONSOLE_MAGIC (0xcafebabe)
#define MCONSOLE_MAX_DATA (512) #define MCONSOLE_MAX_DATA (512)
#define MCONSOLE_VERSION 2 #define MCONSOLE_VERSION 2
struct mconsole_request { struct mconsole_request {
unsigned long magic; u32 magic;
int version; u32 version;
int len; u32 len;
char data[MCONSOLE_MAX_DATA]; char data[MCONSOLE_MAX_DATA];
}; };
struct mconsole_reply { struct mconsole_reply {
int err; u32 err;
int more; u32 more;
int len; u32 len;
char data[MCONSOLE_MAX_DATA]; char data[MCONSOLE_MAX_DATA];
}; };
struct mconsole_notify { struct mconsole_notify {
unsigned long magic; u32 magic;
int version; u32 version;
enum { MCONSOLE_SOCKET, MCONSOLE_PANIC, MCONSOLE_HANG, enum { MCONSOLE_SOCKET, MCONSOLE_PANIC, MCONSOLE_HANG,
MCONSOLE_USER_NOTIFY } type; MCONSOLE_USER_NOTIFY } type;
int len; u32 len;
char data[MCONSOLE_MAX_DATA]; char data[MCONSOLE_MAX_DATA];
}; };
......
...@@ -11,7 +11,7 @@ extern void switch_timers(int to_real); ...@@ -11,7 +11,7 @@ extern void switch_timers(int to_real);
extern void set_interval(int timer_type); extern void set_interval(int timer_type);
extern void idle_sleep(int secs); extern void idle_sleep(int secs);
extern void enable_timer(void); extern void enable_timer(void);
extern void time_lock(void); extern unsigned long time_lock(void);
extern void time_unlock(void); extern void time_unlock(unsigned long);
#endif #endif
...@@ -23,11 +23,11 @@ static void __init find_tempdir(void) ...@@ -23,11 +23,11 @@ static void __init find_tempdir(void)
if(tempdir != NULL) return; /* We've already been called */ if(tempdir != NULL) return; /* We've already been called */
for(i = 0; dirs[i]; i++){ for(i = 0; dirs[i]; i++){
dir = getenv(dirs[i]); dir = getenv(dirs[i]);
if(dir != NULL) break; if((dir != NULL) && (*dir != '\0'))
break;
} }
if(dir == NULL) dir = "/tmp"; if((dir == NULL) || (*dir == '\0'))
else if(*dir == '\0') dir = NULL; dir = "/tmp";
if(dir != NULL) {
tempdir = malloc(strlen(dir) + 2); tempdir = malloc(strlen(dir) + 2);
if(tempdir == NULL){ if(tempdir == NULL){
fprintf(stderr, "Failed to malloc tempdir, " fprintf(stderr, "Failed to malloc tempdir, "
...@@ -36,7 +36,6 @@ static void __init find_tempdir(void) ...@@ -36,7 +36,6 @@ static void __init find_tempdir(void)
} }
strcpy(tempdir, dir); strcpy(tempdir, dir);
strcat(tempdir, "/"); strcat(tempdir, "/");
}
} }
int make_tempfile(const char *template, char **out_tempname, int do_unlink) int make_tempfile(const char *template, char **out_tempname, int do_unlink)
......
...@@ -86,20 +86,23 @@ struct timeval local_offset = { 0, 0 }; ...@@ -86,20 +86,23 @@ struct timeval local_offset = { 0, 0 };
void do_gettimeofday(struct timeval *tv) void do_gettimeofday(struct timeval *tv)
{ {
time_lock(); unsigned long flags;
flags = time_lock();
gettimeofday(tv, NULL); gettimeofday(tv, NULL);
timeradd(tv, &local_offset, tv); timeradd(tv, &local_offset, tv);
time_unlock(); time_unlock(flags);
} }
void do_settimeofday(struct timeval *tv) void do_settimeofday(struct timeval *tv)
{ {
struct timeval now; struct timeval now;
unsigned long flags;
time_lock(); flags = time_lock();
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
timersub(tv, &now, &local_offset); timersub(tv, &now, &local_offset);
time_unlock(); time_unlock(flags);
} }
void idle_sleep(int secs) void idle_sleep(int secs)
......
...@@ -131,14 +131,16 @@ void timer_handler(int sig, union uml_pt_regs *regs) ...@@ -131,14 +131,16 @@ void timer_handler(int sig, union uml_pt_regs *regs)
static spinlock_t timer_spinlock = SPIN_LOCK_UNLOCKED; static spinlock_t timer_spinlock = SPIN_LOCK_UNLOCKED;
void time_lock(void) unsigned long time_lock(void)
{ {
spin_lock(&timer_spinlock); unsigned long flags;
spin_lock_irqsave(&timer_spinlock, flags);
return(flags);
} }
void time_unlock(void) void time_unlock(unsigned long flags)
{ {
spin_unlock(&timer_spinlock); spin_unlock_irqrestore(&timer_spinlock, flags);
} }
int __init timer_init(void) int __init timer_init(void)
......
...@@ -169,7 +169,7 @@ void finish_fork_handler(int sig) ...@@ -169,7 +169,7 @@ void finish_fork_handler(int sig)
#endif #endif
enable_timer(); enable_timer();
change_sig(SIGVTALRM, 1); change_sig(SIGVTALRM, 1);
local_irq_disable(); local_irq_enable();
force_flush_all(); force_flush_all();
if(current->mm != current->parent->mm) if(current->mm != current->parent->mm)
protect_memory(uml_reserved, high_physmem - uml_reserved, 1, protect_memory(uml_reserved, high_physmem - uml_reserved, 1,
...@@ -189,7 +189,7 @@ int fork_tramp(void *stack) ...@@ -189,7 +189,7 @@ int fork_tramp(void *stack)
{ {
int sig = sigusr1; int sig = sigusr1;
local_irq_enable(); local_irq_disable();
init_new_thread_stack(stack, finish_fork_handler); init_new_thread_stack(stack, finish_fork_handler);
kill(os_getpid(), sig); kill(os_getpid(), sig);
......
...@@ -106,7 +106,7 @@ int os_map_memory(void *virt, int fd, unsigned long off, unsigned long len, ...@@ -106,7 +106,7 @@ int os_map_memory(void *virt, int fd, unsigned long off, unsigned long len,
loc = mmap((void *) virt, len, prot, MAP_SHARED | MAP_FIXED, loc = mmap((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
fd, off); fd, off);
if(loc < 0) if(loc == MAP_FAILED)
return(-errno); return(-errno);
return(0); return(0);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment