2 * Copyright (C) 2002 Jeff Dike (jdike@addtoit.com)
3 * Licensed under the GPL
10 #include <linux/unistd.h>
16 #define ARBITRARY_ADDR -1
17 #define FAILURE_PID -1
19 unsigned long os_process_pc(int pid)
21 char proc_stat[sizeof("/proc/#####/stat\0")], buf[256];
25 sprintf(proc_stat, "/proc/%d/stat", pid);
26 fd = os_open_file(proc_stat, of_read(OPENFLAGS()), 0);
28 printk("os_process_pc - couldn't open '%s', err = %d\n",
30 return(ARBITRARY_ADDR);
32 err = os_read_file(fd, buf, sizeof(buf));
34 printk("os_process_pc - couldn't read '%s', err = %d\n",
37 return(ARBITRARY_ADDR);
41 if(sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*d %*d %*d "
42 "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
43 "%*d %*d %*d %*d %ld", &pc) != 1){
44 printk("os_process_pc - couldn't find pc in '%s'\n", buf);
49 int os_process_parent(int pid)
51 char stat[sizeof("/proc/nnnnn/stat\0")];
55 if(pid == -1) return(-1);
57 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
58 fd = os_open_file(stat, of_read(OPENFLAGS()), 0);
60 printk("Couldn't open '%s', err = %d\n", stat, -fd);
64 n = os_read_file(fd, data, sizeof(data));
68 printk("Couldn't read '%s', err = %d\n", stat, -n);
73 /* XXX This will break if there is a space in the command */
74 n = sscanf(data, "%*d %*s %*c %d", &parent);
76 printk("Failed to scan '%s'\n", data);
81 void os_stop_process(int pid)
86 void os_kill_process(int pid, int reap_child)
90 waitpid(pid, NULL, 0);
94 void os_usr1_process(int pid)
96 syscall(__NR_tkill, pid, SIGUSR1);
97 /* kill(pid, SIGUSR1); */
105 int os_map_memory(void *virt, int fd, unsigned long long off, unsigned long len,
111 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
114 loc = mmap64((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
116 if(loc == MAP_FAILED)
121 int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
123 int prot = ((r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
124 (x ? PROT_EXEC : 0));
126 if(mprotect(addr, len, prot) < 0)
131 int os_unmap_memory(void *addr, int len)
135 err = munmap(addr, len);
142 * Overrides for Emacs so that we follow Linus's tabbing style.
143 * Emacs will notice this stuff at the end of the file and automatically
144 * adjust the settings for this buffer only. This must remain at the end
146 * ---------------------------------------------------------------------------
148 * c-file-style: "linux"