2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
15 unsigned long os_process_pc(int pid)
17 char proc_stat[sizeof("/proc/#####/stat\0")], buf[256];
21 sprintf(proc_stat, "/proc/%d/stat", pid);
22 fd = os_open_file(proc_stat, of_read(OPENFLAGS()), 0);
24 printk("os_process_pc - couldn't open '%s', errno = %d\n",
28 if(read(fd, buf, sizeof(buf)) < 0){
29 printk("os_process_pc - couldn't read '%s', errno = %d\n",
36 if(sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*d %*d %*d "
37 "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d "
38 "%*d %*d %*d %*d %ld", &pc) != 1){
39 printk("os_process_pc - couldn't find pc in '%s'\n", buf);
44 int os_process_parent(int pid)
46 char stat[sizeof("/proc/nnnnn/stat\0")];
50 if(pid == -1) return(-1);
52 snprintf(stat, sizeof(stat), "/proc/%d/stat", pid);
53 fd = os_open_file(stat, of_read(OPENFLAGS()), 0);
55 printk("Couldn't open '%s', errno = %d\n", stat, -fd);
59 n = read(fd, data, sizeof(data));
63 printk("Couldn't read '%s', errno = %d\n", stat);
68 /* XXX This will break if there is a space in the command */
69 n = sscanf(data, "%*d %*s %*c %d", &parent);
70 if(n != 1) printk("Failed to scan '%s'\n", data);
75 void os_stop_process(int pid)
80 void os_kill_process(int pid, int reap_child)
84 waitpid(pid, NULL, 0);
88 void os_usr1_process(int pid)
98 int os_map_memory(void *virt, int fd, unsigned long off, unsigned long len,
104 prot = (r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
107 loc = mmap((void *) virt, len, prot, MAP_SHARED | MAP_FIXED,
109 if(loc == MAP_FAILED)
114 int os_protect_memory(void *addr, unsigned long len, int r, int w, int x)
116 int prot = ((r ? PROT_READ : 0) | (w ? PROT_WRITE : 0) |
117 (x ? PROT_EXEC : 0));
119 if(mprotect(addr, len, prot) < 0)
124 int os_unmap_memory(void *addr, int len)
128 err = munmap(addr, len);
129 if(err < 0) return(-errno);
134 * Overrides for Emacs so that we follow Linus's tabbing style.
135 * Emacs will notice this stuff at the end of the file and automatically
136 * adjust the settings for this buffer only. This must remain at the end
138 * ---------------------------------------------------------------------------
140 * c-file-style: "linux"