]> git.saurik.com Git - apple/system_cmds.git/blob - mach_init.tproj/lists.h
system_cmds-279.tar.gz
[apple/system_cmds.git] / mach_init.tproj / lists.h
1 /*
2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * bootstrap -- fundamental service initiator and port server
27 * Mike DeMoney, NeXT, Inc.
28 * Copyright, 1990. All rights reserved.
29 *
30 * lists.h -- interface to list routines
31 */
32
33 #import <sys/types.h>
34 #import <mach/mach.h>
35 #import <mach/boolean.h>
36 #import <servers/bootstrap_defs.h>
37
38 #ifndef NULL
39 #define NULL ((void *)0)
40 #endif NULL
41
42 typedef struct bootstrap bootstrap_info_t;
43 typedef struct service service_t;
44 typedef struct server server_t;
45
46 /* Bootstrap info */
47 struct bootstrap {
48 bootstrap_info_t *next; /* list of all bootstraps */
49 bootstrap_info_t *prev;
50 bootstrap_info_t *parent;
51 bootstrap_info_t *deactivate; /* list being deactivated */
52 mach_port_name_t bootstrap_port;
53 mach_port_name_t requestor_port;
54 unsigned int ref_count;
55 };
56
57 /* Service types */
58 typedef enum {
59 DECLARED, /* Declared in config file */
60 REGISTERED /* Registered dynamically */
61 } servicetype_t;
62
63 struct service {
64 service_t *next; /* list of all services */
65 service_t *prev;
66 name_t name; /* service name */
67 mach_port_name_t port; /* service port,
68 may have all rights if inactive */
69 bootstrap_info_t *bootstrap; /* bootstrap port(s) used at this
70 * level. */
71 boolean_t isActive; /* server is running */
72 servicetype_t servicetype; /* Declared, Registered, or Machport */
73 server_t *server; /* server, declared services only */
74 };
75
76 /* Server types */
77 typedef enum {
78 SERVER, /* Launchable server */
79 RESTARTABLE, /* Restartable server */
80 DEMAND, /* Restartable server - on demand */
81 MACHINIT, /* mach_init doesn't get launched. */
82 } servertype_t;
83
84 #define NULL_SERVER NULL
85 #define ACTIVE TRUE
86
87 struct server {
88 server_t *next; /* list of all servers */
89 server_t *prev;
90 servertype_t servertype;
91 cmd_t cmd; /* server command to exec */
92 int uid; /* uid to exec server with */
93 mach_port_t port; /* server's priv bootstrap port */
94 mach_port_t task_port; /* server's task port */
95 pid_t pid; /* server's pid */
96 int activity; /* count of checkins/registers this instance */
97 int active_services;/* count of active services */
98 bootstrap_info_t *bootstrap; /* bootstrap context */
99 };
100
101 #define NO_PID (-1)
102
103 extern void init_lists(void);
104
105 extern server_t *new_server(
106 bootstrap_info_t *bootstrap,
107 const char *cmd,
108 int uid,
109 servertype_t servertype);
110
111 extern service_t *new_service(
112 bootstrap_info_t *bootstrap,
113 const char *name,
114 mach_port_t service_port,
115 boolean_t isActive,
116 servicetype_t servicetype,
117 server_t *serverp);
118
119 extern bootstrap_info_t *new_bootstrap(
120 bootstrap_info_t *parent,
121 mach_port_name_t bootstrap_port,
122 mach_port_name_t requestor_port);
123
124 extern server_t *lookup_server_by_port(mach_port_t port);
125 extern server_t *lookup_server_by_task_port(mach_port_t port);
126 extern void setup_server(server_t *serverp);
127 extern void delete_server(server_t *serverp);
128 extern boolean_t active_server(server_t *serverp);
129 extern boolean_t useless_server(server_t *serverp);
130
131 extern void delete_service(service_t *servicep);
132 extern service_t *lookup_service_by_name(bootstrap_info_t *bootstrap, name_t name);
133 extern service_t *lookup_service_by_port(mach_port_t port);
134 extern service_t *lookup_service_by_server(server_t *serverp);
135
136 extern bootstrap_info_t *lookup_bootstrap_by_port(mach_port_t port);
137 extern bootstrap_info_t *lookup_bootstrap_by_req_port(mach_port_t port);
138 extern void deactivate_bootstrap(bootstrap_info_t *bootstrap);
139 extern void deallocate_bootstrap(bootstrap_info_t *bootstrap);
140 extern boolean_t active_bootstrap(bootstrap_info_t *bootstrap);
141
142 extern void *ckmalloc(unsigned nbytes);
143
144 extern bootstrap_info_t bootstraps; /* head of list of bootstrap ports */
145 extern server_t servers; /* head of list of all servers */
146 extern service_t services; /* head of list of all services */
147 extern unsigned nservices; /* number of services in list */
148
149 #define FIRST(q) ((q).next)
150 #define NEXT(qe) ((qe)->next)
151 #define PREV(qe) ((qe)->prev)
152 #define IS_END(qe, q) ((qe) == &(q))