Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Beatrici <davidebeatrici@gmail.com>2019-07-25 08:29:19 +0300
committerDavide Beatrici <davidebeatrici@gmail.com>2019-08-09 00:51:13 +0300
commite8afc3872a09472e444b41c92a98f307b27b4efc (patch)
tree5aa17cf36b3a4139e08436cdd2cbb4635640bf6b /plugins/mumble_plugin_linux.h
parent4f0a40423b3474e67458ff644f676324b0ec9984 (diff)
plugins: move common functions and variables from OS-specific headers to mumble_plugin_main.h
This is in preparation for the new Source Engine plugin which will add a few common functions. This commit also improves the functions arguments so that they are passed by reference and marked as const (when possible). A new data type called procid_t is created, intended to be a replacement for pid_t (Linux) and DWORD (Windows).
Diffstat (limited to 'plugins/mumble_plugin_linux.h')
-rw-r--r--plugins/mumble_plugin_linux.h43
1 files changed, 5 insertions, 38 deletions
diff --git a/plugins/mumble_plugin_linux.h b/plugins/mumble_plugin_linux.h
index fbdae1b7c..3fff04201 100644
--- a/plugins/mumble_plugin_linux.h
+++ b/plugins/mumble_plugin_linux.h
@@ -18,11 +18,7 @@
#include "mumble_plugin.h"
-pid_t pPid;
-int is64Bit;
-static procptr_t pModule;
-
-static inline std::string readAll(std::string fn) {
+static inline std::string readAll(const std::string &fn) {
std::ifstream ifs;
ifs.open(fn.c_str(), std::ifstream::binary);
@@ -42,7 +38,7 @@ static inline std::string readAll(std::string fn) {
// This function returns 0 if the process is 32-bit and 1 if it's 64-bit.
// In case of failure, it returns -1.
-static inline int checkProcessIs64Bit(const pid_t pid)
+static inline int checkProcessIs64Bit(const procid_t &pid)
{
// We can know the process architecture by looking at its ELF header.
char elf[5];
@@ -74,7 +70,7 @@ static inline int checkProcessIs64Bit(const pid_t pid)
return elf[4] != 1;
}
-static inline procptr_t getModuleAddr(pid_t pid, const wchar_t *modname) {
+static inline procptr_t getModuleAddr(const procid_t &pid, const wchar_t *modname) {
std::wstring modnameWide(modname);
std::string modnameNonWide(modnameWide.begin(), modnameWide.end());
@@ -182,13 +178,9 @@ static inline procptr_t getModuleAddr(pid_t pid, const wchar_t *modname) {
return 0;
}
-static inline procptr_t getModuleAddr(const wchar_t *modname) {
- return getModuleAddr(pPid, modname);
-}
-
-static inline bool peekProc(procptr_t base, void *dest, size_t len) {
+static inline bool peekProc(const procptr_t &addr, void *dest, const size_t &len) {
struct iovec in;
- in.iov_base = reinterpret_cast<void *>(base); // Address from target process
+ in.iov_base = reinterpret_cast<void *>(addr); // Address from target process
in.iov_len = len; // Length
struct iovec out;
@@ -200,31 +192,6 @@ static inline bool peekProc(procptr_t base, void *dest, size_t len) {
return (nread != -1 && static_cast<size_t>(nread) == in.iov_len);
}
-template<class T>
-bool peekProc(procptr_t base, T &dest) {
- struct iovec in;
- in.iov_base = reinterpret_cast<void *>(base); // Address from target process
- in.iov_len = sizeof(T); // Length
-
- struct iovec out;
- out.iov_base = &dest;
- out.iov_len = sizeof(T);
-
- ssize_t nread = process_vm_readv(pPid, &out, 1, &in, 1, 0);
-
- return (nread != -1 && static_cast<size_t>(nread) == in.iov_len);
-}
-
-static inline procptr_t peekProcPtr(procptr_t base) {
- procptr_t v = 0;
-
- if (!peekProc(base, &v, is64Bit ? 8 : 4)) {
- return 0;
- }
-
- return v;
-}
-
static bool inline initialize(const std::multimap<std::wstring, unsigned long long int> &pids, const wchar_t *procname, const wchar_t *modname = NULL) {
pModule = 0;