1690 lines
28 KiB
JSON

{
"kind": "mapping",
"seed": 20261638,
"events": [
[
"Z"
],
[
"I",
1,
0,
33,
3
],
[
"I",
2,
7,
33,
3
],
[
"I",
3,
14,
33,
3
],
[
"I",
4,
21,
33,
3
],
[
"I",
5,
28,
33,
3
],
[
"I",
6,
35,
33,
3
],
[
"I",
7,
42,
33,
3
],
[
"I",
8,
49,
33,
3
],
[
"I",
9,
56,
33,
3
],
[
"I",
10,
63,
33,
3
],
[
"I",
11,
70,
33,
3
],
[
"I",
12,
77,
33,
3
],
[
"I",
13,
84,
33,
3
],
[
"I",
14,
91,
33,
3
],
[
"I",
15,
98,
33,
3
],
[
"I",
16,
5,
33,
3
],
[
"I",
17,
12,
33,
3
],
[
"I",
18,
19,
33,
3
],
[
"I",
19,
26,
33,
3
],
[
"I",
20,
33,
33,
3
],
[
"I",
21,
40,
33,
3
],
[
"I",
22,
47,
33,
3
],
[
"Z"
],
[
"I",
1,
16,
16,
0
],
[
"H",
1
],
[
"H",
1
],
[
"C",
1
],
[
"R",
1,
0
],
[
"R",
1,
15
],
[
"L",
1
],
[
"R",
1,
14
],
[
"L",
1
],
[
"R",
1,
0
],
[
"I",
1,
0,
1,
0
],
[
"Z"
],
[
"I",
100,
15,
64,
0
],
[
"C",
100
],
[
"I",
20,
17,
13,
0
],
[
"I",
21,
17,
13,
1
],
[
"I",
22,
17,
13,
2
],
[
"I",
23,
17,
13,
3
],
[
"I",
0,
1,
4,
0
],
[
"I",
1,
1,
4,
0
],
[
"I",
6,
1024,
1,
0
],
[
"I",
6,
0,
0,
0
],
[
"I",
6,
1000,
64,
0
],
[
"I",
6,
0,
65,
0
],
[
"I",
6,
0,
1,
4
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"H",
1
],
[
"C",
1
],
[
"C",
1
],
[
"H",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"L",
1
],
[
"Z"
],
[
"I",
1,
0,
64,
0
],
[
"I",
2,
0,
64,
0
],
[
"I",
3,
0,
64,
0
],
[
"I",
4,
0,
64,
0
],
[
"I",
5,
0,
64,
0
],
[
"I",
6,
0,
64,
0
],
[
"I",
7,
0,
64,
0
],
[
"I",
8,
0,
64,
0
],
[
"I",
9,
0,
64,
0
],
[
"C",
1
],
[
"C",
2
],
[
"C",
3
],
[
"C",
4
],
[
"C",
5
],
[
"C",
6
],
[
"C",
7
],
[
"C",
8
],
[
"C",
9
],
[
"Z"
],
[
"R",
5,
47
],
[
"C",
9
],
[
"I",
7,
236,
26,
0
],
[
"I",
4,
691,
14,
2
],
[
"I",
8,
993,
5,
0
],
[
"I",
3,
45,
8,
0
],
[
"R",
5,
6
],
[
"I",
1,
62,
9,
0
],
[
"I",
1,
745,
62,
0
],
[
"I",
7,
521,
25,
2
],
[
"I",
6,
92,
46,
0
],
[
"L",
10
],
[
"R",
4,
5
],
[
"I",
10,
257,
20,
3
],
[
"I",
9,
35,
40,
0
],
[
"I",
9,
960,
28,
2
],
[
"L",
5
],
[
"L",
2
],
[
"H",
1
],
[
"R",
7,
48
],
[
"H",
4
],
[
"I",
4,
633,
6,
2
],
[
"I",
1,
274,
56,
2
],
[
"I",
3,
579,
56,
1
],
[
"I",
7,
209,
12,
2
],
[
"C",
6
],
[
"C",
4
],
[
"I",
9,
343,
23,
3
],
[
"I",
8,
518,
49,
0
],
[
"I",
1,
274,
24,
0
],
[
"C",
10
],
[
"R",
9,
58
],
[
"I",
9,
251,
27,
1
],
[
"L",
4
],
[
"H",
3
],
[
"I",
8,
567,
23,
1
],
[
"I",
7,
529,
25,
1
],
[
"R",
3,
27
],
[
"H",
7
],
[
"C",
4
],
[
"Z"
],
[
"L",
7
],
[
"H",
7
],
[
"I",
5,
961,
6,
1
],
[
"L",
6
],
[
"C",
3
],
[
"C",
4
],
[
"H",
2
],
[
"I",
9,
310,
7,
1
],
[
"C",
6
],
[
"C",
5
],
[
"I",
3,
484,
2,
0
],
[
"C",
5
],
[
"I",
10,
327,
63,
0
],
[
"C",
9
],
[
"I",
6,
837,
51,
1
],
[
"R",
1,
17
],
[
"R",
1,
13
],
[
"L",
9
],
[
"I",
6,
795,
21,
2
],
[
"R",
3,
26
],
[
"I",
2,
155,
55,
2
],
[
"H",
4
],
[
"I",
2,
666,
51,
3
],
[
"I",
6,
229,
30,
1
],
[
"I",
10,
750,
30,
2
],
[
"H",
4
],
[
"I",
2,
49,
42,
2
],
[
"I",
10,
834,
55,
2
],
[
"H",
3
],
[
"I",
3,
473,
39,
1
],
[
"C",
9
],
[
"I",
3,
32,
19,
2
],
[
"I",
8,
866,
39,
0
],
[
"I",
10,
87,
25,
0
],
[
"C",
1
],
[
"H",
6
],
[
"I",
5,
618,
13,
2
],
[
"R",
5,
45
],
[
"R",
10,
14
],
[
"I",
3,
641,
48,
0
],
[
"Z"
],
[
"L",
6
],
[
"L",
6
],
[
"I",
7,
360,
51,
0
],
[
"L",
5
],
[
"I",
7,
539,
60,
2
],
[
"I",
9,
883,
22,
2
],
[
"H",
8
],
[
"L",
7
],
[
"I",
6,
170,
6,
1
],
[
"I",
8,
825,
21,
3
],
[
"H",
2
],
[
"H",
4
],
[
"L",
10
],
[
"I",
10,
525,
12,
1
],
[
"L",
8
],
[
"R",
7,
24
],
[
"L",
7
],
[
"C",
8
],
[
"I",
4,
796,
26,
3
],
[
"C",
6
],
[
"I",
8,
67,
0,
1
],
[
"I",
8,
567,
25,
0
],
[
"C",
1
],
[
"R",
6,
57
],
[
"I",
8,
714,
53,
3
],
[
"C",
7
],
[
"C",
2
],
[
"L",
6
],
[
"I",
1,
111,
35,
0
],
[
"L",
5
],
[
"I",
3,
271,
18,
0
],
[
"I",
9,
842,
50,
3
],
[
"I",
3,
118,
8,
0
],
[
"H",
5
],
[
"C",
4
],
[
"L",
10
],
[
"I",
7,
160,
36,
1
],
[
"C",
1
],
[
"I",
7,
351,
31,
2
],
[
"I",
10,
794,
27,
3
],
[
"Z"
],
[
"R",
9,
19
],
[
"I",
10,
754,
0,
0
],
[
"C",
7
],
[
"R",
9,
11
],
[
"I",
10,
971,
56,
3
],
[
"I",
8,
942,
55,
1
],
[
"L",
7
],
[
"L",
6
],
[
"I",
6,
732,
21,
3
],
[
"I",
1,
64,
51,
0
],
[
"C",
10
],
[
"L",
2
],
[
"R",
4,
0
],
[
"I",
3,
551,
30,
0
],
[
"I",
10,
758,
32,
0
],
[
"I",
4,
648,
1,
0
],
[
"C",
4
],
[
"R",
3,
26
],
[
"C",
9
],
[
"C",
3
],
[
"R",
6,
37
],
[
"I",
6,
840,
23,
0
],
[
"H",
5
],
[
"L",
4
],
[
"H",
3
],
[
"L",
7
],
[
"C",
9
],
[
"I",
6,
92,
37,
0
],
[
"L",
5
],
[
"C",
10
],
[
"R",
6,
39
],
[
"R",
2,
0
],
[
"I",
1,
109,
51,
3
],
[
"I",
2,
181,
28,
1
],
[
"I",
5,
892,
26,
0
],
[
"H",
8
],
[
"I",
9,
51,
60,
1
],
[
"I",
9,
968,
36,
0
],
[
"R",
1,
46
],
[
"L",
5
],
[
"Z"
],
[
"I",
4,
459,
10,
0
],
[
"I",
8,
204,
61,
2
],
[
"I",
10,
548,
64,
3
],
[
"I",
1,
420,
18,
2
],
[
"I",
10,
425,
59,
0
],
[
"R",
6,
64
],
[
"H",
8
],
[
"L",
6
],
[
"H",
3
],
[
"I",
3,
526,
51,
2
],
[
"I",
6,
409,
52,
1
],
[
"I",
1,
824,
51,
3
],
[
"R",
7,
46
],
[
"L",
5
],
[
"I",
3,
647,
47,
0
],
[
"C",
5
],
[
"I",
3,
661,
40,
0
],
[
"C",
10
],
[
"I",
7,
84,
12,
3
],
[
"I",
1,
831,
13,
1
],
[
"I",
7,
797,
62,
0
],
[
"H",
7
],
[
"H",
6
],
[
"L",
4
],
[
"I",
10,
853,
50,
2
],
[
"I",
4,
575,
26,
0
],
[
"I",
1,
589,
29,
0
],
[
"C",
7
],
[
"R",
4,
54
],
[
"R",
2,
16
],
[
"C",
7
],
[
"R",
3,
30
],
[
"I",
3,
444,
31,
2
],
[
"L",
4
],
[
"I",
9,
794,
43,
2
],
[
"H",
4
],
[
"R",
1,
48
],
[
"C",
4
],
[
"C",
10
],
[
"I",
8,
930,
61,
1
],
[
"Z"
],
[
"C",
5
],
[
"I",
4,
1003,
31,
3
],
[
"L",
1
],
[
"C",
9
],
[
"I",
9,
240,
1,
3
],
[
"I",
6,
151,
65,
0
],
[
"I",
2,
77,
55,
0
],
[
"R",
2,
3
],
[
"I",
9,
590,
6,
0
],
[
"C",
1
]
],
"readonly": {
"command.h": "#ifndef COMMAND_H\n#define COMMAND_H\n#include <stddef.h>\n#include <stdint.h>\n#include <stdio.h>\n#define COMMAND_ARGUMENTS 5u\n#define INPUT_CAPACITY 256u\ntypedef struct {\n char code;\n unsigned count;\n uint32_t argument[COMMAND_ARGUMENTS];\n unsigned line;\n} command_t;\ntypedef struct {\n FILE *stream;\n unsigned line;\n unsigned commands;\n unsigned rejected;\n unsigned exhausted;\n} input_t;\ntypedef struct {\n int status;\n unsigned value;\n unsigned detail;\n} result_t;\ntypedef struct {\n FILE *stream;\n unsigned operation;\n unsigned fields;\n unsigned failures;\n unsigned used;\n char buffer[512];\n} observation_t;\nvoid input_init(input_t *input, FILE *stream);\nint input_next(input_t *input, command_t *command);\nint command_arity(char code);\nint parse_uint32(const char *start, const char **end, uint32_t *value);\nunsigned byte_pattern(unsigned seed, unsigned index);\nunsigned checksum_bytes(const unsigned char *data, unsigned length);\nint range_valid(unsigned offset, unsigned length, unsigned capacity);\nvoid observation_init(observation_t *observation, FILE *stream);\nvoid observation_begin(observation_t *observation, unsigned operation,\n const result_t *result);\nvoid observation_unsigned(observation_t *observation, unsigned value);\nvoid observation_bytes(observation_t *observation, const unsigned char *bytes,\n unsigned length);\nvoid observation_array(observation_t *observation, const unsigned *values,\n unsigned length);\nvoid observation_end(observation_t *observation);\nint observation_status(const observation_t *observation);\n#endif\n",
"input.c": "#include \"command.h\"\n#include <ctype.h>\n#include <limits.h>\n#include <string.h>\n\nvoid input_init(input_t *input, FILE *stream)\n{\n input->stream = stream;\n input->line = 0u;\n input->commands = 0u;\n input->rejected = 0u;\n input->exhausted = 0u;\n}\n\nint parse_uint32(const char *start, const char **end, uint32_t *value)\n{\n uint32_t accumulated = 0u;\n unsigned digits = 0u;\n const char *cursor = start;\n while (*cursor >= '0' && *cursor <= '9') {\n unsigned digit = (unsigned)(*cursor - '0');\n if (accumulated > (UINT32_MAX - digit) / 10u) {\n return 0;\n }\n accumulated = accumulated * 10u + digit;\n cursor++;\n digits++;\n }\n if (digits == 0u) {\n return 0;\n }\n *value = accumulated;\n *end = cursor;\n return 1;\n}\n\nstatic const char *skip_space(const char *cursor)\n{\n while (*cursor != '\\0' && isspace((unsigned char)*cursor)) {\n cursor++;\n }\n return cursor;\n}\n\nstatic int read_line(input_t *input, char *buffer, unsigned capacity)\n{\n unsigned length = 0u;\n unsigned overflow = 0u;\n unsigned binary = 0u;\n unsigned saw_byte = 0u;\n int byte;\n if (capacity < 2u) {\n return -1;\n }\n for (;;) {\n byte = fgetc(input->stream);\n if (byte == EOF) {\n if (ferror(input->stream)) {\n return -1;\n }\n if (!saw_byte) {\n return 0;\n }\n break;\n }\n saw_byte = 1u;\n if (byte == '\\n') {\n break;\n }\n if (byte == 0) {\n binary = 1u;\n continue;\n }\n if (length + 1u >= capacity) {\n overflow = 1u;\n continue;\n }\n buffer[length] = (char)byte;\n length++;\n }\n input->line++;\n if (length != 0u && buffer[length - 1u] == '\\r') {\n length--;\n }\n buffer[length] = '\\0';\n if (overflow || binary) {\n return -1;\n }\n return 1;\n}\n\nstatic int decode_line(input_t *input, const char *buffer, command_t *command)\n{\n const char *cursor = skip_space(buffer);\n int expected;\n unsigned index;\n if (*cursor == '\\0' || *cursor == '#') {\n return 0;\n }\n command->code = *cursor;\n command->count = 0u;\n command->line = input->line;\n cursor++;\n if (*cursor != '\\0' && !isspace((unsigned char)*cursor)) {\n return -1;\n }\n expected = command_arity(command->code);\n if (expected < 0 || (unsigned)expected > COMMAND_ARGUMENTS) {\n return -1;\n }\n for (index = 0u; index < COMMAND_ARGUMENTS; index++) {\n command->argument[index] = 0u;\n }\n for (index = 0u; index < (unsigned)expected; index++) {\n const char *end;\n uint32_t value;\n cursor = skip_space(cursor);\n if (!parse_uint32(cursor, &end, &value)) {\n return -1;\n }\n if (*end != '\\0' && *end != '#' && !isspace((unsigned char)*end)) {\n return -1;\n }\n command->argument[index] = value;\n command->count++;\n cursor = end;\n }\n cursor = skip_space(cursor);\n if (*cursor != '\\0' && *cursor != '#') {\n return -1;\n }\n return 1;\n}\n\nint input_next(input_t *input, command_t *command)\n{\n char buffer[INPUT_CAPACITY];\n if (input->exhausted) {\n return 0;\n }\n for (;;) {\n int decoded;\n int available = read_line(input, buffer, sizeof(buffer));\n if (available == 0) {\n input->exhausted = 1u;\n return 0;\n }\n if (available < 0) {\n input->rejected++;\n return -1;\n }\n decoded = decode_line(input, buffer, command);\n if (decoded < 0) {\n input->rejected++;\n return -1;\n }\n if (decoded > 0) {\n input->commands++;\n return 1;\n }\n }\n}\n\nunsigned byte_pattern(unsigned seed, unsigned index)\n{\n return (seed + index) & 255u;\n}\n\nunsigned checksum_bytes(const unsigned char *data, unsigned length)\n{\n unsigned index;\n unsigned result = 0u;\n for (index = 0u; index < length; index++) {\n result = (result + (index + 1u) * data[index]) % 65521u;\n }\n return result;\n}\n\nint range_valid(unsigned offset, unsigned length, unsigned capacity)\n{\n if (offset > capacity) {\n return 0;\n }\n if (length > capacity - offset) {\n return 0;\n }\n return length != 0u;\n}\n",
"observation.c": "#include \"command.h\"\n#include <limits.h>\n\nstatic int observation_flush(observation_t *observation)\n{\n size_t offset = 0u;\n if (observation->failures != 0u) {\n observation->used = 0u;\n return 0;\n }\n while (offset < observation->used) {\n size_t remaining = (size_t)observation->used - offset;\n size_t written = fwrite(observation->buffer + offset, 1u,\n remaining, observation->stream);\n if (written == 0u) {\n observation->failures++;\n observation->used = 0u;\n return 0;\n }\n offset += written;\n }\n observation->used = 0u;\n return 1;\n}\n\nstatic int observation_character(observation_t *observation, char byte)\n{\n if (observation->failures != 0u) {\n return 0;\n }\n if (observation->used == sizeof(observation->buffer)) {\n if (!observation_flush(observation)) {\n return 0;\n }\n }\n observation->buffer[observation->used] = byte;\n observation->used++;\n return 1;\n}\n\nstatic int observation_number(observation_t *observation, unsigned value)\n{\n char reversed[sizeof(unsigned) * CHAR_BIT];\n unsigned count = 0u;\n do {\n unsigned digit = value % 10u;\n reversed[count] = (char)('0' + digit);\n count++;\n value /= 10u;\n } while (value != 0u);\n while (count > 0u) {\n count--;\n if (!observation_character(observation, reversed[count])) {\n return 0;\n }\n }\n return 1;\n}\n\nstatic void observation_signed(observation_t *observation, int value)\n{\n unsigned magnitude;\n if (value < 0) {\n observation_character(observation, '-');\n magnitude = 0u - (unsigned)value;\n } else {\n magnitude = (unsigned)value;\n }\n observation_number(observation, magnitude);\n}\n\nstatic void observation_separator(observation_t *observation)\n{\n observation_character(observation, ' ');\n}\n\nvoid observation_init(observation_t *observation, FILE *stream)\n{\n observation->stream = stream;\n observation->operation = 0u;\n observation->fields = 0u;\n observation->failures = 0u;\n observation->used = 0u;\n}\n\nvoid observation_begin(observation_t *observation, unsigned operation,\n const result_t *result)\n{\n observation->operation = operation;\n observation->fields = 0u;\n observation_character(observation, 'O');\n observation_separator(observation);\n observation_number(observation, operation);\n observation_separator(observation);\n observation_signed(observation, result->status);\n observation_separator(observation);\n observation_number(observation, result->value);\n observation_separator(observation);\n observation_number(observation, result->detail);\n}\n\nvoid observation_unsigned(observation_t *observation, unsigned value)\n{\n observation_separator(observation);\n observation_number(observation, value);\n observation->fields++;\n}\n\nvoid observation_bytes(observation_t *observation, const unsigned char *bytes,\n unsigned length)\n{\n unsigned index;\n for (index = 0u; index < length; index++) {\n observation_unsigned(observation, (unsigned)bytes[index]);\n }\n}\n\nvoid observation_array(observation_t *observation, const unsigned *values,\n unsigned length)\n{\n unsigned index;\n for (index = 0u; index < length; index++) {\n observation_unsigned(observation, values[index]);\n }\n}\n\nvoid observation_end(observation_t *observation)\n{\n observation_character(observation, '\\n');\n observation_flush(observation);\n}\n\nint observation_status(const observation_t *observation)\n{\n if (observation->failures != 0u) {\n return 1;\n }\n if (observation->used != 0u) {\n return 1;\n }\n return ferror(observation->stream) ? 1 : 0;\n}\n",
"harness.c": "#include \"model.h\"\n#include <stdio.h>\n\nstatic void empty_result(result_t *result)\n{\n result->status = 0;\n result->value = 0u;\n result->detail = 0u;\n}\n\nint main(void)\n{\n state_t state;\n input_t input;\n command_t command;\n observation_t observation;\n unsigned operation = 0u;\n int available;\n input_init(&input, stdin);\n observation_init(&observation, stdout);\n model_init(&state);\n for (;;) {\n result_t result;\n available = input_next(&input, &command);\n if (available == 0) {\n break;\n }\n if (available < 0) {\n fprintf(stderr, \"invalid command on line %u\\n\", input.line);\n return 2;\n }\n operation++;\n empty_result(&result);\n model_apply(&state, &command, &result);\n observation_begin(&observation, operation, &result);\n model_observe(&state, &observation);\n observation_end(&observation);\n }\n if (fflush(stdout) != 0) {\n return 3;\n }\n return observation_status(&observation) ? 3 : 0;\n}\n",
"model.h": "#ifndef MODEL_H\n#define MODEL_H\n#include \"command.h\"\n#define MAP_SLOTS 8u\n#define PAGE_BYTES 16u\ntypedef struct {\n unsigned id;\n unsigned used;\n unsigned file_offset;\n unsigned length;\n unsigned mapped_length;\n unsigned displacement;\n unsigned owner;\n unsigned leases;\n unsigned fd;\n unsigned map;\n} mapping_t;\ntypedef struct {\n mapping_t mappings[MAP_SLOTS];\n unsigned descriptors;\n unsigned pages;\n unsigned opened;\n unsigned closed;\n unsigned mapped;\n unsigned unmapped;\n unsigned rejected;\n unsigned next_handle;\n} state_t;\nint mapping_find(const state_t *state, unsigned id);\nint mapping_empty(const state_t *state);\nunsigned resource_open(state_t *state);\nunsigned resource_map(state_t *state, unsigned pages);\nvoid resource_close(state_t *state, mapping_t *mapping);\nvoid resource_unmap(state_t *state, mapping_t *mapping);\nvoid mapping_retire(state_t *state, unsigned index);\nvoid mapping_probe_failed(state_t *state, unsigned index);\nvoid mapping_owner_close(state_t *state, unsigned index);\nvoid model_init(state_t *state);\nvoid model_apply(state_t *state, const command_t *command, result_t *result);\nvoid model_observe(const state_t *state, observation_t *observation);\n#endif\n",
"layout.c": "#include \"model.h\"\nint command_arity(char code)\n{\n switch (code) {\n case 'Z': return 0;\n case 'I': return 4;\n case 'H': return 1;\n case 'C': return 1;\n case 'L': return 1;\n case 'R': return 2;\n default: return -1;\n }\n}\nvoid model_observe(const state_t *state, observation_t *observation)\n{\n unsigned index;\n observation_unsigned(observation, state->descriptors);\n observation_unsigned(observation, state->pages);\n observation_unsigned(observation, state->opened);\n observation_unsigned(observation, state->closed);\n observation_unsigned(observation, state->mapped);\n observation_unsigned(observation, state->unmapped);\n observation_unsigned(observation, state->rejected);\n observation_unsigned(observation, state->next_handle);\n for (index = 0u; index < MAP_SLOTS; index++) {\n const mapping_t *mapping = &state->mappings[index];\n observation_unsigned(observation, mapping->id);\n observation_unsigned(observation, mapping->used);\n observation_unsigned(observation, mapping->file_offset);\n observation_unsigned(observation, mapping->length);\n observation_unsigned(observation, mapping->mapped_length);\n observation_unsigned(observation, mapping->displacement);\n observation_unsigned(observation, mapping->owner);\n observation_unsigned(observation, mapping->leases);\n observation_unsigned(observation, mapping->fd);\n observation_unsigned(observation, mapping->map);\n }\n}\n",
"Makefile": "CC = gcc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -Werror -pedantic\nSOURCES = harness.c input.c observation.c layout.c model.c policy.c\nmemory-demo: $(SOURCES) command.h model.h\n\t$(CC) $(CFLAGS) $(SOURCES) -o $@\n.PHONY: clean\nclean:\n\trm -f memory-demo\n"
},
"candidate_files": [
"model.c",
"policy.c"
]
}