diff --git a/runtime/Makefile b/runtime/Makefile index c589752..63b95c3 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -150,6 +150,7 @@ fetch: @git config --global --add safe.directory /sledge/runtime/tests/speechtotext/thirdparty/sphinxbase @git config --global --add safe.directory /sledge/runtime/thirdparty/http-parser @git config --global --add safe.directory /sledge/runtime/thirdparty/jsmn + @git config --global --add safe.directory /sledge/runtime/thirdparty/hashmap @git config --global --add safe.directory /sledge/runtime/tests/C-Image-Manip @git submodule update --init --recursive diff --git a/runtime/include/map.h b/runtime/include/map.h index 61574b3..89fa83a 100644 --- a/runtime/include/map.h +++ b/runtime/include/map.h @@ -16,7 +16,7 @@ struct map_node { struct map_node *next; - void *key; + char *key; void *value; uint32_t key_len; uint32_t value_len; @@ -44,13 +44,12 @@ map_init(struct hashmap *restrict map) /* See https://en.wikipedia.org/wiki/Jenkins_hash_function */ static inline uint32_t -jenkins_hash(void *key, uint32_t key_len) +jenkins_hash(char *key, uint32_t key_len) { uint32_t i = 0; uint32_t hash = 0; - unsigned char *data = (unsigned char *)key; while (i != key_len) { - hash += data[i++]; + hash += key[i++]; hash += hash << 10; hash ^= hash >> 6; } @@ -61,7 +60,7 @@ jenkins_hash(void *key, uint32_t key_len) } static inline void * -map_get(struct hashmap *map, void *key, uint32_t key_len, uint32_t *ret_value_len) +map_get(struct hashmap *map, char *key, uint32_t key_len, uint32_t *ret_value_len) { void *value = NULL; @@ -86,7 +85,7 @@ DONE: } static inline bool -map_set(struct hashmap *map, void *key, uint32_t key_len, void *value, uint32_t value_len, bool manage_mvalue) +map_set(struct hashmap *map, char *key, uint32_t key_len, void *value, uint32_t value_len, bool manage_mvalue) { bool did_set = false; @@ -127,7 +126,7 @@ DONE: * @returns boolean if node was deleted or not */ static inline bool -map_delete(struct hashmap *map, void *key, uint32_t key_len) +map_delete(struct hashmap *map, char *key, uint32_t key_len) { bool did_delete = false; @@ -164,7 +163,7 @@ DONE: } static inline void -map_upsert(struct hashmap *map, void *key, uint32_t key_len, void *value, uint32_t value_len) +map_upsert(struct hashmap *map, char *key, uint32_t key_len, void *value, uint32_t value_len) { uint32_t hash = MAP_HASH(key, key_len); struct map_bucket *bucket = &map->buckets[hash % MAP_BUCKET_COUNT]; diff --git a/runtime/src/current_sandbox.c b/runtime/src/current_sandbox.c index ab30eb2..df7de09 100644 --- a/runtime/src/current_sandbox.c +++ b/runtime/src/current_sandbox.c @@ -245,7 +245,7 @@ current_sandbox_start(void) map_set(sandbox_req_map, cur_request_id, strlen(cur_request_id), sandbox_request, sizeof(struct sandbox_request *), false); }else { - uint32_t rest_pre_count =*requet_id; + uint32_t rest_pre_count = *requet_id; assert(rest_pre_count >= 1); struct sandbox_request *sandbox_request = map_get(sandbox_req_map, cur_request_id, strlen(cur_request_id), &ret_value_len); @@ -263,18 +263,19 @@ current_sandbox_start(void) uint64_t enqueue_timestamp = __getcycles(); const char *previous_output = sandbox_request->previous_function_output ? sandbox_request->previous_function_output : ""; - int new_output_length = strlen(previous_output) + output_length + 1; + ssize_t new_output_length = sandbox_request->output_length + output_length + 2; char *new_output = (char *)malloc(new_output_length); if (!new_output) { fprintf(stderr, "Failed to allocate memory for the new output: %s\n", strerror(errno)); free(pre_func_output); goto err; } - snprintf(new_output, new_output_length, "%s+%s", previous_output, pre_func_output); + snprintf(new_output, new_output_length, "%s&%s", previous_output, pre_func_output); free(sandbox_request->previous_function_output); + sandbox_request->previous_function_output = NULL; sandbox_request->previous_function_output = new_output; free(pre_func_output); - sandbox_request->output_length +=output_length; + sandbox_request->output_length = new_output_length; rest_pre_count --; if (rest_pre_count != 0) diff --git a/runtime/src/memlogging.c b/runtime/src/memlogging.c index 2c3e7b7..45da59d 100644 --- a/runtime/src/memlogging.c +++ b/runtime/src/memlogging.c @@ -93,6 +93,7 @@ mem_log(char const * fmt, ...) } else { /* Write Success */ log_obj.offset += n; +// dump_log_to_file(log_obj); } } diff --git a/runtime/tests/fibonacciadd/main b/runtime/tests/fibonacciadd/main new file mode 100755 index 0000000..a5f9aeb Binary files /dev/null and b/runtime/tests/fibonacciadd/main differ diff --git a/runtime/tests/fibonacciadd/main.c b/runtime/tests/fibonacciadd/main.c index 94dc880..98f3ae2 100644 --- a/runtime/tests/fibonacciadd/main.c +++ b/runtime/tests/fibonacciadd/main.c @@ -1,8 +1,9 @@ +#include #include -#include #include -#include +#include +// 假设的 Fibonacci 函数实现 unsigned long int fib(unsigned long int n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); @@ -17,28 +18,29 @@ int main() { perror("Error reading input"); return 1; } - buffer[bytes_read] = '\0'; // Null-terminate the string + buffer[bytes_read] = '\0'; - // Variables to store the two numbers unsigned long int num1, num2; - // Split the input into two parts based on newline and parse them - char *line = strtok(buffer, "+"); - if (line != NULL && sscanf(line, "%lu", &num1) == 1) { - line = strtok(NULL, "\n"); - if (line != NULL && sscanf(line, "%lu", &num2) == 1) { - // Calculate Fibonacci numbers and their sum - unsigned long int fib1 = fib(num1); - unsigned long int fib2 = fib(num2); - unsigned long int sum = fib1 + fib2; - - printf("Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum); - } else { - printf("Invalid input. Please enter two numbers on separate lines.\n"); - return 1; - } + char *line = strtok(buffer, "&"); + char *second_part = strtok(NULL, "\0"); // Assume the rest of the string is the second number + + if (line && sscanf(line, "%lu", &num1) == 1 && + second_part && sscanf(second_part, "%lu", &num2) == 1) { + // Calculate Fibonacci numbers and their sum + unsigned long int fib1 = fib(num1); + unsigned long int fib2 = fib(num2); + unsigned long int sum = fib1 + fib2; + + // Prepare output string + char output[1024]; + int len = snprintf(output, sizeof(output), "Fibonacci(%lu) + Fibonacci(%lu) = %lu + %lu = %lu\n", num1, num2, fib1, fib2, sum); + + // Write to stdout + write(1, output, len); } else { - printf("Invalid input. Please enter two numbers on separate lines.\n"); + const char *error_msg = "Invalid input. Please enter two numbers separated by .\n"; + write(1, error_msg, strlen(error_msg)); return 1; } diff --git a/runtime/tests/fibonacciadd/test b/runtime/tests/fibonacciadd/test deleted file mode 100755 index 45f4126..0000000 Binary files a/runtime/tests/fibonacciadd/test and /dev/null differ