fb2cf1128843869c5ba882676c0392682b5bab41
[monolithium.git] / kernel / include / object.h
1 /*
2  * object.h
3  *
4  * Copyright (C) 2013 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as
8  * published by the Free Software Foundation, either version 3 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef _OBJECT_H_
21 #define _OBJECT_H_
22
23 #include <common.h>
24 #include <list.h>
25
26 #define INVALID_HANDLE (handle_t)-1
27
28 typedef dword_t handle_t;
29 typedef dword_t access_flags_t;
30
31 typedef enum
32 {
33     OBJECT_FILE,
34     OBJECT_FILE_INSTANCE,
35     OBJECT_PIPE,
36     OBJECT_PROCESS,
37     OBJECT_THREAD,
38     OBJECT_MEMORY,
39     OBJECT_SEMAPHORE,
40     OBJECT_USER,
41
42     OBJECT_TYPE_MAX
43 } object_type_t;
44
45 typedef enum
46 {
47     HANDLE_INFO_NAME,
48     HANDLE_INFO_TYPE,
49 } handle_info_type_t;
50
51 typedef enum
52 {
53     ACCESS_DEFAULT_ALLOW = 0,
54     ACCESS_DEFAULT_DENY,
55 } access_control_policy_t;
56
57 typedef struct
58 {
59     list_entry_t list;
60     dword_t uid;
61     access_flags_t access_mask;
62 } access_control_entry_t;
63
64 typedef struct
65 {
66     list_entry_t by_name_list;
67     list_entry_t by_type_list;
68     char *name;
69     qword_t ref_count, open_count;
70     object_type_t type;
71     access_control_policy_t acp;
72     list_entry_t acl;
73 } object_t;
74
75 typedef void (*object_cleanup_proc_t)(object_t *obj);
76
77 dword_t create_object(object_t *object);
78 void reference(object_t *object);
79 void dereference(object_t *object);
80 bool_t reference_by_name(const char *name, object_type_t type, object_t **object);
81 bool_t reference_by_handle(handle_t handle, object_type_t type, object_t **object);
82 dword_t open_object(object_t *obj, access_flags_t access_flags, handle_t *handle);
83 dword_t open_object_by_name(const char *name, object_type_t type, access_flags_t access_flags, handle_t *handle);
84 void close_object_internal(object_t *obj);
85 dword_t close_object(handle_t handle);
86 dword_t query_handle(handle_t handle, handle_info_type_t type, void *buffer, size_t size);
87 dword_t duplicate_handle(handle_t source_process, handle_t handle, handle_t dest_process, handle_t *duplicate);
88 dword_t enum_objects_by_type(object_type_t type, object_t **object);
89
90 #endif