forked from parallella/pal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_load.c
49 lines (39 loc) · 1.13 KB
/
p_load.c
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
#include <pal.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "pal_base.h"
#include "pal_base_private.h"
/**
*
* Loads a program from a file into an object in memory and prepares the program
* for execution.
*
* @param dev Pointer to object containing device information
* @param file File name of executable to load.
* @param function Name of function within 'prog' to run
* @param flags Optional flags
*
* @return Returns a reference. Negative value indicates error.
*
*/
p_prog_t p_load(p_dev_t dev, const char *file, const char *function, int flags)
{
size_t len;
struct prog *prog;
if (p_ref_is_err(dev))
return p_ref_err(EINVAL);
prog = malloc(sizeof(*prog));
if (!prog)
return p_ref_err(ENOMEM);
len = strnlen(file, 4096);
if (len == 4096)
return p_ref_err(ENAMETOOLONG);
prog->path = strndup(file, len);;
if (!prog->path)
return p_ref_err(ENOMEM);
strncpy(prog->path, file, len+1);
return prog;
// TODO: Load into memory etc.
// TODO: Add to global prog table. We're leaking memory here people.
}