execve():

- COKERNEL_PATH and COKERNEL_EXEC_ROOT support for co-kernels with different architecture than the host (i.e., Xeon Phi).
- fix various error codes: ENAMETOOLONG, ENOENT, ENOTDIR, EACCES, ENOEXEC, EFAULT.
- support for shell code execution.
This commit is contained in:
Balazs Gerofi bgerofi@riken.jp
2014-09-03 18:15:43 +09:00
parent 308987c1ee
commit cd366de097
6 changed files with 224 additions and 92 deletions

View File

@@ -28,6 +28,6 @@ int memcmp(const void *s1, const void *s2, size_t n);
void *memset(void *s, int n, size_t l);
unsigned long strtol(const char *cp, char **endp, unsigned int base);
int flatten_strings(int nr_strings, char **strings, char **flat);
int flatten_strings(int nr_strings, char *first, char **strings, char **flat);
#endif

View File

@@ -181,7 +181,7 @@ int memcmp(const void *s1, const void *s2, size_t n)
* returns the total length of the flat string and updates flat to
* point to the beginning.
*/
int flatten_strings(int nr_strings, char **strings, char **flat)
int flatten_strings(int nr_strings, char *first, char **strings, char **flat)
{
int full_len, string_i;
unsigned long flat_offset;
@@ -194,6 +194,10 @@ int flatten_strings(int nr_strings, char **strings, char **flat)
/* Count full length */
full_len = sizeof(int) + sizeof(char *); // Counter and terminating NULL
if (first) {
full_len += sizeof(char *) + strlen(first) + 1;
}
for (string_i = 0; string_i < nr_strings; ++string_i) {
// Pointer + actual value
full_len += sizeof(char *) + strlen(strings[string_i]) + 1;
@@ -207,18 +211,25 @@ int flatten_strings(int nr_strings, char **strings, char **flat)
memset(_flat, 0, full_len);
/* Number of strings */
*((int*)_flat) = nr_strings;
*((int*)_flat) = nr_strings + (first ? 1 : 0);
// Actual offset
flat_offset = sizeof(int) + sizeof(char *) * (nr_strings + 1);
flat_offset = sizeof(int) + sizeof(char *) * (nr_strings + 1 +
(first ? 1 : 0));
if (first) {
*((char **)(_flat + sizeof(int))) = (void *)flat_offset;
memcpy(_flat + flat_offset, first, strlen(first) + 1);
flat_offset += strlen(first) + 1;
}
for (string_i = 0; string_i < nr_strings; ++string_i) {
/* Fabricate the string */
*((char **)(_flat + sizeof(int) + string_i * sizeof(char *))) = (void *)flat_offset;
*((char **)(_flat + sizeof(int) + (string_i + (first ? 1 : 0))
* sizeof(char *))) = (void *)flat_offset;
memcpy(_flat + flat_offset, strings[string_i], strlen(strings[string_i]) + 1);
flat_offset += strlen(strings[string_i]) + 1;
}
*flat = _flat;