]> git.saurik.com Git - apple/system_cmds.git/blame - mach_init.tproj/lists.h
system_cmds-230.0.2.tar.gz
[apple/system_cmds.git] / mach_init.tproj / lists.h
CommitLineData
1815bff5 1/*
b51d5b5f 2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
1815bff5
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6d658acd
A
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.
1815bff5
A
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,
6d658acd
A
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.
1815bff5
A
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
b51d5b5f 33#import <sys/types.h>
1815bff5
A
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
42typedef struct bootstrap bootstrap_info_t;
43typedef struct service service_t;
44typedef struct server server_t;
45
46/* Bootstrap info */
47struct bootstrap {
48 bootstrap_info_t *next; /* list of all bootstraps */
49 bootstrap_info_t *prev;
50 bootstrap_info_t *parent;
b51d5b5f 51 bootstrap_info_t *deactivate; /* list being deactivated */
1815bff5
A
52 mach_port_name_t bootstrap_port;
53 mach_port_name_t requestor_port;
b51d5b5f 54 unsigned int ref_count;
1815bff5
A
55};
56
57/* Service types */
58typedef enum {
59 DECLARED, /* Declared in config file */
60 REGISTERED, /* Registered dynamically */
61 SELF /* Name bound bootstrap service itself */
62} servicetype_t;
63
64struct service {
65 service_t *next; /* list of all services */
66 service_t *prev;
67 name_t name; /* service name */
68 mach_port_name_t port; /* service port,
69 may have all rights if inactive */
70 bootstrap_info_t *bootstrap; /* bootstrap port(s) used at this
71 * level. */
72 boolean_t isActive; /* server is running */
73 servicetype_t servicetype; /* Declared, Registered, or Machport */
74 server_t *server; /* server, declared services only */
75};
76
77/* Server types */
78typedef enum {
79 SERVER, /* Launchable server */
80 RESTARTABLE, /* Restartable server */
b51d5b5f
A
81 DEMAND, /* Restartable server - on demand */
82 MACHINIT, /* mach_init doesn't get launched. */
1815bff5
A
83} servertype_t;
84
85#define NULL_SERVER NULL
86#define ACTIVE TRUE
87
88struct server {
89 server_t *next; /* list of all servers */
90 server_t *prev;
91 servertype_t servertype;
92 cmd_t cmd; /* server command to exec */
b51d5b5f 93 int uid; /* uid to exec server with */
1815bff5 94 mach_port_t port; /* server's priv bootstrap port */
b51d5b5f
A
95 mach_port_t task_port; /* server's task port */
96 pid_t pid; /* server's pid */
97 int activity; /* count of checkins/registers this instance */
98 int active_services;/* count of active services */
99 bootstrap_info_t *bootstrap; /* bootstrap context */
1815bff5
A
100};
101
102#define NO_PID (-1)
103
104extern void init_lists(void);
b51d5b5f 105
1815bff5 106extern server_t *new_server(
b51d5b5f
A
107 bootstrap_info_t *bootstrap,
108 const char *cmd,
109 int uid,
110 servertype_t servertype);
111
112extern service_t *new_service(
1815bff5 113 bootstrap_info_t *bootstrap,
b51d5b5f
A
114 const char *name,
115 mach_port_t service_port,
116 boolean_t isActive,
117 servicetype_t servicetype,
118 server_t *serverp);
119
1815bff5
A
120extern bootstrap_info_t *new_bootstrap(
121 bootstrap_info_t *parent,
122 mach_port_name_t bootstrap_port,
123 mach_port_name_t requestor_port);
124
125extern server_t *lookup_server_by_port(mach_port_t port);
126extern server_t *lookup_server_by_task_port(mach_port_t port);
b51d5b5f
A
127extern void setup_server(server_t *serverp);
128extern void delete_server(server_t *serverp);
129extern boolean_t active_server(server_t *serverp);
130extern boolean_t useless_server(server_t *serverp);
131
132extern void delete_service(service_t *servicep);
1815bff5
A
133extern service_t *lookup_service_by_name(bootstrap_info_t *bootstrap, name_t name);
134extern service_t *lookup_service_by_port(mach_port_t port);
b51d5b5f
A
135extern service_t *lookup_service_by_server(server_t *serverp);
136
137extern bootstrap_info_t *lookup_bootstrap_by_port(mach_port_t port);
138extern bootstrap_info_t *lookup_bootstrap_by_req_port(mach_port_t port);
139extern void deactivate_bootstrap(bootstrap_info_t *bootstrap);
140extern void deallocate_bootstrap(bootstrap_info_t *bootstrap);
141extern boolean_t active_bootstrap(bootstrap_info_t *bootstrap);
142
1815bff5
A
143extern void *ckmalloc(unsigned nbytes);
144
145extern bootstrap_info_t bootstraps; /* head of list of bootstrap ports */
146extern server_t servers; /* head of list of all servers */
147extern service_t services; /* head of list of all services */
148extern unsigned nservices; /* number of services in list */
149
150#define FIRST(q) ((q).next)
151#define NEXT(qe) ((qe)->next)
152#define PREV(qe) ((qe)->prev)
153#define IS_END(qe, q) ((qe) == &(q))