Skip to content

Commit a323624

Browse files
committed
Added a string channel (though I haven't hooked it up yet).
Then I proceeded to make an awful lot of changes in the process of porting to Linux, to try to figure out the magic problem I was having, where things were working in a debugger, but not outside it. Most of them seemed to not be necessary. It looks like the problem was, I somehow started to get a poll trigger for the stdout fd to be readable before the stdin trigger. I don't know why my machine suddenly freaked out, but the issue does make sense. Stdin and stdout are the same underlying pty when I'm running at the command line, but the debugger has them as two pipes, and not a terminal. Some of the work I did was useful, or made things simpler: For instance: 1) I moved the 'stop the world' used in Garbage Collection from a spin lock to use progressive locking. 2) I added an option to protect the entire heap, and align allocs to the page, so if there's a pointer math error, I can detect it as it happens.
1 parent 2c9e581 commit a323624

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4247
-711
lines changed

include/adts/dt_lists.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include "n00b.h"
44

55
typedef struct {
6+
n00b_rw_lock_t lock;
67
int64_t **data;
78
uint64_t noscan;
8-
n00b_rw_lock_t lock;
99
int32_t append_ix : 30;
1010
// The actual length if treated properly. We should be
1111
// careful about it.

include/adts/duration.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,9 @@ n00b_timeval_to_duration(struct timeval *s)
4848
{
4949
return n00b_new(n00b_type_duration(), n00b_kw("timeval", s));
5050
}
51+
52+
static inline void
53+
n00b_write_now(n00b_duration_t *output)
54+
{
55+
clock_gettime(CLOCK_REALTIME, output);
56+
}

include/channels/channel_buffer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ extern n00b_channel_t *_n00b_io_buf_channel(n00b_buf_t *, bool, ...);
2121
_n00b_out_buf_channel(buffer, __VA_ARGS__ __VA_OPT__(, ) 0ULL, 0ULL)
2222
#define n00b_io_buf_channel(buffer, ...) \
2323
_n00b_io_buf_channel(buffer, __VA_ARGS__ __VA_OPT__(, ) 0ULL, 0ULL)
24+
25+
static inline n00b_buf_t *
26+
n00b_channel_extract_buffer(n00b_channel_t *s)
27+
{
28+
n00b_buffer_channel_t *c = (void *)s->cookie;
29+
30+
if (!n00b_type_is_buffer(n00b_get_my_type(c->buffer))) {
31+
return NULL;
32+
}
33+
34+
return c->buffer;
35+
}

include/channels/channel_fd.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ extern void *_n00b_read_file(n00b_string_t *, ...);
1818
extern n00b_channel_t *_n00b_create_listener(n00b_net_addr_t *, ...);
1919
extern n00b_channel_t *_n00b_channel_connect(n00b_net_addr_t *, ...);
2020

21-
extern void n00b_channel_fd_pause_reads(n00b_channel_t *);
22-
extern void n00b_channel_fd_unpause_reads(n00b_channel_t *);
23-
2421
#define n00b_new_fd_channel(fdstrm, ...) \
2522
_n00b_new_fd_channel(fdstrm, N00B_VA(__VA_ARGS__));
2623

include/channels/channel_string.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
#include "n00b.h"
3+
4+
typedef struct {
5+
n00b_list_t *l;
6+
int ix;
7+
} n00b_string_channel_t;
8+
9+
extern n00b_channel_t *
10+
_n00b_new_string_channel(n00b_string_t *, ...);
11+
12+
#define n00b_string_channel(string, ...) \
13+
_n00b_in_buf_channel(string, __VA_ARGS__ __VA_OPT__(, ) 0ULL)

include/channels/fd_event.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ struct n00b_fd_stream_t {
5353
unsigned int needs_r : 1;
5454
unsigned int r_added : 1;
5555
unsigned int w_added : 1;
56-
unsigned int pause_req : 1; // request pause.
57-
unsigned int is_paused : 1; // Paused.
5856
// This is set externally if the dispatcher should not do the r/w
5957
// itself for a stream. In that case, you probably set the notify
6058
// callback.
@@ -214,28 +212,6 @@ n00b_fd_is_other(n00b_fd_stream_t *s)
214212
|| n00b_fd_is_link(s)));
215213
}
216214

217-
// This is potentially racy, but ideally shouldn't be good design to
218-
// use willy nilly, so didn't work to get it fully safe.
219-
static inline void
220-
n00b_fd_pause_reads(n00b_fd_stream_t *s)
221-
{
222-
if (!s->is_paused) {
223-
s->pause_req = true;
224-
}
225-
226-
n00b_list_append(s->evloop->pending, s);
227-
}
228-
229-
static inline void
230-
n00b_fd_unpause_reads(n00b_fd_stream_t *s)
231-
{
232-
if (s->is_paused) {
233-
s->pause_req = true;
234-
}
235-
236-
n00b_list_append(s->evloop->pending, s);
237-
}
238-
239215
#ifdef N00B_USE_INTERNAL_API
240216
typedef bool (*n00b_condition_test_fn)(void *);
241217
extern bool n00b_condition_poll(n00b_condition_test_fn, void *, int to);

include/channels/filter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,7 @@ typedef struct {
7272
n00b_filter_impl *impl;
7373
int policy;
7474
} n00b_filter_spec_t;
75+
76+
extern n00b_filter_spec_t *n00b_filter_apply_color(void);
77+
extern n00b_filter_spec_t *n00b_filter_json(void);
78+
extern n00b_filter_spec_t *n00b_filter_marshal(void);

include/channels/proc.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ typedef struct {
3838
n00b_list_t *pending_stderr_subs;
3939
n00b_lock_t run_lock;
4040
n00b_condition_t cv;
41-
n00b_buf_t *cap_in;
42-
n00b_buf_t *cap_out;
43-
n00b_buf_t *cap_err;
41+
n00b_channel_t *cap_in;
42+
n00b_channel_t *cap_out;
43+
n00b_channel_t *cap_err;
44+
n00b_channel_t *exit_cb;
4445
n00b_post_fork_hook_t hook;
4546
void *param;
4647
struct winsize dimensions;
@@ -167,7 +168,7 @@ n00b_proc_get_stdout_capture(n00b_proc_t *proc)
167168
if (!proc->cap_out) {
168169
N00B_CRAISE("stdout was not monitored for this process.");
169170
}
170-
return proc->cap_out;
171+
return n00b_channel_extract_buffer(proc->cap_out);
171172
}
172173

173174
static inline n00b_buf_t *
@@ -178,7 +179,7 @@ n00b_proc_get_stderr_capture(n00b_proc_t *proc)
178179
if (!proc->cap_err) {
179180
N00B_CRAISE("stderr was not monitored for this process.");
180181
}
181-
return proc->cap_err;
182+
return n00b_channel_extract_buffer(proc->cap_err);
182183
}
183184

184185
static inline n00b_buf_t *
@@ -190,7 +191,7 @@ n00b_proc_get_stdin_capture(n00b_proc_t *proc)
190191
N00B_CRAISE("stdin was not monitored for this process.");
191192
}
192193

193-
return proc->cap_in;
194+
return n00b_channel_extract_buffer(proc->cap_in);
194195
}
195196

196197
static inline bool

include/channels/terminal_io.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
n00b_channel_t *n00b_chan_stdin(void);
44
n00b_channel_t *n00b_chan_stdout(void);
55
n00b_channel_t *n00b_chan_stderr(void);
6+
n00b_channel_t *n00b_chan_raw_stdin(void);
7+
n00b_channel_t *n00b_chan_raw_stdout(void);
8+
n00b_channel_t *n00b_chan_raw_stderr(void);
69

710
extern void n00b_terminal_dimensions(size_t *cols, size_t *rows);
811
extern void n00b_termcap_apply_raw_mode(struct termios *termcap);

include/core/locks.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22
#include "n00b/base.h"
33

4-
extern bool n00b_is_world_stopped(void);
54
extern bool n00b_abort_signal;
65

76
// Must be a power of 2.

include/core/thread.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ typedef struct {
6363
} n00b_global_thread_info_t;
6464

6565
// Use the first one on thread first start-up only.
66-
extern void n00b_gts_start(void);
67-
extern void n00b_gts_suspend(void);
68-
extern void n00b_gts_resume(void);
69-
extern void n00b_gts_checkin(void);
70-
extern void n00b_gts_stop_the_world(void);
71-
extern void n00b_gts_restart_the_world(void);
66+
extern void _n00b_gts_start(char *, int);
67+
extern void _n00b_gts_suspend(char *, int);
68+
extern void _n00b_gts_resume(char *, int);
69+
extern void _n00b_gts_might_stop(char *, int);
70+
extern void _n00b_gts_stop_the_world(char *, int);
71+
extern void _n00b_gts_wont_stop(char *, int);
72+
extern void _n00b_gts_restart_the_world(char *, int);
73+
extern void n00b_gts_reacquire(void);
7274
extern void n00b_gts_notify_abort(void);
7375

76+
#define n00b_gts_start() _n00b_gts_start(__FILE__, __LINE__)
77+
#define n00b_gts_suspend() _n00b_gts_suspend(__FILE__, __LINE__)
78+
#define n00b_gts_resume() _n00b_gts_resume(__FILE__, __LINE__)
79+
#define n00b_gts_might_stop() _n00b_gts_might_stop(__FILE__, __LINE__)
80+
#define n00b_gts_wont_stop() _n00b_gts_stop_the_world(__FILE__, __LINE__)
81+
#define n00b_gts_stop_the_world() _n00b_gts_stop_the_world(__FILE__, __LINE__)
82+
#define n00b_gts_restart_the_world() _n00b_gts_restart_the_world(__FILE__, __LINE__)
83+
7484
extern void n00b_thread_stack_region(n00b_thread_t *);
7585
extern n00b_thread_t *n00b_thread_register(void);
7686
extern void n00b_thread_unregister(void *);

include/core/tsi.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ typedef struct {
5050
// This flag is used for critical sections with private
5151
// data structures to suspend locking.
5252
int suspend_locking : 1;
53+
int gti_s : 1;
54+
int gti_w : 1;
55+
int gti_r;
56+
char *gti_file;
57+
int gti_line;
58+
int gti_next;
5359
#if defined(N00B_ENABLE_ALLOC_DEBUG)
5460
int show_alloc_locations : 1;
5561
#endif
@@ -247,12 +253,17 @@ n00b_alloc_guard_next_new(void)
247253
#endif
248254

249255
// Use to stash on the stack.
256+
#if 0
250257
#define n00b_push_heap(heap) \
251258
n00b_heap_t *__n00b_saved_heap = n00b_thread_heap(); \
252259
n00b_set_thread_heap(heap)
253260

254261
#define n00b_pop_heap() \
255262
n00b_set_thread_heap(__n00b_saved_heap)
263+
#endif
264+
265+
#define n00b_push_heap(heap)
266+
#define n00b_pop_heap()
256267

257268
#ifdef N00B_USE_INTERNAL_API
258269
extern void

include/crypto/dt_crypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ typedef void *EVP_MD;
66
typedef void *OSSL_PARAM;
77

88
typedef struct {
9+
EVP_MD_CTX openssl_ctx;
910
n00b_buf_t *digest;
10-
EVP_MD_CTX openssl_ctx;
1111
} n00b_sha_t;

include/n00b.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extern bool n00b_startup_complete;
8787
#include "channels/channel_topic.h"
8888
#include "channels/channel_exit.h"
8989
#include "channels/channel_proxy.h"
90-
// #include "channels/channel_string.h"
90+
#include "channels/channel_string.h"
9191
#include "channels/terminal_io.h"
9292
#include "channels/debug.h"
9393

include/n00b/config.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#ifdef n00b_some_stuff_i_may_occasionally_enable_in_testing
22

3-
#define N00B_SHOW_GARBAGE_REPORTS
43
#define N00B_USE_LOCK_DEBUGGING
54
#define N00B_ENABLE_ALLOC_DEBUG_OPT_IN
65
#define N00B_GC_SHOW_COLLECT_STACK_TRACES
@@ -13,7 +12,11 @@
1312
#else
1413
#endif
1514

16-
#define N00B_USE_LOCK_DEBUGGING
15+
// #define N00B_GC_STATS
16+
// #define N00B_DEBUG_GC_ROOTS
17+
// #define N00B_FIND_SCRIBBLES
18+
// #define N00B_SCAN_ALLOC
19+
// #define N00B_USE_LOCK_DEBUGGING
1720

1821
#pragma once
1922
// Home of anything remotely configurable. Don't change this file;
@@ -143,19 +146,6 @@
143146
#define N00B_DEFAULT_HEAP_SIZE (1 << 26) // 30 == 1 g
144147
#endif
145148

146-
#ifndef N00B_SYSTEM_HEAP_SIZE
147-
// Can't be any smaller than this for startup.
148-
#define N00B_SYSTEM_HEAP_SIZE (1 << 24)
149-
#endif
150-
151-
#ifndef N00B_START_STRING_HEAP_SIZE
152-
#define N00B_START_STRING_HEAP_SIZE (1 << 24)
153-
#endif
154-
155-
#ifndef N00B_START_SCRATCH_HEAP_SIZE
156-
#define N00B_START_SCRATCH_HEAP_SIZE (1 << 18)
157-
#endif
158-
159149
#ifndef N00B_MARSHAL_CHUNK_SIZE
160150
#define N00B_MARSHAL_CHUNK_SIZE 512
161151
#endif

include/text/breaks.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static inline n00b_break_info_t *
2424
n00b_alloc_break_structure(n00b_string_t *s, int shift)
2525
{
2626
n00b_break_info_t *result;
27-
int32_t alloc_slots = n00b_max(n00b_string_codepoint_len(s) >> shift,
27+
int32_t alloc_slots = n00b_max(n00b_string_codepoint_len(s)
28+
>> shift,
2829
n00b_minimum_break_slots);
2930

3031
result = n00b_gc_flex_alloc(n00b_break_info_t, int32_t, alloc_slots, NULL);

0 commit comments

Comments
 (0)