aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils/lua/patches/020-shared_liblua.patch
blob: f67ee2b3c7f3085107dc113459f63f854ffe7583 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
--- a/Makefile
+++ b/Makefile
@@ -42,8 +42,8 @@ PLATS= aix ansi bsd freebsd generic linu
 
 # What to install.
 TO_BIN= lua$V luac$V
-TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
-TO_LIB= liblua.a
+TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp lnum_config.h
+TO_LIB= liblua.a liblua.so.$R
 TO_MAN= lua$V.1 luac$V.1
 
 # Lua version and release.
@@ -63,6 +63,7 @@ install: dummy
 	cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
 	cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
 	cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
+	ln -s liblua.so.$R $(INSTALL_LIB)/liblua.so
 	cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
 
 ranlib:
--- a/src/ldo.h
+++ b/src/ldo.h
@@ -46,7 +46,7 @@ LUAI_FUNC int luaD_pcall (lua_State *L,
 LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult);
 LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize);
 LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize);
-LUAI_FUNC void luaD_growstack (lua_State *L, int n);
+LUA_API void luaD_growstack (lua_State *L, int n);
 
 LUAI_FUNC void luaD_throw (lua_State *L, int errcode);
 LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
--- a/src/lfunc.h
+++ b/src/lfunc.h
@@ -18,7 +18,7 @@
                          cast(int, sizeof(TValue *)*((n)-1)))
 
 
-LUAI_FUNC Proto *luaF_newproto (lua_State *L);
+LUA_API Proto *luaF_newproto (lua_State *L);
 LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
 LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
 LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
--- a/src/lmem.h
+++ b/src/lmem.h
@@ -38,9 +38,9 @@
    ((v)=cast(t *, luaM_reallocv(L, v, oldn, n, sizeof(t))))
 
 
-LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
+LUA_API void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize,
                                                           size_t size);
-LUAI_FUNC void *luaM_toobig (lua_State *L);
+LUA_API void *luaM_toobig (lua_State *L);
 LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int *size,
                                size_t size_elem, int limit,
                                const char *errormsg);
--- a/src/lstring.h
+++ b/src/lstring.h
@@ -25,7 +25,7 @@
 
 LUAI_FUNC void luaS_resize (lua_State *L, int newsize);
 LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
-LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
+LUA_API TString *luaS_newlstr (lua_State *L, const char *str, size_t l);
 
 
 #endif
--- a/src/lundump.h
+++ b/src/lundump.h
@@ -17,7 +17,7 @@ LUAI_FUNC Proto* luaU_undump (lua_State*
 LUAI_FUNC void luaU_header (char* h);
 
 /* dump one chunk; from ldump.c */
-LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
+LUA_API int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
 
 #ifdef luac_c
 /* print one chunk; from print.c */
--- a/src/Makefile
+++ b/src/Makefile
@@ -23,6 +23,7 @@ MYLIBS=
 PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
 
 LUA_A=	liblua.a
+LUA_SO= liblua.so
 CORE_O=	lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
 	lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o  \
 	lundump.o lvm.o lzio.o lnum.o
@@ -33,11 +34,12 @@ LUA_T=	lua$V
 LUA_O=	lua.o
 
 LUAC_T=	luac$V
-LUAC_O=	luac.o print.o
+LUAC_O=	luac.o print.o lopcodes.o
 
 ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+ALL_T= $(LUA_A) $(LUA_SO) $(LUA_T) $(LUAC_T)
 ALL_A= $(LUA_A)
+ALL_SO= $(LUA_SO)
 
 default: $(PLAT)
 
@@ -47,14 +49,23 @@ o:	$(ALL_O)
 
 a:	$(ALL_A)
 
+so:	$(ALL_SO)
+
 $(LUA_A): $(CORE_O) $(LIB_O)
 	$(AR) $@ $(CORE_O) $(LIB_O)	# DLL needs all object files
 	$(RANLIB) $@
 
-$(LUA_T): $(LUA_O) $(LUA_A)
-	$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
+$(LUA_SO): $(CORE_O) $(LIB_O)
+	$(CC) -o $@.$(PKG_VERSION) -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
+	ln -fs $@.$(PKG_VERSION) $@
+
+$(LUA_T): $(LUA_O) $(LUA_SO)
+	$(CC) -o $@ -L. -llua $(MYLDFLAGS) $(LUA_O) $(LIBS)
+
+$(LUAC_T): $(LUAC_O) $(LUA_SO)
+	$(CC) -o $@ -L. -llua $(MYLDFLAGS) $(LUAC_O) $(LIBS)
 
-$(LUAC_T): $(LUAC_O) $(LUA_A)
+$(LUAC_T)-host: $(LUAC_O) $(LUA_A)
 	$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
 
 clean:
@@ -96,7 +107,7 @@ generic:
 	$(MAKE) all MYCFLAGS=
 
 linux:
-	$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
+	$(MAKE) all MYCFLAGS+=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
 
 macosx:
 	$(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
ervisor.h> #include <events.h> #include <os.h> #include <lib.h> #include <xenbus.h> #include <xen/io/console.h> #include <xen/io/protocols.h> #include <xen/io/ring.h> #include <xmalloc.h> #include <gnttab.h> DECLARE_WAIT_QUEUE_HEAD(console_queue); static inline void notify_daemon(struct consfront_dev *dev) { /* Use evtchn: this is called early, before irq is set up. */ if (!dev) notify_remote_via_evtchn(start_info.console.domU.evtchn); else notify_remote_via_evtchn(dev->evtchn); } static inline struct xencons_interface *xencons_interface(void) { return mfn_to_virt(start_info.console.domU.mfn); } int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len) { int sent = 0; struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; if (!dev) intf = xencons_interface(); else intf = dev->ring; cons = intf->out_cons; prod = intf->out_prod; mb(); BUG_ON((prod - cons) > sizeof(intf->out)); while ((sent < len) && ((prod - cons) < sizeof(intf->out))) intf->out[MASK_XENCONS_IDX(prod++, intf->out)] = data[sent++]; wmb(); intf->out_prod = prod; return sent; } int xencons_ring_send(struct consfront_dev *dev, const char *data, unsigned len) { int sent; sent = xencons_ring_send_no_notify(dev, data, len); notify_daemon(dev); return sent; } static void handle_input(evtchn_port_t port, struct pt_regs *regs, void *data) { #ifdef HAVE_LIBC struct consfront_dev *dev = (struct consfront_dev *) data; int fd = dev ? dev->fd : -1; if (fd != -1) files[fd].read = 1; wake_up(&console_queue); #else struct xencons_interface *intf = xencons_interface(); XENCONS_RING_IDX cons, prod; cons = intf->in_cons; prod = intf->in_prod; mb(); BUG_ON((prod - cons) > sizeof(intf->in)); while (cons != prod) { xencons_rx(intf->in+MASK_XENCONS_IDX(cons,intf->in), 1, regs); cons++; } mb(); intf->in_cons = cons; notify_daemon(dev); xencons_tx(); #endif } #ifdef HAVE_LIBC int xencons_ring_avail(struct consfront_dev *dev) { struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; if (!dev) intf = xencons_interface(); else intf = dev->ring; cons = intf->in_cons; prod = intf->in_prod; mb(); BUG_ON((prod - cons) > sizeof(intf->in)); return prod - cons; } int xencons_ring_recv(struct consfront_dev *dev, char *data, unsigned len) { struct xencons_interface *intf; XENCONS_RING_IDX cons, prod; unsigned filled = 0; if (!dev) intf = xencons_interface(); else intf = dev->ring; cons = intf->in_cons; prod = intf->in_prod; mb(); BUG_ON((prod - cons) > sizeof(intf->in)); while (filled < len && cons + filled != prod) { data[filled] = *(intf->in + MASK_XENCONS_IDX(cons + filled, intf->in)); filled++; } mb(); intf->in_cons = cons + filled; notify_daemon(dev); return filled; } #endif struct consfront_dev *xencons_ring_init(void) { int err; struct consfront_dev *dev; if (!start_info.console.domU.evtchn) return 0; dev = malloc(sizeof(struct consfront_dev)); memset(dev, 0, sizeof(struct consfront_dev)); dev->nodename = "device/console"; dev->dom = 0; dev->backend = 0; dev->ring_ref = 0; #ifdef HAVE_LIBC dev->fd = -1; #endif dev->evtchn = start_info.console.domU.evtchn; dev->ring = (struct xencons_interface *) mfn_to_virt(start_info.console.domU.mfn); err = bind_evtchn(dev->evtchn, handle_input, dev); if (err <= 0) { printk("XEN console request chn bind failed %i\n", err); free(dev); return NULL; } unmask_evtchn(dev->evtchn); /* In case we have in-flight data after save/restore... */ notify_daemon(dev); return dev; } void free_consfront(struct consfront_dev *dev) { mask_evtchn(dev->evtchn); free(dev->backend); gnttab_end_access(dev->ring_ref); free_page(dev->ring); unbind_evtchn(dev->evtchn); free(dev->nodename); free(dev); } struct consfront_dev *init_consfront(char *_nodename) { xenbus_transaction_t xbt; char* err; char* message=NULL; int retry=0; char* msg; char nodename[256]; char path[256]; static int consfrontends = 1; struct consfront_dev *dev; int res; if (!_nodename) snprintf(nodename, sizeof(nodename), "device/console/%d", consfrontends); else strncpy(nodename, _nodename, sizeof(nodename)); printk("******************* CONSFRONT for %s **********\n\n\n", nodename); consfrontends++; dev = malloc(sizeof(*dev)); memset(dev, 0, sizeof(*dev)); dev->nodename = strdup(nodename); #ifdef HAVE_LIBC dev->fd = -1; #endif snprintf(path, sizeof(path), "%s/backend-id", nodename); if ((res = xenbus_read_integer(path)) < 0) return NULL; else dev->dom = res; evtchn_alloc_unbound(dev->dom, handle_input, dev, &dev->evtchn); dev->ring = (struct xencons_interface *) alloc_page(); memset(dev->ring, 0, PAGE_SIZE); dev->ring_ref = gnttab_grant_access(dev->dom, virt_to_mfn(dev->ring), 0); dev->events = NULL; again: err = xenbus_transaction_start(&xbt); if (err) { printk("starting transaction\n"); } err = xenbus_printf(xbt, nodename, "ring-ref","%u", dev->ring_ref); if (err) { message = "writing ring-ref"; goto abort_transaction; } err = xenbus_printf(xbt, nodename, "port", "%u", dev->evtchn); if (err) { message = "writing event-channel"; goto abort_transaction; } err = xenbus_printf(xbt, nodename, "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE); if (err) { message = "writing protocol"; goto abort_transaction; } err = xenbus_printf(xbt, nodename, "type", "%s", "ioemu"); if (err) { message = "writing type"; goto abort_transaction; } snprintf(path, sizeof(path), "%s/state", nodename); err = xenbus_switch_state(xbt, path, XenbusStateConnected); if (err) { message = "switching state"; goto abort_transaction; } err = xenbus_transaction_end(xbt, 0, &retry); if (retry) { goto again; printk("completing transaction\n"); } goto done; abort_transaction: xenbus_transaction_end(xbt, 1, &retry); goto error; done: snprintf(path, sizeof(path), "%s/backend", nodename); msg = xenbus_read(XBT_NIL, path, &dev->backend); if (msg) { printk("Error %s when reading the backend path %s\n", msg, path); goto error; } printk("backend at %s\n", dev->backend); { XenbusState state; char path[strlen(dev->backend) + 1 + 19 + 1]; snprintf(path, sizeof(path), "%s/state", dev->backend); xenbus_watch_path_token(XBT_NIL, path, path, &dev->events); msg = NULL; state = xenbus_read_integer(path); while (msg == NULL && state < XenbusStateConnected) msg = xenbus_wait_for_state_change(path, &state, &dev->events); if (msg != NULL || state != XenbusStateConnected) { printk("backend not available, state=%d\n", state); xenbus_unwatch_path(XBT_NIL, path); goto error; } } unmask_evtchn(dev->evtchn); printk("**************************\n"); return dev; error: free_consfront(dev); return NULL; } void xencons_resume(void) { (void)xencons_ring_init(); }