this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement proc_pidinfo(PROC_PIDPATHINFO)

+17 -2
+17 -2
src/kernel/emulation/linux/misc/proc_info.c
··· 10 10 #include "../fcntl/open.h" 11 11 #include "../unistd/close.h" 12 12 #include "../unistd/read.h" 13 + #include "../unistd/readlink.h" 13 14 #include "../unistd/getuid.h" 14 15 #include "../unistd/getgid.h" 15 16 #include "../simple.h" ··· 18 19 #include <stdbool.h> 19 20 #include <sys/proc.h> 20 21 #include <lkm/api.h> 22 + #include "../mach/lkm.h" 21 23 #include "sysctl_proc.h" 22 24 23 25 #define LINUX_PR_SET_NAME 15 24 26 25 27 static long _proc_pidinfo(int32_t pid, uint32_t flavor, uint64_t arg, void* buffer, int32_t bufsize); 26 28 29 + extern __SIZE_TYPE__ strlen(const char *s); 27 30 extern void *memset(void *s, int c, __SIZE_TYPE__ n); 28 31 extern void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n); 29 32 extern char *strcpy(char *dest, const char *src); ··· 53 56 // thus we can ignore pid and assume we're talking about 54 57 // the current thread. 55 58 int ret; 56 - 59 + 57 60 ret = LINUX_SYSCALL(__NR_prctl, LINUX_PR_SET_NAME, buffer, 0UL, 0UL, 0UL); 58 61 if (ret < 0) 59 62 return errno_linux_to_bsd(ret); ··· 82 85 static long _proc_pidonfo_uniqinfo(int32_t pid, void* buffer, int32_t bufsize); 83 86 static long _proc_pidinfo_tbsdinfo(int32_t pid, void* buffer, int32_t bufsize); 84 87 static long _proc_pidinfo_pidthreadinfo(int32_t pid, uint64_t thread_handle, void* buffer, int32_t bufsize); 88 + static long _proc_pidinfo_pathinfo(int32_t pid, void* buffer, int32_t bufsize); 85 89 86 90 long _proc_pidinfo(int32_t pid, uint32_t flavor, uint64_t arg, void* buffer, int32_t bufsize) 87 91 { ··· 110 114 case PROC_PIDTHREADINFO: 111 115 { 112 116 return _proc_pidinfo_pidthreadinfo(pid, arg, buffer, bufsize); 117 + } 118 + case PROC_PIDPATHINFO: 119 + { 120 + return _proc_pidinfo_pathinfo(pid, buffer, bufsize); 113 121 } 114 122 default: 115 123 { ··· 385 393 386 394 // Parses line such as: 387 395 // 5568e1914000-5568e1915000 r--p 00024000 08:01 4861625 /usr/bin/less 388 - bool parse_smaps_firstline(const char* line, struct proc_regioninfo* ri, struct vnode_info_path* vip) 396 + static bool parse_smaps_firstline(const char* line, struct proc_regioninfo* ri, struct vnode_info_path* vip) 389 397 { 390 398 const char* p; 391 399 const char* minus = NULL; ··· 446 454 return true; 447 455 } 448 456 457 + static long _proc_pidinfo_pathinfo(int32_t pid, void* buffer, int32_t bufsize) 458 + { 459 + char path[64]; 460 + __simple_sprintf(path, "/proc/%d/exe", pid); 461 + memset(buffer, 0, bufsize); 462 + return sys_readlink(path, buffer, bufsize); 463 + }