Rizin
unix-like reverse engineering framework and cli tools
darwin-proctitle.c File Reference
#include "uv.h"
#include "internal.h"
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <TargetConditionals.h>
#include "darwin-stub.h"

Go to the source code of this file.

Macros

#define S(s)   pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
 

Functions

static int uv__pthread_setname_np (const char *name)
 
int uv__set_process_title (const char *title)
 

Macro Definition Documentation

◆ S

#define S (   s)    pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)

Function Documentation

◆ uv__pthread_setname_np()

static int uv__pthread_setname_np ( const char *  name)
static

Definition at line 37 of file darwin-proctitle.c.

37  {
38  char namebuf[64]; /* MAXTHREADNAMESIZE */
39  int err;
40 
41  strncpy(namebuf, name, sizeof(namebuf) - 1);
42  namebuf[sizeof(namebuf) - 1] = '\0';
43 
44  err = pthread_setname_np(namebuf);
45  if (err)
46  return UV__ERR(err);
47 
48  return 0;
49 }
static bool err
Definition: armass.c:435
char namebuf[CAB_NAMEMAX]
Definition: cabinfo.c:331
#define UV__ERR(x)
Definition: errno.h:29
Definition: z80asm.h:102

References err, namebuf, and UV__ERR.

Referenced by uv__set_process_title().

◆ uv__set_process_title()

int uv__set_process_title ( const char *  title)

Definition at line 52 of file darwin-proctitle.c.

52  {
53 #if TARGET_OS_IPHONE
54  return uv__pthread_setname_np(title);
55 #else
56  CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
57  const char*,
59  CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
60  void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
61  void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
62  CFTypeRef (*pLSGetCurrentApplicationASN)(void);
63  OSStatus (*pLSSetApplicationInformationItem)(int,
64  CFTypeRef,
68  void* application_services_handle;
69  void* core_foundation_handle;
70  CFBundleRef launch_services_bundle;
71  CFStringRef* display_name_key;
72  CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
73  CFBundleRef (*pCFBundleGetMainBundle)(void);
74  CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
75  void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
76  void*);
77  CFTypeRef asn;
78  int err;
79 
80  err = UV_ENOENT;
81  application_services_handle = dlopen("/System/Library/Frameworks/"
82  "ApplicationServices.framework/"
83  "Versions/A/ApplicationServices",
84  RTLD_LAZY | RTLD_LOCAL);
85  core_foundation_handle = dlopen("/System/Library/Frameworks/"
86  "CoreFoundation.framework/"
87  "Versions/A/CoreFoundation",
88  RTLD_LAZY | RTLD_LOCAL);
89 
90  if (application_services_handle == NULL || core_foundation_handle == NULL)
91  goto out;
92 
93  *(void **)(&pCFStringCreateWithCString) =
94  dlsym(core_foundation_handle, "CFStringCreateWithCString");
95  *(void **)(&pCFBundleGetBundleWithIdentifier) =
96  dlsym(core_foundation_handle, "CFBundleGetBundleWithIdentifier");
97  *(void **)(&pCFBundleGetDataPointerForName) =
98  dlsym(core_foundation_handle, "CFBundleGetDataPointerForName");
99  *(void **)(&pCFBundleGetFunctionPointerForName) =
100  dlsym(core_foundation_handle, "CFBundleGetFunctionPointerForName");
101 
102  if (pCFStringCreateWithCString == NULL ||
103  pCFBundleGetBundleWithIdentifier == NULL ||
104  pCFBundleGetDataPointerForName == NULL ||
105  pCFBundleGetFunctionPointerForName == NULL) {
106  goto out;
107  }
108 
109 #define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
110 
111  launch_services_bundle =
112  pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices"));
113 
114  if (launch_services_bundle == NULL)
115  goto out;
116 
117  *(void **)(&pLSGetCurrentApplicationASN) =
118  pCFBundleGetFunctionPointerForName(launch_services_bundle,
119  S("_LSGetCurrentApplicationASN"));
120 
121  if (pLSGetCurrentApplicationASN == NULL)
122  goto out;
123 
124  *(void **)(&pLSSetApplicationInformationItem) =
125  pCFBundleGetFunctionPointerForName(launch_services_bundle,
126  S("_LSSetApplicationInformationItem"));
127 
128  if (pLSSetApplicationInformationItem == NULL)
129  goto out;
130 
131  display_name_key = pCFBundleGetDataPointerForName(launch_services_bundle,
132  S("_kLSDisplayNameKey"));
133 
134  if (display_name_key == NULL || *display_name_key == NULL)
135  goto out;
136 
137  *(void **)(&pCFBundleGetInfoDictionary) = dlsym(core_foundation_handle,
138  "CFBundleGetInfoDictionary");
139  *(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
140  "CFBundleGetMainBundle");
141  if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
142  goto out;
143 
144  *(void **)(&pLSApplicationCheckIn) = pCFBundleGetFunctionPointerForName(
145  launch_services_bundle,
146  S("_LSApplicationCheckIn"));
147 
148  if (pLSApplicationCheckIn == NULL)
149  goto out;
150 
151  *(void **)(&pLSSetApplicationLaunchServicesServerConnectionStatus) =
152  pCFBundleGetFunctionPointerForName(
153  launch_services_bundle,
154  S("_LSSetApplicationLaunchServicesServerConnectionStatus"));
155 
156  if (pLSSetApplicationLaunchServicesServerConnectionStatus == NULL)
157  goto out;
158 
159  pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
160 
161  /* Check into process manager?! */
162  pLSApplicationCheckIn(-2,
163  pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
164 
165  asn = pLSGetCurrentApplicationASN();
166 
167  err = UV_EBUSY;
168  if (asn == NULL)
169  goto out;
170 
171  err = UV_EINVAL;
172  if (pLSSetApplicationInformationItem(-2, /* Magic value. */
173  asn,
174  *display_name_key,
175  S(title),
176  NULL) != noErr) {
177  goto out;
178  }
179 
180  uv__pthread_setname_np(title); /* Don't care if it fails. */
181  err = 0;
182 
183 out:
184  if (core_foundation_handle != NULL)
185  dlclose(core_foundation_handle);
186 
187  if (application_services_handle != NULL)
188  dlclose(application_services_handle);
189 
190  return err;
191 #endif /* !TARGET_OS_IPHONE */
192 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define NULL
Definition: cris-opc.c:27
static int uv__pthread_setname_np(const char *name)
#define S(s)
void * CFBundleRef
Definition: darwin-stub.h:45
static const OSStatus noErr
Definition: darwin-stub.h:89
void * CFDictionaryRef
Definition: darwin-stub.h:47
int OSStatus
Definition: darwin-stub.h:35
void * CFStringRef
Definition: darwin-stub.h:52
void * CFAllocatorRef
Definition: darwin-stub.h:43
void * CFTypeRef
Definition: darwin-stub.h:53
unsigned CFStringEncoding
Definition: darwin-stub.h:42
static int
Definition: sfsocketcall.h:114
unsigned long uint64_t
Definition: sftypes.h:28

References err, int, noErr, NULL, out, S, and uv__pthread_setname_np().