Skip to content

Commit edb70ed

Browse files
committed
feat: added new but unfinished tty object to ksurface
1 parent 2d78377 commit edb70ed

File tree

11 files changed

+261
-20
lines changed

11 files changed

+261
-20
lines changed

Config.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
// https://developer.apple.com/documentation/xcode/adding-a-build-configuration-file-to-your-project
1010

1111
VERSION = 0.9.0
12-
BUILD_NUMBER = 20260224.75.US.seanistethered
12+
BUILD_NUMBER = 20260224.76.US.seanistethered

Nyxian.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@
223223
LindChain/ProcEnvironment/Surface/proc/lookup.m,
224224
LindChain/ProcEnvironment/Surface/proc/proc.m,
225225
LindChain/ProcEnvironment/Surface/proc/remove.m,
226-
LindChain/ProcEnvironment/Surface/radix/radix.m,
226+
LindChain/ProcEnvironment/Surface/radix/radix.c,
227227
LindChain/ProcEnvironment/Surface/surface.m,
228228
LindChain/ProcEnvironment/Surface/sys/compat/bamset.m,
229229
LindChain/ProcEnvironment/Surface/sys/compat/getent.m,
@@ -243,6 +243,8 @@
243243
LindChain/ProcEnvironment/Surface/sys/proc/kill.m,
244244
LindChain/ProcEnvironment/Surface/sys/proc/wait4.m,
245245
LindChain/ProcEnvironment/Surface/sys/syscall.m,
246+
LindChain/ProcEnvironment/Surface/tty/lookup.m,
247+
LindChain/ProcEnvironment/Surface/tty/tty.m,
246248
LindChain/ProcEnvironment/syscall.m,
247249
LindChain/ProcEnvironment/Syscall/mach_syscall_client.m,
248250
LindChain/ProcEnvironment/Syscall/mach_syscall_server.m,

Nyxian/LindChain/ProcEnvironment/Surface/lock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#define proc_table_wrlock() pthread_rwlock_wrlock(&(ksurface->proc_info.struct_lock))
2525
#define proc_table_unlock() pthread_rwlock_unlock(&(ksurface->proc_info.struct_lock))
2626

27+
#define tty_table_rdlock() pthread_rwlock_rdlock(&(ksurface->tty_info.struct_lock))
28+
#define tty_table_wrlock() pthread_rwlock_wrlock(&(ksurface->tty_info.struct_lock))
29+
#define tty_table_unlock() pthread_rwlock_unlock(&(ksurface->tty_info.struct_lock))
30+
2731
#define host_rdlock() pthread_rwlock_rdlock(&(ksurface->host_info.struct_lock))
2832
#define host_wrlock() pthread_rwlock_wrlock(&(ksurface->host_info.struct_lock))
2933
#define host_unlock() pthread_rwlock_unlock(&(ksurface->host_info.struct_lock))

Nyxian/LindChain/ProcEnvironment/Surface/mapping.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ typedef struct {
9191
*/
9292
ksurface_proc_t *kern_proc;
9393
} proc_info;
94+
95+
struct {
96+
/* rwlock securing structures */
97+
pthread_rwlock_t struct_lock;
98+
99+
/*
100+
* radix tree where all processes are
101+
* listed inside.
102+
*/
103+
radix_tree_t tty;
104+
} tty_info;
94105
} ksurface_mapping_t;
95106

96107
#endif /* PROCENVIRONMENT_MAPPING_H */

Nyxian/LindChain/ProcEnvironment/Surface/radix/radix.m renamed to Nyxian/LindChain/ProcEnvironment/Surface/radix/radix.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
#include <stdlib.h>
2525
#include <stdbool.h>
2626

27-
static inline int radix_chunk(pid_t pid,
27+
static inline int radix_chunk(uint64_t ident,
2828
int level)
2929
{
3030
int shift = (RADIX_LEVELS - 1 - level) * RADIX_BITS;
31-
return(pid >> shift) & RADIX_MASK;
31+
return(ident >> shift) & RADIX_MASK;
3232
}
3333

3434
void *radix_lookup(radix_tree_t *tree,
35-
pid_t pid)
35+
uint64_t ident)
3636
{
3737
radix_node_t *node = tree->root;
3838

@@ -43,7 +43,7 @@ static inline int radix_chunk(pid_t pid,
4343
return NULL;
4444
}
4545

46-
int chunk = radix_chunk(pid, level);
46+
int chunk = radix_chunk(ident, level);
4747
node = (radix_node_t *)node->slots[chunk];
4848
}
4949

@@ -52,12 +52,12 @@ static inline int radix_chunk(pid_t pid,
5252
return NULL;
5353
}
5454

55-
int chunk = radix_chunk(pid, RADIX_LEVELS - 1);
55+
int chunk = radix_chunk(ident, RADIX_LEVELS - 1);
5656
return node->slots[chunk];
5757
}
5858

5959
int radix_insert(radix_tree_t *tree,
60-
pid_t pid,
60+
uint64_t ident,
6161
void *value)
6262
{
6363
if(tree->root == NULL)
@@ -69,7 +69,7 @@ int radix_insert(radix_tree_t *tree,
6969

7070
for(int level = 0; level < RADIX_LEVELS - 1; level++)
7171
{
72-
int chunk = radix_chunk(pid, level);
72+
int chunk = radix_chunk(ident, level);
7373

7474
if(node->slots[chunk] == NULL)
7575
{
@@ -79,13 +79,14 @@ int radix_insert(radix_tree_t *tree,
7979
node = (radix_node_t *)node->slots[chunk];
8080
}
8181

82-
int chunk = radix_chunk(pid, RADIX_LEVELS - 1);
82+
int chunk = radix_chunk(ident, RADIX_LEVELS - 1);
8383
node->slots[chunk] = value;
8484

8585
return 0;
8686
}
8787

88-
void *radix_remove(radix_tree_t *tree, pid_t pid)
88+
void *radix_remove(radix_tree_t *tree,
89+
uint64_t ident)
8990
{
9091
radix_node_t *node = tree->root;
9192
radix_node_t *path[RADIX_LEVELS];
@@ -99,7 +100,7 @@ int radix_insert(radix_tree_t *tree,
99100
}
100101

101102
path[level] = node;
102-
chunks[level] = radix_chunk(pid, level);
103+
chunks[level] = radix_chunk(ident, level);
103104

104105
if(level < RADIX_LEVELS - 1)
105106
{
@@ -137,7 +138,7 @@ int radix_insert(radix_tree_t *tree,
137138

138139
static void radix_walk_node(radix_node_t *node,
139140
int level,
140-
pid_t pid_prefix,
141+
uint64_t ident_prefix,
141142
radix_walk_fn callback,
142143
void *ctx)
143144
{
@@ -153,15 +154,15 @@ static void radix_walk_node(radix_node_t *node,
153154
continue;
154155
}
155156

156-
pid_t pid = pid_prefix | (i << ((RADIX_LEVELS - 1 - level) * RADIX_BITS));
157+
uint64_t ident = ident_prefix | (i << ((RADIX_LEVELS - 1 - level) * RADIX_BITS));
157158

158159
if(level == RADIX_LEVELS - 1)
159160
{
160-
callback(pid, node->slots[i], ctx);
161+
callback(ident_prefix, node->slots[i], ctx);
161162
}
162163
else
163164
{
164-
radix_walk_node((radix_node_t *)node->slots[i], level + 1, pid, callback, ctx);
165+
radix_walk_node((radix_node_t *)node->slots[i], level + 1, ident_prefix, callback, ctx);
165166
}
166167
}
167168
}

Nyxian/LindChain/ProcEnvironment/Surface/radix/radix.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#import <LindChain/ProcEnvironment/Surface/radix/type/tree.h>
2424
#include <stdlib.h>
2525

26-
typedef void (*radix_walk_fn)(pid_t pid, void *value, void *ctx);
26+
typedef void (*radix_walk_fn)(uint64_t ident, void *value, void *ctx);
2727

28-
void *radix_lookup(radix_tree_t *tree, pid_t pid);
29-
int radix_insert(radix_tree_t *tree, pid_t pid, void *value);
30-
void *radix_remove(radix_tree_t *tree, pid_t pid);
28+
void *radix_lookup(radix_tree_t *tree, uint64_t ident);
29+
int radix_insert(radix_tree_t *tree, uint64_t ident, void *value);
30+
void *radix_remove(radix_tree_t *tree, uint64_t ident);
3131
void radix_walk(radix_tree_t *tree, radix_walk_fn callback, void *ctx);
3232

3333
#endif /* RADIX_H */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright (C) 2025 cr4zyengineer
3+
4+
This file is part of Nyxian.
5+
6+
Nyxian is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Nyxian 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 General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with Nyxian. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef TTY_DEF_H
21+
#define TTY_DEF_H
22+
23+
#import <LindChain/ProcEnvironment/Surface/obj/kvobject.h>
24+
#import <LindChain/ProcEnvironment/Surface/proc/def.h>
25+
#import <limits.h>
26+
#include <unistd.h>
27+
28+
typedef struct ksurface_tty ksurface_tty_t;
29+
30+
struct ksurface_tty {
31+
/* object header */
32+
kvobject_t header;
33+
34+
/* file descriptors */
35+
int masterfd;
36+
int slavefd;
37+
uint64_t slavehandle;
38+
};
39+
40+
#endif /* TTY_DEF_H */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright (C) 2025 cr4zyengineer
3+
4+
This file is part of Nyxian.
5+
6+
Nyxian is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Nyxian 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 General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with Nyxian. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef TTY_LOOKUP_H
21+
#define TTY_LOOKUP_H
22+
23+
#import <LindChain/ProcEnvironment/Surface/tty/def.h>
24+
25+
ksurface_return_t tty_for_handle(uint64_t handle, ksurface_tty_t **tty);
26+
27+
#endif /* TTY_LOOKUP_H */
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright (C) 2025 cr4zyengineer
3+
4+
This file is part of Nyxian.
5+
6+
Nyxian is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Nyxian 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 General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with Nyxian. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#import <LindChain/ProcEnvironment/Surface/surface.h>
21+
#import <LindChain/ProcEnvironment/Surface/tty/lookup.h>
22+
23+
ksurface_return_t tty_for_handle(uint64_t handle,
24+
ksurface_tty_t **tty)
25+
{
26+
/* sanity check */
27+
if(tty == NULL)
28+
{
29+
return SURFACE_NULLPTR;
30+
}
31+
32+
/* tty lookup */
33+
tty_table_rdlock();
34+
*tty = radix_lookup(&(ksurface->tty_info.tty), handle);
35+
tty_table_unlock();
36+
37+
/*
38+
* caller expects retained tty object, so
39+
* attempting to retain it and if it doesnt work
40+
* returning with an error.
41+
*/
42+
if(*tty == NULL ||
43+
!kvo_retain(*tty))
44+
{
45+
return SURFACE_RETAIN_FAILED;
46+
}
47+
48+
return SURFACE_SUCCESS;
49+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
Copyright (C) 2025 cr4zyengineer
3+
4+
This file is part of Nyxian.
5+
6+
Nyxian is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
Nyxian 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 General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with Nyxian. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
#ifndef TTY_TTY_H
21+
#define TTY_TTY_H
22+
23+
#import <LindChain/ProcEnvironment/Surface/surface.h>
24+
#import <LindChain/ProcEnvironment/Surface/tty/def.h>
25+
26+
DEFINE_KVOBJECT_MAIN_EVENT_HANDLER(tty);
27+
28+
#endif /* TTY_TTY_H */

0 commit comments

Comments
 (0)