~swisschili/bluejay

ref: a7568dc427ab04f649fecea3e9425f1c18e586d0 bluejay/src/lisp/plat/linux.c -rw-r--r-- 1.1 KiB
a7568dc4swissChili Add unquote-splice (,@) 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "plat.h"
#include "../error.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#ifndef NO_READLINE
#include <readline/readline.h>
#include <readline/history.h>
#endif

void *malloc_aligned(size_t size)
{
	// https://www.gnu.org/software/libc/manual/html_node/Aligned-Memory-Blocks.html
	// On glibc malloc() and realloc() return 8-byte aligned addresses.
	return malloc(size);
}

void *realloc_aligned(void *addr, size_t size)
{
	return realloc(addr, size);
}

void free_aligned(void *addr)
{
	free(addr);
}

void *link_program(dasm_State **Dst)
{
	size_t size;
	void *buf;

	dasm_link(Dst, &size);
	buf = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1,
	           0);
	dasm_encode(Dst, buf);

	mprotect(buf, size, PROT_READ | PROT_EXEC);
	return buf;
}

bool file_exists(const char *path)
{
	return access(path, F_OK) == 0;
}

char *read_input_line(char *prompt)
{
#ifndef NO_READLINE
	return readline(prompt);
#else
	UNUSED(prompt);
	return "";
#endif
}

void add_line_to_history(char *line)
{
#ifndef NO_READLINE
	add_history(line);
#else
	UNUSED(line);
#endif
}