Process-in-Process
 All Functions Groups Pages
pip.h
1 /*
2  * $PIP_license: <Simplified BSD License>
3  * Redistribution and use in source and binary forms, with or without
4  * modification, are permitted provided that the following conditions are met:
5  *
6  * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  *
9  * Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  * $
25  * $RIKEN_copyright: Riken Center for Computational Sceience (R-CCS),
26  * System Software Development Team, 2016-2021
27  * $
28  * $PIP_VERSION: Version 3.1.0$
29  *
30  * $Author: Atsushi Hori (R-CCS)
31  * Query: procinproc-info@googlegroups.com
32  * User ML: procinproc-users@googlegroups.com
33  * $
34  */
35 
36 #ifndef _pip_h_
37 #define _pip_h_
38 
39 #ifndef DOXYGEN_INPROGRESS
40 
41 #include <stdint.h>
42 #include <stddef.h>
43 #include <string.h>
44 #include <signal.h>
45 #include <stdio.h>
46 #include <errno.h>
47 
48 #define PIP_OPTS_NONE (0x0)
49 
50 #define PIP_MODE_PTHREAD (0x1000U)
51 #define PIP_MODE_PROCESS (0x2000U)
52 /* the following two modes are a submode of PIP_MODE_PROCESS */
53 #define PIP_MODE_PROCESS_PRELOAD (0x2100U)
54 #define PIP_MODE_PROCESS_PIPCLONE (0x2200U)
55 #define PIP_MODE_PROCESS_GOT (0x2400U)
56 #define PIP_MODE_MASK (0xFF00U)
57 
58 #define PIP_ENV_MODE "PIP_MODE"
59 #define PIP_ENV_MODE_THREAD "thread"
60 #define PIP_ENV_MODE_PTHREAD "pthread"
61 #define PIP_ENV_MODE_PROCESS "process"
62 #define PIP_ENV_MODE_PROCESS_PRELOAD "process:preload"
63 #define PIP_ENV_MODE_PROCESS_PIPCLONE "process:pipclone"
64 #define PIP_ENV_MODE_PROCESS_GOT "process:got"
65 
66 #define PIP_ENV_STOP_ON_START "PIP_STOP_ON_START"
67 
68 #define PIP_ENV_GDB_PATH "PIP_GDB_PATH"
69 #define PIP_ENV_GDB_COMMAND "PIP_GDB_COMMAND"
70 #define PIP_ENV_GDB_SIGNALS "PIP_GDB_SIGNALS"
71 #define PIP_ENV_SHOW_MAPS "PIP_SHOW_MAPS"
72 #define PIP_ENV_SHOW_PIPS "PIP_SHOW_PIPS"
73 
74 #define PIP_VALID_OPTS \
75  ( PIP_MODE_PTHREAD | PIP_MODE_PROCESS_PRELOAD | \
76  PIP_MODE_PROCESS_PIPCLONE | PIP_MODE_PROCESS_GOT )
77 
78 #define PIP_ENV_STACKSZ "PIP_STACKSZ"
79 
80 #define PIP_MAGIC_NUM (-747) /* "PIP" P=7, I=4 */
81 
82 #define PIP_PIPID_ROOT (PIP_MAGIC_NUM-1)
83 #define PIP_PIPID_MYSELF (PIP_MAGIC_NUM-2)
84 #define PIP_PIPID_ANY (PIP_MAGIC_NUM-3)
85 #define PIP_PIPID_NULL (PIP_MAGIC_NUM-4)
86 #define PIP_PIPID_SELF PIP_PIPID_MYSELF
87 
88 #define PIP_NTASKS_MAX (300)
89 
90 #define PIP_CPUCORE_FLAG_SHIFT (24)
91 #define PIP_CPUCORE_FLAG_MASK (0xFFU<<PIP_CPUCORE_FLAG_SHIFT)
92 #define PIP_CPUCORE_CORENO_MAX ((1U<<20)-1)
93 #define PIP_CPUCORE_ASIS (0x1U<<PIP_CPUCORE_FLAG_SHIFT)
94 #define PIP_CPUCORE_ABS (0x2U<<PIP_CPUCORE_FLAG_SHIFT)
95 #define PIP_CPUCORE_CORENO_MASK ((0x1U<<PIP_CPUCORE_FLAG_SHIFT)-1)
96 
97 #define PIP_YIELD_DEFAULT (0x0U)
98 #define PIP_YIELD_USER (0x1U)
99 #define PIP_YIELD_SYSTEM (0x2U)
100 
101 typedef struct {
102  char *prog;
103  char **argv;
104  char **envv;
105  char *funcname;
106  void *arg;
107  void *exp;
108  void *aux;
109  void *reserved[2];
110 } pip_spawn_program_t;
111 
112 typedef int (*pip_spawnhook_t)( void* );
113 
114 typedef struct {
115  pip_spawnhook_t before;
116  pip_spawnhook_t after;
117  void *hookarg;
118  void *reserved[5];
119 } pip_spawn_hook_t;
120 
121 typedef uintptr_t pip_id_t;
122 
123 #ifdef __cplusplus
124 extern "C" {
125 #endif
126 
127 #ifndef INLINE
128 #define INLINE inline static
129 #endif
130 
131 #endif /* DOXYGEN */
132 
252  int pip_init( int *pipidp, int *ntasks, void **root_expp, uint32_t opts );
253 
277  int pip_fin( void );
278 
319 #ifndef DOXYGEN_INPROGRESS
320 INLINE
321 #endif
322 void pip_spawn_from_main( pip_spawn_program_t *progp,
323  char *prog, char **argv, char **envv,
324  void *exp, void *aux ) {
325  memset( progp, 0, sizeof(pip_spawn_program_t) );
326  if( prog != NULL ) {
327  progp->prog = prog;
328  } else {
329  progp->prog = argv[0];
330  }
331  progp->argv = argv;
332  if( envv == NULL ) {
333  extern char **environ;
334  progp->envv = environ;
335  } else {
336  progp->envv = envv;
337  }
338  progp->exp = exp;
339  progp->aux = aux;
340 }
341 
381 #ifndef DOXYGEN_INPROGRESS
382 INLINE
383 #endif
384 void pip_spawn_from_func( pip_spawn_program_t *progp,
385  char *prog, char *funcname, void *arg, char **envv,
386  void *exp, void *aux ) {
387  memset( progp, 0, sizeof(pip_spawn_program_t) );
388  progp->prog = prog;
389  progp->funcname = funcname;
390  progp->arg = arg;
391  if( envv == NULL ) {
392  extern char **environ;
393  progp->envv = environ;
394  } else {
395  progp->envv = envv;
396  }
397  progp->exp = exp;
398  progp->aux = aux;
399 }
400 
455 #ifndef DOXYGEN_INPROGRESS
456 INLINE
457 #endif
458 void pip_spawn_hook( pip_spawn_hook_t *hook,
459  pip_spawnhook_t before,
460  pip_spawnhook_t after,
461  void *hookarg ) {
462  hook->before = before;
463  hook->after = after;
464  hook->hookarg = hookarg;
465 }
466 
533 int pip_task_spawn( pip_spawn_program_t *progp,
534  uint32_t coreno,
535  uint32_t opts,
536  int *pipidp,
537  pip_spawn_hook_t *hookp );
538 
611  int pip_spawn( char *filename, char **argv, char **envv,
612  uint32_t coreno, int *pipidp,
613  pip_spawnhook_t before, pip_spawnhook_t after, void *hookarg);
614 
659  int pip_named_export( void *exp, const char *format, ... )
660  __attribute__ ((format (printf, 2, 3)));
661 
703  int pip_named_import( int pipid, void **expp, const char *format, ... )
704  __attribute__ ((format (printf, 3, 4)));
705 
742  int pip_named_tryimport( int pipid, void **expp, const char *format, ... )
743  __attribute__ ((format (printf, 3, 4)));
744 
770  int pip_export( void *exp );
771 
798  int pip_import( int pipid, void **expp );
799 
817  int pip_set_aux( void *aux );
818 
837  int pip_get_aux( void **auxp );
838 
858  int pip_get_dlmopen_info( int pipid, void **handlep, long *lmidp );
859 
903  int pip_wait( int pipid, int *status );
904 
942  int pip_trywait( int pipid, int *status );
943 
974  int pip_wait_any( int *pipid, int *status );
975 
1004  int pip_trywait_any( int *pipid, int *status );
1005 
1032  int pip_get_pipid( int *pipidp );
1033 
1046  int pip_is_initialized( void );
1047 
1063  int pip_get_ntasks( int *ntasksp );
1064 
1081  int pip_get_mode( int *modep );
1082 
1097  const char *pip_get_mode_str( void );
1098 
1121  int pip_get_system_id( int pipid, pip_id_t *idp );
1122 
1135  int pip_isa_root( void );
1136 
1149  int pip_isa_task( void );
1150 
1166  int pip_is_threaded( int *flagp );
1167 
1183  int pip_is_shared_fd( int *flagp );
1184 
1224  void pip_exit( int status );
1225 
1242  int pip_kill_all_tasks( void );
1243 
1252  void pip_abort(void);
1253 
1258 #ifndef DOXYGEN_INPROGRESS
1259 
1260  pid_t pip_gettid( void );
1261  void pip_glibc_lock( void );
1262  void pip_glibc_unlock( void );
1263  void pip_debug_info( void );
1264  size_t pip_idstr( char*, size_t );
1265  int pip_check_pie( const char*, int );
1266 
1267 #ifdef __cplusplus
1268 }
1269 #endif
1270 
1271 #include <pip/pip_blt.h>
1272 #include <pip/pip_dlfcn.h>
1273 #include <pip/pip_signal.h>
1274 
1275 #endif /* DOXYGEN */
1276 
1277 #endif /* _pip_h_ */
void pip_spawn_from_main(pip_spawn_program_t *progp, char *prog, char **argv, char **envv, void *exp, void *aux)
Setting information to invoke a PiP task starting from the main function.
Definition: pip.h:322
int pip_init(int *pipidp, int *ntasks, void **root_expp, uint32_t opts)
Initialize the PiP library.
int pip_get_dlmopen_info(int pipid, void **handlep, long *lmidp)
Retrieve the loaded link map info. of the specified Pip task.
void pip_spawn_from_func(pip_spawn_program_t *progp, char *prog, char *funcname, void *arg, char **envv, void *exp, void *aux)
Setting information to invoke a PiP task starting from a function defined in a program.
Definition: pip.h:384
int pip_fin(void)
Finalize the PiP library.
void pip_exit(int status)
terminate the calling PiP task
int pip_is_initialized(void)
Query is PiP library is already initialized.
int pip_named_export(void *exp, const char *format,...) __attribute__((format(printf
export an address of the calling PiP root or a PiP task to the others.
int pip_isa_task(void)
check if calling PiP task is a PiP task or not
int int int pip_named_tryimport(int pipid, void **expp, const char *format,...) __attribute__((format(printf
import the named exported address (non-blocking)
int pip_wait_any(int *pipid, int *status)
Wait for the termination of any PiP task.
int pip_get_system_id(int pipid, pip_id_t *idp)
deliver a process or thread ID defined by the system
int int int int pip_export(void *exp)
export an address
int pip_trywait(int pipid, int *status)
wait for the termination of a PiP task in a non-blocking way
int pip_isa_root(void)
check if calling PiP task is a PiP root or not
int pip_get_aux(void **auxp)
Retrieve the user data associated with a PiP task.
int pip_import(int pipid, void **expp)
import exported address of a PiP task
int pip_set_aux(void *aux)
Associate user data with a PiP task.
int pip_is_threaded(int *flagp)
check if PiP execution mode is pthread or not
int pip_trywait_any(int *pipid, int *status)
non-blocking version of pip_wait_any
int pip_wait(int pipid, int *status)
wait for the termination of a PiP task
int pip_is_shared_fd(int *flagp)
check if file descriptors are shared or not. This is equivalent with the pip_is_threaded function...
int pip_task_spawn(pip_spawn_program_t *progp, uint32_t coreno, uint32_t opts, int *pipidp, pip_spawn_hook_t *hookp)
Spawning a PiP task.
const char * pip_get_mode_str(void)
get a character string of the current execution mode
int pip_get_ntasks(int *ntasksp)
get the maximum number of the PiP tasks
void pip_abort(void)
Kill all PiP tasks and then kill PiP root.
int pip_spawn(char *filename, char **argv, char **envv, uint32_t coreno, int *pipidp, pip_spawnhook_t before, pip_spawnhook_t after, void *hookarg)
spawn a PiP task (PiP v1 API and deprecated)
int pip_get_mode(int *modep)
get the PiP execution mode
int int pip_named_import(int pipid, void **expp, const char *format,...) __attribute__((format(printf
import the named exported address
int pip_kill_all_tasks(void)
kill all PiP tasks
void pip_spawn_hook(pip_spawn_hook_t *hook, pip_spawnhook_t before, pip_spawnhook_t after, void *hookarg)
Setting invocation hook information.
Definition: pip.h:458
int pip_get_pipid(int *pipidp)
get PiP ID of the calling task