提交 512b6fb1 编写于 作者: J Jeff Dike 提交者: Linus Torvalds

uml: userspace files should call libc directly

A number of files that were changed in the recent removal of tt mode
are userspace files which call the os_* wrappers instead of calling
libc directly.  A few other files were affected by this, through

This patch makes these call glibc directly.

There are also style fixes in the affected areas.

os_print_error has no remaining callers, so it is deleted.

There is a interface change to os_set_exec_close, eliminating a
parameter which was always the same.  The callers are fixed as well.

os_process_pc got its error path cleaned up.
Signed-off-by: NJeff Dike <jdike@linux.intel.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 b21d4b08
...@@ -128,9 +128,8 @@ static inline struct openflags of_cloexec(struct openflags flags) ...@@ -128,9 +128,8 @@ static inline struct openflags of_cloexec(struct openflags flags)
extern int os_stat_file(const char *file_name, struct uml_stat *buf); extern int os_stat_file(const char *file_name, struct uml_stat *buf);
extern int os_stat_fd(const int fd, struct uml_stat *buf); extern int os_stat_fd(const int fd, struct uml_stat *buf);
extern int os_access(const char *file, int mode); extern int os_access(const char *file, int mode);
extern void os_print_error(int error, const char* str);
extern int os_get_exec_close(int fd, int *close_on_exec); extern int os_get_exec_close(int fd, int *close_on_exec);
extern int os_set_exec_close(int fd, int close_on_exec); extern int os_set_exec_close(int fd);
extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg); extern int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg);
extern int os_get_ifname(int fd, char *namebuf); extern int os_get_ifname(int fd, char *namebuf);
extern int os_set_slip(int fd); extern int os_set_slip(int fd);
......
...@@ -40,7 +40,6 @@ EXPORT_SYMBOL(uml_strdup); ...@@ -40,7 +40,6 @@ EXPORT_SYMBOL(uml_strdup);
EXPORT_SYMBOL(os_stat_fd); EXPORT_SYMBOL(os_stat_fd);
EXPORT_SYMBOL(os_stat_file); EXPORT_SYMBOL(os_stat_file);
EXPORT_SYMBOL(os_access); EXPORT_SYMBOL(os_access);
EXPORT_SYMBOL(os_print_error);
EXPORT_SYMBOL(os_get_exec_close); EXPORT_SYMBOL(os_get_exec_close);
EXPORT_SYMBOL(os_set_exec_close); EXPORT_SYMBOL(os_set_exec_close);
EXPORT_SYMBOL(os_getpid); EXPORT_SYMBOL(os_getpid);
......
...@@ -99,7 +99,9 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end, ...@@ -99,7 +99,9 @@ void __init setup_physmem(unsigned long start, unsigned long reserve_end,
err = os_map_memory((void *) uml_reserved, physmem_fd, offset, err = os_map_memory((void *) uml_reserved, physmem_fd, offset,
len - offset, 1, 1, 1); len - offset, 1, 1, 1);
if (err < 0) { if (err < 0) {
os_print_error(err, "Mapping memory"); printf("setup_physmem - mapping %ld bytes of memory at 0x%p "
"failed - errno = %d\n", len - offset,
(void *) uml_reserved, err);
exit(1); exit(1);
} }
......
...@@ -226,8 +226,8 @@ static int init_aio_24(void) ...@@ -226,8 +226,8 @@ static int init_aio_24(void)
goto out; goto out;
out_close_pipe: out_close_pipe:
os_close_file(fds[0]); close(fds[0]);
os_close_file(fds[1]); close(fds[1]);
aio_req_fd_w = -1; aio_req_fd_w = -1;
aio_req_fd_r = -1; aio_req_fd_r = -1;
out: out:
......
...@@ -87,11 +87,11 @@ static void etap_pre_exec(void *arg) ...@@ -87,11 +87,11 @@ static void etap_pre_exec(void *arg)
struct etap_pre_exec_data *data = arg; struct etap_pre_exec_data *data = arg;
dup2(data->control_remote, 1); dup2(data->control_remote, 1);
os_close_file(data->data_me); close(data->data_me);
os_close_file(data->control_me); close(data->control_me);
} }
static int etap_tramp(char *dev, char *gate, int control_me, static int etap_tramp(char *dev, char *gate, int control_me,
int control_remote, int data_me, int data_remote) int control_remote, int data_me, int data_remote)
{ {
struct etap_pre_exec_data pe_data; struct etap_pre_exec_data pe_data;
...@@ -101,7 +101,7 @@ static int etap_tramp(char *dev, char *gate, int control_me, ...@@ -101,7 +101,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")]; char gate_buf[sizeof("nnn.nnn.nnn.nnn\0")];
char *setup_args[] = { "uml_net", version_buf, "ethertap", dev, char *setup_args[] = { "uml_net", version_buf, "ethertap", dev,
data_fd_buf, gate_buf, NULL }; data_fd_buf, gate_buf, NULL };
char *nosetup_args[] = { "uml_net", version_buf, "ethertap", char *nosetup_args[] = { "uml_net", version_buf, "ethertap",
dev, data_fd_buf, NULL }; dev, data_fd_buf, NULL };
char **args, c; char **args, c;
...@@ -121,8 +121,8 @@ static int etap_tramp(char *dev, char *gate, int control_me, ...@@ -121,8 +121,8 @@ static int etap_tramp(char *dev, char *gate, int control_me,
if(pid < 0) if(pid < 0)
err = pid; err = pid;
os_close_file(data_remote); close(data_remote);
os_close_file(control_remote); close(control_remote);
CATCH_EINTR(n = read(control_me, &c, sizeof(c))); CATCH_EINTR(n = read(control_me, &c, sizeof(c)));
if(n != sizeof(c)){ if(n != sizeof(c)){
err = -errno; err = -errno;
...@@ -151,19 +151,23 @@ static int etap_open(void *data) ...@@ -151,19 +151,23 @@ static int etap_open(void *data)
if(err) if(err)
return err; return err;
err = os_pipe(data_fds, 0, 0); err = socketpair(AF_UNIX, SOCK_DGRAM, 0, data_fds);
if(err < 0){ if(err){
printk("data os_pipe failed - err = %d\n", -err); err = -errno;
printk("etap_open - data socketpair failed - err = %d\n",
errno);
return err; return err;
} }
err = os_pipe(control_fds, 1, 0); err = socketpair(AF_UNIX, SOCK_STREAM, 0, control_fds);
if(err < 0){ if(err){
printk("control os_pipe failed - err = %d\n", -err); err = -errno;
return err; printk("etap_open - control socketpair failed - err = %d\n",
errno);
goto out_close_data;
} }
err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0], err = etap_tramp(pri->dev_name, pri->gate_addr, control_fds[0],
control_fds[1], data_fds[0], data_fds[1]); control_fds[1], data_fds[0], data_fds[1]);
output_len = UM_KERN_PAGE_SIZE; output_len = UM_KERN_PAGE_SIZE;
output = kmalloc(output_len, UM_GFP_KERNEL); output = kmalloc(output_len, UM_GFP_KERNEL);
...@@ -178,13 +182,21 @@ static int etap_open(void *data) ...@@ -178,13 +182,21 @@ static int etap_open(void *data)
if(err < 0){ if(err < 0){
printk("etap_tramp failed - err = %d\n", -err); printk("etap_tramp failed - err = %d\n", -err);
return err; goto out_close_control;
} }
pri->data_fd = data_fds[0]; pri->data_fd = data_fds[0];
pri->control_fd = control_fds[0]; pri->control_fd = control_fds[0];
iter_addresses(pri->dev, etap_open_addr, &pri->control_fd); iter_addresses(pri->dev, etap_open_addr, &pri->control_fd);
return data_fds[0]; return data_fds[0];
out_close_control:
close(control_fds[0]);
close(control_fds[1]);
out_close_data:
close(data_fds[0]);
close(data_fds[1]);
return err;
} }
static void etap_close(int fd, void *data) static void etap_close(int fd, void *data)
...@@ -192,11 +204,19 @@ static void etap_close(int fd, void *data) ...@@ -192,11 +204,19 @@ static void etap_close(int fd, void *data)
struct ethertap_data *pri = data; struct ethertap_data *pri = data;
iter_addresses(pri->dev, etap_close_addr, &pri->control_fd); iter_addresses(pri->dev, etap_close_addr, &pri->control_fd);
os_close_file(fd); close(fd);
os_shutdown_socket(pri->data_fd, 1, 1);
os_close_file(pri->data_fd); if(shutdown(pri->data_fd, SHUT_RDWR) < 0)
printk("etap_close - shutdown data socket failed, errno = %d\n",
errno);
if(shutdown(pri->control_fd, SHUT_RDWR) < 0)
printk("etap_close - shutdown control socket failed, "
"errno = %d\n", errno);
close(pri->data_fd);
pri->data_fd = -1; pri->data_fd = -1;
os_close_file(pri->control_fd); close(pri->control_fd);
pri->control_fd = -1; pri->control_fd = -1;
} }
...@@ -216,13 +236,14 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask, ...@@ -216,13 +236,14 @@ static void etap_add_addr(unsigned char *addr, unsigned char *netmask,
etap_open_addr(addr, netmask, &pri->control_fd); etap_open_addr(addr, netmask, &pri->control_fd);
} }
static void etap_del_addr(unsigned char *addr, unsigned char *netmask, static void etap_del_addr(unsigned char *addr, unsigned char *netmask,
void *data) void *data)
{ {
struct ethertap_data *pri = data; struct ethertap_data *pri = data;
if(pri->control_fd == -1) if(pri->control_fd == -1)
return; return;
etap_close_addr(addr, netmask, &pri->control_fd); etap_close_addr(addr, netmask, &pri->control_fd);
} }
......
...@@ -62,7 +62,7 @@ static void tuntap_pre_exec(void *arg) ...@@ -62,7 +62,7 @@ static void tuntap_pre_exec(void *arg)
struct tuntap_pre_exec_data *data = arg; struct tuntap_pre_exec_data *data = arg;
dup2(data->stdout, 1); dup2(data->stdout, 1);
os_close_file(data->close_me); close(data->close_me);
} }
static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
...@@ -88,7 +88,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, ...@@ -88,7 +88,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
if(pid < 0) if(pid < 0)
return -pid; return -pid;
os_close_file(remote); close(remote);
msg.msg_name = NULL; msg.msg_name = NULL;
msg.msg_namelen = 0; msg.msg_namelen = 0;
...@@ -125,7 +125,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote, ...@@ -125,7 +125,7 @@ static int tuntap_open_tramp(char *gate, int *fd_out, int me, int remote,
return -EINVAL; return -EINVAL;
} }
*fd_out = ((int *) CMSG_DATA(cmsg))[0]; *fd_out = ((int *) CMSG_DATA(cmsg))[0];
os_set_exec_close(*fd_out, 1); os_set_exec_close(*fd_out);
return 0; return 0;
} }
...@@ -154,20 +154,22 @@ static int tuntap_open(void *data) ...@@ -154,20 +154,22 @@ static int tuntap_open(void *data)
if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){ if(ioctl(pri->fd, TUNSETIFF, (void *) &ifr) < 0){
err = -errno; err = -errno;
printk("TUNSETIFF failed, errno = %d\n", errno); printk("TUNSETIFF failed, errno = %d\n", errno);
os_close_file(pri->fd); close(pri->fd);
return err; return err;
} }
} }
else { else {
err = os_pipe(fds, 0, 0); err = socketpair(AF_UNIX, SOCK_DGRAM, 0, fds);
if(err < 0){ if(err){
printk("tuntap_open : os_pipe failed - err = %d\n", err = -errno;
-err); printk("tuntap_open : socketpair failed - errno = %d\n",
errno);
return err; return err;
} }
buffer = get_output_buffer(&len); buffer = get_output_buffer(&len);
if(buffer != NULL) len--; if(buffer != NULL)
len--;
used = 0; used = 0;
err = tuntap_open_tramp(pri->gate_addr, &pri->fd, fds[0], err = tuntap_open_tramp(pri->gate_addr, &pri->fd, fds[0],
...@@ -186,7 +188,7 @@ static int tuntap_open(void *data) ...@@ -186,7 +188,7 @@ static int tuntap_open(void *data)
printk("%s", output); printk("%s", output);
free_output_buffer(buffer); free_output_buffer(buffer);
os_close_file(fds[0]); close(fds[0]);
iter_addresses(pri->dev, open_addr, pri->dev_name); iter_addresses(pri->dev, open_addr, pri->dev_name);
} }
...@@ -199,7 +201,7 @@ static void tuntap_close(int fd, void *data) ...@@ -199,7 +201,7 @@ static void tuntap_close(int fd, void *data)
if(!pri->fixed_config) if(!pri->fixed_config)
iter_addresses(pri->dev, close_addr, pri->dev_name); iter_addresses(pri->dev, close_addr, pri->dev_name);
os_close_file(fd); close(fd);
pri->fd = -1; pri->fd = -1;
} }
......
...@@ -82,13 +82,6 @@ int os_access(const char* file, int mode) ...@@ -82,13 +82,6 @@ int os_access(const char* file, int mode)
return 0; return 0;
} }
void os_print_error(int error, const char* str)
{
errno = error < 0 ? -error : error;
perror(str);
}
/* FIXME? required only by hostaudio (because it passes ioctls verbatim) */ /* FIXME? required only by hostaudio (because it passes ioctls verbatim) */
int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg) int os_ioctl_generic(int fd, unsigned int cmd, unsigned long arg)
{ {
...@@ -181,19 +174,19 @@ int os_file_mode(char *file, struct openflags *mode_out) ...@@ -181,19 +174,19 @@ int os_file_mode(char *file, struct openflags *mode_out)
*mode_out = OPENFLAGS(); *mode_out = OPENFLAGS();
err = os_access(file, OS_ACC_W_OK); err = access(file, W_OK);
if((err < 0) && (err != -EACCES)) if(err && (errno != EACCES))
return(err); return -errno;
else if(!err)
*mode_out = of_write(*mode_out); *mode_out = of_write(*mode_out);
err = os_access(file, OS_ACC_R_OK);
if((err < 0) && (err != -EACCES))
return(err);
*mode_out = of_read(*mode_out); err = access(file, R_OK);
if(err && (errno != EACCES))
return -errno;
else if(!err)
*mode_out = of_read(*mode_out);
return(0); return err;
} }
int os_open_file(char *file, struct openflags flags, int mode) int os_open_file(char *file, struct openflags flags, int mode)
...@@ -212,15 +205,15 @@ int os_open_file(char *file, struct openflags flags, int mode) ...@@ -212,15 +205,15 @@ int os_open_file(char *file, struct openflags flags, int mode)
fd = open64(file, f, mode); fd = open64(file, f, mode);
if(fd < 0) if(fd < 0)
return(-errno); return -errno;
if(flags.cl && fcntl(fd, F_SETFD, 1)){ if(flags.cl && fcntl(fd, F_SETFD, 1)){
err = -errno; err = -errno;
os_close_file(fd); close(fd);
return err; return err;
} }
return(fd); return fd;
} }
int os_connect_socket(char *name) int os_connect_socket(char *name)
...@@ -292,31 +285,33 @@ int os_file_size(char *file, unsigned long long *size_out) ...@@ -292,31 +285,33 @@ int os_file_size(char *file, unsigned long long *size_out)
err = os_stat_file(file, &buf); err = os_stat_file(file, &buf);
if(err < 0){ if(err < 0){
printk("Couldn't stat \"%s\" : err = %d\n", file, -err); printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
return(err); return err;
} }
if(S_ISBLK(buf.ust_mode)){ if(S_ISBLK(buf.ust_mode)){
int fd; int fd;
long blocks; long blocks;
fd = os_open_file(file, of_read(OPENFLAGS()), 0); fd = open(file, O_RDONLY, 0);
if(fd < 0){ if(fd < 0) {
printk("Couldn't open \"%s\", errno = %d\n", file, -fd); err = -errno;
return(fd); printk("Couldn't open \"%s\", errno = %d\n", file,
errno);
return err;
} }
if(ioctl(fd, BLKGETSIZE, &blocks) < 0){ if(ioctl(fd, BLKGETSIZE, &blocks) < 0){
err = -errno; err = -errno;
printk("Couldn't get the block size of \"%s\", " printk("Couldn't get the block size of \"%s\", "
"errno = %d\n", file, errno); "errno = %d\n", file, errno);
os_close_file(fd); close(fd);
return(err); return err;
} }
*size_out = ((long long) blocks) * 512; *size_out = ((long long) blocks) * 512;
os_close_file(fd); close(fd);
return(0);
} }
*size_out = buf.ust_size; else *size_out = buf.ust_size;
return(0);
return 0;
} }
int os_file_modtime(char *file, unsigned long *modtime) int os_file_modtime(char *file, unsigned long *modtime)
...@@ -334,35 +329,28 @@ int os_file_modtime(char *file, unsigned long *modtime) ...@@ -334,35 +329,28 @@ int os_file_modtime(char *file, unsigned long *modtime)
return 0; return 0;
} }
int os_get_exec_close(int fd, int* close_on_exec) int os_get_exec_close(int fd, int *close_on_exec)
{ {
int ret; int ret;
do { CATCH_EINTR(ret = fcntl(fd, F_GETFD));
ret = fcntl(fd, F_GETFD);
} while((ret < 0) && (errno == EINTR)) ;
if(ret < 0) if(ret < 0)
return(-errno); return -errno;
*close_on_exec = (ret&FD_CLOEXEC) ? 1 : 0; *close_on_exec = (ret & FD_CLOEXEC) ? 1 : 0;
return(ret); return ret;
} }
int os_set_exec_close(int fd, int close_on_exec) int os_set_exec_close(int fd)
{ {
int flag, err; int err;
if(close_on_exec) flag = FD_CLOEXEC;
else flag = 0;
do { CATCH_EINTR(err = fcntl(fd, F_SETFD, FD_CLOEXEC));
err = fcntl(fd, F_SETFD, flag);
} while((err < 0) && (errno == EINTR)) ;
if(err < 0) if(err < 0)
return(-errno); return -errno;
return(err); return err;
} }
int os_pipe(int *fds, int stream, int close_on_exec) int os_pipe(int *fds, int stream, int close_on_exec)
...@@ -371,16 +359,16 @@ int os_pipe(int *fds, int stream, int close_on_exec) ...@@ -371,16 +359,16 @@ int os_pipe(int *fds, int stream, int close_on_exec)
err = socketpair(AF_UNIX, type, 0, fds); err = socketpair(AF_UNIX, type, 0, fds);
if(err < 0) if(err < 0)
return(-errno); return -errno;
if(!close_on_exec) if(!close_on_exec)
return(0); return 0;
err = os_set_exec_close(fds[0], 1); err = os_set_exec_close(fds[0]);
if(err < 0) if(err < 0)
goto error; goto error;
err = os_set_exec_close(fds[1], 1); err = os_set_exec_close(fds[1]);
if(err < 0) if(err < 0)
goto error; goto error;
...@@ -388,9 +376,9 @@ int os_pipe(int *fds, int stream, int close_on_exec) ...@@ -388,9 +376,9 @@ int os_pipe(int *fds, int stream, int close_on_exec)
error: error:
printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err); printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
os_close_file(fds[1]); close(fds[1]);
os_close_file(fds[0]); close(fds[0]);
return(err); return err;
} }
int os_set_fd_async(int fd, int owner) int os_set_fd_async(int fd, int owner)
...@@ -537,7 +525,7 @@ int os_create_unix_socket(char *file, int len, int close_on_exec) ...@@ -537,7 +525,7 @@ int os_create_unix_socket(char *file, int len, int close_on_exec)
return -errno; return -errno;
if(close_on_exec) { if(close_on_exec) {
err = os_set_exec_close(sock, 1); err = os_set_exec_close(sock);
if(err < 0) if(err < 0)
printk("create_unix_socket : close_on_exec failed, " printk("create_unix_socket : close_on_exec failed, "
"err = %d", -err); "err = %d", -err);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <limits.h> #include <limits.h>
#include <sys/signal.h> #include <sys/signal.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/socket.h>
#include "user.h" #include "user.h"
#include "kern_util.h" #include "kern_util.h"
#include "os.h" #include "os.h"
...@@ -54,13 +55,14 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv) ...@@ -54,13 +55,14 @@ int run_helper(void (*pre_exec)(void *), void *pre_data, char **argv)
if (stack == 0) if (stack == 0)
return -ENOMEM; return -ENOMEM;
ret = os_pipe(fds, 1, 0); ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
if (ret < 0) { if (ret < 0) {
printk("run_helper : pipe failed, ret = %d\n", -ret); ret = -errno;
printk("run_helper : pipe failed, errno = %d\n", errno);
goto out_free; goto out_free;
} }
ret = os_set_exec_close(fds[1], 1); ret = os_set_exec_close(fds[1]);
if (ret < 0) { if (ret < 0) {
printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n", printk("run_helper : setting FD_CLOEXEC failed, ret = %d\n",
-ret); -ret);
......
...@@ -218,7 +218,7 @@ int __init create_tmp_file(unsigned long long len) ...@@ -218,7 +218,7 @@ int __init create_tmp_file(unsigned long long len)
err = fchmod(fd, 0777); err = fchmod(fd, 0777);
if(err < 0){ if(err < 0){
perror("os_mode_fd"); perror("fchmod");
exit(1); exit(1);
} }
...@@ -226,7 +226,7 @@ int __init create_tmp_file(unsigned long long len) ...@@ -226,7 +226,7 @@ int __init create_tmp_file(unsigned long long len)
* increase the file size by one byte, to the desired length. * increase the file size by one byte, to the desired length.
*/ */
if (lseek64(fd, len - 1, SEEK_SET) < 0) { if (lseek64(fd, len - 1, SEEK_SET) < 0) {
perror("os_seek_file"); perror("lseek64");
exit(1); exit(1);
} }
...@@ -247,7 +247,7 @@ int __init create_mem_file(unsigned long long len) ...@@ -247,7 +247,7 @@ int __init create_mem_file(unsigned long long len)
fd = create_tmp_file(len); fd = create_tmp_file(len);
err = os_set_exec_close(fd, 1); err = os_set_exec_close(fd);
if(err < 0){ if(err < 0){
errno = -err; errno = -err;
perror("exec_close"); perror("exec_close");
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <sys/wait.h> #include <sys/wait.h>
...@@ -28,31 +29,32 @@ ...@@ -28,31 +29,32 @@
unsigned long os_process_pc(int pid) unsigned long os_process_pc(int pid)
{ {
char proc_stat[STAT_PATH_LEN], buf[256]; char proc_stat[STAT_PATH_LEN], buf[256];
unsigned long pc; unsigned long pc = ARBITRARY_ADDR;
int fd, err; int fd, err;
sprintf(proc_stat, "/proc/%d/stat", pid); sprintf(proc_stat, "/proc/%d/stat", pid);
fd = os_open_file(proc_stat, of_read(OPENFLAGS()), 0); fd = open(proc_stat, O_RDONLY, 0);
if (fd < 0) { if (fd < 0) {
printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', " printk(UM_KERN_ERR "os_process_pc - couldn't open '%s', "
"err = %d\n", proc_stat, -fd); "errno = %d\n", proc_stat, errno);
return ARBITRARY_ADDR; goto out;
} }
CATCH_EINTR(err = read(fd, buf, sizeof(buf))); CATCH_EINTR(err = read(fd, buf, sizeof(buf)));
if (err < 0) { if (err < 0) {
printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', " printk(UM_KERN_ERR "os_process_pc - couldn't read '%s', "
"err = %d\n", proc_stat, errno); "err = %d\n", proc_stat, errno);
os_close_file(fd); goto out_close;
return ARBITRARY_ADDR;
} }
os_close_file(fd); os_close_file(fd);
pc = ARBITRARY_ADDR; pc = ARBITRARY_ADDR;
if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d " if (sscanf(buf, "%*d " COMM_SCANF " %*c %*d %*d %*d %*d %*d %*d %*d "
"%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d " "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
"%*d %*d %*d %*d %*d %lu", &pc) != 1) { "%*d %*d %*d %*d %*d %lu", &pc) != 1)
printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n", printk(UM_KERN_ERR "os_process_pc - couldn't find pc in '%s'\n",
buf); buf);
} out_close:
close(fd);
out:
return pc; return pc;
} }
...@@ -60,25 +62,26 @@ int os_process_parent(int pid) ...@@ -60,25 +62,26 @@ int os_process_parent(int pid)
{ {
char stat[STAT_PATH_LEN]; char stat[STAT_PATH_LEN];
char data[256]; char data[256];
int parent, n, fd; int parent = FAILURE_PID, n, fd;
if (pid == -1) if (pid == -1)
return -1; return parent;
snprintf(stat, sizeof(stat), "/proc/%d/stat", pid); snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
fd = os_open_file(stat, of_read(OPENFLAGS()), 0); fd = open(stat, O_RDONLY, 0);
if (fd < 0) { if (fd < 0) {
printk(UM_KERN_ERR "Couldn't open '%s', err = %d\n", stat, -fd); printk(UM_KERN_ERR "Couldn't open '%s', errno = %d\n", stat,
return FAILURE_PID; errno);
return parent;
} }
CATCH_EINTR(n = read(fd, data, sizeof(data))); CATCH_EINTR(n = read(fd, data, sizeof(data)));
os_close_file(fd); close(fd);
if (n < 0) { if (n < 0) {
printk(UM_KERN_ERR "Couldn't read '%s', err = %d\n", stat, printk(UM_KERN_ERR "Couldn't read '%s', errno = %d\n", stat,
errno); errno);
return FAILURE_PID; return parent;
} }
parent = FAILURE_PID; parent = FAILURE_PID;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
int is_skas_winch(int pid, int fd, void *data) int is_skas_winch(int pid, int fd, void *data)
{ {
if (pid != os_getpgrp()) if (pid != getpgrp())
return 0; return 0;
register_winch_irq(-1, fd, -1, data, 0); register_winch_irq(-1, fd, -1, data, 0);
...@@ -233,7 +233,7 @@ static int userspace_tramp(void *stack) ...@@ -233,7 +233,7 @@ static int userspace_tramp(void *stack)
"failed - errno = %d\n", errno); "failed - errno = %d\n", errno);
} }
os_stop_process(os_getpid()); kill(os_getpid(), SIGSTOP);
return 0; return 0;
} }
......
...@@ -28,13 +28,14 @@ ...@@ -28,13 +28,14 @@
static int ptrace_child(void) static int ptrace_child(void)
{ {
int ret; int ret;
/* Calling os_getpid because some libcs cached getpid incorrectly */
int pid = os_getpid(), ppid = getppid(); int pid = os_getpid(), ppid = getppid();
int sc_result; int sc_result;
change_sig(SIGWINCH, 0); change_sig(SIGWINCH, 0);
if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) { if (ptrace(PTRACE_TRACEME, 0, 0, 0) < 0) {
perror("ptrace"); perror("ptrace");
os_kill_process(pid, 0); kill(pid, SIGKILL);
} }
kill(pid, SIGSTOP); kill(pid, SIGSTOP);
...@@ -496,7 +497,7 @@ int __init parse_iomem(char *str, int *add) ...@@ -496,7 +497,7 @@ int __init parse_iomem(char *str, int *add)
file++; file++;
fd = open(file, O_RDWR, 0); fd = open(file, O_RDWR, 0);
if (fd < 0) { if (fd < 0) {
os_print_error(fd, "parse_iomem - Couldn't open io file"); perror("parse_iomem - Couldn't open io file");
goto out; goto out;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册