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